From 7f54cf26511b2716d35e2f2198bbff9da5a33123 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Fri, 31 Jul 2020 12:58:37 +0100 Subject: [PATCH 01/12] compiletest: ignore-endian-big, fixes #74829, fixes #74885 --- .../mir-opt/const-promotion-extern-static.rs | 2 +- src/test/mir-opt/const_allocation.rs | 2 +- src/test/mir-opt/const_allocation2.rs | 2 +- src/test/mir-opt/const_allocation3.rs | 2 +- .../mir-opt/inline/inline-into-box-place.rs | 2 +- .../ui/simd/simd-intrinsic-generic-bitmask.rs | 1 + .../ui/simd/simd-intrinsic-generic-select.rs | 5 +---- src/tools/compiletest/src/header.rs | 1 + src/tools/compiletest/src/util.rs | 20 +++++++++++++++++++ 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/test/mir-opt/const-promotion-extern-static.rs b/src/test/mir-opt/const-promotion-extern-static.rs index e63309a9bd2ad..9c30e0400312a 100644 --- a/src/test/mir-opt/const-promotion-extern-static.rs +++ b/src/test/mir-opt/const-promotion-extern-static.rs @@ -1,7 +1,7 @@ +// ignore-endian-big extern "C" { static X: i32; } - static Y: i32 = 42; // EMIT_MIR const_promotion_extern_static.BAR.PromoteTemps.diff diff --git a/src/test/mir-opt/const_allocation.rs b/src/test/mir-opt/const_allocation.rs index bb1c48e8e3c81..b0fcb86fcee0f 100644 --- a/src/test/mir-opt/const_allocation.rs +++ b/src/test/mir-opt/const_allocation.rs @@ -1,5 +1,5 @@ +// ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH - static FOO: &[(Option, &[&str])] = &[(None, &[]), (None, &["foo", "bar"]), (Some(42), &["meh", "mop", "möp"])]; diff --git a/src/test/mir-opt/const_allocation2.rs b/src/test/mir-opt/const_allocation2.rs index 56839255c0e91..30afedffb39b3 100644 --- a/src/test/mir-opt/const_allocation2.rs +++ b/src/test/mir-opt/const_allocation2.rs @@ -1,5 +1,5 @@ +// ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH - // EMIT_MIR const_allocation2.main.ConstProp.after.mir fn main() { FOO; diff --git a/src/test/mir-opt/const_allocation3.rs b/src/test/mir-opt/const_allocation3.rs index 2ce289aea3fc9..ddeb32ab9a583 100644 --- a/src/test/mir-opt/const_allocation3.rs +++ b/src/test/mir-opt/const_allocation3.rs @@ -1,5 +1,5 @@ +// ignore-endian-big // EMIT_MIR_FOR_EACH_BIT_WIDTH - // EMIT_MIR const_allocation3.main.ConstProp.after.mir fn main() { FOO; diff --git a/src/test/mir-opt/inline/inline-into-box-place.rs b/src/test/mir-opt/inline/inline-into-box-place.rs index 30c9a5d6b8ff7..57298605b1873 100644 --- a/src/test/mir-opt/inline/inline-into-box-place.rs +++ b/src/test/mir-opt/inline/inline-into-box-place.rs @@ -1,8 +1,8 @@ +// ignore-endian-big // ignore-wasm32-bare compiled with panic=abort by default // compile-flags: -Z mir-opt-level=3 // EMIT_MIR_FOR_EACH_BIT_WIDTH #![feature(box_syntax)] - // EMIT_MIR inline_into_box_place.main.Inline.diff fn main() { let _x: Box> = box Vec::new(); diff --git a/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs b/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs index a323bd9e82b4a..8c436841b44e8 100644 --- a/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs +++ b/src/test/ui/simd/simd-intrinsic-generic-bitmask.rs @@ -2,6 +2,7 @@ #![allow(non_camel_case_types)] // ignore-emscripten +// ignore-endian-big behavior of simd_bitmask is endian-specific // Test that the simd_bitmask intrinsic produces correct results. diff --git a/src/test/ui/simd/simd-intrinsic-generic-select.rs b/src/test/ui/simd/simd-intrinsic-generic-select.rs index 22bda4fc9d919..dc9ec5d2760fe 100644 --- a/src/test/ui/simd/simd-intrinsic-generic-select.rs +++ b/src/test/ui/simd/simd-intrinsic-generic-select.rs @@ -2,10 +2,7 @@ #![allow(non_camel_case_types)] // ignore-emscripten -// ignore-mips behavior of simd_select_bitmask is endian-specific -// ignore-mips64 behavior of simd_select_bitmask is endian-specific -// ignore-powerpc behavior of simd_select_bitmask is endian-specific -// ignore-powerpc64 behavior of simd_select_bitmask is endian-specific +// ignore-endian-big behavior of simd_select_bitmask is endian-specific // Test that the simd_select intrinsics produces correct results. diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 2ab764eb9207c..99ab31ca067c3 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -815,6 +815,7 @@ impl Config { name == util::get_pointer_width(&self.target) || // pointer width name == self.stage_id.split('-').next().unwrap() || // stage (self.target != self.host && name == "cross-compile") || + (name == "endian-big" && util::is_big_endian(&self.target)) || (self.remote_test_client.is_some() && name == "remote") || match self.compare_mode { Some(CompareMode::Nll) => name == "compare-mode-nll", diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 0437ff8c9440a..ddd7941b11469 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -99,6 +99,20 @@ pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] = pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] = &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]; +const BIG_ENDIAN: &'static [&'static str] = &[ + "armebv7r", + "mips", + "mips64", + "mipsisa32r6", + "mipsisa64r6", + "powerpc", + "powerpc64", + "s390x", + "sparc", + "sparc64", + "sparcv9", +]; + pub fn matches_os(triple: &str, name: &str) -> bool { // For the wasm32 bare target we ignore anything also ignored on emscripten // and then we also recognize `wasm32-bare` as the os for the target @@ -125,6 +139,12 @@ pub fn get_arch(triple: &str) -> &'static str { panic!("Cannot determine Architecture from triple"); } +/// Determine the endianness from `triple` +pub fn is_big_endian(triple: &str) -> bool { + let triple_arch = triple.split('-').next().unwrap(); + BIG_ENDIAN.contains(&triple_arch) +} + pub fn matches_env(triple: &str, name: &str) -> bool { if let Some(env) = triple.split('-').nth(3) { env.starts_with(name) } else { false } } From 725d37cae0a175edb0c013b3de5b337ce5b5054d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 5 Aug 2020 05:31:17 +0000 Subject: [PATCH 02/12] Make doctests of Ipv4Addr::from(u32) easier to read --- library/std/src/net/ip.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index a64b43ca3ad45..726d1a88e93ae 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -982,8 +982,8 @@ impl From for u32 { /// ``` /// use std::net::Ipv4Addr; /// - /// let addr = Ipv4Addr::new(13, 12, 11, 10); - /// assert_eq!(0x0d0c0b0au32, u32::from(addr)); + /// let addr = Ipv4Addr::new(0xca, 0xfe, 0xba, 0xbe); + /// assert_eq!(0xcafebabe, u32::from(addr)); /// ``` fn from(ip: Ipv4Addr) -> u32 { let ip = ip.octets(); @@ -1000,8 +1000,8 @@ impl From for Ipv4Addr { /// ``` /// use std::net::Ipv4Addr; /// - /// let addr = Ipv4Addr::from(0x0d0c0b0au32); - /// assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr); + /// let addr = Ipv4Addr::from(0xcafebabe); + /// assert_eq!(Ipv4Addr::new(0xca, 0xfe, 0xba, 0xbe), addr); /// ``` fn from(ip: u32) -> Ipv4Addr { Ipv4Addr::from(ip.to_be_bytes()) From d9f260e95efcb3ada02d1cd85d304438de8af294 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 5 Aug 2020 05:53:07 +0000 Subject: [PATCH 03/12] Remove unused FromInner impl for Ipv4Addr --- library/std/src/net/ip.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index a64b43ca3ad45..2535b10b956f5 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -967,11 +967,6 @@ impl AsInner for Ipv4Addr { &self.inner } } -impl FromInner for Ipv4Addr { - fn from_inner(addr: c::in_addr) -> Ipv4Addr { - Ipv4Addr { inner: addr } - } -} #[stable(feature = "ip_u32", since = "1.1.0")] impl From for u32 { From 188ef3a200c6d39aa343da4d556d8354424f2314 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Wed, 5 Aug 2020 11:02:47 +0300 Subject: [PATCH 04/12] Fix typo in `librustc_feature/active.rs` --- src/librustc_feature/active.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index d7c310a8b4c8b..7e42f219ce284 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -576,7 +576,7 @@ declare_features! ( /// Lazily evaluate constants. This allows constants to depend on type parameters. (active, lazy_normalization_consts, "1.46.0", Some(72219), None), - /// Alloc calling `transmute` in const fn + /// Allows calling `transmute` in const fn (active, const_fn_transmute, "1.46.0", Some(53605), None), // ------------------------------------------------------------------------- From 0d8260ee48d19291ad99f1228a638e75a5453379 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 5 Aug 2020 05:03:08 -0400 Subject: [PATCH 05/12] Label rustfmt toolstate issues with A-rustfmt This makes it easier to filter toolstate issues by the tool involved. --- src/tools/publish_toolstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index c0631fcedd349..55e2d7cf8278f 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -42,7 +42,7 @@ LABELS = { 'miri': ['A-miri', 'C-bug'], 'rls': ['A-rls', 'C-bug'], - 'rustfmt': ['C-bug'], + 'rustfmt': ['A-rustfmt', 'C-bug'], 'book': ['C-bug'], 'nomicon': ['C-bug'], 'reference': ['C-bug'], From 48bc3982079685763a5bde07b7e4efb94ce622e0 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 5 Aug 2020 07:59:26 -0400 Subject: [PATCH 06/12] Handle fieldless tuple structs in diagnostic code Fixes #75062 --- src/librustc_resolve/diagnostics.rs | 7 +++---- .../privacy/issue-75062-fieldless-tuple-struct.rs | 10 ++++++++++ .../issue-75062-fieldless-tuple-struct.stderr | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/privacy/issue-75062-fieldless-tuple-struct.rs create mode 100644 src/test/ui/privacy/issue-75062-fieldless-tuple-struct.stderr diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 81e29047dc5e2..a6b5b0ff3017a 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1075,10 +1075,9 @@ impl<'a> Resolver<'a> { ) = binding.kind { let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor"); - if let Some(fields) = self.field_names.get(&def_id) { - let first_field = fields.first().expect("empty field list in the map"); - return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span))); - } + let fields = self.field_names.get(&def_id)?; + let first_field = fields.first()?; // Handle `struct Foo()` + return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span))); } None } diff --git a/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.rs b/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.rs new file mode 100644 index 0000000000000..4601a3d4741f5 --- /dev/null +++ b/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.rs @@ -0,0 +1,10 @@ +// Regression test for issue #75062 +// Tests that we don't ICE on a privacy error for a fieldless tuple struct. + +mod foo { + struct Bar(); +} + +fn main() { + foo::Bar(); //~ ERROR tuple struct +} diff --git a/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.stderr b/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.stderr new file mode 100644 index 0000000000000..14a12003e2de8 --- /dev/null +++ b/src/test/ui/privacy/issue-75062-fieldless-tuple-struct.stderr @@ -0,0 +1,15 @@ +error[E0603]: tuple struct `Bar` is private + --> $DIR/issue-75062-fieldless-tuple-struct.rs:9:10 + | +LL | foo::Bar(); + | ^^^ private tuple struct + | +note: the tuple struct `Bar` is defined here + --> $DIR/issue-75062-fieldless-tuple-struct.rs:5:5 + | +LL | struct Bar(); + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0603`. From cd4633917d4dd446f9f37efbf750bbd4ed2b46d6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 Aug 2020 14:14:21 +0200 Subject: [PATCH 07/12] Clean up E0746 explanation --- src/librustc_error_codes/error_codes/E0746.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0746.md b/src/librustc_error_codes/error_codes/E0746.md index 305667e58f8fb..90755d47f6790 100644 --- a/src/librustc_error_codes/error_codes/E0746.md +++ b/src/librustc_error_codes/error_codes/E0746.md @@ -1,4 +1,4 @@ -Return types cannot be `dyn Trait`s as they must be `Sized`. +An unboxed trait object was used as a return value. Erroneous code example: @@ -13,11 +13,13 @@ impl T for S { // Having the trait `T` as return type is invalid because // unboxed trait objects do not have a statically known size: -fn foo() -> dyn T { +fn foo() -> dyn T { // error! S(42) } ``` +Return types cannot be `dyn Trait`s as they must be `Sized`. + To avoid the error there are a couple of options. If there is a single type involved, you can use [`impl Trait`]: @@ -32,7 +34,7 @@ If there is a single type involved, you can use [`impl Trait`]: # } // The compiler will select `S(usize)` as the materialized return type of this // function, but callers will only know that the return type implements `T`. -fn foo() -> impl T { +fn foo() -> impl T { // ok! S(42) } ``` @@ -57,7 +59,7 @@ impl T for O { // This now returns a "trait object" and callers are only be able to access // associated items from `T`. -fn foo(x: bool) -> Box { +fn foo(x: bool) -> Box { // ok! if x { Box::new(S(42)) } else { From eff7d568d820a07d621bac85502d6236103ca908 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 6 Aug 2020 07:33:07 +0000 Subject: [PATCH 08/12] Note about endianness of returned value in {integer}::from_be_bytes and friends. --- library/core/src/num/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index eb50dc28b9f11..95eae7e2a73a1 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -4383,8 +4383,8 @@ assert_eq!( } doc_comment! { - concat!("Create an integer value from its representation as a byte array in -big endian. + concat!("Create a native endian integer value from its representation +as a byte array in big endian. ", $from_xe_bytes_doc, " @@ -4416,8 +4416,8 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), doc_comment! { concat!(" -Create an integer value from its representation as a byte array in -little endian. +Create a native endian integer value from its representation +as a byte array in little endian. ", $from_xe_bytes_doc, " @@ -4448,8 +4448,8 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), } doc_comment! { - concat!("Create an integer value from its memory representation as a byte -array in native endianness. + concat!("Create a native endian integer value from its memory representation +as a byte array in native endianness. As the target platform's native endianness is used, portable code likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as From 57b517bf1ddc450983815646bdf003d71fd72840 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Aug 2020 13:33:54 +0200 Subject: [PATCH 09/12] Clean up E0747 explanation --- src/librustc_error_codes/error_codes/E0747.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0747.md b/src/librustc_error_codes/error_codes/E0747.md index df1afbfef46df..caf7e0fba07a3 100644 --- a/src/librustc_error_codes/error_codes/E0747.md +++ b/src/librustc_error_codes/error_codes/E0747.md @@ -1,4 +1,4 @@ -Generic arguments must be provided in the same order as the corresponding +Generic arguments were not provided in the same order as the corresponding generic parameters are declared. Erroneous code example: @@ -11,7 +11,7 @@ type X = S<(), 'static>; // error: the type argument is provided before the ``` The argument order should be changed to match the parameter declaration -order, as in the following. +order, as in the following: ``` struct S<'a, T>(&'a T); From ebbf07a1544151867e20ff75f740836aba1ff73a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 6 Aug 2020 15:58:23 +1000 Subject: [PATCH 10/12] Change the type of `AssertModuleSource::available_cgus`. It's currently a `BTreeSet`, which is a strange type. The `BTreeSet` suggests that element order is important, but `Symbol` is a type whose ordering isn't useful to humans. The ordering of the collection only manifests in an obscure error message ("no module named `...`") that doesn't appear in any tests. This commit changes the `Symbol` to a `String`, which is more typical. --- src/librustc_incremental/assert_module_sources.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc_incremental/assert_module_sources.rs b/src/librustc_incremental/assert_module_sources.rs index d451d9a22a48b..29d615b04a394 100644 --- a/src/librustc_incremental/assert_module_sources.rs +++ b/src/librustc_incremental/assert_module_sources.rs @@ -39,8 +39,8 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) { .collect_and_partition_mono_items(LOCAL_CRATE) .1 .iter() - .map(|cgu| cgu.name()) - .collect::>(); + .map(|cgu| cgu.name().to_string()) + .collect::>(); let ams = AssertModuleSource { tcx, available_cgus }; @@ -52,7 +52,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) { struct AssertModuleSource<'tcx> { tcx: TyCtxt<'tcx>, - available_cgus: BTreeSet, + available_cgus: BTreeSet, } impl AssertModuleSource<'tcx> { @@ -121,12 +121,11 @@ impl AssertModuleSource<'tcx> { debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name); - if !self.available_cgus.contains(&cgu_name) { + if !self.available_cgus.contains(&*cgu_name.as_str()) { self.tcx.sess.span_err( attr.span, &format!( - "no module named `{}` (mangled: {}). \ - Available modules: {}", + "no module named `{}` (mangled: {}). Available modules: {}", user_path, cgu_name, self.available_cgus From 6eeae7d42013cc5deab74a43010721b98847c80d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 6 Aug 2020 14:37:32 -0700 Subject: [PATCH 11/12] Fix typo "TraitObligatiom" -> "TraitObligation" --- src/librustc_trait_selection/traits/select/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trait_selection/traits/select/mod.rs b/src/librustc_trait_selection/traits/select/mod.rs index 75e1161992430..dbb64e571781e 100644 --- a/src/librustc_trait_selection/traits/select/mod.rs +++ b/src/librustc_trait_selection/traits/select/mod.rs @@ -440,7 +440,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation ); - // `previous_stack` stores a `TraitObligatiom`, while `obligation` is + // `previous_stack` stores a `TraitObligation`, while `obligation` is // a `PredicateObligation`. These are distinct types, so we can't // use any `Option` combinator method that would force them to be // the same. From b809f453cac600acef9de5fedb457f842563266c Mon Sep 17 00:00:00 2001 From: Izzy Swart Date: Thu, 6 Aug 2020 16:13:29 -0700 Subject: [PATCH 12/12] Fix typo "biset" -> "bitset" --- src/tools/unicode-table-generator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/unicode-table-generator/src/main.rs b/src/tools/unicode-table-generator/src/main.rs index eabbcee9d73fd..d2d1807b3bb22 100644 --- a/src/tools/unicode-table-generator/src/main.rs +++ b/src/tools/unicode-table-generator/src/main.rs @@ -15,7 +15,7 @@ //! We have two separate encoding schemes: a skiplist-like approach, and a //! compressed bitset. The datasets we consider mostly use the skiplist (it's //! smaller) but the lowercase and uppercase sets are sufficiently sparse for -//! the bitset to be worthwhile -- for those sets the biset is a 2x size win. +//! the bitset to be worthwhile -- for those sets the bitset is a 2x size win. //! Since the bitset is also faster, this seems an obvious choice. (As a //! historical note, the bitset was also the prior implementation, so its //! relative complexity had already been paid).