From b12e142bc5a6f6312ce2fd3305f449d03410a37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 5 Nov 2019 19:27:42 +0100 Subject: [PATCH 01/32] alloc: Add new_zeroed() versions like new_uninit(). MaybeUninit has both uninit() and zeroed(), it seems reasonable to have the same surface on Box/Rc/Arc. Needs tests. --- src/liballoc/boxed.rs | 27 +++++++++++++++++++++++++++ src/liballoc/rc.rs | 29 +++++++++++++++++++++++++++++ src/liballoc/sync.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 567b8ea722491..51ad3a04e87fe 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -152,6 +152,33 @@ impl Box { Box(ptr.cast().into()) } + /// Constructs a new `Box` with uninitialized contents, with the memory + /// being filled with `0` bytes. + /// + /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage + /// of this method. + /// + /// # Examples + /// + /// ``` + /// #![feature(new_uninit)] + /// + /// let zero = Box::::new_zeroed(); + /// let zero = unsafe { zero.assume_init() }; + /// + /// assert_eq!(*zero, 0) + /// ``` + /// + /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed + #[unstable(feature = "new_uninit", issue = "63291")] + pub fn new_zeroed() -> Box> { + unsafe { + let mut uninit = Self::new_uninit(); + ptr::write_bytes::(uninit.as_mut_ptr(), 0, 1); + uninit + } + } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then /// `x` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f1c4c32e116ea..b25f2ef98e256 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -361,6 +361,35 @@ impl Rc { } } + /// Constructs a new `Rc` with uninitialized contents, with the memory + /// being filled with `0` bytes. + /// + /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and + /// incorrect usage of this method. + /// + /// # Examples + /// + /// ``` + /// #![feature(new_uninit)] + /// + /// use std::rc::Rc; + /// + /// let zero = Rc::::new_zeroed(); + /// let zero = unsafe { zero.assume_init() }; + /// + /// assert_eq!(*zero, 0) + /// ``` + /// + /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed + #[unstable(feature = "new_uninit", issue = "63291")] + pub fn new_zeroed() -> Rc> { + unsafe { + let mut uninit = Self::new_uninit(); + ptr::write_bytes::(Rc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1); + uninit + } + } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then /// `value` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 80d6c6e0d4390..8153e63e8f537 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -341,6 +341,35 @@ impl Arc { } } + /// Constructs a new `Arc` with uninitialized contents, with the memory + /// being filled with `0` bytes. + /// + /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage + /// of this method. + /// + /// # Examples + /// + /// ``` + /// #![feature(new_uninit)] + /// + /// use std::sync::Arc; + /// + /// let zero = Arc::::new_zeroed(); + /// let zero = unsafe { zero.assume_init() }; + /// + /// assert_eq!(*zero, 0) + /// ``` + /// + /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed + #[unstable(feature = "new_uninit", issue = "63291")] + pub fn new_zeroed() -> Arc> { + unsafe { + let mut uninit = Self::new_uninit(); + ptr::write_bytes::(Arc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1); + uninit + } + } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then /// `data` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] From 75dac389fb168159e0b049f72141f889b7215889 Mon Sep 17 00:00:00 2001 From: msizanoen1 Date: Sat, 23 Nov 2019 14:15:27 +0700 Subject: [PATCH 02/32] Add riscv64gc-unknown-linux-gnu target --- src/librustc_target/spec/mod.rs | 1 + .../spec/riscv64gc_unknown_linux_gnu.rs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 716aef056a35b..1a7cb943de76b 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -487,6 +487,7 @@ supported_targets! { ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf), ("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf), ("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf), + ("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu), ("aarch64-unknown-none", aarch64_unknown_none), ("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat), diff --git a/src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs b/src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs new file mode 100644 index 0000000000000..638e6770ebf8c --- /dev/null +++ b/src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs @@ -0,0 +1,25 @@ +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; + +pub fn target() -> TargetResult { + Ok(Target { + llvm_target: "riscv64-unknown-linux-gnu".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_env: "gnu".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), + arch: "riscv64".to_string(), + target_os: "linux".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: TargetOptions { + abi_blacklist: super::riscv_base::abi_blacklist(), + code_model: Some("medium".to_string()), + cpu: "generic-rv64".to_string(), + features: "+m,+a,+f,+d,+c".to_string(), + llvm_abiname: "lp64d".to_string(), + max_atomic_width: Some(64), + ..super::linux_base::opts() + }, + }) +} From a8430a4ee5cc3863f2cb160822f5ae0eb4c7ed53 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 Nov 2019 09:12:17 +0100 Subject: [PATCH 03/32] Miri: print leak report even without tracing --- src/librustc_mir/interpret/eval_context.rs | 4 +++- src/librustc_mir/interpret/memory.rs | 23 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 08640476f7ab7..b5bd96db1f430 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -703,7 +703,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local { trace!("deallocating local"); let ptr = ptr.to_ptr()?; - self.memory.dump_alloc(ptr.alloc_id); + if log_enabled!(::log::Level::Trace) { + self.memory.dump_alloc(ptr.alloc_id); + } self.memory.deallocate_local(ptr)?; }; Ok(()) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 842ef915ad226..dc8b035f43afd 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -635,7 +635,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Ok(()) } - /// For debugging, print an allocation and all allocations it points to, recursively. + /// Print an allocation and all allocations it points to, recursively. + /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to + /// control for this. pub fn dump_alloc(&self, id: AllocId) { self.dump_allocs(vec![id]); } @@ -674,7 +676,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } } - trace!( + eprintln!( "{}({} bytes, alignment {}){}", msg, alloc.size.bytes(), @@ -695,15 +697,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { write!(msg, "└{0:─^1$}┘ ", target, relocation_width as usize).unwrap(); pos = i + self.pointer_size(); } - trace!("{}", msg); + eprintln!("{}", msg); } } - /// For debugging, print a list of allocations and all allocations they point to, recursively. + /// Print a list of allocations and all allocations they point to, recursively. + /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to + /// control for this. pub fn dump_allocs(&self, mut allocs: Vec) { - if !log_enabled!(::log::Level::Trace) { - return; - } allocs.sort(); allocs.dedup(); let mut allocs_to_print = VecDeque::from(allocs); @@ -735,13 +736,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { ); } Some(GlobalAlloc::Function(func)) => { - trace!("{} {}", msg, func); + eprintln!("{} {}", msg, func); } Some(GlobalAlloc::Static(did)) => { - trace!("{} {:?}", msg, did); + eprintln!("{} {:?}", msg, did); } None => { - trace!("{} (deallocated)", msg); + eprintln!("{} (deallocated)", msg); } } }, @@ -751,7 +752,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } pub fn leak_report(&self) -> usize { - trace!("### LEAK REPORT ###"); + eprintln!("### LEAK REPORT ###"); let leaks: Vec<_> = self.alloc_map.filter_map_collect(|&id, &(kind, _)| { if kind.may_leak() { None } else { Some(id) } }); From 9233a54176441b9d63b3da33814794adb8bf0e5d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 Nov 2019 09:24:47 +0100 Subject: [PATCH 04/32] only print LEAK REPORT if there is a leak --- src/librustc_mir/interpret/memory.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index dc8b035f43afd..eccdc5b03261b 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -752,12 +752,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { } pub fn leak_report(&self) -> usize { - eprintln!("### LEAK REPORT ###"); let leaks: Vec<_> = self.alloc_map.filter_map_collect(|&id, &(kind, _)| { if kind.may_leak() { None } else { Some(id) } }); let n = leaks.len(); - self.dump_allocs(leaks); + if n > 0 { + eprintln!("### LEAK REPORT ###"); + self.dump_allocs(leaks); + } n } From 01d01ce3ca9727cf647292eb3d9300d05c30a710 Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Sun, 24 Nov 2019 13:39:03 -0600 Subject: [PATCH 05/32] Add hardware floating point features to aarch64-pc-windows-msvc --- src/librustc_target/spec/aarch64_pc_windows_msvc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/aarch64_pc_windows_msvc.rs b/src/librustc_target/spec/aarch64_pc_windows_msvc.rs index 1aee381d604c3..37dd9427ef4f2 100644 --- a/src/librustc_target/spec/aarch64_pc_windows_msvc.rs +++ b/src/librustc_target/spec/aarch64_pc_windows_msvc.rs @@ -4,6 +4,7 @@ pub fn target() -> TargetResult { let mut base = super::windows_msvc_base::opts(); base.max_atomic_width = Some(64); base.has_elf_tls = true; + base.features = "+neon,+fp-armv8".to_string(); // FIXME: this shouldn't be panic=abort, it should be panic=unwind base.panic_strategy = PanicStrategy::Abort; From 28c6ef83c6d148b2d13563591fa8c6dad8474f2d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 24 Nov 2019 21:05:32 +0100 Subject: [PATCH 06/32] introduce a target to build the kernel HermitCore - the target avoids the usage of SSE & AVX within the kernel --- .../spec/hermit_kernel_base.rs | 26 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 2 ++ .../spec/x86_64_unknown_hermit_kernel.rs | 23 ++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/librustc_target/spec/hermit_kernel_base.rs create mode 100644 src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs diff --git a/src/librustc_target/spec/hermit_kernel_base.rs b/src/librustc_target/spec/hermit_kernel_base.rs new file mode 100644 index 0000000000000..f31de4dbd5194 --- /dev/null +++ b/src/librustc_target/spec/hermit_kernel_base.rs @@ -0,0 +1,26 @@ +use crate::spec::{LldFlavor, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions}; +use std::default::Default; + +pub fn opts() -> TargetOptions { + let mut pre_link_args = LinkArgs::new(); + pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![ + "--build-id".to_string(), + "--hash-style=gnu".to_string(), + "--Bstatic".to_string(), + ]); + + TargetOptions { + linker: Some("rust-lld".to_owned()), + executables: true, + has_elf_tls: true, + linker_is_gnu: true, + pre_link_args, + no_default_libraries: true, + panic_strategy: PanicStrategy::Abort, + position_independent_executables: true, + relocation_model: "static".to_string(), + target_family: None, + tls_model: "initial-exec".to_string(), + .. Default::default() + } +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 716aef056a35b..feaf0430e1467 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -54,6 +54,7 @@ mod dragonfly_base; mod freebsd_base; mod haiku_base; mod hermit_base; +mod hermit_kernel_base; mod linux_base; mod linux_kernel_base; mod linux_musl_base; @@ -481,6 +482,7 @@ supported_targets! { ("aarch64-unknown-hermit", aarch64_unknown_hermit), ("x86_64-unknown-hermit", x86_64_unknown_hermit), + ("x86_64-unknown-hermit-kernel", x86_64_unknown_hermit_kernel), ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf), ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf), diff --git a/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs b/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs new file mode 100644 index 0000000000000..9979b94833ebf --- /dev/null +++ b/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs @@ -0,0 +1,23 @@ +use crate::spec::{LldFlavor, LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::hermit_kernel_base::opts(); + base.cpu = "x86-64".to_string(); + base.max_atomic_width = Some(64); + base.features = "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float".to_string(); + base.stack_probes = true; + + Ok(Target { + llvm_target: "x86_64-unknown-hermit".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), + arch: "x86_64".to_string(), + target_os: "hermit".to_string(), + target_env: String::new(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + options: base, + }) +} From fdcf854bb9b03ff9f8c60c824f0c6709a38269d0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Nov 2019 12:44:49 -0800 Subject: [PATCH 07/32] tidy: Accommodate rustfmt's preferred layout of stability attributes Previously tidy would require that the `feature = "name_of_feature"` part of the stability attribute was on the same line as the `#[stable(` / `#[unstable(` opening part of the attribute, and that `)]` was on the same line as the last key-value pair. That didn't work with rustfmt's preferred layout of long attributes, which is like: #[unstable( feature = "c_variadic", reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930" )] --- src/tools/tidy/src/features.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index a824546d436f7..defe85ef46a23 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -397,7 +397,8 @@ fn map_lib_features(base_src_path: &Path, } let mut becoming_feature: Option<(&str, Feature)> = None; - for (i, line) in contents.lines().enumerate() { + let mut iter_lines = contents.lines().enumerate().peekable(); + while let Some((i, line)) = iter_lines.next() { macro_rules! err { ($msg:expr) => {{ mf(Err($msg), file, i + 1); @@ -411,7 +412,7 @@ fn map_lib_features(base_src_path: &Path, } if line.ends_with(']') { mf(Ok((name, f.clone())), file, i + 1); - } else if !line.ends_with(',') && !line.ends_with('\\') { + } else if !line.ends_with(',') && !line.ends_with('\\') && !line.ends_with('"') { // We need to bail here because we might have missed the // end of a stability attribute above because the ']' // might not have been at the end of the line. @@ -450,7 +451,9 @@ fn map_lib_features(base_src_path: &Path, } else { continue; }; - let feature_name = match find_attr_val(line, "feature") { + let feature_name = match find_attr_val(line, "feature") + .or_else(|| iter_lines.peek().and_then(|next| find_attr_val(next.1, "feature"))) + { Some(name) => name, None => err!("malformed stability attribute: missing `feature` key"), }; From 66dce1114d1014258c8cc586e176f2ea53ab4ed1 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 24 Nov 2019 16:25:20 -0500 Subject: [PATCH 08/32] Store ptr_width as u32 on Config This removes the dependency on IntTy, UintTy from Session. --- src/librustc/session/config.rs | 16 +++++++--------- src/librustc_codegen_llvm/builder.rs | 4 ++-- src/librustc_codegen_llvm/intrinsic.rs | 4 ++-- src/librustc_lint/types.rs | 13 ++----------- src/libsyntax/ast.rs | 24 ++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 2b1dfcaf68cec..a02f01d0c9764 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -12,7 +12,7 @@ use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel use rustc_target::spec::{Target, TargetTriple}; use syntax; -use syntax::ast::{self, IntTy, UintTy}; +use syntax::ast; use syntax::source_map::{FileName, FilePathMapping}; use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION}; use syntax::symbol::{sym, Symbol}; @@ -36,8 +36,7 @@ use std::path::{Path, PathBuf}; pub struct Config { pub target: Target, - pub isize_ty: IntTy, - pub usize_ty: UintTy, + pub ptr_width: u32, } #[derive(Clone, Hash, Debug)] @@ -1570,10 +1569,10 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { FatalError.raise(); }); - let (isize_ty, usize_ty) = match &target.target_pointer_width[..] { - "16" => (ast::IntTy::I16, ast::UintTy::U16), - "32" => (ast::IntTy::I32, ast::UintTy::U32), - "64" => (ast::IntTy::I64, ast::UintTy::U64), + let ptr_width = match &target.target_pointer_width[..] { + "16" => 16, + "32" => 32, + "64" => 64, w => sp.fatal(&format!( "target specification was invalid: \ unrecognized target-pointer-width {}", @@ -1583,8 +1582,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { Config { target, - isize_ty, - usize_ty, + ptr_width, } } diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index 312c41b88b092..6f72466c559dc 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -325,8 +325,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { use rustc::ty::{Int, Uint}; let new_kind = match ty.kind { - Int(Isize) => Int(self.tcx.sess.target.isize_ty), - Uint(Usize) => Uint(self.tcx.sess.target.usize_ty), + Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)), + Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)), ref t @ Uint(_) | ref t @ Int(_) => t.clone(), _ => panic!("tried to get overflow intrinsic for op applied to non-int type") }; diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 12ec4e1074874..aa55f3a19e2be 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -1926,7 +1926,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#, fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> { match ty.kind { ty::Int(t) => Some((match t { - ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64, + ast::IntTy::Isize => cx.tcx.sess.target.ptr_width as u64, ast::IntTy::I8 => 8, ast::IntTy::I16 => 16, ast::IntTy::I32 => 32, @@ -1934,7 +1934,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo ast::IntTy::I128 => 128, }, true)), ty::Uint(t) => Some((match t { - ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64, + ast::UintTy::Usize => cx.tcx.sess.target.ptr_width as u64, ast::UintTy::U8 => 8, ast::UintTy::U16 => 16, ast::UintTy::U32 => 32, diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 9a4e981081fcf..f2e56c69fd79f 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -252,12 +252,7 @@ fn lint_int_literal<'a, 'tcx>( t: ast::IntTy, v: u128, ) { - let int_type = if let ast::IntTy::Isize = t { - cx.sess().target.isize_ty - } else { - t - }; - + let int_type = t.normalize(cx.sess().target.ptr_width); let (_, max) = int_ty_range(int_type); let max = max as u128; let negative = type_limits.negated_expr_id == e.hir_id; @@ -303,11 +298,7 @@ fn lint_uint_literal<'a, 'tcx>( lit: &hir::Lit, t: ast::UintTy, ) { - let uint_type = if let ast::UintTy::Usize = t { - cx.sess().target.usize_ty - } else { - t - }; + let uint_type = t.normalize(cx.sess().target.ptr_width); let (min, max) = uint_ty_range(uint_type); let lit_val: u128 = match lit.node { // _v is u8, within range by definition diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 142430769411f..b8561216896e2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1693,6 +1693,18 @@ impl IntTy { IntTy::I128 => 128, }) } + + pub fn normalize(&self, target_width: u32) -> Self { + match self { + IntTy::Isize => match target_width { + 16 => IntTy::I16, + 32 => IntTy::I32, + 64 => IntTy::I64, + _ => unreachable!(), + }, + _ => *self, + } + } } #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, @@ -1743,6 +1755,18 @@ impl UintTy { UintTy::U128 => 128, }) } + + pub fn normalize(&self, target_width: u32) -> Self { + match self { + UintTy::Usize => match target_width { + 16 => UintTy::U16, + 32 => UintTy::U32, + 64 => UintTy::U64, + _ => unreachable!(), + }, + _ => *self, + } + } } /// A constraint on an associated type (e.g., `A = Bar` in `Foo` or From 1475944bdc56c7f0e266056368f83e17c21b36b0 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 24 Nov 2019 22:36:50 +0100 Subject: [PATCH 09/32] use nicer code style to pass tidy check --- src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs b/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs index 9979b94833ebf..ebaada8f4f8eb 100644 --- a/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs +++ b/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs @@ -4,7 +4,9 @@ pub fn target() -> TargetResult { let mut base = super::hermit_kernel_base::opts(); base.cpu = "x86-64".to_string(); base.max_atomic_width = Some(64); - base.features = "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float".to_string(); + base.features = + "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" + .to_string(); base.stack_probes = true; Ok(Target { From 55ce5c09ff501d14ef2cce4498267372450a60d1 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 24 Nov 2019 23:40:32 +0100 Subject: [PATCH 10/32] disable redzone --- src/librustc_target/spec/hermit_kernel_base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/hermit_kernel_base.rs b/src/librustc_target/spec/hermit_kernel_base.rs index f31de4dbd5194..ad1027c7bc775 100644 --- a/src/librustc_target/spec/hermit_kernel_base.rs +++ b/src/librustc_target/spec/hermit_kernel_base.rs @@ -10,6 +10,7 @@ pub fn opts() -> TargetOptions { ]); TargetOptions { + disable_redzone: true, linker: Some("rust-lld".to_owned()), executables: true, has_elf_tls: true, From e5816a75cc9951218e6ec06f64a5f07575c36770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 24 Nov 2019 18:42:22 -0800 Subject: [PATCH 11/32] Fix some rustdoc error capitalization --- src/librustdoc/passes/mod.rs | 6 +++--- src/test/rustdoc-ui/doc-without-codeblock.rs | 8 ++++---- src/test/rustdoc-ui/doc-without-codeblock.stderr | 8 ++++---- src/test/rustdoc-ui/lint-group.rs | 4 ++-- src/test/rustdoc-ui/lint-group.stderr | 4 ++-- src/test/rustdoc-ui/lint-missing-doc-code-example.stderr | 4 ++-- src/test/rustdoc-ui/private-item-doc-test.rs | 2 +- src/test/rustdoc-ui/private-item-doc-test.stderr | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index f6560218a78c8..0a95d4209ac6a 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -344,7 +344,7 @@ pub fn look_for_tests<'tcx>( lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, - "Missing code example in this documentation"); + "missing code example in this documentation"); diag.emit(); } else if check_missing_code == false && tests.found_tests > 0 && @@ -353,7 +353,7 @@ pub fn look_for_tests<'tcx>( lint::builtin::PRIVATE_DOC_TESTS, hir_id, span_of_attrs(&item.attrs).unwrap_or(item.source.span()), - "Documentation test in private item"); + "documentation test in private item"); diag.emit(); } } @@ -367,7 +367,7 @@ crate fn span_of_attrs(attrs: &clean::Attributes) -> Option { if start == DUMMY_SP { return None; } - let end = attrs.doc_strings.last().expect("No doc strings provided").span(); + let end = attrs.doc_strings.last().expect("no doc strings provided").span(); Some(start.to(end)) } diff --git a/src/test/rustdoc-ui/doc-without-codeblock.rs b/src/test/rustdoc-ui/doc-without-codeblock.rs index 4b2a91e9c8127..5ad8e8a826f05 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.rs +++ b/src/test/rustdoc-ui/doc-without-codeblock.rs @@ -1,13 +1,13 @@ -#![deny(missing_doc_code_examples)] //~ ERROR Missing code example in this documentation +#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation /// Some docs. -//~^ ERROR Missing code example in this documentation +//~^ ERROR missing code example in this documentation pub struct Foo; /// And then, the princess died. -//~^ ERROR Missing code example in this documentation +//~^ ERROR missing code example in this documentation pub mod foo { /// Or maybe not because she saved herself! - //~^ ERROR Missing code example in this documentation + //~^ ERROR missing code example in this documentation pub fn bar() {} } diff --git a/src/test/rustdoc-ui/doc-without-codeblock.stderr b/src/test/rustdoc-ui/doc-without-codeblock.stderr index 23c07c4d32d64..bf65fcf19a0d6 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.stderr +++ b/src/test/rustdoc-ui/doc-without-codeblock.stderr @@ -1,4 +1,4 @@ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:1:1 | LL | / #![deny(missing_doc_code_examples)] @@ -16,19 +16,19 @@ note: lint level defined here LL | #![deny(missing_doc_code_examples)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:3:1 | LL | /// Some docs. | ^^^^^^^^^^^^^^ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:7:1 | LL | /// And then, the princess died. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:10:5 | LL | /// Or maybe not because she saved herself! diff --git a/src/test/rustdoc-ui/lint-group.rs b/src/test/rustdoc-ui/lint-group.rs index 0e0ebd9ce7080..06766db5335a1 100644 --- a/src/test/rustdoc-ui/lint-group.rs +++ b/src/test/rustdoc-ui/lint-group.rs @@ -14,11 +14,11 @@ pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it /// wait, this doesn't have a doctest? -pub fn no_doctest() {} //~^ ERROR Missing code example in this documentation +pub fn no_doctest() {} //~^ ERROR missing code example in this documentation /// wait, this *does* have a doctest? /// /// ``` /// println!("sup"); /// ``` -fn private_doctest() {} //~^^^^^ ERROR Documentation test in private item +fn private_doctest() {} //~^^^^^ ERROR documentation test in private item diff --git a/src/test/rustdoc-ui/lint-group.stderr b/src/test/rustdoc-ui/lint-group.stderr index cd523b227deb1..63274ae2be4f6 100644 --- a/src/test/rustdoc-ui/lint-group.stderr +++ b/src/test/rustdoc-ui/lint-group.stderr @@ -1,4 +1,4 @@ -error: Documentation test in private item +error: documentation test in private item --> $DIR/lint-group.rs:19:1 | LL | / /// wait, this *does* have a doctest? @@ -29,7 +29,7 @@ LL | #![deny(rustdoc)] = note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]` = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]` -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/lint-group.rs:16:1 | LL | /// wait, this doesn't have a doctest? diff --git a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr index 97a52a13e3f65..179dba17c6d81 100644 --- a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr +++ b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr @@ -1,4 +1,4 @@ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/lint-missing-doc-code-example.rs:19:1 | LL | / mod module1 { @@ -11,7 +11,7 @@ note: lint level defined here LL | #![deny(missing_doc_code_examples)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: Missing code example in this documentation +error: missing code example in this documentation --> $DIR/lint-missing-doc-code-example.rs:37:3 | LL | /// doc diff --git a/src/test/rustdoc-ui/private-item-doc-test.rs b/src/test/rustdoc-ui/private-item-doc-test.rs index 20ac292aeaf80..2f1bddc7c75cc 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.rs +++ b/src/test/rustdoc-ui/private-item-doc-test.rs @@ -6,6 +6,6 @@ mod foo { /// ``` /// assert!(false); /// ``` - //~^^^^^ ERROR Documentation test in private item + //~^^^^^ ERROR documentation test in private item fn bar() {} } diff --git a/src/test/rustdoc-ui/private-item-doc-test.stderr b/src/test/rustdoc-ui/private-item-doc-test.stderr index 20f3eb8b12025..8abbdb31ec91a 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.stderr +++ b/src/test/rustdoc-ui/private-item-doc-test.stderr @@ -1,4 +1,4 @@ -error: Documentation test in private item +error: documentation test in private item --> $DIR/private-item-doc-test.rs:4:5 | LL | / /// private doc test From bf5c64abff4994c2743b675d1d39c57571155a53 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:31:05 +0100 Subject: [PATCH 12/32] Clean up E0062 long explanation --- src/librustc_error_codes/error_codes/E0062.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0062.md b/src/librustc_error_codes/error_codes/E0062.md index 0ebeb1bd78ed0..64fc027b885b6 100644 --- a/src/librustc_error_codes/error_codes/E0062.md +++ b/src/librustc_error_codes/error_codes/E0062.md @@ -1,6 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was specified more than once. Erroneous code -example: +A struct's or struct-like enum variant's field was specified more than once. + +Erroneous code example: ```compile_fail,E0062 struct Foo { @@ -15,7 +15,9 @@ fn main() { } ``` -Each field should be specified exactly one time. Example: +This error indicates that during an attempt to build a struct or struct-like +enum variant, one of the fields was specified more than once. Each field should +be specified exactly one time. Example: ``` struct Foo { From 7e813c4a014de141a09b4e8b74532b2896b2766a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:32:11 +0100 Subject: [PATCH 13/32] Clean up E0063 long explanation --- src/librustc_error_codes/error_codes/E0063.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0063.md b/src/librustc_error_codes/error_codes/E0063.md index 0d1f60437acf0..0e611deac426f 100644 --- a/src/librustc_error_codes/error_codes/E0063.md +++ b/src/librustc_error_codes/error_codes/E0063.md @@ -1,5 +1,6 @@ -This error indicates that during an attempt to build a struct or struct-like -enum variant, one of the fields was not provided. Erroneous code example: +A struct's or struct-like enum variant's field was not provided. + +Erroneous code example: ```compile_fail,E0063 struct Foo { From 98e29176264635da8a8c0b2f2ccabf282cfa2282 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:49:32 +0100 Subject: [PATCH 14/32] Clean up E0067 long explanation --- src/librustc_error_codes/error_codes/E0067.md | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0067.md b/src/librustc_error_codes/error_codes/E0067.md index 101b96f7983f6..11041bb53ee55 100644 --- a/src/librustc_error_codes/error_codes/E0067.md +++ b/src/librustc_error_codes/error_codes/E0067.md @@ -1,33 +1,15 @@ -The left-hand side of a compound assignment expression must be a place -expression. A place expression represents a memory location and includes -item paths (ie, namespaced variables), dereferences, indexing expressions, -and field references. +An invalid left-hand side expression was used on an assignment operation. -Let's start with some erroneous code examples: +Erroneous code example: ```compile_fail,E0067 -use std::collections::LinkedList; - -// Bad: assignment to non-place expression -LinkedList::new() += 1; - -// ... - -fn some_func(i: &mut i32) { - i += 12; // Error : '+=' operation cannot be applied on a reference ! -} +12 += 1; // error! ``` -And now some working examples: +You need to have a place expression to be able to assign it something. For +example: ``` -let mut i : i32 = 0; - -i += 12; // Good ! - -// ... - -fn some_func(i: &mut i32) { - *i += 12; // Good ! -} +let mut x: i8 = 12; +x += 1; // ok! ``` From ef35980ffbdf70870c37b78aa2da1bcf1ee775a2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:50:25 +0100 Subject: [PATCH 15/32] Clean up E0069 long explanation --- src/librustc_error_codes/error_codes/E0069.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_error_codes/error_codes/E0069.md b/src/librustc_error_codes/error_codes/E0069.md index ad3b1803b54db..7367a5c0922ea 100644 --- a/src/librustc_error_codes/error_codes/E0069.md +++ b/src/librustc_error_codes/error_codes/E0069.md @@ -1,5 +1,7 @@ The compiler found a function whose body contains a `return;` statement but -whose return type is not `()`. An example of this is: +whose return type is not `()`. + +Erroneous code example: ```compile_fail,E0069 // error From 1bd28b1087b067df4037cbbe2f48db7776e3deaa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Nov 2019 13:53:55 +0100 Subject: [PATCH 16/32] Clean up E0070 long explanation --- src/librustc_error_codes/error_codes/E0070.md | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0070.md b/src/librustc_error_codes/error_codes/E0070.md index 1a56080a09734..97522af3da867 100644 --- a/src/librustc_error_codes/error_codes/E0070.md +++ b/src/librustc_error_codes/error_codes/E0070.md @@ -1,41 +1,43 @@ -The left-hand side of an assignment operator must be a place expression. A -place expression represents a memory location and can be a variable (with -optional namespacing), a dereference, an indexing expression or a field -reference. +An assignment operator was used on a non-place expression. -More details can be found in the [Expressions] section of the Reference. - -[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries - -Now, we can go further. Here are some erroneous code examples: +Erroneous code examples: ```compile_fail,E0070 struct SomeStruct { x: i32, - y: i32 + y: i32, } -const SOME_CONST : i32 = 12; +const SOME_CONST: i32 = 12; fn some_other_func() {} fn some_function() { - SOME_CONST = 14; // error : a constant value cannot be changed! - 1 = 3; // error : 1 isn't a valid place! - some_other_func() = 4; // error : we cannot assign value to a function! - SomeStruct.x = 12; // error : SomeStruct a structure name but it is used - // like a variable! + SOME_CONST = 14; // error: a constant value cannot be changed! + 1 = 3; // error: 1 isn't a valid place! + some_other_func() = 4; // error: we cannot assign value to a function! + SomeStruct::x = 12; // error: SomeStruct a structure name but it is used + // like a variable! } ``` +The left-hand side of an assignment operator must be a place expression. A +place expression represents a memory location and can be a variable (with +optional namespacing), a dereference, an indexing expression or a field +reference. + +More details can be found in the [Expressions] section of the Reference. + +[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries + And now let's give working examples: ``` struct SomeStruct { x: i32, - y: i32 + y: i32, } -let mut s = SomeStruct {x: 0, y: 0}; +let mut s = SomeStruct { x: 0, y: 0 }; s.x = 3; // that's good ! From 00fe97ad0e440d78a3dbf8df77ac5192ca6d6403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:26:32 -0800 Subject: [PATCH 17/32] Fix capitalization when mentioning different crate versions in E0308 --- src/librustc/infer/error_reporting/mod.rs | 15 +++++---------- src/test/ui/type/type-mismatch-same-crate-name.rs | 4 ++-- .../ui/type/type-mismatch-same-crate-name.stderr | 12 ++---------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 0f93ef6b1a9e4..3ff5b2521ae81 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -463,7 +463,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, err: &mut DiagnosticBuilder<'_>, terr: &TypeError<'tcx>, - sp: Span, ) { use hir::def_id::CrateNum; use hir::map::DisambiguatedDefPathData; @@ -577,14 +576,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }; if same_path().unwrap_or(false) { let crate_name = self.tcx.crate_name(did1.krate); - err.span_note( - sp, - &format!( - "Perhaps two different versions \ - of crate `{}` are being used?", - crate_name - ), - ); + err.note(&format!( + "perhaps two different versions of crate `{}` are being used?", + crate_name + )); } } }; @@ -1263,7 +1258,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { .unwrap_or_else(|| { self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id }) }); - self.check_and_note_conflicting_crates(diag, terr, span); + self.check_and_note_conflicting_crates(diag, terr); self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id); // It reads better to have the error origin as the final diff --git a/src/test/ui/type/type-mismatch-same-crate-name.rs b/src/test/ui/type/type-mismatch-same-crate-name.rs index b1f9a28e16d56..eeda5460ac36a 100644 --- a/src/test/ui/type/type-mismatch-same-crate-name.rs +++ b/src/test/ui/type/type-mismatch-same-crate-name.rs @@ -15,11 +15,11 @@ fn main() { extern crate crate_a1 as a; a::try_foo(foo2); //~^ ERROR mismatched types - //~| Perhaps two different versions of crate `crate_a1` + //~| perhaps two different versions of crate `crate_a1` //~| expected struct `main::a::Foo` a::try_bar(bar2); //~^ ERROR mismatched types - //~| Perhaps two different versions of crate `crate_a1` + //~| perhaps two different versions of crate `crate_a1` //~| expected trait `main::a::Bar` //~| expected struct `std::boxed::Box<(dyn main::a::Bar + 'static)>` //~| found struct `std::boxed::Box` diff --git a/src/test/ui/type/type-mismatch-same-crate-name.stderr b/src/test/ui/type/type-mismatch-same-crate-name.stderr index 91bbe9c1fbe2a..be5406696b7de 100644 --- a/src/test/ui/type/type-mismatch-same-crate-name.stderr +++ b/src/test/ui/type/type-mismatch-same-crate-name.stderr @@ -4,11 +4,7 @@ error[E0308]: mismatched types LL | a::try_foo(foo2); | ^^^^ expected struct `main::a::Foo`, found a different struct `main::a::Foo` | -note: Perhaps two different versions of crate `crate_a1` are being used? - --> $DIR/type-mismatch-same-crate-name.rs:16:20 - | -LL | a::try_foo(foo2); - | ^^^^ + = note: perhaps two different versions of crate `crate_a1` are being used? error[E0308]: mismatched types --> $DIR/type-mismatch-same-crate-name.rs:20:20 @@ -18,11 +14,7 @@ LL | a::try_bar(bar2); | = note: expected struct `std::boxed::Box<(dyn main::a::Bar + 'static)>` found struct `std::boxed::Box` -note: Perhaps two different versions of crate `crate_a1` are being used? - --> $DIR/type-mismatch-same-crate-name.rs:20:20 - | -LL | a::try_bar(bar2); - | ^^^^ + = note: perhaps two different versions of crate `crate_a1` are being used? error: aborting due to 2 previous errors From 9a595417a2d5fdff62fb2a570756c5ce6f8eb0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:27:50 -0800 Subject: [PATCH 18/32] Tweak multiple allocators error --- src/librustc_metadata/creader.rs | 4 +++- src/test/ui/allocator/two-allocators.stderr | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index a721e381b4e99..7b54b98cbc13c 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -698,7 +698,9 @@ impl<'a> CrateLoader<'a> { let has_global_allocator = match &*global_allocator_spans(krate) { [span1, span2, ..] => { self.sess.struct_span_err(*span2, "cannot define multiple global allocators") - .span_note(*span1, "the previous global allocator is defined here").emit(); + .span_label(*span2, "cannot define a new global allocator") + .span_label(*span1, "previous global allocator is defined here") + .emit(); true } spans => !spans.is_empty() diff --git a/src/test/ui/allocator/two-allocators.stderr b/src/test/ui/allocator/two-allocators.stderr index ed0aa13eb8078..35d9f0f42f001 100644 --- a/src/test/ui/allocator/two-allocators.stderr +++ b/src/test/ui/allocator/two-allocators.stderr @@ -1,14 +1,11 @@ error: cannot define multiple global allocators --> $DIR/two-allocators.rs:6:1 | -LL | static B: System = System; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: the previous global allocator is defined here - --> $DIR/two-allocators.rs:4:1 - | LL | static A: System = System; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | -------------------------- previous global allocator is defined here +LL | #[global_allocator] +LL | static B: System = System; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator error: aborting due to previous error From 9c97d73a2dad4828e64e152c1ce9ced94022f4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:32:57 -0800 Subject: [PATCH 19/32] Tweak move error due to non-Copy --- src/librustc_mir/borrow_check/move_errors.rs | 9 +- .../borrowck-move-error-with-note.stderr | 18 +-- .../borrowck-move-out-of-vec-tail.stderr | 8 +- .../borrowck/borrowck-vec-pattern-nesting.rs | 2 +- .../borrowck-vec-pattern-nesting.stderr | 6 +- src/test/ui/issues/issue-12567.stderr | 18 +-- .../issue-40402-2.stderr | 6 +- src/test/ui/nll/move-errors.stderr | 14 +-- .../duplicate-suggestions.stderr | 108 +++--------------- .../dont-suggest-ref/simple.stderr | 17 +-- 10 files changed, 31 insertions(+), 175 deletions(-) diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index d9e958d945001..21191792b8237 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -555,7 +555,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'a>, binds_to: &[Local], ) { - let mut noncopy_var_spans = Vec::new(); for (j, local) in binds_to.into_iter().enumerate() { let bind_to = &self.body.local_decls[*local]; let binding_span = bind_to.source_info.span; @@ -573,16 +572,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { bind_to.ty, Some(binding_span) ); - } else { - noncopy_var_spans.push(binding_span); } } if binds_to.len() > 1 { - err.span_note( - noncopy_var_spans, - "move occurs because these variables have types that \ - don't implement the `Copy` trait", + err.note("move occurs because these variables have types that \ + don't implement the `Copy` trait", ); } } diff --git a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr index d56b9f562c932..26de39101f211 100644 --- a/src/test/ui/borrowck/borrowck-move-error-with-note.stderr +++ b/src/test/ui/borrowck/borrowck-move-error-with-note.stderr @@ -10,15 +10,7 @@ LL | num2) => (), LL | Foo::Foo2(num) => (), | --- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/borrowck-move-error-with-note.rs:12:19 - | -LL | Foo::Foo1(num1, - | ^^^^ -LL | num2) => (), - | ^^^^ -LL | Foo::Foo2(num) => (), - | ^^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0509]: cannot move out of type `S`, which implements the `Drop` trait --> $DIR/borrowck-move-error-with-note.rs:28:11 @@ -31,13 +23,7 @@ LL | f: _s, LL | g: _t | -- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/borrowck-move-error-with-note.rs:31:16 - | -LL | f: _s, - | ^^ -LL | g: _t - | ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of `a.a` which is behind a shared reference --> $DIR/borrowck-move-error-with-note.rs:46:11 diff --git a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr index 9f0670c6bc72d..8fb4c062c0363 100644 --- a/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr +++ b/src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr @@ -9,13 +9,7 @@ LL | &[Foo { string: a }, LL | Foo { string: b }] => { | - ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/borrowck-move-out-of-vec-tail.rs:21:33 - | -LL | &[Foo { string: a }, - | ^ -LL | Foo { string: b }] => { - | ^ + = note: move occurs because these variables have types that don't implement the `Copy` trait help: consider removing the `&` | LL | [Foo { string: a }, diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs index a215305f684dd..e274d105e0503 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs @@ -75,12 +75,12 @@ fn e() { match vec { //~^ ERROR cannot move out //~| NOTE cannot move out + //~| NOTE move occurs because these variables have types &mut [_a, _b, _c] => {} //~^ NOTE data moved here //~| NOTE and here //~| NOTE and here //~| HELP consider removing the `&mut` - //~| NOTE move occurs because these variables have types _ => {} } let a = vec[0]; //~ ERROR cannot move out diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr index ad5e206a9a1be..a3324f25d0bb5 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr @@ -97,11 +97,7 @@ LL | &mut [_a, _b, _c] => {} | | data moved here | help: consider removing the `&mut`: `[_a, _b, _c]` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/borrowck-vec-pattern-nesting.rs:78:15 - | -LL | &mut [_a, _b, _c] => {} - | ^^ ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0508]: cannot move out of type `[std::boxed::Box]`, a non-copy slice --> $DIR/borrowck-vec-pattern-nesting.rs:86:13 diff --git a/src/test/ui/issues/issue-12567.stderr b/src/test/ui/issues/issue-12567.stderr index 1de29dc8c6108..9d9a88f4f9b06 100644 --- a/src/test/ui/issues/issue-12567.stderr +++ b/src/test/ui/issues/issue-12567.stderr @@ -10,14 +10,7 @@ LL | => println!("one empty"), LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/issue-12567.rs:8:17 - | -LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) - | ^^ -LL | => println!("one empty"), -LL | (&[hd1, ..], &[hd2, ..]) - | ^^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0508]: cannot move out of type `[T]`, a non-copy slice --> $DIR/issue-12567.rs:4:11 @@ -31,14 +24,7 @@ LL | => println!("one empty"), LL | (&[hd1, ..], &[hd2, ..]) | --- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/issue-12567.rs:8:17 - | -LL | (&[], &[hd, ..]) | (&[hd, ..], &[]) - | ^^ -LL | => println!("one empty"), -LL | (&[hd1, ..], &[hd2, ..]) - | ^^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr index e547ec7e4754c..d0a4097de6816 100644 --- a/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr +++ b/src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr @@ -7,11 +7,7 @@ LL | let (a, b) = x[0]; | | ...and here | data moved here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/issue-40402-2.rs:5:10 - | -LL | let (a, b) = x[0]; - | ^ ^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error: aborting due to previous error diff --git a/src/test/ui/nll/move-errors.stderr b/src/test/ui/nll/move-errors.stderr index 7139617a97a4f..d4a0e45648c25 100644 --- a/src/test/ui/nll/move-errors.stderr +++ b/src/test/ui/nll/move-errors.stderr @@ -83,13 +83,7 @@ LL | B::U(d) => (), LL | B::V(s) => (), | - ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/move-errors.rs:76:14 - | -LL | B::U(d) => (), - | ^ -LL | B::V(s) => (), - | ^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0509]: cannot move out of type `D`, which implements the `Drop` trait --> $DIR/move-errors.rs:83:11 @@ -138,11 +132,7 @@ LL | F(s, mut t) => (), | | | data moved here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/move-errors.rs:104:11 - | -LL | F(s, mut t) => (), - | ^ ^^^^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of `x.0` which is behind a shared reference --> $DIR/move-errors.rs:110:11 diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr index c0b7a5a5b6250..1f1211aa198f8 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr @@ -8,11 +8,7 @@ LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); | | data moved here | help: consider removing the `&`: `(X(_t), X(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:39:13 - | -LL | let &(X(_t), X(_u)) = &(x.clone(), x.clone()); - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:43:50 @@ -24,11 +20,7 @@ LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:43:26 - | -LL | if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:47:53 @@ -40,11 +32,7 @@ LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:47:29 - | -LL | while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:51:11 @@ -60,14 +48,7 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), LL | &(Either::Two(_t), Either::One(_u)) => (), | -- ...and here -- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:53:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ -... -LL | &(Either::Two(_t), Either::One(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait help: consider removing the `&` | LL | (Either::One(_t), Either::Two(_u)) => (), @@ -90,11 +71,7 @@ LL | &(Either::One(_t), Either::Two(_u)) | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:63:23 - | -LL | &(Either::One(_t), Either::Two(_u)) - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:70:11 @@ -109,11 +86,7 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:72:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:78:11 @@ -128,11 +101,7 @@ LL | &(Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:80:23 - | -LL | &(Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:91:31 @@ -144,11 +113,7 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | | data moved here | help: consider removing the `&mut`: `(X(_t), X(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:91:17 - | -LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:95:54 @@ -160,11 +125,7 @@ LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:95:30 - | -LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:99:57 @@ -176,11 +137,7 @@ LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:99:33 - | -LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:103:11 @@ -196,14 +153,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), LL | &mut (Either::Two(_t), Either::One(_u)) => (), | -- ...and here -- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:105:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ -... -LL | &mut (Either::Two(_t), Either::One(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait help: consider removing the `&mut` | LL | (Either::One(_t), Either::Two(_u)) => (), @@ -226,11 +176,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:115:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:122:11 @@ -245,11 +191,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:124:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:130:11 @@ -264,11 +206,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:132:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:138:11 @@ -283,11 +221,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), | | data moved here | help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:140:27 - | -LL | &mut (Either::One(_t), Either::Two(_u)) => (), - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/duplicate-suggestions.rs:86:11 @@ -299,11 +233,7 @@ LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } | | data moved here | help: consider removing the `&`: `(X(_t), X(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:86:15 - | -LL | fn f5(&(X(_t), X(_u)): &(X, X)) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a mutable reference --> $DIR/duplicate-suggestions.rs:146:11 @@ -315,11 +245,7 @@ LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } | | data moved here | help: consider removing the `&mut`: `(X(_t), X(_u))` | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/duplicate-suggestions.rs:146:19 - | -LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } - | ^^ ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error: aborting due to 17 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr index cb3ce5991aeee..ac91ac43736f9 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr @@ -337,14 +337,7 @@ LL | &mut Either::One(_t) => (), LL | &mut Either::Two(_t) => (), | -- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/simple.rs:221:26 - | -LL | &mut Either::One(_t) => (), - | ^^ -... -LL | &mut Either::Two(_t) => (), - | ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait help: consider removing the `&mut` | LL | Either::One(_t) => (), @@ -470,13 +463,7 @@ LL | (&mut Either::One(_t),) => (), LL | (&mut Either::Two(_t),) => (), | -- ...and here | -note: move occurs because these variables have types that don't implement the `Copy` trait - --> $DIR/simple.rs:280:27 - | -LL | (&mut Either::One(_t),) => (), - | ^^ -LL | (&mut Either::Two(_t),) => (), - | ^^ + = note: move occurs because these variables have types that don't implement the `Copy` trait error[E0507]: cannot move out of a shared reference --> $DIR/simple.rs:288:18 From 1eeed17c9ebc5a5bcae5613cdef77a0fa17828aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:34:16 -0800 Subject: [PATCH 20/32] Tweak duplicate fmt arg error --- src/libsyntax_ext/format.rs | 3 ++- src/test/ui/if/ifmt-bad-arg.stderr | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 25daca9237fd6..0a19d64200ce7 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -172,7 +172,8 @@ fn parse_args<'a>( let e = p.parse_expr()?; if let Some(prev) = names.get(&name) { ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name)) - .span_note(args[*prev].span, "previously here") + .span_label(args[*prev].span, "previously here") + .span_label(e.span, "duplicate argument") .emit(); continue; } diff --git a/src/test/ui/if/ifmt-bad-arg.stderr b/src/test/ui/if/ifmt-bad-arg.stderr index 07917c2a540d5..c024094dd5610 100644 --- a/src/test/ui/if/ifmt-bad-arg.stderr +++ b/src/test/ui/if/ifmt-bad-arg.stderr @@ -138,13 +138,9 @@ error: duplicate argument named `foo` --> $DIR/ifmt-bad-arg.rs:40:33 | LL | format!("{foo}", foo=1, foo=2); - | ^ - | -note: previously here - --> $DIR/ifmt-bad-arg.rs:40:26 - | -LL | format!("{foo}", foo=1, foo=2); - | ^ + | - ^ duplicate argument + | | + | previously here error: positional arguments cannot follow named arguments --> $DIR/ifmt-bad-arg.rs:41:35 From 3893d16341b966df1e1a0acf80cfd00d6159057f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:34:56 -0800 Subject: [PATCH 21/32] Tweak duplicate matcher binding error --- src/libsyntax_expand/mbe/macro_check.rs | 3 +- .../macro-multiple-matcher-bindings.stderr | 40 ++++++------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/libsyntax_expand/mbe/macro_check.rs b/src/libsyntax_expand/mbe/macro_check.rs index 25754ed42177f..837e04afd3401 100644 --- a/src/libsyntax_expand/mbe/macro_check.rs +++ b/src/libsyntax_expand/mbe/macro_check.rs @@ -269,7 +269,8 @@ fn check_binders( // for nested macro definitions. sess.span_diagnostic .struct_span_err(span, "duplicate matcher binding") - .span_note(prev_info.span, "previous declaration was here") + .span_label(span, "duplicate binding") + .span_label(prev_info.span, "previous binding") .emit(); *valid = false; } else { diff --git a/src/test/ui/macros/macro-multiple-matcher-bindings.stderr b/src/test/ui/macros/macro-multiple-matcher-bindings.stderr index 65362388d7de1..3ad1297ffb2f3 100644 --- a/src/test/ui/macros/macro-multiple-matcher-bindings.stderr +++ b/src/test/ui/macros/macro-multiple-matcher-bindings.stderr @@ -2,49 +2,33 @@ error: duplicate matcher binding --> $DIR/macro-multiple-matcher-bindings.rs:7:16 | LL | ($a:ident, $a:ident) => {}; - | ^^^^^^^^ - | -note: previous declaration was here - --> $DIR/macro-multiple-matcher-bindings.rs:7:6 - | -LL | ($a:ident, $a:ident) => {}; - | ^^^^^^^^ + | -------- ^^^^^^^^ duplicate binding + | | + | previous binding error: duplicate matcher binding --> $DIR/macro-multiple-matcher-bindings.rs:8:16 | LL | ($a:ident, $a:path) => {}; - | ^^^^^^^ - | -note: previous declaration was here - --> $DIR/macro-multiple-matcher-bindings.rs:8:6 - | -LL | ($a:ident, $a:path) => {}; - | ^^^^^^^^ + | -------- ^^^^^^^ duplicate binding + | | + | previous binding error: duplicate matcher binding --> $DIR/macro-multiple-matcher-bindings.rs:17:18 | LL | ($a:ident, $($a:ident),*) => {}; - | ^^^^^^^^ - | -note: previous declaration was here - --> $DIR/macro-multiple-matcher-bindings.rs:17:6 - | -LL | ($a:ident, $($a:ident),*) => {}; - | ^^^^^^^^ + | -------- ^^^^^^^^ duplicate binding + | | + | previous binding error: duplicate matcher binding --> $DIR/macro-multiple-matcher-bindings.rs:18:25 | LL | ($($a:ident)+ # $($($a:path),+);*) => {}; - | ^^^^^^^ - | -note: previous declaration was here - --> $DIR/macro-multiple-matcher-bindings.rs:18:8 - | -LL | ($($a:ident)+ # $($($a:path),+);*) => {}; - | ^^^^^^^^ + | -------- ^^^^^^^ duplicate binding + | | + | previous binding error: aborting due to 4 previous errors From 5ef47160e84c82b86ee96f41cf40477855c2c5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:35:30 -0800 Subject: [PATCH 22/32] Tweak bad `continue` error --- src/librustc_passes/loops.rs | 4 ++-- src/test/ui/label/label_break_value_continue.stderr | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 6140d0438d8a7..50f0d66b5e3fd 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -144,8 +144,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { "`continue` pointing to a labeled block") .span_label(e.span, "labeled blocks cannot be `continue`'d") - .span_note(block.span, - "labeled block the continue points to") + .span_label(block.span, + "labeled block the `continue` points to") .emit(); } } diff --git a/src/test/ui/label/label_break_value_continue.stderr b/src/test/ui/label/label_break_value_continue.stderr index b3c0b421023ac..c5f79ed6333ee 100644 --- a/src/test/ui/label/label_break_value_continue.stderr +++ b/src/test/ui/label/label_break_value_continue.stderr @@ -7,16 +7,11 @@ LL | continue; error[E0696]: `continue` pointing to a labeled block --> $DIR/label_break_value_continue.rs:14:9 | -LL | continue 'b; - | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d - | -note: labeled block the continue points to - --> $DIR/label_break_value_continue.rs:13:5 - | LL | / 'b: { LL | | continue 'b; + | | ^^^^^^^^^^^ labeled blocks cannot be `continue`'d LL | | } - | |_____^ + | |_____- labeled block the `continue` points to error[E0695]: unlabeled `continue` inside of a labeled block --> $DIR/label_break_value_continue.rs:22:13 From 85fb054fefd1787260c72ee281ed7d436bc524f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:36:26 -0800 Subject: [PATCH 23/32] Tweak removed feature error --- src/libsyntax/feature_gate/check.rs | 5 ++--- src/test/ui/macros/macro-reexport-removed.stderr | 8 ++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index f966850254f9a..d37f48f9a4f90 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -688,10 +688,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], crate_edition: Edition, allow_features: &Option>) -> Features { fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) { let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed"); + err.span_label(span, "feature has been removed"); if let Some(reason) = reason { - err.span_note(span, reason); - } else { - err.span_label(span, "feature has been removed"); + err.note(reason); } err.emit(); } diff --git a/src/test/ui/macros/macro-reexport-removed.stderr b/src/test/ui/macros/macro-reexport-removed.stderr index 4bec70850aff7..475a586ddc083 100644 --- a/src/test/ui/macros/macro-reexport-removed.stderr +++ b/src/test/ui/macros/macro-reexport-removed.stderr @@ -2,13 +2,9 @@ error[E0557]: feature has been removed --> $DIR/macro-reexport-removed.rs:3:12 | LL | #![feature(macro_reexport)] - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ feature has been removed | -note: subsumed by `pub use` - --> $DIR/macro-reexport-removed.rs:3:12 - | -LL | #![feature(macro_reexport)] - | ^^^^^^^^^^^^^^ + = note: subsumed by `pub use` error: cannot find attribute `macro_reexport` in this scope --> $DIR/macro-reexport-removed.rs:5:3 From 5ea922aec4a66458728fbe74a6e8096ab76f9aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 25 Nov 2019 12:37:07 -0800 Subject: [PATCH 24/32] Various cleanups --- .../borrow_check/conflict_errors.rs | 18 ++++++------------ src/librustc_parse/parser/item.rs | 17 +++++++++++------ src/librustc_resolve/resolve_imports.rs | 6 ++++-- src/libsyntax_ext/proc_macro_harness.rs | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index ebc25138a0619..b78d3475a413c 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -1256,23 +1256,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Applicability::MachineApplicable, ); - match category { - ConstraintCategory::Return => { - err.span_note(constraint_span, "closure is returned here"); - } - ConstraintCategory::OpaqueType => { - err.span_note(constraint_span, "generator is returned here"); - } + let msg = match category { + ConstraintCategory::Return => "closure is returned here".to_string(), + ConstraintCategory::OpaqueType => "generator is returned here".to_string(), ConstraintCategory::CallArgument => { fr_name.highlight_region_name(&mut err); - err.span_note( - constraint_span, - &format!("function requires argument type to outlive `{}`", fr_name), - ); + format!("function requires argument type to outlive `{}`", fr_name) } _ => bug!("report_escaping_closure_capture called with unexpected constraint \ category: `{:?}`", category), - } + }; + err.span_note(constraint_span, &msg); err } diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 20b96d5cd62f6..199125125c64e 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -490,9 +490,12 @@ impl<'a> Parser<'a> { } /// Parses a macro invocation inside a `trait`, `impl` or `extern` block. - fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>, - at_end: &mut bool) -> PResult<'a, Option> - { + fn parse_assoc_macro_invoc( + &mut self, + item_kind: &str, + vis: Option<&Visibility>, + at_end: &mut bool, + ) -> PResult<'a, Option> { if self.token.is_path_start() && !(self.is_async_fn() && self.token.span.rust_2015()) { let prev_span = self.prev_span; @@ -531,9 +534,11 @@ impl<'a> Parser<'a> { } } - fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span) - -> DiagnosticBuilder<'a> - { + fn missing_assoc_item_kind_err( + &self, + item_type: &str, + prev_span: Span, + ) -> DiagnosticBuilder<'a> { let expected_kinds = if item_type == "extern" { "missing `fn`, `type`, or `static`" } else { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 5c8e79096312f..3ad53737f4969 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -1160,8 +1160,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> { .emit(); } else { let msg = format!("`{}` is private, and cannot be re-exported", ident); - let note_msg = - format!("consider marking `{}` as `pub` in the imported module", ident); + let note_msg = format!( + "consider marking `{}` as `pub` in the imported module", + ident, + ); struct_span_err!(self.r.session, directive.span, E0364, "{}", &msg) .span_note(directive.span, ¬e_msg) .emit(); diff --git a/src/libsyntax_ext/proc_macro_harness.rs b/src/libsyntax_ext/proc_macro_harness.rs index fbded7dc130eb..604400c3cc2ff 100644 --- a/src/libsyntax_ext/proc_macro_harness.rs +++ b/src/libsyntax_ext/proc_macro_harness.rs @@ -270,7 +270,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> { }; self.handler.struct_span_err(attr.span, &msg) - .span_note(prev_attr.span, "previous attribute here") + .span_label(prev_attr.span, "previous attribute here") .emit(); return; From 395408ec18eeedc458746af24e4b3614fc822f46 Mon Sep 17 00:00:00 2001 From: Parth Mehrotra Date: Mon, 25 Nov 2019 19:34:32 -0500 Subject: [PATCH 25/32] Update documentation-tests.md --- src/doc/rustdoc/src/documentation-tests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index bc1da5ff15a8c..96fa4344b04b7 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -1,7 +1,7 @@ # Documentation tests `rustdoc` supports executing your documentation examples as tests. This makes sure -that your tests are up to date and working. +that examples within your documentation are up to date and working. The basic idea is this: From 37f440fd9a3d6c79647549bf559d2c19712b83d9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 25 Nov 2019 19:44:35 -0500 Subject: [PATCH 26/32] Add wildcard test for const_if_match Closes https://github.com/rust-lang/rust/issues/66758 --- .../control-flow/single-arm-match-wild.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/ui/consts/control-flow/single-arm-match-wild.rs diff --git a/src/test/ui/consts/control-flow/single-arm-match-wild.rs b/src/test/ui/consts/control-flow/single-arm-match-wild.rs new file mode 100644 index 0000000000000..59a42bb05caf0 --- /dev/null +++ b/src/test/ui/consts/control-flow/single-arm-match-wild.rs @@ -0,0 +1,19 @@ +// check-pass + +#![feature(const_if_match)] + +enum E { + A, + B, + C +} + +const fn f(e: E) -> usize { + match e { + _ => 0 + } +} + +fn main() { + assert_eq!(f(E::A), 0); +} From 55d725884b1fb62cbec038d8633bd40c39cc896f Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Tue, 26 Nov 2019 22:55:01 +0800 Subject: [PATCH 27/32] follow the same function order in the trait This removes several warnings in IDE. --- src/libcore/cmp.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index eb5121dd0e081..eea3dc39d345e 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -464,9 +464,9 @@ impl PartialOrd for Reverse { #[inline] fn le(&self, other: &Self) -> bool { other.0 <= self.0 } #[inline] - fn ge(&self, other: &Self) -> bool { other.0 >= self.0 } - #[inline] fn gt(&self, other: &Self) -> bool { other.0 > self.0 } + #[inline] + fn ge(&self, other: &Self) -> bool { other.0 >= self.0 } } #[stable(feature = "reverse_cmp_key", since = "1.19.0")] @@ -1176,9 +1176,9 @@ mod impls { #[inline] fn le(&self, other: & &B) -> bool { PartialOrd::le(*self, *other) } #[inline] - fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) } - #[inline] fn gt(&self, other: & &B) -> bool { PartialOrd::gt(*self, *other) } + #[inline] + fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) } } #[stable(feature = "rust1", since = "1.0.0")] impl Ord for &A where A: Ord { @@ -1208,9 +1208,9 @@ mod impls { #[inline] fn le(&self, other: &&mut B) -> bool { PartialOrd::le(*self, *other) } #[inline] - fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) } - #[inline] fn gt(&self, other: &&mut B) -> bool { PartialOrd::gt(*self, *other) } + #[inline] + fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) } } #[stable(feature = "rust1", since = "1.0.0")] impl Ord for &mut A where A: Ord { From f1f83ef8f84c15ab5292cd2dbbb0c7b0f14cbc1e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 26 Nov 2019 12:37:55 -0500 Subject: [PATCH 28/32] Test multiple variants Co-Authored-By: Mazdak Farrokhzad --- src/test/ui/consts/control-flow/single-arm-match-wild.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/ui/consts/control-flow/single-arm-match-wild.rs b/src/test/ui/consts/control-flow/single-arm-match-wild.rs index 59a42bb05caf0..fba6e3583cc29 100644 --- a/src/test/ui/consts/control-flow/single-arm-match-wild.rs +++ b/src/test/ui/consts/control-flow/single-arm-match-wild.rs @@ -15,5 +15,7 @@ const fn f(e: E) -> usize { } fn main() { + const X: usize = f(E::C); + assert_eq!(X, 0); assert_eq!(f(E::A), 0); } From 2626cfbb586800144e0fde579849f4afc813d5ff Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 11:36:53 -0800 Subject: [PATCH 29/32] Allow `Unreachable` terminators behind `const_if_match` --- src/librustc_mir/transform/qualify_min_const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 71f13c169d41e..81f4c277f4d76 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -337,6 +337,9 @@ fn check_terminator( check_operand(tcx, discr, span, def_id, body) } + // FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally. + TerminatorKind::Unreachable if tcx.features().const_if_match => Ok(()), + | TerminatorKind::Abort | TerminatorKind::Unreachable => { Err((span, "const fn with unreachable code is not stable".into())) } From 582affd657701aa8fff42b9e0eb32d23796167b5 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 11:37:16 -0800 Subject: [PATCH 30/32] Add regression test for #66756 --- .../exhaustive-c-like-enum-match.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs new file mode 100644 index 0000000000000..d24179d856f46 --- /dev/null +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -0,0 +1,27 @@ +// Test for + +// check-pass + +#![feature(const_if_match)] + +enum E { + A, + B, + C +} + +const fn f(e: E) { + match e { + E::A => {} + E::B => {} + E::C => {} + } +} + +const fn g(e: E) { + match e { + _ => {} + } +} + +fn main() {} From 2299586ffc3b635c4bb90c15cd0ad92e1ea3128d Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 24 Nov 2019 16:59:56 -0500 Subject: [PATCH 31/32] Move ErrorReported to rustc_errors --- src/librustc/util/common.rs | 6 +----- src/librustc_errors/lib.rs | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 3e52a6aa50850..8581a5b220ac6 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -7,7 +7,6 @@ use std::fmt::Debug; use std::time::{Duration, Instant}; use syntax::symbol::{Symbol, sym}; -use rustc_macros::HashStable; use crate::session::Session; #[cfg(test)] @@ -16,10 +15,7 @@ mod tests; // The name of the associated type for `Fn` return types. pub const FN_OUTPUT_NAME: Symbol = sym::Output; -// Useful type to use with `Result<>` indicate that an error has already -// been reported to the user, so no need to continue checking. -#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, HashStable)] -pub struct ErrorReported; +pub use errors::ErrorReported; thread_local!(static TIME_DEPTH: Cell = Cell::new(0)); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 8a1799faaf8ee..ae5876848185b 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -993,3 +993,10 @@ macro_rules! pluralize { if $x != 1 { "s" } else { "" } }; } + +// Useful type to use with `Result<>` indicate that an error has already +// been reported to the user, so no need to continue checking. +#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, Hash, PartialEq, Eq)] +pub struct ErrorReported; + +rustc_data_structures::impl_stable_hash_via_hash!(ErrorReported); From a626bf68b882d41dc608692dc52b2a9fb06bff26 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 26 Nov 2019 12:13:15 -0800 Subject: [PATCH 32/32] Remove test for #66758 --- .../ui/consts/control-flow/exhaustive-c-like-enum-match.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs index d24179d856f46..9e22151f2e9ee 100644 --- a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs +++ b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs @@ -18,10 +18,4 @@ const fn f(e: E) { } } -const fn g(e: E) { - match e { - _ => {} - } -} - fn main() {}