From 8731d4dfb479914a91f650f4f124528e332e8128 Mon Sep 17 00:00:00 2001 From: Michael Lamparski Date: Sat, 19 Jun 2021 15:50:29 -0400 Subject: [PATCH 001/181] Automatic exponential formatting in Debug * {:.PREC?} already had legitimately useful behavior (recursive formatting of structs using fixed precision for floats) and I suspect that changes to the output there would be unwelcome. (besides, precision introduces sinister edge cases where a number can be rounded up to one of the thresholds) Thus, the new behavior of Debug is, "dynamically switch to exponential, but only if there's no precision." * This could not be implemented in terms of float_to_decimal_common without repeating the branch on precision, so 'float_to_general_debug' is a new function. The name is '_debug' instead of '_common' because the considerations in the previous bullet make this logic pretty specific to Debug. * 'float_to_decimal_common' is now only used by Display, so I inlined the min_precision argument and renamed the function accordingly. --- library/core/src/fmt/float.rs | 53 ++++++++++++++++++++++++++++++--- library/core/src/num/f32.rs | 2 +- library/core/src/num/f64.rs | 2 +- library/core/tests/fmt/float.rs | 24 +++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/library/core/src/fmt/float.rs b/library/core/src/fmt/float.rs index ece3cde001580..9ddd6c96b9642 100644 --- a/library/core/src/fmt/float.rs +++ b/library/core/src/fmt/float.rs @@ -2,6 +2,26 @@ use crate::fmt::{Debug, Display, Formatter, LowerExp, Result, UpperExp}; use crate::mem::MaybeUninit; use crate::num::flt2dec; +#[doc(hidden)] +trait GeneralFormat: PartialOrd { + /// Determines if a value should use exponential based on its magnitude, given the precondition + /// that it will not be rounded any further before it is displayed. + fn already_rounded_value_should_use_exponential(&self) -> bool; +} + +macro_rules! impl_general_format { + ($($t:ident)*) => { + $(impl GeneralFormat for $t { + fn already_rounded_value_should_use_exponential(&self) -> bool { + let abs = $t::abs_private(*self); + (abs != 0.0 && abs < 1e-4) || abs >= 1e+16 + } + })* + } +} + +impl_general_format! { f32 f64 } + // Don't inline this so callers don't use the stack space this function // requires unless they have to. #[inline(never)] @@ -53,8 +73,7 @@ where fmt.pad_formatted_parts(&formatted) } -// Common code of floating point Debug and Display. -fn float_to_decimal_common(fmt: &mut Formatter<'_>, num: &T, min_precision: usize) -> Result +fn float_to_decimal_display(fmt: &mut Formatter<'_>, num: &T) -> Result where T: flt2dec::DecodableFloat, { @@ -67,6 +86,7 @@ where if let Some(precision) = fmt.precision { float_to_decimal_common_exact(fmt, num, sign, precision) } else { + let min_precision = 0; float_to_decimal_common_shortest(fmt, num, sign, min_precision) } } @@ -144,19 +164,44 @@ where } } +fn float_to_general_debug(fmt: &mut Formatter<'_>, num: &T) -> Result +where + T: flt2dec::DecodableFloat + GeneralFormat, +{ + let force_sign = fmt.sign_plus(); + let sign = match force_sign { + false => flt2dec::Sign::Minus, + true => flt2dec::Sign::MinusPlus, + }; + + if let Some(precision) = fmt.precision { + // this behavior of {:.PREC?} predates exponential formatting for {:?} + float_to_decimal_common_exact(fmt, num, sign, precision) + } else { + // since there is no precision, there will be no rounding + if num.already_rounded_value_should_use_exponential() { + let upper = false; + float_to_exponential_common_shortest(fmt, num, sign, upper) + } else { + let min_precision = 1; + float_to_decimal_common_shortest(fmt, num, sign, min_precision) + } + } +} + macro_rules! floating { ($ty:ident) => { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for $ty { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { - float_to_decimal_common(fmt, self, 1) + float_to_general_debug(fmt, self) } } #[stable(feature = "rust1", since = "1.0.0")] impl Display for $ty { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { - float_to_decimal_common(fmt, self, 0) + float_to_decimal_display(fmt, self) } } diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index c47a2e8b05c4b..4104d48b4a2db 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -448,7 +448,7 @@ impl f32 { // private use internally. #[inline] #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] - const fn abs_private(self) -> f32 { + pub(crate) const fn abs_private(self) -> f32 { f32::from_bits(self.to_bits() & 0x7fff_ffff) } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index cfcc08b9addeb..8a8fbae1941c3 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -447,7 +447,7 @@ impl f64 { // private use internally. #[inline] #[rustc_const_unstable(feature = "const_float_classify", issue = "72505")] - const fn abs_private(self) -> f64 { + pub(crate) const fn abs_private(self) -> f64 { f64::from_bits(self.to_bits() & 0x7fff_ffff_ffff_ffff) } diff --git a/library/core/tests/fmt/float.rs b/library/core/tests/fmt/float.rs index bd0daf7a8eb84..47a7400f76ef9 100644 --- a/library/core/tests/fmt/float.rs +++ b/library/core/tests/fmt/float.rs @@ -12,6 +12,16 @@ fn test_format_f64() { assert_eq!("1.23456789E3", format!("{:E}", 1234.56789f64)); assert_eq!("0.0", format!("{:?}", 0.0f64)); assert_eq!("1.01", format!("{:?}", 1.01f64)); + + let high_cutoff = 1e16_f64; + assert_eq!("1e16", format!("{:?}", high_cutoff)); + assert_eq!("-1e16", format!("{:?}", -high_cutoff)); + assert!(!is_exponential(&format!("{:?}", high_cutoff * (1.0 - 2.0 * f64::EPSILON)))); + assert_eq!("-3.0", format!("{:?}", -3f64)); + assert_eq!("0.0001", format!("{:?}", 0.0001f64)); + assert_eq!("9e-5", format!("{:?}", 0.00009f64)); + assert_eq!("1234567.9", format!("{:.1?}", 1234567.89f64)); + assert_eq!("1234.6", format!("{:.1?}", 1234.56789f64)); } #[test] @@ -28,4 +38,18 @@ fn test_format_f32() { assert_eq!("1.2345679E3", format!("{:E}", 1234.56789f32)); assert_eq!("0.0", format!("{:?}", 0.0f32)); assert_eq!("1.01", format!("{:?}", 1.01f32)); + + let high_cutoff = 1e16_f32; + assert_eq!("1e16", format!("{:?}", high_cutoff)); + assert_eq!("-1e16", format!("{:?}", -high_cutoff)); + assert!(!is_exponential(&format!("{:?}", high_cutoff * (1.0 - 2.0 * f32::EPSILON)))); + assert_eq!("-3.0", format!("{:?}", -3f32)); + assert_eq!("0.0001", format!("{:?}", 0.0001f32)); + assert_eq!("9e-5", format!("{:?}", 0.00009f32)); + assert_eq!("1234567.9", format!("{:.1?}", 1234567.89f32)); + assert_eq!("1234.6", format!("{:.1?}", 1234.56789f32)); +} + +fn is_exponential(s: &str) -> bool { + s.contains("e") || s.contains("E") } From a333b91e5b252eba2d3dee10454c386582bf75ba Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Sat, 4 Sep 2021 15:25:55 -0500 Subject: [PATCH 002/181] linux/aarch64 Now() should be actually_monotonic() While issues have been seen on arm64 platforms the Arm architecture requires that the counter monotonically increases and that it must provide a uniform view of system time (e.g. it must not be possible for a core to receive a message from another core with a time stamp and observe time going backwards (ARM DDI 0487G.b D11.1.2). While there have been a few 64bit SoCs that have bugs (#49281, #56940) which cause time to not monotonically increase, these have been fixed in the Linux kernel and we shouldn't penalize all Arm SoCs for those who refuse to update their kernels: SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 255a3f3e183 std: Force `Instant::now()` to be monotonic added a mutex to work around this problem and a small test program using glommio shows the majority of time spent acquiring and releasing this Mutex. 3914a7b0da8 tries to improve this, but actually makes it worse on big systems as for 128b atomics a ldxp/stxp pair (and successful loop) is required which is expensive as a lock and because of how the load/store-exclusives scale on large Arm systems is both unfair to threads and tends to go backwards in performance. --- library/std/src/sys/unix/time.rs | 1 + library/std/src/time.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 7dc09add27fd7..824283ef6c41e 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -303,6 +303,7 @@ mod inner { pub fn actually_monotonic() -> bool { (cfg!(target_os = "linux") && cfg!(target_arch = "x86_64")) || (cfg!(target_os = "linux") && cfg!(target_arch = "x86")) + || (cfg!(target_os = "linux") && cfg!(target_arch = "aarch64")) || cfg!(target_os = "fuchsia") } diff --git a/library/std/src/time.rs b/library/std/src/time.rs index e9207ee36171b..5e2ce6d3f463b 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -263,6 +263,20 @@ impl Instant { // // To hopefully mitigate the impact of this, a few platforms are // excluded as "these at least haven't gone backwards yet". + // + // While issues have been seen on arm64 platforms the Arm architecture + // requires that the counter monotonically increases and that it must + // provide a uniform view of system time (e.g. it must not be possible + // for a core to recieve a message from another core with a time stamp + // and observe time going backwards (ARM DDI 0487G.b D11.1.2). While + // there have been a few 64bit SoCs that have bugs which cause time to + // not monoticially increase, these have been fixed in the Linux kernel + // and we shouldn't penalize all Arm SoCs for those who refuse to + // update their kernels: + // SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 + // FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 + // HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 + // ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 if time::Instant::actually_monotonic() { return Instant(os_now); } From a456a55feaee9cdda257f80720c09a5dc731e5d4 Mon Sep 17 00:00:00 2001 From: tabokie Date: Tue, 7 Sep 2021 18:44:10 +0800 Subject: [PATCH 003/181] Optimize VecDeque::append Signed-off-by: tabokie --- .../alloc/src/collections/vec_deque/mod.rs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e4b28204158d9..e702ddb3f2ae6 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -417,6 +417,26 @@ impl VecDeque { } } + /// Append all values from `src` to `self`, wrapping around if needed. + /// Assumes capacity is sufficient. + #[inline] + unsafe fn append_slice(&mut self, src: &[T]) { + debug_assert!(self.len() + src.len() + 1 <= self.cap()); + let head_room = self.cap() - self.head; + if self.head < self.tail || src.len() <= head_room { + unsafe { + ptr::copy_nonoverlapping(src.as_ptr(), self.ptr().add(self.head), src.len()); + } + } else { + let (left, right) = src.split_at(head_room); + unsafe { + ptr::copy_nonoverlapping(left.as_ptr(), self.ptr().add(self.head), left.len()); + ptr::copy_nonoverlapping(right.as_ptr(), self.ptr(), right.len()); + } + } + self.head = self.wrap_add(self.head, src.len()); + } + /// Frobs the head and tail sections around to handle the fact that we /// just reallocated. Unsafe because it trusts old_capacity. #[inline] @@ -2088,8 +2108,14 @@ impl VecDeque { #[inline] #[stable(feature = "append", since = "1.4.0")] pub fn append(&mut self, other: &mut Self) { - // naive impl - self.extend(other.drain(..)); + self.reserve(other.len()); + unsafe { + let (left, right) = other.as_slices(); + self.append_slice(left); + self.append_slice(right); + } + // Silently drop values in `other`. + other.tail = other.head; } /// Retains only the elements specified by the predicate. From a929e6070777279ab326abd27efdc724afecd334 Mon Sep 17 00:00:00 2001 From: tabokie Date: Wed, 8 Sep 2021 11:46:20 +0800 Subject: [PATCH 004/181] rearrange to be panic safe Signed-off-by: tabokie --- .../alloc/src/collections/vec_deque/mod.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e702ddb3f2ae6..f703efd6fbe97 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -417,24 +417,23 @@ impl VecDeque { } } - /// Append all values from `src` to `self`, wrapping around if needed. + /// Append all values from `src` to `dst`, wrapping around if needed. /// Assumes capacity is sufficient. #[inline] - unsafe fn append_slice(&mut self, src: &[T]) { - debug_assert!(self.len() + src.len() + 1 <= self.cap()); - let head_room = self.cap() - self.head; - if self.head < self.tail || src.len() <= head_room { + unsafe fn copy_slice(&mut self, dst: usize, src: &[T]) { + debug_assert!(src.len() <= self.cap()); + let head_room = self.cap() - dst; + if src.len() <= head_room { unsafe { - ptr::copy_nonoverlapping(src.as_ptr(), self.ptr().add(self.head), src.len()); + ptr::copy_nonoverlapping(src.as_ptr(), self.ptr().add(dst), src.len()); } } else { let (left, right) = src.split_at(head_room); unsafe { - ptr::copy_nonoverlapping(left.as_ptr(), self.ptr().add(self.head), left.len()); + ptr::copy_nonoverlapping(left.as_ptr(), self.ptr().add(dst), left.len()); ptr::copy_nonoverlapping(right.as_ptr(), self.ptr(), right.len()); } } - self.head = self.wrap_add(self.head, src.len()); } /// Frobs the head and tail sections around to handle the fact that we @@ -2111,9 +2110,12 @@ impl VecDeque { self.reserve(other.len()); unsafe { let (left, right) = other.as_slices(); - self.append_slice(left); - self.append_slice(right); + self.copy_slice(self.head, left); + self.copy_slice(self.wrap_add(self.head, left.len()), right); } + // SAFETY: Update pointers after copying to avoid leaving doppelganger + // in case of panics. + self.head = self.wrap_add(self.head, other.len()); // Silently drop values in `other`. other.tail = other.head; } From 4b743bfef0c0cc20df47b7ae04c162a20f1a70d7 Mon Sep 17 00:00:00 2001 From: The8472 Date: Thu, 9 Sep 2021 20:20:27 +0200 Subject: [PATCH 005/181] remove unnecessary bound on Zip specialization impl I originally added this bound in an attempt to make the specialization sound for owning iterators but it was never correct here and the correct and already implemented solution is is to place it on the IntoIter implementation. --- library/core/src/iter/adapters/zip.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/library/core/src/iter/adapters/zip.rs b/library/core/src/iter/adapters/zip.rs index 17697fa0e045a..78f640624ceef 100644 --- a/library/core/src/iter/adapters/zip.rs +++ b/library/core/src/iter/adapters/zip.rs @@ -429,13 +429,9 @@ where } } +// Since SourceIter forwards the left hand side we do the same here #[unstable(issue = "none", feature = "inplace_iteration")] -// Limited to Item: Copy since interaction between Zip's use of TrustedRandomAccess -// and Drop implementation of the source is unclear. -// -// An additional method returning the number of times the source has been logically advanced -// (without calling next()) would be needed to properly drop the remainder of the source. -unsafe impl InPlaceIterable for Zip where A::Item: Copy {} +unsafe impl InPlaceIterable for Zip {} #[stable(feature = "rust1", since = "1.0.0")] impl Debug for Zip { From 58b1a127d66b71e1a2180b509856f2c52feca9b3 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 28 Sep 2021 13:03:31 -0700 Subject: [PATCH 006/181] Avoid allocations and copying in Vec::leak Don't shrink the Vec (by calling into_boxed_slice) before leaking it. --- library/alloc/src/vec/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index c37ec37556157..a8b939bc249e0 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1976,7 +1976,8 @@ impl Vec { where A: 'a, { - Box::leak(self.into_boxed_slice()) + let mut me = ManuallyDrop::new(self); + unsafe { slice::from_raw_parts_mut(me.as_mut_ptr(), me.len) } } /// Returns the remaining spare capacity of the vector as a slice of From 1fca2ce9010a581798fa39d1742eddcaada359ad Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 28 Sep 2021 16:27:47 -0700 Subject: [PATCH 007/181] Additional docs about Vec::leak behavior --- library/alloc/src/vec/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a8b939bc249e0..30cd95d695989 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1952,8 +1952,11 @@ impl Vec { /// `'a`. If the type has only static references, or none at all, then this /// may be chosen to be `'static`. /// - /// This function is similar to the [`leak`][Box::leak] function on [`Box`] - /// except that there is no way to recover the leaked memory. + /// This method does not reallocate or shrink the `Vec`, so the leaked + /// allocation may include unused capacity that is not part of the returned + /// slice. Unsafe code that later reconstructs or deallocates the `Vec` + /// (for example, by calling [`Vec::from_raw_parts`]) must keep track of the + /// original capacity. /// /// This function is mainly useful for data that lives for the remainder of /// the program's life. Dropping the returned reference will cause a memory From 273e522af6c7b28704688b2a7b8b423c7472fb3c Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Fri, 1 Oct 2021 08:37:39 -0700 Subject: [PATCH 008/181] Fix ctrl-c causing reads of stdin to return empty on Windows. Fixes #89177 --- library/std/src/sys/windows/stdio.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/library/std/src/sys/windows/stdio.rs b/library/std/src/sys/windows/stdio.rs index 2719a530dfd41..a4fe5f67f699a 100644 --- a/library/std/src/sys/windows/stdio.rs +++ b/library/std/src/sys/windows/stdio.rs @@ -291,15 +291,25 @@ fn read_u16s(handle: c::HANDLE, buf: &mut [u16]) -> io::Result { }; let mut amount = 0; - cvt(unsafe { - c::ReadConsoleW( - handle, - buf.as_mut_ptr() as c::LPVOID, - buf.len() as u32, - &mut amount, - &mut input_control as c::PCONSOLE_READCONSOLE_CONTROL, - ) - })?; + loop { + cvt(unsafe { + c::SetLastError(0); + c::ReadConsoleW( + handle, + buf.as_mut_ptr() as c::LPVOID, + buf.len() as u32, + &mut amount, + &mut input_control as c::PCONSOLE_READCONSOLE_CONTROL, + ) + })?; + + // ReadConsoleW returns success with ERROR_OPERATION_ABORTED for Ctrl-C or Ctrl-Break. + // Explicitly check for that case here and try again. + if amount == 0 && unsafe { c::GetLastError() } == c::ERROR_OPERATION_ABORTED { + continue; + } + break; + } if amount > 0 && buf[amount as usize - 1] == CTRL_Z { amount -= 1; From 50433a0bf4a1d75f4d68c7d7b0acf5a75522421b Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 1 Oct 2021 14:40:42 +0000 Subject: [PATCH 009/181] polymorphize: don't check foreign items Foreign items do not have bodies and so cannot be polymorphized. Signed-off-by: David Wood --- compiler/rustc_monomorphize/src/polymorphize.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 0f768b7819b5b..b5a1a1a74c845 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -52,6 +52,11 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { return FiniteBitSet::new_empty(); } + // Exit early for foreign items, these have no bodies to analyze. + if tcx.is_foreign_item(def_id) { + return FiniteBitSet::new_empty(); + } + // Exit early when there is no MIR available. let context = tcx.hir().body_const_context(def_id.expect_local()); match context { From da2b69b6142725586a41d6db751921043a1786af Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 20 Aug 2020 11:42:56 +0100 Subject: [PATCH 010/181] polymorphize: remove predicate logic This commit removes all logic which marks parameters as used based on their presence in predicates - given rust-lang/rust#75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped. Signed-off-by: David Wood --- .../rustc_monomorphize/src/polymorphize.rs | 41 ------------------- src/test/ui/polymorphization/predicates.rs | 5 +++ .../ui/polymorphization/predicates.stderr | 39 +++++++++++++++++- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index b5a1a1a74c845..bb04f91e5acaa 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -89,9 +89,6 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { }; let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters }; vis.visit_body(body); - debug!(?unused_parameters, "(after visitor)"); - - mark_used_by_predicates(tcx, def_id, &mut unused_parameters); debug!(?unused_parameters, "(end)"); // Emit errors for debugging and testing if enabled. @@ -161,44 +158,6 @@ fn mark_used_by_default_parameters<'tcx>( } } -/// Search the predicates on used generic parameters for any unused generic parameters, and mark -/// those as used. -#[instrument(level = "debug", skip(tcx, def_id))] -fn mark_used_by_predicates<'tcx>( - tcx: TyCtxt<'tcx>, - def_id: DefId, - unused_parameters: &mut FiniteBitSet, -) { - let def_id = tcx.closure_base_def_id(def_id); - let predicates = tcx.explicit_predicates_of(def_id); - - let mut current_unused_parameters = FiniteBitSet::new_empty(); - // Run to a fixed point to support `where T: Trait, U: Trait`, starting with an empty - // bit set so that this is skipped if all parameters are already used. - while current_unused_parameters != *unused_parameters { - debug!(?current_unused_parameters, ?unused_parameters); - current_unused_parameters = *unused_parameters; - - for (predicate, _) in predicates.predicates { - // Consider all generic params in a predicate as used if any other parameter in the - // predicate is used. - let any_param_used = { - let mut vis = HasUsedGenericParams { tcx, unused_parameters }; - predicate.visit_with(&mut vis).is_break() - }; - - if any_param_used { - let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters }; - predicate.visit_with(&mut vis); - } - } - } - - if let Some(parent) = predicates.parent { - mark_used_by_predicates(tcx, parent, unused_parameters); - } -} - /// Emit errors for the function annotated by `#[rustc_polymorphize_error]`, labelling each generic /// parameter which was unused. #[instrument(level = "debug", skip(tcx, generics))] diff --git a/src/test/ui/polymorphization/predicates.rs b/src/test/ui/polymorphization/predicates.rs index 97f1ef2c90ae0..dea1e21e77fe3 100644 --- a/src/test/ui/polymorphization/predicates.rs +++ b/src/test/ui/polymorphization/predicates.rs @@ -12,6 +12,7 @@ fn bar() { #[rustc_polymorphize_error] fn foo(_: I) +//~^ ERROR item has unused generic parameters where I: Iterator, { @@ -20,6 +21,7 @@ where #[rustc_polymorphize_error] fn baz(_: I) +//~^ ERROR item has unused generic parameters where std::iter::Repeat: Iterator, { @@ -40,6 +42,7 @@ where #[rustc_polymorphize_error] fn next(&mut self) -> Option { self.find(|_| true) + //~^ ERROR item has unused generic parameters } } @@ -53,6 +56,7 @@ impl Baz for u16 {} #[rustc_polymorphize_error] fn quux() -> usize +//~^ ERROR item has unused generic parameters where A: Baz, B: Baz, @@ -69,6 +73,7 @@ impl Foobar for () {} #[rustc_polymorphize_error] fn foobar() -> usize +//~^ ERROR item has unused generic parameters where (): Foobar, { diff --git a/src/test/ui/polymorphization/predicates.stderr b/src/test/ui/polymorphization/predicates.stderr index c23730fc995e7..5fc51e58d728a 100644 --- a/src/test/ui/polymorphization/predicates.stderr +++ b/src/test/ui/polymorphization/predicates.stderr @@ -1,8 +1,45 @@ +error: item has unused generic parameters + --> $DIR/predicates.rs:14:4 + | +LL | fn foo(_: I) + | ^^^ - generic parameter `T` is unused + +error: item has unused generic parameters + --> $DIR/predicates.rs:23:4 + | +LL | fn baz(_: I) + | ^^^ - generic parameter `T` is unused + +error: item has unused generic parameters + --> $DIR/predicates.rs:44:19 + | +LL | impl<'a, I, T: 'a, E> Iterator for Foo<'a, I, E> + | - - generic parameter `E` is unused + | | + | generic parameter `I` is unused +... +LL | self.find(|_| true) + | ^^^^^^^^ + +error: item has unused generic parameters + --> $DIR/predicates.rs:58:4 + | +LL | fn quux() -> usize + | ^^^^ - - generic parameter `B` is unused + | | + | generic parameter `A` is unused + +error: item has unused generic parameters + --> $DIR/predicates.rs:75:4 + | +LL | fn foobar() -> usize + | ^^^^^^ - generic parameter `F` is unused + error: item has unused generic parameters --> $DIR/predicates.rs:9:4 | LL | fn bar() { | ^^^ - generic parameter `I` is unused -error: aborting due to previous error +error: aborting due to 6 previous errors From 4528b8e581eb1bb24f4f264d43244d7912f812f7 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 1 Oct 2021 16:23:07 +0000 Subject: [PATCH 011/181] collector: limit pme context note to user-defd fns rustc adds notes to errors which happen post-monomorphization to provide the user with helpful context (as these errors may rely on the specific instantiations). To prevent this note being added where it is not appropriate, the node is checked to originate outwith the current crate. However, when polymorphization is enabled, this can result in some errors (produced by `optimized_mir`) to occur earlier in compilation than they normally would, during the collection of shims. Some shims have ids that originate in the standard library, but these should not receive the PME note, so instances for compiler-generated functions no longer receive this note. Signed-off-by: David Wood --- compiler/rustc_middle/src/mir/mono.rs | 8 ++++++++ compiler/rustc_monomorphize/src/collector.rs | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 776cf002c1703..1c0b274f0631b 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -47,6 +47,14 @@ pub enum MonoItem<'tcx> { } impl<'tcx> MonoItem<'tcx> { + /// Returns `true` if the mono item is user-defined (i.e. not compiler-generated, like shims). + pub fn is_user_defined(&self) -> bool { + match *self { + MonoItem::Fn(instance) => matches!(instance.def, InstanceDef::Item(..)), + MonoItem::Static(..) | MonoItem::GlobalAsm(..) => true, + } + } + pub fn size_estimate(&self, tcx: TyCtxt<'tcx>) -> usize { match *self { MonoItem::Fn(instance) => { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 1e39b1bd5e80e..5ccf8997d28ce 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -450,7 +450,9 @@ fn collect_items_rec<'tcx>( // involving a dependency, and the lack of context is confusing) in this MVP, we focus on // diagnostics on edges crossing a crate boundary: the collected mono items which are not // defined in the local crate. - if tcx.sess.diagnostic().err_count() > error_count && starting_point.node.krate() != LOCAL_CRATE + if tcx.sess.diagnostic().err_count() > error_count + && starting_point.node.krate() != LOCAL_CRATE + && starting_point.node.is_user_defined() { let formatted_item = with_no_trimmed_paths(|| starting_point.node.to_string()); tcx.sess.span_note_without_error( From 76b05531cab9bc24a54791b46b5bb9a7c3dcdd7c Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 1 Oct 2021 17:08:06 +0000 Subject: [PATCH 012/181] polymorphize: polymorphize shims This commit removes the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. Signed-off-by: David Wood --- .../rustc_const_eval/src/interpret/util.rs | 3 +- .../src/rmeta/decoder/cstore_impl.rs | 6 ++ compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +- compiler/rustc_middle/src/query/mod.rs | 6 +- compiler/rustc_middle/src/ty/instance.rs | 45 +++++++--- compiler/rustc_monomorphize/src/collector.rs | 20 ++--- .../rustc_monomorphize/src/polymorphize.rs | 89 ++++++++++++------- 7 files changed, 112 insertions(+), 61 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index eb0fdebb665fa..a16388d5de219 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -35,7 +35,8 @@ where ty::Closure(def_id, substs) | ty::Generator(def_id, substs, ..) | ty::FnDef(def_id, substs) => { - let unused_params = self.tcx.unused_generic_params(def_id); + let instance = ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)); + let unused_params = self.tcx.unused_generic_params(instance); for (index, subst) in substs.into_iter().enumerate() { let index = index .try_into() diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index bd1d99640f81d..79f1beb0799b3 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -84,6 +84,12 @@ impl IntoArgs for (CrateNum, DefId) { } } +impl IntoArgs for ty::InstanceDef<'tcx> { + fn into_args(self) -> (DefId, DefId) { + (self.def_id(), self.def_id()) + } +} + provide! { <'tcx> tcx, def_id, other, cdata, type_of => { cdata.get_type(def_id.index, tcx) } generics_of => { cdata.get_generics(def_id.index, tcx.sess) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 1e3bf8aca8bdc..8947c13430fc5 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1320,7 +1320,9 @@ impl EncodeContext<'a, 'tcx> { } record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id)); - let unused = self.tcx.unused_generic_params(def_id); + let instance = + ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id())); + let unused = self.tcx.unused_generic_params(instance); if !unused.is_empty() { record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused); } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index b4f7a9fa8e9d6..d0a1c8ce3cfd8 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1551,11 +1551,11 @@ rustc_queries! { query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> { desc { "codegen_unit" } } - query unused_generic_params(key: DefId) -> FiniteBitSet { - cache_on_disk_if { key.is_local() } + query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet { + cache_on_disk_if { key.def_id().is_local() } desc { |tcx| "determining which generic parameters are unused by `{}`", - tcx.def_path_str(key) + tcx.def_path_str(key.def_id()) } } query backend_optimization_level(_: ()) -> OptLevel { diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 9b8247fd0283e..4b38105e44717 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -152,6 +152,22 @@ impl<'tcx> InstanceDef<'tcx> { } } + /// Returns the `DefId` of instances which might not require codegen locally. + pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option { + match self { + ty::InstanceDef::Item(def) => Some(def.did), + ty::InstanceDef::DropGlue(def_id, Some(_)) => Some(def_id), + InstanceDef::VtableShim(..) + | InstanceDef::ReifyShim(..) + | InstanceDef::FnPtrShim(..) + | InstanceDef::Virtual(..) + | InstanceDef::Intrinsic(..) + | InstanceDef::ClosureOnceShim { .. } + | InstanceDef::DropGlue(..) + | InstanceDef::CloneShim(..) => None, + } + } + #[inline] pub fn with_opt_param(self) -> ty::WithOptConstParam { match self { @@ -567,29 +583,26 @@ impl<'tcx> Instance<'tcx> { return self; } - if let InstanceDef::Item(def) = self.def { - let polymorphized_substs = polymorphize(tcx, def.did, self.substs); - debug!("polymorphize: self={:?} polymorphized_substs={:?}", self, polymorphized_substs); - Self { def: self.def, substs: polymorphized_substs } - } else { - self - } + let polymorphized_substs = polymorphize(tcx, self.def, self.substs); + debug!("polymorphize: self={:?} polymorphized_substs={:?}", self, polymorphized_substs); + Self { def: self.def, substs: polymorphized_substs } } } fn polymorphize<'tcx>( tcx: TyCtxt<'tcx>, - def_id: DefId, + instance: ty::InstanceDef<'tcx>, substs: SubstsRef<'tcx>, ) -> SubstsRef<'tcx> { - debug!("polymorphize({:?}, {:?})", def_id, substs); - let unused = tcx.unused_generic_params(def_id); + debug!("polymorphize({:?}, {:?})", instance, substs); + let unused = tcx.unused_generic_params(instance); debug!("polymorphize: unused={:?}", unused); // If this is a closure or generator then we need to handle the case where another closure // from the function is captured as an upvar and hasn't been polymorphized. In this case, // the unpolymorphized upvar closure would result in a polymorphized closure producing // multiple mono items (and eventually symbol clashes). + let def_id = instance.def_id(); let upvars_ty = if tcx.is_closure(def_id) { Some(substs.as_closure().tupled_upvars_ty()) } else if tcx.type_of(def_id).is_generator() { @@ -613,7 +626,11 @@ fn polymorphize<'tcx>( debug!("fold_ty: ty={:?}", ty); match ty.kind { ty::Closure(def_id, substs) => { - let polymorphized_substs = polymorphize(self.tcx, def_id, substs); + let polymorphized_substs = polymorphize( + self.tcx, + ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), + substs, + ); if substs == polymorphized_substs { ty } else { @@ -621,7 +638,11 @@ fn polymorphize<'tcx>( } } ty::Generator(def_id, substs, movability) => { - let polymorphized_substs = polymorphize(self.tcx, def_id, substs); + let polymorphized_substs = polymorphize( + self.tcx, + ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), + substs, + ); if substs == polymorphized_substs { ty } else { diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 5ccf8997d28ce..7b7c4d23af506 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -936,21 +936,13 @@ fn visit_instance_use<'tcx>( } } -// Returns `true` if we should codegen an instance in the local crate. -// Returns `false` if we can just link to the upstream crate and therefore don't -// need a mono item. +/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we +/// can just link to the upstream crate and therefore don't need a mono item. fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> bool { - let def_id = match instance.def { - ty::InstanceDef::Item(def) => def.did, - ty::InstanceDef::DropGlue(def_id, Some(_)) => def_id, - ty::InstanceDef::VtableShim(..) - | ty::InstanceDef::ReifyShim(..) - | ty::InstanceDef::ClosureOnceShim { .. } - | ty::InstanceDef::Virtual(..) - | ty::InstanceDef::FnPtrShim(..) - | ty::InstanceDef::DropGlue(..) - | ty::InstanceDef::Intrinsic(_) - | ty::InstanceDef::CloneShim(..) => return true, + let def_id = if let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() { + def_id + } else { + return true; }; if tcx.is_foreign_item(def_id) { diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index bb04f91e5acaa..e6e4438b6d41a 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -27,20 +27,23 @@ pub fn provide(providers: &mut Providers) { providers.unused_generic_params = unused_generic_params; } -/// Determine which generic parameters are used by the function/method/closure represented by -/// `def_id`. Returns a bitset where bits representing unused parameters are set (`is_empty` -/// indicates all parameters are used). +/// Determine which generic parameters are used by the instance. +/// +/// Returns a bitset where bits representing unused parameters are set (`is_empty` indicates all +/// parameters are used). #[instrument(level = "debug", skip(tcx))] -fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { +fn unused_generic_params<'tcx>( + tcx: TyCtxt<'tcx>, + instance: ty::InstanceDef<'tcx>, +) -> FiniteBitSet { if !tcx.sess.opts.debugging_opts.polymorphize { // If polymorphization disabled, then all parameters are used. return FiniteBitSet::new_empty(); } - // Polymorphization results are stored in cross-crate metadata only when there are unused - // parameters, so assume that non-local items must have only used parameters (else this query - // would not be invoked, and the cross-crate metadata used instead). - if !def_id.is_local() { + let def_id = instance.def_id(); + // Exit early if this instance should not be polymorphized. + if !should_polymorphize(tcx, def_id, instance) { return FiniteBitSet::new_empty(); } @@ -52,38 +55,20 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { return FiniteBitSet::new_empty(); } - // Exit early for foreign items, these have no bodies to analyze. - if tcx.is_foreign_item(def_id) { - return FiniteBitSet::new_empty(); - } - - // Exit early when there is no MIR available. - let context = tcx.hir().body_const_context(def_id.expect_local()); - match context { - Some(ConstContext::ConstFn) | None if !tcx.is_mir_available(def_id) => { - debug!("no mir available"); - return FiniteBitSet::new_empty(); - } - Some(_) if !tcx.is_ctfe_mir_available(def_id) => { - debug!("no ctfe mir available"); - return FiniteBitSet::new_empty(); - } - _ => {} - } - // Create a bitset with N rightmost ones for each parameter. let generics_count: u32 = generics.count().try_into().expect("more generic parameters than can fit into a `u32`"); let mut unused_parameters = FiniteBitSet::::new_empty(); unused_parameters.set_range(0..generics_count); debug!(?unused_parameters, "(start)"); + mark_used_by_default_parameters(tcx, def_id, generics, &mut unused_parameters); debug!(?unused_parameters, "(after default)"); // Visit MIR and accumululate used generic parameters. - let body = match context { + let body = match tcx.hir().body_const_context(def_id.expect_local()) { // Const functions are actually called and should thus be considered for polymorphization - // via their runtime MIR + // via their runtime MIR. Some(ConstContext::ConstFn) | None => tcx.optimized_mir(def_id), Some(_) => tcx.mir_for_ctfe(def_id), }; @@ -99,6 +84,49 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { unused_parameters } +/// Returns `true` if the instance should be polymorphized. +fn should_polymorphize<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: DefId, + instance: ty::InstanceDef<'tcx>, +) -> bool { + // If an instance's MIR body is not polymorphic then the modified substitutions that are + // derived from polymorphization's result won't make any difference. + if !instance.has_polymorphic_mir_body() { + return false; + } + + // Don't polymorphize intrinsics or virtual calls - calling `instance_mir` will panic. + if matches!(instance, ty::InstanceDef::Intrinsic(..) | ty::InstanceDef::Virtual(..)) { + return false; + } + + // Polymorphization results are stored in cross-crate metadata only when there are unused + // parameters, so assume that non-local items must have only used parameters (else this query + // would not be invoked, and the cross-crate metadata used instead). + if !def_id.is_local() { + return false; + } + + // Foreign items have no bodies to analyze. + if tcx.is_foreign_item(def_id) { + return false; + } + + // Make sure there is MIR available. + match tcx.hir().body_const_context(def_id.expect_local()) { + Some(ConstContext::ConstFn) | None if !tcx.is_mir_available(def_id) => { + debug!("no mir available"); + return false; + } + Some(_) if !tcx.is_ctfe_mir_available(def_id) => { + debug!("no ctfe mir available"); + return false; + } + _ => true, + } +} + /// Some parameters are considered used-by-default, such as non-generic parameters and the dummy /// generic parameters from closures, this function marks them as used. `leaf_is_closure` should /// be `true` if the item that `unused_generic_params` was invoked on is a closure. @@ -207,7 +235,8 @@ impl<'a, 'tcx> MarkUsedGenericParams<'a, 'tcx> { /// a closure, generator or constant). #[instrument(level = "debug", skip(self, def_id, substs))] fn visit_child_body(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) { - let unused = self.tcx.unused_generic_params(def_id); + let instance = ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)); + let unused = self.tcx.unused_generic_params(instance); debug!(?self.unused_parameters, ?unused); for (i, arg) in substs.iter().enumerate() { let i = i.try_into().unwrap(); From cd773c358793beaae4688b4bbb60d793509f7cc0 Mon Sep 17 00:00:00 2001 From: Xinye Tao Date: Mon, 4 Oct 2021 00:27:32 +0800 Subject: [PATCH 013/181] Update outdated comment --- library/alloc/src/collections/vec_deque/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index f703efd6fbe97..8a9f06ff242e9 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -417,7 +417,7 @@ impl VecDeque { } } - /// Append all values from `src` to `dst`, wrapping around if needed. + /// Copies all values from `src` to `dst`, wrapping around if needed. /// Assumes capacity is sufficient. #[inline] unsafe fn copy_slice(&mut self, dst: usize, src: &[T]) { From e41bb97c253bf99a33ee077578d876d3d6b94148 Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Sun, 3 Oct 2021 20:59:54 -0700 Subject: [PATCH 014/181] Add `#[repr(i8)]` to `Ordering` Followup to #89491 to allow `Ordering` to auto-derive `AsRepr` once the proposal to add `AsRepr` (#81642) lands. --- library/core/src/cmp.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 5ac9fdec0cf58..7456f886ea5d8 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -323,6 +323,7 @@ pub struct AssertParamIsEq { /// ``` #[derive(Clone, Copy, PartialEq, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] +#[repr(i8)] pub enum Ordering { /// An ordering where a compared value is less than another. #[stable(feature = "rust1", since = "1.0.0")] From 11140ff1a0dd3a395dd3ca1488bf580559f782f8 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 4 Oct 2021 01:04:17 -0400 Subject: [PATCH 015/181] Stabilize `unreachable_unchecked` as `const fn` --- library/core/src/hint.rs | 2 +- library/core/src/intrinsics.rs | 2 +- library/core/src/lib.rs | 1 - src/test/ui/consts/const_unsafe_unreachable.rs | 4 +--- src/test/ui/consts/const_unsafe_unreachable_ub.rs | 3 +-- src/test/ui/consts/const_unsafe_unreachable_ub.stderr | 6 +++--- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 1c3afcdaa69e9..95798879155c5 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -44,7 +44,7 @@ use crate::intrinsics; /// ``` #[inline] #[stable(feature = "unreachable", since = "1.27.0")] -#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")] +#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")] pub const unsafe fn unreachable_unchecked() -> ! { // SAFETY: the safety contract for `intrinsics::unreachable` must // be upheld by the caller. diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 3e26d46ddcaf9..067a27fed4142 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -735,7 +735,7 @@ extern "rust-intrinsic" { /// reach code marked with this function. /// /// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`]. - #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")] + #[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")] pub fn unreachable() -> !; /// Informs the optimizer that a condition is always true. diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 2230461b5f4b5..9a966cc51280a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -103,7 +103,6 @@ #![feature(const_trait_impl)] #![feature(const_type_id)] #![feature(const_type_name)] -#![feature(const_unreachable_unchecked)] #![feature(const_default_impls)] #![feature(duration_consts_2)] #![feature(ptr_metadata)] diff --git a/src/test/ui/consts/const_unsafe_unreachable.rs b/src/test/ui/consts/const_unsafe_unreachable.rs index 1fec491ca95b1..1c3baec5d8638 100644 --- a/src/test/ui/consts/const_unsafe_unreachable.rs +++ b/src/test/ui/consts/const_unsafe_unreachable.rs @@ -1,7 +1,5 @@ // run-pass -#![feature(const_unreachable_unchecked)] - const unsafe fn foo(x: bool) -> bool { match x { true => true, @@ -12,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool { const BAR: bool = unsafe { foo(true) }; fn main() { - assert_eq!(BAR, true); + assert_eq!(BAR, true); } diff --git a/src/test/ui/consts/const_unsafe_unreachable_ub.rs b/src/test/ui/consts/const_unsafe_unreachable_ub.rs index 8cee5b5065136..b418fea617cea 100644 --- a/src/test/ui/consts/const_unsafe_unreachable_ub.rs +++ b/src/test/ui/consts/const_unsafe_unreachable_ub.rs @@ -1,5 +1,4 @@ // error-pattern: evaluation of constant value failed -#![feature(const_unreachable_unchecked)] const unsafe fn foo(x: bool) -> bool { match x { @@ -11,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool { const BAR: bool = unsafe { foo(false) }; fn main() { - assert_eq!(BAR, true); + assert_eq!(BAR, true); } diff --git a/src/test/ui/consts/const_unsafe_unreachable_ub.stderr b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr index 65cb3d74b233e..ec6ce1f5d7c08 100644 --- a/src/test/ui/consts/const_unsafe_unreachable_ub.stderr +++ b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr @@ -7,13 +7,13 @@ LL | unsafe { intrinsics::unreachable() } | entering unreachable code | inside `unreachable_unchecked` at $SRC_DIR/core/src/hint.rs:LL:COL | - ::: $DIR/const_unsafe_unreachable_ub.rs:7:18 + ::: $DIR/const_unsafe_unreachable_ub.rs:6:18 | LL | false => std::hint::unreachable_unchecked(), - | ---------------------------------- inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:7:18 + | ---------------------------------- inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:6:18 ... LL | const BAR: bool = unsafe { foo(false) }; - | ---------- inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:11:28 + | ---------- inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:10:28 error: aborting due to previous error From b39e915981a59fed6fba7bee727e603ddc1be4c4 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 4 Oct 2021 09:50:10 +0000 Subject: [PATCH 016/181] polymorphize: don't normalize self-ty need substs `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function, resulting in an ICE in the 'generic-names' debuginfo test. If partitioning is enabled and the instance needs substitution then this is now skipped. Signed-off-by: David Wood --- .../src/partitioning/default.rs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_monomorphize/src/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs index 429ed53d37977..be6820822586d 100644 --- a/compiler/rustc_monomorphize/src/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -9,7 +9,7 @@ use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::ty::print::characteristic_def_id_of_type; -use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt}; +use rustc_middle::ty::{self, fold::TypeFoldable, DefIdTree, InstanceDef, TyCtxt}; use rustc_span::symbol::Symbol; use super::PartitioningCx; @@ -300,14 +300,21 @@ fn characteristic_def_id_of_mono_item<'tcx>( // call it. return None; } - // This is a method within an impl, find out what the self-type is: - let impl_self_ty = tcx.subst_and_normalize_erasing_regions( - instance.substs, - ty::ParamEnv::reveal_all(), - tcx.type_of(impl_def_id), - ); - if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) { - return Some(def_id); + + // When polymorphization is enabled, methods which do not depend on their generic + // parameters, but the self-type of their impl block do will fail to normalize. + if !tcx.sess.opts.debugging_opts.polymorphize + || !instance.definitely_needs_subst(tcx) + { + // This is a method within an impl, find out what the self-type is: + let impl_self_ty = tcx.subst_and_normalize_erasing_regions( + instance.substs, + ty::ParamEnv::reveal_all(), + tcx.type_of(impl_def_id), + ); + if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) { + return Some(def_id); + } } } From 947a33bf206e8bec15a9734e217cd540b8a2fb5c Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Fri, 23 Jul 2021 16:25:58 +0200 Subject: [PATCH 017/181] Add support for artifact size profiling --- Cargo.lock | 25 ++++++++--- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_data_structures/Cargo.toml | 2 +- .../rustc_data_structures/src/profiling.rs | 43 +++++++++++++++++-- .../src/persist/file_format.rs | 6 +++ compiler/rustc_query_impl/Cargo.toml | 2 +- .../src/dep_graph/serialized.rs | 10 +++-- compiler/rustc_session/src/options.rs | 2 +- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 197b2c8f3f06a..3576bd0b3f8c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2138,6 +2138,19 @@ dependencies = [ "smallvec", ] +[[package]] +name = "measureme" +version = "9.1.2" +source = "git+https://github.com/rylev/measureme#b9cccd7ad4c859a5e0e3dd6bff3daac7a190bdd7" +dependencies = [ + "log", + "memmap2", + "parking_lot", + "perf-event-open-sys", + "rustc-hash", + "smallvec", +] + [[package]] name = "memchr" version = "2.4.1" @@ -2242,8 +2255,8 @@ dependencies = [ "hex 0.4.2", "libc", "log", - "measureme", - "rand 0.8.4", + "measureme 9.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.8.3", "rustc-workspace-hack", "rustc_version 0.4.0", "shell-escape", @@ -3219,7 +3232,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme", + "measureme 9.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "memmap2", "parking_lot", "rustc-ap-rustc_graphviz", @@ -3657,7 +3670,7 @@ dependencies = [ "bitflags", "cstr", "libc", - "measureme", + "measureme 9.1.2 (git+https://github.com/rylev/measureme)", "rustc-demangle", "rustc_arena", "rustc_ast", @@ -3752,7 +3765,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme", + "measureme 9.1.2 (git+https://github.com/rylev/measureme)", "memmap2", "parking_lot", "rustc-hash", @@ -4276,7 +4289,7 @@ dependencies = [ name = "rustc_query_impl" version = "0.0.0" dependencies = [ - "measureme", + "measureme 9.1.2 (git+https://github.com/rylev/measureme)", "rustc-rayon-core", "rustc_ast", "rustc_data_structures", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index a6a553b31a326..d39c0bed5f89d 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -11,7 +11,7 @@ doctest = false bitflags = "1.0" cstr = "0.2" libc = "0.2" -measureme = "9.1.0" +measureme = { git = "https://github.com/rylev/measureme" } snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 4996257012970..b67329de2e8fb 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -23,7 +23,7 @@ rustc-hash = "1.1.0" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_index = { path = "../rustc_index", package = "rustc_index" } bitflags = "1.2.1" -measureme = "9.1.0" +measureme = { git = "https://github.com/rylev/measureme" } libc = "0.2" stacker = "0.1.14" tempfile = "3.2" diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 0bbd0eda0c6e1..c21939209fc3b 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -110,12 +110,14 @@ bitflags::bitflags! { const FUNCTION_ARGS = 1 << 6; const LLVM = 1 << 7; const INCR_RESULT_HASHING = 1 << 8; + const ARTIFACT_SIZES = 1 << 9; const DEFAULT = Self::GENERIC_ACTIVITIES.bits | Self::QUERY_PROVIDERS.bits | Self::QUERY_BLOCKED.bits | Self::INCR_CACHE_LOADS.bits | - Self::INCR_RESULT_HASHING.bits; + Self::INCR_RESULT_HASHING.bits | + Self::ARTIFACT_SIZES.bits; const ARGS = Self::QUERY_KEYS.bits | Self::FUNCTION_ARGS.bits; } @@ -136,6 +138,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[ ("args", EventFilter::ARGS), ("llvm", EventFilter::LLVM), ("incr-result-hashing", EventFilter::INCR_RESULT_HASHING), + ("artifact-sizes", EventFilter::ARTIFACT_SIZES), ]; /// Something that uniquely identifies a query invocation. @@ -285,6 +288,33 @@ impl SelfProfilerRef { }) } + /// Record the size of an artifact that the compiler produces + /// + /// `artifact_kind` is the class of artifact (e.g., query_cache, object_file, etc.) + /// `artifact_name` is an identifier to the specific artifact being stored (usually a filename) + #[inline(always)] + pub fn artifact_size(&self, artifact_kind: &str, artifact_name: A, size: u64) + where + A: Borrow + Into, + { + drop(self.exec(EventFilter::ARTIFACT_SIZES, |profiler| { + let builder = EventIdBuilder::new(&profiler.profiler); + let event_label = profiler.get_or_alloc_cached_string(artifact_kind); + let event_arg = profiler.get_or_alloc_cached_string(artifact_name); + let event_id = builder.from_label_and_arg(event_label, event_arg); + let thread_id = get_thread_id(); + + profiler.profiler.record_integer_event( + profiler.artifact_size_event_kind, + event_id, + thread_id, + size, + ); + + TimingGuard::none() + })) + } + #[inline(always)] pub fn generic_activity_with_args( &self, @@ -372,7 +402,7 @@ impl SelfProfilerRef { ) { drop(self.exec(event_filter, |profiler| { let event_id = StringId::new_virtual(query_invocation_id.0); - let thread_id = std::thread::current().id().as_u64().get() as u32; + let thread_id = get_thread_id(); profiler.profiler.record_instant_event( event_kind(profiler), @@ -425,6 +455,7 @@ pub struct SelfProfiler { incremental_result_hashing_event_kind: StringId, query_blocked_event_kind: StringId, query_cache_hit_event_kind: StringId, + artifact_size_event_kind: StringId, } impl SelfProfiler { @@ -447,6 +478,7 @@ impl SelfProfiler { profiler.alloc_string("IncrementalResultHashing"); let query_blocked_event_kind = profiler.alloc_string("QueryBlocked"); let query_cache_hit_event_kind = profiler.alloc_string("QueryCacheHit"); + let artifact_size_event_kind = profiler.alloc_string("ArtifactSize"); let mut event_filter_mask = EventFilter::empty(); @@ -491,6 +523,7 @@ impl SelfProfiler { incremental_result_hashing_event_kind, query_blocked_event_kind, query_cache_hit_event_kind, + artifact_size_event_kind, }) } @@ -561,7 +594,7 @@ impl<'a> TimingGuard<'a> { event_kind: StringId, event_id: EventId, ) -> TimingGuard<'a> { - let thread_id = std::thread::current().id().as_u64().get() as u32; + let thread_id = get_thread_id(); let raw_profiler = &profiler.profiler; let timing_guard = raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id); @@ -655,6 +688,10 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String { format!("{:.3}", dur.as_secs_f64()) } +fn get_thread_id() -> u32 { + std::thread::current().id().as_u64().get() as u32 +} + // Memory reporting cfg_if! { if #[cfg(windows)] { diff --git a/compiler/rustc_incremental/src/persist/file_format.rs b/compiler/rustc_incremental/src/persist/file_format.rs index 572a4fc697173..392c5bdc15ad2 100644 --- a/compiler/rustc_incremental/src/persist/file_format.rs +++ b/compiler/rustc_incremental/src/persist/file_format.rs @@ -95,6 +95,12 @@ where return; } + sess.prof.artifact_size( + &name.replace(' ', "_"), + path_buf.file_name().unwrap().to_string_lossy(), + encoder.position() as u64, + ); + debug!("save: data written to disk successfully"); } diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index 89df3d4674b6b..c4da929e29873 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" doctest = false [dependencies] -measureme = "9.0.0" +measureme = { git = "https://github.com/rylev/measureme" } rustc-rayon-core = "0.3.1" tracing = "0.1" rustc_ast = { path = "../rustc_ast" } diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index f5f67fcd0a08c..47197a1e492a3 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -222,7 +222,7 @@ impl EncoderState { index } - fn finish(self) -> FileEncodeResult { + fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult { let Self { mut encoder, total_node_count, total_edge_count, result, stats: _ } = self; let () = result?; @@ -235,7 +235,11 @@ impl EncoderState { IntEncodedWithFixedSize(edge_count).encode(&mut encoder)?; debug!("position: {:?}", encoder.position()); // Drop the encoder so that nothing is written after the counts. - encoder.flush() + let result = encoder.flush(); + // FIXME(rylev): we hardcode the dep graph file name so we don't need a dependency on + // rustc_incremental just for that. + profiler.artifact_size("dep_graph", "dep-graph.bin", encoder.position() as u64); + result } } @@ -332,6 +336,6 @@ impl> GraphEncoder { pub fn finish(self, profiler: &SelfProfilerRef) -> FileEncodeResult { let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph"); - self.status.into_inner().finish() + self.status.into_inner().finish(profiler) } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 8ecb7a031ad81..b7f4396f9d715 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1279,7 +1279,7 @@ options! { "specify the events recorded by the self profiler; for example: `-Z self-profile-events=default,query-keys` all options: none, all, default, generic-activity, query-provider, query-cache-hit - query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm"), + query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"), share_generics: Option = (None, parse_opt_bool, [TRACKED], "make the current crate share its generic instantiations"), show_span: Option = (None, parse_opt_string, [TRACKED], From 757f76ef73245f69c9262760ee4ff3cababd41d1 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Thu, 7 Oct 2021 15:08:44 +0200 Subject: [PATCH 018/181] Update to measureme v10 --- Cargo.lock | 17 +++++++++-------- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_data_structures/Cargo.toml | 2 +- compiler/rustc_query_impl/Cargo.toml | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3576bd0b3f8c1..e9b31473a8f70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2140,8 +2140,9 @@ dependencies = [ [[package]] name = "measureme" -version = "9.1.2" -source = "git+https://github.com/rylev/measureme#b9cccd7ad4c859a5e0e3dd6bff3daac7a190bdd7" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd460fad6e55ca82fa0cd9dab0d315294188fd9ec6efbf4105e5635d4872ef9c" dependencies = [ "log", "memmap2", @@ -2255,8 +2256,8 @@ dependencies = [ "hex 0.4.2", "libc", "log", - "measureme 9.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.8.3", + "measureme 9.1.2", + "rand 0.8.4", "rustc-workspace-hack", "rustc_version 0.4.0", "shell-escape", @@ -3232,7 +3233,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme 9.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "measureme 9.1.2", "memmap2", "parking_lot", "rustc-ap-rustc_graphviz", @@ -3670,7 +3671,7 @@ dependencies = [ "bitflags", "cstr", "libc", - "measureme 9.1.2 (git+https://github.com/rylev/measureme)", + "measureme 10.0.0", "rustc-demangle", "rustc_arena", "rustc_ast", @@ -3765,7 +3766,7 @@ dependencies = [ "indexmap", "jobserver", "libc", - "measureme 9.1.2 (git+https://github.com/rylev/measureme)", + "measureme 10.0.0", "memmap2", "parking_lot", "rustc-hash", @@ -4289,7 +4290,7 @@ dependencies = [ name = "rustc_query_impl" version = "0.0.0" dependencies = [ - "measureme 9.1.2 (git+https://github.com/rylev/measureme)", + "measureme 10.0.0", "rustc-rayon-core", "rustc_ast", "rustc_data_structures", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index d39c0bed5f89d..5f3f533447532 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -11,7 +11,7 @@ doctest = false bitflags = "1.0" cstr = "0.2" libc = "0.2" -measureme = { git = "https://github.com/rylev/measureme" } +measureme = "10.0.0" snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index b67329de2e8fb..e3395df35908c 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -23,7 +23,7 @@ rustc-hash = "1.1.0" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_index = { path = "../rustc_index", package = "rustc_index" } bitflags = "1.2.1" -measureme = { git = "https://github.com/rylev/measureme" } +measureme = "10.0.0" libc = "0.2" stacker = "0.1.14" tempfile = "3.2" diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index c4da929e29873..814581563896e 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" doctest = false [dependencies] -measureme = { git = "https://github.com/rylev/measureme" } +measureme = "10.0.0" rustc-rayon-core = "0.3.1" tracing = "0.1" rustc_ast = { path = "../rustc_ast" } From 54c3299b3aed464b5c658c2dbfc1a270fb4c051f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 6 Jun 2021 13:48:00 +0200 Subject: [PATCH 019/181] Remove eval_always for HIR queries. They depend on `hir_crate` and `index_hir`. --- compiler/rustc_middle/src/hir/mod.rs | 2 +- compiler/rustc_middle/src/query/mod.rs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 5016c5ce95432..ded724c9badf7 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -163,7 +163,7 @@ pub fn provide(providers: &mut Providers) { let index = tcx.index_hir(()); index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID) }; - providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.untracked_crate.attrs, prefix: id }; + providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.hir_crate(()).attrs, prefix: id }; providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id); providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); providers.fn_arg_names = |tcx, id| { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 9b0b1377875d1..7e9391b98f7ed 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -62,7 +62,6 @@ rustc_queries! { /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. query hir_owner(key: LocalDefId) -> Option> { - eval_always desc { |tcx| "HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -71,7 +70,6 @@ rustc_queries! { /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. query hir_owner_parent(key: LocalDefId) -> hir::HirId { - eval_always desc { |tcx| "HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -80,7 +78,6 @@ rustc_queries! { /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> { - eval_always desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -89,7 +86,6 @@ rustc_queries! { /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. query hir_attrs(key: LocalDefId) -> rustc_middle::hir::AttributeMap<'tcx> { - eval_always desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -933,12 +929,6 @@ rustc_queries! { query def_span(def_id: DefId) -> Span { desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) } - // FIXME(mw): DefSpans are not really inputs since they are derived from - // HIR. But at the moment HIR hashing still contains some hacks that allow - // to make type debuginfo to be source location independent. Declaring - // DefSpan an input makes sure that changes to these are always detected - // regardless of HIR hashing. - eval_always } query def_ident_span(def_id: DefId) -> Option { From 8fc329f5d2305d2f127752e7af3a37e07a1a89dc Mon Sep 17 00:00:00 2001 From: Noble-Mushtak Date: Wed, 8 Sep 2021 21:30:22 -0400 Subject: [PATCH 020/181] Add check that region is live in sanitize_promoted --- .../rustc_borrowck/src/region_infer/mod.rs | 2 +- .../rustc_borrowck/src/region_infer/values.rs | 20 ++++++++++--------- compiler/rustc_borrowck/src/type_check/mod.rs | 17 ++++++++++------ .../borrowck/issue-88434-minimal-example.rs | 13 ++++++++++++ .../issue-88434-minimal-example.stderr | 17 ++++++++++++++++ ...ssue-88434-removal-index-should-be-less.rs | 13 ++++++++++++ ...-88434-removal-index-should-be-less.stderr | 17 ++++++++++++++++ 7 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 src/test/ui/borrowck/issue-88434-minimal-example.rs create mode 100644 src/test/ui/borrowck/issue-88434-minimal-example.stderr create mode 100644 src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs create mode 100644 src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 734a5b4972bcc..21c26af8178ff 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -2154,7 +2154,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // appears to be the most interesting point to report to the // user via an even more ad-hoc guess. categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category)); - debug!("`: sorted_path={:#?}", categorized_path); + debug!("best_blame_constraint: sorted_path={:#?}", categorized_path); categorized_path.remove(0) } diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 2864abde0022c..8819039c75296 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -174,17 +174,19 @@ impl LivenessValues { self.points.contains(row, index) } + /// Returns an iterator of all the elements contained by the region `r` + crate fn get_elements(&self, row: N) -> impl Iterator + '_ { + self.points + .row(row) + .into_iter() + .flat_map(|set| set.iter()) + .take_while(move |&p| self.elements.point_in_range(p)) + .map(move |p| self.elements.to_location(p)) + } + /// Returns a "pretty" string value of the region. Meant for debugging. crate fn region_value_str(&self, r: N) -> String { - region_value_str( - self.points - .row(r) - .into_iter() - .flat_map(|set| set.iter()) - .take_while(|&p| self.elements.point_in_range(p)) - .map(|p| self.elements.to_location(p)) - .map(RegionElement::Location), - ) + region_value_str(self.get_elements(r).map(RegionElement::Location)) } } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 55790bd2daa9b..fbb73a3187b03 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -663,12 +663,17 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { } self.cx.borrowck_context.constraints.outlives_constraints.push(constraint) } - for live_region in liveness_constraints.rows() { - self.cx - .borrowck_context - .constraints - .liveness_constraints - .add_element(live_region, location); + for region in liveness_constraints.rows() { + // If the region is live at at least one location in the promoted MIR, + // then add a liveness constraint to the main MIR for this region + // at the location provided as an argument to this method + if let Some(_) = liveness_constraints.get_elements(region).next() { + self.cx + .borrowck_context + .constraints + .liveness_constraints + .add_element(region, location); + } } if !closure_bounds.is_empty() { diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.rs b/src/test/ui/borrowck/issue-88434-minimal-example.rs new file mode 100644 index 0000000000000..db348a50aa429 --- /dev/null +++ b/src/test/ui/borrowck/issue-88434-minimal-example.rs @@ -0,0 +1,13 @@ +#![feature(const_fn_trait_bound)] +// Regression test related to issue 88434 + +const _CONST: &() = &f(&|_| {}); + +const fn f(_: &F) +where + F: FnMut(&u8), +{ + panic!() //~ ERROR evaluation of constant value failed +} + +fn main() { } diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.stderr b/src/test/ui/borrowck/issue-88434-minimal-example.stderr new file mode 100644 index 0000000000000..845e1bdba8fc0 --- /dev/null +++ b/src/test/ui/borrowck/issue-88434-minimal-example.stderr @@ -0,0 +1,17 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/issue-88434-minimal-example.rs:10:5 + | +LL | const _CONST: &() = &f(&|_| {}); + | ---------- inside `_CONST` at $DIR/issue-88434-minimal-example.rs:4:22 +... +LL | panic!() + | ^^^^^^^^ + | | + | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5 + | inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:4:25: 4:31]>` at $SRC_DIR/std/src/panic.rs:LL:COL + | + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs new file mode 100644 index 0000000000000..4db073c66b1f3 --- /dev/null +++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs @@ -0,0 +1,13 @@ +#![feature(const_fn_trait_bound)] +// Regression test for issue 88434 + +const _CONST: &[u8] = &f(&[], |_| {}); + +const fn f(_: &[u8], _: F) -> &[u8] +where + F: FnMut(&u8), +{ + panic!() //~ ERROR evaluation of constant value failed +} + +fn main() { } diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr new file mode 100644 index 0000000000000..8cbb6a6340c7f --- /dev/null +++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr @@ -0,0 +1,17 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5 + | +LL | const _CONST: &[u8] = &f(&[], |_| {}); + | -------------- inside `_CONST` at $DIR/issue-88434-removal-index-should-be-less.rs:4:24 +... +LL | panic!() + | ^^^^^^^^ + | | + | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5 + | inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:4:31: 4:37]>` at $SRC_DIR/std/src/panic.rs:LL:COL + | + = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. From df03b083c99626bc3728cdf6b49377a749c4d9bd Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 4 Jun 2021 17:02:13 -0500 Subject: [PATCH 021/181] move implicit `Sized` predicate to end of list In `Bounds::predicates()`, move the implicit `Sized` predicate to the end of the generated list. This means that if there is an explicit `Sized` bound, it will be checked first, and any resulting diagnostics will have a more useful span. --- compiler/rustc_typeck/src/bounds.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs index 24474e163b9da..ff04e07acc4f6 100644 --- a/compiler/rustc_typeck/src/bounds.rs +++ b/compiler/rustc_typeck/src/bounds.rs @@ -64,16 +64,16 @@ impl<'tcx> Bounds<'tcx> { }) }); - sized_predicate - .into_iter() - .chain(self.region_bounds.iter().map(|&(region_bound, span)| { + self.region_bounds + .iter() + .map(|&(region_bound, span)| { ( region_bound .map_bound(|region_bound| ty::OutlivesPredicate(param_ty, region_bound)) .to_predicate(tcx), span, ) - })) + }) .chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| { let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx); (predicate, span) @@ -83,6 +83,7 @@ impl<'tcx> Bounds<'tcx> { .iter() .map(|&(projection, span)| (projection.to_predicate(tcx), span)), ) + .chain(sized_predicate.into_iter()) .collect() } } From c07f5c43fca9a39da4efdac38fa2c6e301d267d8 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 8 Oct 2021 18:15:53 -0500 Subject: [PATCH 022/181] update ui test expectations --- ...rives-span-Hash-enum-struct-variant.stderr | 2 +- .../ui/derives/derives-span-Hash-enum.stderr | 2 +- .../derives/derives-span-Hash-struct.stderr | 2 +- .../derives-span-Hash-tuple-struct.stderr | 2 +- .../issue-74816.stderr | 24 +++++++++---------- .../issue-86483.stderr | 4 ++-- ...e-param-can-reference-self-in-trait.stderr | 4 ++-- src/test/ui/issues/issue-16966.stderr | 14 +++++++++-- src/test/ui/issues/issue-21160.stderr | 2 +- src/test/ui/issues/issue-23122-2.stderr | 2 +- src/test/ui/issues/issue-54954.stderr | 4 ++-- .../trait-where-clause.stderr | 12 +++++----- .../suggestions/issue-84973-blacklist.stderr | 4 ++-- .../ui/suggestions/slice-issue-87994.stderr | 8 +++---- .../generic_duplicate_param_use9.rs | 2 +- .../generic_duplicate_param_use9.stderr | 24 +++++++++---------- src/test/ui/unique-object-noncopyable.stderr | 4 ++-- .../ui/unsized/unsized-bare-typaram.stderr | 4 ++-- src/test/ui/unsized/unsized-struct.stderr | 4 ++-- 19 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr index 47c7f1c2c3340..89186817e099c 100644 --- a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr @@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); - | ^ required by this bound in `std::hash::Hash::hash` + | ^^^^^^ required by this bound in `std::hash::Hash::hash` = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-enum.stderr b/src/test/ui/derives/derives-span-Hash-enum.stderr index 92f084b58e35b..6abb7e78b1330 100644 --- a/src/test/ui/derives/derives-span-Hash-enum.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum.stderr @@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); - | ^ required by this bound in `std::hash::Hash::hash` + | ^^^^^^ required by this bound in `std::hash::Hash::hash` = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-struct.stderr b/src/test/ui/derives/derives-span-Hash-struct.stderr index c57cebe04ebcb..405285f883810 100644 --- a/src/test/ui/derives/derives-span-Hash-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-struct.stderr @@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); - | ^ required by this bound in `std::hash::Hash::hash` + | ^^^^^^ required by this bound in `std::hash::Hash::hash` = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr index 200937f0c9fc3..aa12314c05176 100644 --- a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr @@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); - | ^ required by this bound in `std::hash::Hash::hash` + | ^^^^^^ required by this bound in `std::hash::Hash::hash` = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr index 49ae87cbfe9dc..d5cc5cfbe912d 100644 --- a/src/test/ui/generic-associated-types/issue-74816.stderr +++ b/src/test/ui/generic-associated-types/issue-74816.stderr @@ -1,34 +1,34 @@ -error[E0277]: the trait bound `Self: Trait1` is not satisfied +error[E0277]: the size for values of type `Self` cannot be known at compilation time --> $DIR/issue-74816.rs:9:5 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait1` is not implemented for `Self` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | note: required by a bound in `Trait2::Associated` - --> $DIR/issue-74816.rs:9:22 + --> $DIR/issue-74816.rs:9:5 | LL | type Associated: Trait1 = Self; - | ^^^^^^ required by this bound in `Trait2::Associated` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait2::Associated` help: consider further restricting `Self` | -LL | trait Trait2: Trait1 { - | ++++++++ +LL | trait Trait2: Sized { + | +++++++ -error[E0277]: the size for values of type `Self` cannot be known at compilation time +error[E0277]: the trait bound `Self: Trait1` is not satisfied --> $DIR/issue-74816.rs:9:5 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait1` is not implemented for `Self` | note: required by a bound in `Trait2::Associated` - --> $DIR/issue-74816.rs:9:5 + --> $DIR/issue-74816.rs:9:22 | LL | type Associated: Trait1 = Self; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait2::Associated` + | ^^^^^^ required by this bound in `Trait2::Associated` help: consider further restricting `Self` | -LL | trait Trait2: Sized { - | +++++++ +LL | trait Trait2: Trait1 { + | ++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/generic-associated-types/issue-86483.stderr b/src/test/ui/generic-associated-types/issue-86483.stderr index d6978794e1e95..5d0fcbca552d6 100644 --- a/src/test/ui/generic-associated-types/issue-86483.stderr +++ b/src/test/ui/generic-associated-types/issue-86483.stderr @@ -20,13 +20,13 @@ LL | for<'a> T: 'a, | ^^ error[E0311]: the parameter type `T` may not live long enough - --> $DIR/issue-86483.rs:9:5 + --> $DIR/issue-86483.rs:9:19 | LL | pub trait IceIce | - help: consider adding an explicit lifetime bound...: `T: 'a` ... LL | type Ice<'v>: IntoIterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds... + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds... | note: ...that is required by this bound --> $DIR/issue-86483.rs:7:16 diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index 2c397d80b013e..50f90618e4db7 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -6,10 +6,10 @@ LL | impl Tsized for () {} | = help: the trait `Sized` is not implemented for `[()]` note: required by a bound in `Tsized` - --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14 + --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:17 | LL | trait Tsized {} - | ^ required by this bound in `Tsized` + | ^^^^^ required by this bound in `Tsized` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr index f9467af9e3c4c..875a3fce87c9e 100644 --- a/src/test/ui/issues/issue-16966.stderr +++ b/src/test/ui/issues/issue-16966.stderr @@ -1,11 +1,21 @@ -error[E0282]: type annotations needed +error[E0283]: type annotations needed --> $DIR/issue-16966.rs:2:5 | LL | panic!(std::default::Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` declared on the function `begin_panic` | + = note: cannot satisfy `_: Any` +note: required by a bound in `begin_panic` + --> $SRC_DIR/std/src/panicking.rs:LL:COL + | +LL | pub fn begin_panic(msg: M) -> ! { + | ^^^ required by this bound in `begin_panic` = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider specifying the type argument in the function call + | +LL | $crate::rt::begin_panic::($msg) + | +++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/issues/issue-21160.stderr b/src/test/ui/issues/issue-21160.stderr index 92742b50619e0..c2f6fc21acd7f 100644 --- a/src/test/ui/issues/issue-21160.stderr +++ b/src/test/ui/issues/issue-21160.stderr @@ -10,7 +10,7 @@ note: required by a bound in `std::hash::Hash::hash` --> $SRC_DIR/core/src/hash/mod.rs:LL:COL | LL | fn hash(&self, state: &mut H); - | ^ required by this bound in `std::hash::Hash::hash` + | ^^^^^^ required by this bound in `std::hash::Hash::hash` = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/issues/issue-23122-2.stderr b/src/test/ui/issues/issue-23122-2.stderr index b345e90178742..e6cec722978dd 100644 --- a/src/test/ui/issues/issue-23122-2.stderr +++ b/src/test/ui/issues/issue-23122-2.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized` +error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Next` --> $DIR/issue-23122-2.rs:9:17 | LL | type Next = as Next>::Next; diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr index df76a985559d0..d88397fd7e15d 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -12,10 +12,10 @@ LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); | = note: cannot satisfy `_: Tt` note: required by a bound in `Tt::const_val` - --> $DIR/issue-54954.rs:5:24 + --> $DIR/issue-54954.rs:5:27 | LL | const fn const_val() -> usize { - | ^ required by this bound in `Tt::const_val` + | ^^^^^ required by this bound in `Tt::const_val` error: aborting due to 2 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr index fffb91f98700b..4a4544c16c941 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -20,11 +20,11 @@ error[E0277]: the trait bound `T: Bar` is not satisfied LL | T::c::(); | ^^^^^^^^^ the trait `Bar` is not implemented for `T` | -note: required by `Foo::c` - --> $DIR/trait-where-clause.rs:9:5 +note: required by a bound in `Foo::c` + --> $DIR/trait-where-clause.rs:9:10 | LL | fn c(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^ required by this bound in `Foo::c` help: consider further restricting this bound | LL | const fn test1() { @@ -52,11 +52,11 @@ error[E0277]: the trait bound `T: Bar` is not satisfied LL | T::c::(); | ^^^^^^^^^ the trait `Bar` is not implemented for `T` | -note: required by `Foo::c` - --> $DIR/trait-where-clause.rs:9:5 +note: required by a bound in `Foo::c` + --> $DIR/trait-where-clause.rs:9:10 | LL | fn c(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^ required by this bound in `Foo::c` help: consider further restricting this bound | LL | fn test3() { diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index ae55c96702ada..58075ed7caebc 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -49,10 +49,10 @@ LL | f_sized(*ref_cl); | = help: the trait `Sized` is not implemented for `dyn Fn()` note: required by a bound in `f_sized` - --> $DIR/issue-84973-blacklist.rs:9:12 + --> $DIR/issue-84973-blacklist.rs:9:15 | LL | fn f_sized(t: T) {} - | ^ required by this bound in `f_sized` + | ^^^^^ required by this bound in `f_sized` error[E0277]: `Rc<{integer}>` cannot be sent between threads safely --> $DIR/issue-84973-blacklist.rs:27:12 diff --git a/src/test/ui/suggestions/slice-issue-87994.stderr b/src/test/ui/suggestions/slice-issue-87994.stderr index 0275fd475d8c6..9e0d4ced01153 100644 --- a/src/test/ui/suggestions/slice-issue-87994.stderr +++ b/src/test/ui/suggestions/slice-issue-87994.stderr @@ -1,4 +1,4 @@ -error[E0277]: the size for values of type `[i32]` cannot be known at compilation time +error[E0277]: `[i32]` is not an iterator --> $DIR/slice-issue-87994.rs:3:12 | LL | for _ in v[1..] { @@ -18,7 +18,7 @@ LL | for _ in &v[1..] { LL | for _ in &mut v[1..] { | ++++ -error[E0277]: `[i32]` is not an iterator +error[E0277]: the size for values of type `[i32]` cannot be known at compilation time --> $DIR/slice-issue-87994.rs:3:12 | LL | for _ in v[1..] { @@ -38,7 +38,7 @@ LL | for _ in &v[1..] { LL | for _ in &mut v[1..] { | ++++ -error[E0277]: the size for values of type `[K]` cannot be known at compilation time +error[E0277]: `[K]` is not an iterator --> $DIR/slice-issue-87994.rs:11:13 | LL | for i2 in v2[1..] { @@ -58,7 +58,7 @@ LL | for i2 in &v2[1..] { LL | for i2 in &mut v2[1..] { | ++++ -error[E0277]: `[K]` is not an iterator +error[E0277]: the size for values of type `[K]` cannot be known at compilation time --> $DIR/slice-issue-87994.rs:11:13 | LL | for i2 in v2[1..] { diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs index 747081933172b..4baf198b12fae 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs @@ -5,7 +5,7 @@ use std::fmt::Debug; fn main() {} type Two = impl Debug; -//~^ ERROR the trait bound `A: Foo` is not satisfied in `(A, B, ::Bar)` +//~^ ERROR the trait bound `A: Foo` is not satisfied //~| ERROR `A` doesn't implement `Debug` //~| ERROR `B` doesn't implement `Debug` diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr index a8eb53a50e38b..f21e036edc2ca 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr @@ -10,18 +10,6 @@ note: previous use here LL | fn two(t: T, u: U) -> Two { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0277]: the trait bound `A: Foo` is not satisfied in `(A, B, ::Bar)` - --> $DIR/generic_duplicate_param_use9.rs:7:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ within `(A, B, ::Bar)`, the trait `Foo` is not implemented for `A` - | - = note: required because it appears within the type `(A, B, ::Bar)` -help: consider restricting type parameter `A` - | -LL | type Two = impl Debug; - | +++++ - error[E0277]: `A` doesn't implement `Debug` --> $DIR/generic_duplicate_param_use9.rs:7:18 | @@ -46,6 +34,18 @@ help: consider restricting type parameter `B` LL | type Two = impl Debug; | +++++++++++++++++ +error[E0277]: the trait bound `A: Foo` is not satisfied + --> $DIR/generic_duplicate_param_use9.rs:7:18 + | +LL | type Two = impl Debug; + | ^^^^^^^^^^ the trait `Foo` is not implemented for `A` + | + = note: required because of the requirements on the impl of `Debug` for `(A, B, ::Bar)` +help: consider restricting type parameter `A` + | +LL | type Two = impl Debug; + | +++++ + error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unique-object-noncopyable.stderr b/src/test/ui/unique-object-noncopyable.stderr index 5c40787febfb7..8626b726f47c4 100644 --- a/src/test/ui/unique-object-noncopyable.stderr +++ b/src/test/ui/unique-object-noncopyable.stderr @@ -19,10 +19,10 @@ LL | | >(Unique, A); | |________________- doesn't satisfy `Box: Clone` | = note: the following trait bounds were not satisfied: - `dyn Foo: Sized` - which is required by `Box: Clone` `dyn Foo: Clone` which is required by `Box: Clone` + `dyn Foo: Sized` + which is required by `Box: Clone` error: aborting due to previous error diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr index 531e9b4c9c955..0dd439e14e3cd 100644 --- a/src/test/ui/unsized/unsized-bare-typaram.stderr +++ b/src/test/ui/unsized/unsized-bare-typaram.stderr @@ -7,10 +7,10 @@ LL | fn foo() { bar::() } | this type parameter needs to be `std::marker::Sized` | note: required by a bound in `bar` - --> $DIR/unsized-bare-typaram.rs:1:8 + --> $DIR/unsized-bare-typaram.rs:1:11 | LL | fn bar() { } - | ^ required by this bound in `bar` + | ^^^^^ required by this bound in `bar` help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn foo() { bar::() } diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr index 1c70a840c77dc..88ba7567402db 100644 --- a/src/test/ui/unsized/unsized-struct.stderr +++ b/src/test/ui/unsized/unsized-struct.stderr @@ -38,10 +38,10 @@ note: required because it appears within the type `Bar` LL | struct Bar { data: T } | ^^^ note: required by a bound in `is_sized` - --> $DIR/unsized-struct.rs:1:13 + --> $DIR/unsized-struct.rs:1:15 | LL | fn is_sized() { } - | ^ required by this bound in `is_sized` + | ^^^^^ required by this bound in `is_sized` help: consider removing the `?Sized` bound to make the type parameter `Sized` | LL - fn bar2() { is_sized::>() } From f9e1de979db1e19acad5c2785057e0f2c25ee1f5 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 19 Sep 2021 23:16:28 +0200 Subject: [PATCH 023/181] Stop referring to hir::Crate in hir_pretty. --- compiler/rustc_driver/src/pretty.rs | 30 ++++++++++++++++++---------- compiler/rustc_hir_pretty/src/lib.rs | 17 ++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 8e8bea9525dc9..2e9050dd672e1 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -59,23 +59,23 @@ where } fn call_with_pp_support_hir(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> A where - F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A, + F: FnOnce(&dyn HirPrinterSupport<'_>, hir_map::Map<'_>) -> A, { match *ppmode { PpHirMode::Normal => { let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) }; - f(&annotation, tcx.hir().krate()) + f(&annotation, tcx.hir()) } PpHirMode::Identified => { let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) }; - f(&annotation, tcx.hir().krate()) + f(&annotation, tcx.hir()) } PpHirMode::Typed => { abort_on_err(tcx.analysis(()), tcx.sess); let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) }; - tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate())) + tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir())) } } } @@ -443,17 +443,27 @@ pub fn print_after_hir_lowering<'tcx>( format!("{:#?}", krate) } - Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| { + Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, hir_map| { debug!("pretty printing HIR {:?}", s); let sess = annotation.sess(); let sm = sess.source_map(); - pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann()) + let attrs = |id| hir_map.attrs(id); + pprust_hir::print_crate( + sm, + hir_map.root_module(), + src_name, + src, + &attrs, + annotation.pp_ann(), + ) }), - HirTree => call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| { - debug!("pretty printing HIR tree"); - format!("{:#?}", krate) - }), + HirTree => { + call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, hir_map| { + debug!("pretty printing HIR tree"); + format!("{:#?}", hir_map.krate()) + }) + } _ => unreachable!(), }; diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 9196344cb3ffd..c1992b9b91bbf 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -15,7 +15,6 @@ use rustc_target::spec::abi::Abi; use std::borrow::Cow; use std::cell::Cell; -use std::collections::BTreeMap; use std::vec; pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: hir::HirId) -> String { @@ -69,7 +68,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> { pub struct State<'a> { pub s: pp::Printer, comments: Option>, - attrs: &'a BTreeMap, + attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], ann: &'a (dyn PpAnn + 'a), } @@ -146,17 +145,18 @@ pub const INDENT_UNIT: usize = 4; /// it can scan the input text for comments to copy forward. pub fn print_crate<'a>( sm: &'a SourceMap, - krate: &hir::Crate<'_>, + krate: &hir::Mod<'_>, filename: FileName, input: String, + attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], ann: &'a dyn PpAnn, ) -> String { - let mut s = State::new_from_input(sm, filename, input, &krate.attrs, ann); + let mut s = State::new_from_input(sm, filename, input, attrs, ann); // When printing the AST, we sometimes need to inject `#[no_std]` here. // Since you can't compile the HIR, it's not necessary. - s.print_mod(&krate.module(), s.attrs(hir::CRATE_HIR_ID)); + s.print_mod(krate, (*attrs)(hir::CRATE_HIR_ID)); s.print_remaining_comments(); s.s.eof() } @@ -166,7 +166,7 @@ impl<'a> State<'a> { sm: &'a SourceMap, filename: FileName, input: String, - attrs: &'a BTreeMap, + attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], ann: &'a dyn PpAnn, ) -> State<'a> { State { @@ -178,7 +178,7 @@ impl<'a> State<'a> { } fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] { - self.attrs.get(&id).map_or(&[], |la| *la) + (self.attrs)(id) } } @@ -186,8 +186,7 @@ pub fn to_string(ann: &dyn PpAnn, f: F) -> String where F: FnOnce(&mut State<'_>), { - let mut printer = - State { s: pp::mk_printer(), comments: None, attrs: &BTreeMap::default(), ann }; + let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann }; f(&mut printer); printer.s.eof() } From 48a339ddbbc1e1c364d1cb39d3fef8aad9105345 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 16 Jul 2021 14:42:26 +0200 Subject: [PATCH 024/181] Store lowering outputs per owner. --- Cargo.lock | 1 + compiler/rustc_ast_lowering/src/expr.rs | 5 +- compiler/rustc_ast_lowering/src/item.rs | 21 +++-- compiler/rustc_ast_lowering/src/lib.rs | 92 ++++++++++++------- compiler/rustc_hir/src/hir.rs | 39 +++++--- compiler/rustc_middle/Cargo.toml | 1 + .../rustc_middle/src/hir/map/collector.rs | 16 ++-- compiler/rustc_middle/src/hir/map/mod.rs | 54 ++++++++--- compiler/rustc_middle/src/hir/mod.rs | 46 ++-------- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 3 +- compiler/rustc_resolve/src/late.rs | 6 +- compiler/rustc_resolve/src/lib.rs | 8 +- 13 files changed, 169 insertions(+), 124 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 197b2c8f3f06a..00d470017bb7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4088,6 +4088,7 @@ dependencies = [ "polonius-engine", "rand 0.8.4", "rand_xoshiro 0.6.0", + "rustc-rayon", "rustc-rayon-core", "rustc_apfloat", "rustc_arena", diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 6027027428eee..22f93f5078817 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -252,9 +252,10 @@ impl<'hir> LoweringContext<'_, 'hir> { } // Merge attributes into the inner expression. if !e.attrs.is_empty() { - let old_attrs = self.attrs.get(&ex.hir_id).map(|la| *la).unwrap_or(&[]); + let old_attrs = + self.attrs.get(&ex.hir_id.local_id).map(|la| *la).unwrap_or(&[]); self.attrs.insert( - ex.hir_id, + ex.hir_id.local_id, &*self.arena.alloc_from_iter( e.attrs .iter() diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index ea9eb0cf2742b..c6572b19d1d1d 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -10,6 +10,7 @@ use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::LocalDefId; +use rustc_index::vec::Idx; use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; @@ -99,11 +100,12 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> T { let old_len = self.in_scope_lifetimes.len(); - let parent_generics = match self.owners[parent_hir_id].unwrap().expect_item().kind { - hir::ItemKind::Impl(hir::Impl { ref generics, .. }) - | hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params, - _ => &[], - }; + let parent_generics = + match self.owners[parent_hir_id].as_ref().unwrap().node.expect_item().kind { + hir::ItemKind::Impl(hir::Impl { ref generics, .. }) + | hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params, + _ => &[], + }; let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind { hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()), _ => None, @@ -493,7 +495,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let kind = hir::ItemKind::Use(path, hir::UseKind::Single); let vis = this.rebuild_vis(&vis); if let Some(attrs) = attrs { - this.attrs.insert(hir::HirId::make_owner(new_id), attrs); + this.attrs.insert(hir::ItemLocalId::new(0), attrs); } let item = hir::Item { @@ -568,7 +570,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let kind = this.lower_use_tree(use_tree, &prefix, id, &mut vis, &mut ident, attrs); if let Some(attrs) = attrs { - this.attrs.insert(hir::HirId::make_owner(new_hir_id), attrs); + this.attrs.insert(hir::ItemLocalId::new(0), attrs); } let item = hir::Item { @@ -971,7 +973,8 @@ impl<'hir> LoweringContext<'_, 'hir> { ) -> hir::BodyId { let body = hir::Body { generator_kind: self.generator_kind, params, value }; let id = body.id(); - self.bodies.insert(id, body); + debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner); + self.bodies.insert(id.hir_id.local_id, body); id } @@ -1124,7 +1127,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // // If this is the simple case, this parameter will end up being the same as the // original parameter, but with a different pattern id. - let stmt_attrs = this.attrs.get(¶meter.hir_id).copied(); + let stmt_attrs = this.attrs.get(¶meter.hir_id.local_id).copied(); let (new_parameter_pat, new_parameter_id) = this.pat_ident(desugared_span, ident); let new_parameter = hir::Param { hir_id: parameter.hir_id, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 245199e375113..1b82ac68e159d 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -35,14 +35,13 @@ #![feature(iter_zip)] #![recursion_limit = "256"] -use rustc_ast::node_id::NodeMap; use rustc_ast::token::{self, Token}; use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream, TokenTree}; use rustc_ast::visit; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust; use rustc_data_structures::captures::Captures; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; @@ -97,13 +96,12 @@ struct LoweringContext<'a, 'hir: 'a> { arena: &'hir Arena<'hir>, /// The items being lowered are collected here. - owners: IndexVec>>, - bodies: BTreeMap>, + owners: IndexVec>>, + bodies: BTreeMap>, + attrs: BTreeMap, generator_kind: Option, - attrs: BTreeMap, - /// When inside an `async` context, this is the `HirId` of the /// `task_context` local bound to the resume argument of the generator. task_context: Option, @@ -152,6 +150,9 @@ struct LoweringContext<'a, 'hir: 'a> { item_local_id_counter: hir::ItemLocalId, node_id_to_hir_id: IndexVec>, + /// NodeIds that are lowered inside the current HIR owner. + local_node_ids: Vec, + allow_try_trait: Option>, allow_gen_future: Option>, } @@ -182,7 +183,7 @@ pub trait ResolverAstLowering { fn next_node_id(&mut self) -> NodeId; - fn take_trait_map(&mut self) -> NodeMap>; + fn take_trait_map(&mut self, node: NodeId) -> Option>; fn opt_local_def_id(&self, node: NodeId) -> Option; @@ -314,12 +315,13 @@ pub fn lower_crate<'a, 'hir>( ) -> &'hir hir::Crate<'hir> { let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering"); + let owners = IndexVec::from_fn_n(|_| None, resolver.definitions().def_index_count()); LoweringContext { sess, resolver, nt_to_tokenstream, arena, - owners: IndexVec::default(), + owners, bodies: BTreeMap::new(), attrs: BTreeMap::default(), catch_scope: None, @@ -331,6 +333,7 @@ pub fn lower_crate<'a, 'hir>( current_hir_id_owner: CRATE_DEF_ID, item_local_id_counter: hir::ItemLocalId::new(0), node_id_to_hir_id: IndexVec::new(), + local_node_ids: Vec::new(), generator_kind: None, task_context: None, current_item: None, @@ -420,14 +423,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::OwnerNode::Crate(lctx.arena.alloc(module)) }); - let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default(); - for (k, v) in self.resolver.take_trait_map().into_iter() { - if let Some(Some(hir_id)) = self.node_id_to_hir_id.get(k) { - let map = trait_map.entry(hir_id.owner).or_default(); - map.insert(hir_id.local_id, v.into_boxed_slice()); - } - } - let mut def_id_to_hir_id = IndexVec::default(); for (node_id, hir_id) in self.node_id_to_hir_id.into_iter_enumerated() { @@ -441,16 +436,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.resolver.definitions().init_def_id_to_hir_id_mapping(def_id_to_hir_id); - #[cfg(debug_assertions)] - for (&id, attrs) in self.attrs.iter() { - // Verify that we do not store empty slices in the map. - if attrs.is_empty() { - panic!("Stored empty attributes for {:?}", id); - } - } - - let krate = - hir::Crate { owners: self.owners, bodies: self.bodies, trait_map, attrs: self.attrs }; + let krate = hir::Crate { owners: self.owners }; self.arena.alloc(krate) } @@ -468,25 +454,57 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ) -> LocalDefId { let def_id = self.resolver.local_def_id(owner); - // Always allocate the first `HirId` for the owner itself. - let _old = self.node_id_to_hir_id.insert(owner, hir::HirId::make_owner(def_id)); - debug_assert_eq!(_old, None); - + let current_attrs = std::mem::take(&mut self.attrs); + let current_bodies = std::mem::take(&mut self.bodies); + let current_node_ids = std::mem::take(&mut self.local_node_ids); let current_owner = std::mem::replace(&mut self.current_hir_id_owner, def_id); let current_local_counter = std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1)); + // Always allocate the first `HirId` for the owner itself. + let _old = self.node_id_to_hir_id.insert(owner, hir::HirId::make_owner(def_id)); + debug_assert_eq!(_old, None); + self.local_node_ids.push(owner); + let item = f(self); + let info = self.make_owner_info(item); + self.attrs = current_attrs; + self.bodies = current_bodies; + self.local_node_ids = current_node_ids; self.current_hir_id_owner = current_owner; self.item_local_id_counter = current_local_counter; - let _old = self.owners.insert(def_id, item); + let _old = self.owners.insert(def_id, info); debug_assert!(_old.is_none()); def_id } + fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> hir::OwnerInfo<'hir> { + let attrs = std::mem::take(&mut self.attrs); + let bodies = std::mem::take(&mut self.bodies); + let local_node_ids = std::mem::take(&mut self.local_node_ids); + let trait_map = local_node_ids + .into_iter() + .filter_map(|node_id| { + let hir_id = self.node_id_to_hir_id[node_id]?; + let traits = self.resolver.take_trait_map(node_id)?; + Some((hir_id.local_id, traits.into_boxed_slice())) + }) + .collect(); + + #[cfg(debug_assertions)] + for (&id, attrs) in attrs.iter() { + // Verify that we do not store empty slices in the map. + if attrs.is_empty() { + panic!("Stored empty attributes for {:?}", id); + } + } + + hir::OwnerInfo { node, attrs, bodies, trait_map } + } + /// This method allocates a new `HirId` for the given `NodeId` and stores it in /// the `LoweringContext`'s `NodeId => HirId` map. /// Take care not to call this method if the resulting `HirId` is then not @@ -501,6 +519,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let owner = self.current_hir_id_owner; let local_id = self.item_local_id_counter; self.item_local_id_counter.increment_by(1); + self.local_node_ids.push(ast_node_id); hir::HirId { owner, local_id } }) } @@ -791,9 +810,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { if attrs.is_empty() { None } else { + debug_assert_eq!(id.owner, self.current_hir_id_owner); let ret = self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a))); debug_assert!(!ret.is_empty()); - self.attrs.insert(id, ret); + self.attrs.insert(id.local_id, ret); Some(ret) } } @@ -819,9 +839,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) { - if let Some(&a) = self.attrs.get(&target_id) { + debug_assert_eq!(id.owner, self.current_hir_id_owner); + debug_assert_eq!(target_id.owner, self.current_hir_id_owner); + if let Some(&a) = self.attrs.get(&target_id.local_id) { debug_assert!(!a.is_empty()); - self.attrs.insert(id, a); + self.attrs.insert(id.local_id, a); } } @@ -2066,7 +2088,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let hir_id = self.next_id(); if let Some(a) = attrs { debug_assert!(!a.is_empty()); - self.attrs.insert(hir_id, a); + self.attrs.insert(hir_id.local_id, a); } let local = hir::Local { hir_id, init, pat, source, span: self.lower_span(span), ty: None }; self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local))) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index fdd52bd74952f..a24d92d0c01b7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -662,6 +662,16 @@ pub struct WhereEqPredicate<'hir> { pub rhs_ty: &'hir Ty<'hir>, } +#[derive(Debug)] +pub struct OwnerInfo<'hir> { + pub node: OwnerNode<'hir>, + pub attrs: BTreeMap, + pub bodies: BTreeMap>, + /// Map indicating what traits are in scope for places where this + /// is relevant; generated by resolve. + pub trait_map: FxHashMap>, +} + /// The top-level data structure that stores the entire contents of /// the crate currently being compiled. /// @@ -670,40 +680,39 @@ pub struct WhereEqPredicate<'hir> { /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html #[derive(Debug)] pub struct Crate<'hir> { - pub owners: IndexVec>>, - pub bodies: BTreeMap>, - - /// Map indicating what traits are in scope for places where this - /// is relevant; generated by resolve. - pub trait_map: FxHashMap>>, - - /// Collected attributes from HIR nodes. - pub attrs: BTreeMap, + pub owners: IndexVec>>, } impl Crate<'hir> { pub fn module(&self) -> &'hir Mod<'hir> { - if let Some(OwnerNode::Crate(m)) = self.owners[CRATE_DEF_ID] { m } else { panic!() } + let i = self.owners[CRATE_DEF_ID].as_ref().unwrap().node; + if let OwnerNode::Crate(m) = i { m } else { panic!() } } pub fn item(&self, id: ItemId) -> &'hir Item<'hir> { - self.owners[id.def_id].as_ref().unwrap().expect_item() + self.owners[id.def_id].as_ref().unwrap().node.expect_item() } pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().expect_trait_item() + self.owners[id.def_id].as_ref().unwrap().node.expect_trait_item() } pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().expect_impl_item() + self.owners[id.def_id].as_ref().unwrap().node.expect_impl_item() } pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().expect_foreign_item() + self.owners[id.def_id].as_ref().unwrap().node.expect_foreign_item() } pub fn body(&self, id: BodyId) -> &Body<'hir> { - &self.bodies[&id] + let HirId { owner, local_id } = id.hir_id; + &self.owners[owner].as_ref().unwrap().bodies[&local_id] + } + + pub fn attrs(&self, id: HirId) -> &'hir [Attribute] { + let HirId { owner, local_id } = id; + &self.owners[owner].as_ref().unwrap().attrs.get(&local_id).map(|la| *la).unwrap_or(&[]) } } diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index d06c593d39481..daeccde6024e6 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -12,6 +12,7 @@ bitflags = "1.2.1" either = "1.5.0" gsgdt = "0.1.2" tracing = "0.1" +rustc-rayon = "0.3.1" rustc-rayon-core = "0.3.1" polonius-engine = "0.13.0" rustc_apfloat = { path = "../rustc_apfloat" } diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index efebf73224f27..1e405d0d7fc12 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -86,12 +86,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { collector } - pub(super) fn finalize_and_compute_crate_hash(mut self) -> IndexedHir<'hir> { - // Insert bodies into the map - for (id, body) in self.krate.bodies.iter() { - let bodies = &mut self.map[id.hir_id.owner].as_mut().unwrap().bodies; - assert!(bodies.insert(id.hir_id.local_id, body).is_none()); - } + pub(super) fn finalize_and_compute_crate_hash(self) -> IndexedHir<'hir> { IndexedHir { map: self.map, parenting: self.parenting } } @@ -101,9 +96,14 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { let mut nodes = IndexVec::new(); nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: node.into() })); + let mut bodies = FxHashMap::default(); + for (id, body) in self.krate.owners[owner].as_ref().unwrap().bodies.iter() { + let _old = bodies.insert(*id, body); + debug_assert!(_old.is_none()); + } + debug_assert!(self.map[owner].is_none()); - self.map[owner] = - Some(self.arena.alloc(OwnerNodes { hash, nodes, bodies: FxHashMap::default() })); + self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, nodes, bodies })); } fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index e6f56b0be9303..9a1bdba824e1d 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1,6 +1,6 @@ use self::collector::NodeCollector; -use crate::hir::{AttributeMap, IndexedHir, ModuleItems, Owner}; +use crate::hir::{IndexedHir, ModuleItems, Owner}; use crate::ty::TyCtxt; use rustc_ast as ast; use rustc_data_structures::fingerprint::Fingerprint; @@ -166,8 +166,8 @@ impl<'hir> Map<'hir> { pub fn items(&self) -> impl Iterator> + 'hir { let krate = self.krate(); - krate.owners.iter().filter_map(|owner| match owner.as_ref()? { - OwnerNode::Item(item) => Some(*item), + krate.owners.iter().filter_map(|owner| match owner.as_ref()?.node { + OwnerNode::Item(item) => Some(item), _ => None, }) } @@ -495,11 +495,35 @@ impl<'hir> Map<'hir> { /// crate. If you would prefer to iterate over the bodies /// themselves, you can do `self.hir().krate().body_ids.iter()`. pub fn body_owners(self) -> impl Iterator + 'hir { - self.krate().bodies.keys().map(move |&body_id| self.body_owner_def_id(body_id)) + self.krate() + .owners + .iter_enumerated() + .flat_map(move |(owner, owner_info)| { + let bodies = &owner_info.as_ref()?.bodies; + Some(bodies.keys().map(move |&local_id| { + let hir_id = HirId { owner, local_id }; + let body_id = BodyId { hir_id }; + self.body_owner_def_id(body_id) + })) + }) + .flatten() } pub fn par_body_owners(self, f: F) { - par_for_each_in(&self.krate().bodies, |(&body_id, _)| f(self.body_owner_def_id(body_id))); + use rustc_data_structures::sync::{par_iter, ParallelIterator}; + #[cfg(parallel_compiler)] + use rustc_rayon::iter::IndexedParallelIterator; + + par_iter(&self.krate().owners.raw).enumerate().for_each(|(owner, owner_info)| { + let owner = LocalDefId::new(owner); + if let Some(owner_info) = owner_info { + par_iter(&owner_info.bodies).for_each(|(&local_id, _)| { + let hir_id = HirId { owner, local_id }; + let body_id = BodyId { hir_id }; + f(self.body_owner_def_id(body_id)) + }) + } + }); } pub fn ty_param_owner(&self, id: HirId) -> HirId { @@ -551,9 +575,14 @@ impl<'hir> Map<'hir> { /// Walks the attributes in a crate. pub fn walk_attributes(self, visitor: &mut impl Visitor<'hir>) { let krate = self.krate(); - for (&id, attrs) in krate.attrs.iter() { - for a in *attrs { - visitor.visit_attribute(id, a) + for (owner, info) in krate.owners.iter_enumerated() { + if let Some(info) = info { + for (&local_id, attrs) in info.attrs.iter() { + let id = HirId { owner, local_id }; + for a in *attrs { + visitor.visit_attribute(id, a) + } + } } } } @@ -572,7 +601,7 @@ impl<'hir> Map<'hir> { { let krate = self.krate(); for owner in krate.owners.iter().filter_map(Option::as_ref) { - match owner { + match owner.node { OwnerNode::Item(item) => visitor.visit_item(item), OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item), OwnerNode::ImplItem(item) => visitor.visit_impl_item(item), @@ -588,7 +617,7 @@ impl<'hir> Map<'hir> { V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send, { let krate = self.krate(); - par_for_each_in(&krate.owners.raw, |owner| match owner.as_ref() { + par_for_each_in(&krate.owners.raw, |owner| match owner.as_ref().map(|o| o.node) { Some(OwnerNode::Item(item)) => visitor.visit_item(item), Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item), Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item), @@ -1091,7 +1120,10 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { for (def_path_hash, fingerprint, def_id) in hir_body_nodes.iter() { def_path_hash.0.hash_stable(&mut hcx, &mut stable_hasher); fingerprint.hash_stable(&mut hcx, &mut stable_hasher); - AttributeMap { map: &tcx.untracked_crate.attrs, prefix: *def_id } + tcx.untracked_crate.owners[*def_id] + .as_ref() + .unwrap() + .attrs .hash_stable(&mut hcx, &mut stable_hasher); if tcx.sess.opts.debugging_opts.incremental_relative_spans { let span = tcx.untracked_resolutions.definitions.def_span(*def_id); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ded724c9badf7..9f2ee9f341c3c 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -77,47 +77,21 @@ impl<'a, 'tcx> HashStable> for OwnerNodes<'tcx> { } } -/// Attributes owner by a HIR owner. It is build as a slice inside the attributes map, restricted -/// to the nodes whose `HirId::owner` is `prefix`. -#[derive(Copy, Clone)] +/// Attributes owner by a HIR owner. +#[derive(Copy, Clone, Debug, HashStable)] pub struct AttributeMap<'tcx> { - map: &'tcx BTreeMap, - prefix: LocalDefId, -} - -impl<'a, 'tcx> HashStable> for AttributeMap<'tcx> { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let range = self.range(); - - range.clone().count().hash_stable(hcx, hasher); - for (key, value) in range { - key.hash_stable(hcx, hasher); - value.hash_stable(hcx, hasher); - } - } -} - -impl<'tcx> std::fmt::Debug for AttributeMap<'tcx> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("AttributeMap") - .field("prefix", &self.prefix) - .field("range", &&self.range().collect::>()[..]) - .finish() - } + map: &'tcx BTreeMap, } impl<'tcx> AttributeMap<'tcx> { - fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] { - self.map.get(&HirId { owner: self.prefix, local_id: id }).copied().unwrap_or(&[]) + fn new(owner_info: &'tcx Option>) -> AttributeMap<'tcx> { + const FALLBACK: &'static BTreeMap = &BTreeMap::new(); + let map = owner_info.as_ref().map_or(FALLBACK, |info| &info.attrs); + AttributeMap { map } } - fn range(&self) -> std::collections::btree_map::Range<'_, rustc_hir::HirId, &[Attribute]> { - let local_zero = ItemLocalId::from_u32(0); - let range = HirId { owner: self.prefix, local_id: local_zero }..HirId { - owner: LocalDefId { local_def_index: self.prefix.local_def_index + 1 }, - local_id: local_zero, - }; - self.map.range(range) + fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] { + self.map.get(&id).copied().unwrap_or(&[]) } } @@ -163,7 +137,7 @@ pub fn provide(providers: &mut Providers) { let index = tcx.index_hir(()); index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID) }; - providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.hir_crate(()).attrs, prefix: id }; + providers.hir_attrs = |tcx, id| AttributeMap::new(&tcx.hir_crate(()).owners[id]); providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id); providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); providers.fn_arg_names = |tcx, id| { diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index e41f5add457fb..e7219cc58a18a 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -30,6 +30,7 @@ #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(core_intrinsics)] +#![feature(const_btree_new)] #![feature(discriminant_kind)] #![feature(exhaustive_patterns)] #![feature(if_let_guard)] diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6a6fb30dce837..cbbd89e903335 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2828,7 +2828,8 @@ fn ptr_eq(t: *const T, u: *const U) -> bool { } pub fn provide(providers: &mut ty::query::Providers) { - providers.in_scope_traits_map = |tcx, id| tcx.hir_crate(()).trait_map.get(&id); + providers.in_scope_traits_map = + |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|owner_info| &owner_info.trait_map); providers.resolutions = |tcx, ()| &tcx.untracked_resolutions; providers.module_exports = |tcx, id| tcx.resolutions(()).export_map.get(&id).map(|v| &v[..]); providers.crate_name = |tcx, id| { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 9563325796538..0a24e00ee4bf5 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1994,7 +1994,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { if ns == ValueNS { let item_name = path.last().unwrap().ident; let traits = self.traits_in_scope(item_name, ns); - self.r.trait_map.as_mut().unwrap().insert(id, traits); + self.r.trait_map.insert(id, traits); } if PrimTy::from_name(path[0].ident.name).is_some() { @@ -2479,12 +2479,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { // the field name so that we can do some nice error reporting // later on in typeck. let traits = self.traits_in_scope(ident, ValueNS); - self.r.trait_map.as_mut().unwrap().insert(expr.id, traits); + self.r.trait_map.insert(expr.id, traits); } ExprKind::MethodCall(ref segment, ..) => { debug!("(recording candidate traits for expr) recording traits for {}", expr.id); let traits = self.traits_in_scope(segment.ident, ValueNS); - self.r.trait_map.as_mut().unwrap().insert(expr.id, traits); + self.r.trait_map.insert(expr.id, traits); } _ => { // Nothing to do. diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 3e7783033efa5..28fe365fb584b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -930,7 +930,7 @@ pub struct Resolver<'a> { /// `CrateNum` resolutions of `extern crate` items. extern_crate_map: FxHashMap, export_map: ExportMap, - trait_map: Option>>, + trait_map: NodeMap>, /// A map from nodes to anonymous modules. /// Anonymous modules are pseudo-modules that are implicitly created around items @@ -1185,8 +1185,8 @@ impl ResolverAstLowering for Resolver<'_> { self.next_node_id() } - fn take_trait_map(&mut self) -> NodeMap> { - std::mem::replace(&mut self.trait_map, None).unwrap() + fn take_trait_map(&mut self, node: NodeId) -> Option> { + self.trait_map.remove(&node) } fn opt_local_def_id(&self, node: NodeId) -> Option { @@ -1363,7 +1363,7 @@ impl<'a> Resolver<'a> { label_res_map: Default::default(), extern_crate_map: Default::default(), export_map: FxHashMap::default(), - trait_map: Some(NodeMap::default()), + trait_map: NodeMap::default(), underscore_disambiguator: 0, empty_module, module_map, From cd1ace488fc328ee20397783e3046971e6f09ac5 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 17 Sep 2021 19:41:05 +0200 Subject: [PATCH 025/181] Use an IndexVec for bodies. --- compiler/rustc_ast_lowering/src/item.rs | 3 ++- compiler/rustc_ast_lowering/src/lib.rs | 4 ++-- compiler/rustc_hir/src/arena.rs | 1 + compiler/rustc_hir/src/hir.rs | 6 +++--- .../rustc_middle/src/hir/map/collector.rs | 6 +----- compiler/rustc_middle/src/hir/map/mod.rs | 20 ++++++++++++------- compiler/rustc_middle/src/hir/mod.rs | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index c6572b19d1d1d..cac5bb56c9f5f 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -974,7 +974,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let body = hir::Body { generator_kind: self.generator_kind, params, value }; let id = body.id(); debug_assert_eq!(id.hir_id.owner, self.current_hir_id_owner); - self.bodies.insert(id.hir_id.local_id, body); + self.bodies.ensure_contains_elem(id.hir_id.local_id, || None); + self.bodies[id.hir_id.local_id] = Some(self.arena.alloc(body)); id } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1b82ac68e159d..8375a37d32a48 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -97,7 +97,7 @@ struct LoweringContext<'a, 'hir: 'a> { /// The items being lowered are collected here. owners: IndexVec>>, - bodies: BTreeMap>, + bodies: IndexVec>>, attrs: BTreeMap, generator_kind: Option, @@ -322,7 +322,7 @@ pub fn lower_crate<'a, 'hir>( nt_to_tokenstream, arena, owners, - bodies: BTreeMap::new(), + bodies: IndexVec::new(), attrs: BTreeMap::default(), catch_scope: None, loop_scope: None, diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index f07e52e04daa9..5334f6d729dc5 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -19,6 +19,7 @@ macro_rules! arena_types { [] attribute: rustc_ast::Attribute, [] block: rustc_hir::Block<$tcx>, [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>, + [] body: rustc_hir::Body<$tcx>, [] generic_arg: rustc_hir::GenericArg<$tcx>, [] generic_args: rustc_hir::GenericArgs<$tcx>, [] generic_bound: rustc_hir::GenericBound<$tcx>, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a24d92d0c01b7..1d1c0a0de13d8 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -666,7 +666,7 @@ pub struct WhereEqPredicate<'hir> { pub struct OwnerInfo<'hir> { pub node: OwnerNode<'hir>, pub attrs: BTreeMap, - pub bodies: BTreeMap>, + pub bodies: IndexVec>>, /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. pub trait_map: FxHashMap>, @@ -705,9 +705,9 @@ impl Crate<'hir> { self.owners[id.def_id].as_ref().unwrap().node.expect_foreign_item() } - pub fn body(&self, id: BodyId) -> &Body<'hir> { + pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { let HirId { owner, local_id } = id.hir_id; - &self.owners[owner].as_ref().unwrap().bodies[&local_id] + self.owners[owner].as_ref().unwrap().bodies[local_id].unwrap() } pub fn attrs(&self, id: HirId) -> &'hir [Attribute] { diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 1e405d0d7fc12..868c1b7853e5e 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -96,11 +96,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { let mut nodes = IndexVec::new(); nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: node.into() })); - let mut bodies = FxHashMap::default(); - for (id, body) in self.krate.owners[owner].as_ref().unwrap().bodies.iter() { - let _old = bodies.insert(*id, body); - debug_assert!(_old.is_none()); - } + let bodies = &self.krate.owners[owner].as_ref().unwrap().bodies; debug_assert!(self.map[owner].is_none()); self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, nodes, bodies })); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 9a1bdba824e1d..66d4ec2eeb6da 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -381,7 +381,7 @@ impl<'hir> Map<'hir> { } pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { - self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies.get(&id.hir_id.local_id).unwrap() + self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[id.hir_id.local_id].unwrap() } pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { @@ -500,10 +500,13 @@ impl<'hir> Map<'hir> { .iter_enumerated() .flat_map(move |(owner, owner_info)| { let bodies = &owner_info.as_ref()?.bodies; - Some(bodies.keys().map(move |&local_id| { + Some(bodies.iter_enumerated().filter_map(move |(local_id, body)| { + if body.is_none() { + return None; + } let hir_id = HirId { owner, local_id }; let body_id = BodyId { hir_id }; - self.body_owner_def_id(body_id) + Some(self.body_owner_def_id(body_id)) })) }) .flatten() @@ -517,10 +520,13 @@ impl<'hir> Map<'hir> { par_iter(&self.krate().owners.raw).enumerate().for_each(|(owner, owner_info)| { let owner = LocalDefId::new(owner); if let Some(owner_info) = owner_info { - par_iter(&owner_info.bodies).for_each(|(&local_id, _)| { - let hir_id = HirId { owner, local_id }; - let body_id = BodyId { hir_id }; - f(self.body_owner_def_id(body_id)) + par_iter(&owner_info.bodies.raw).enumerate().for_each(|(local_id, body)| { + if body.is_some() { + let local_id = ItemLocalId::new(local_id); + let hir_id = HirId { owner, local_id }; + let body_id = BodyId { hir_id }; + f(self.body_owner_def_id(body_id)) + } }) } }); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 9f2ee9f341c3c..094198713cc21 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -65,7 +65,7 @@ pub struct OwnerNodes<'tcx> { // The zeroth node's parent is trash, but is never accessed. nodes: IndexVec>>, /// Content of local bodies. - bodies: FxHashMap>, + bodies: &'tcx IndexVec>>, } impl<'a, 'tcx> HashStable> for OwnerNodes<'tcx> { From 457de0848777473ddafda998ab9384cbfbf4b87a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 19 Sep 2021 22:17:50 +0200 Subject: [PATCH 026/181] Forbid hashing HIR outside of indexing. --- Cargo.lock | 2 + compiler/rustc_ast_lowering/Cargo.toml | 1 + compiler/rustc_ast_lowering/src/lib.rs | 45 ++----------- .../rustc_middle/src/hir/map/collector.rs | 22 ++++--- compiler/rustc_middle/src/hir/map/mod.rs | 8 +-- compiler/rustc_middle/src/hir/mod.rs | 13 ++-- compiler/rustc_middle/src/ty/context.rs | 7 +- compiler/rustc_query_system/src/ich/hcx.rs | 64 +++++++++++-------- .../rustc_query_system/src/ich/impls_hir.rs | 10 ++- compiler/rustc_resolve/Cargo.toml | 1 + compiler/rustc_resolve/src/lib.rs | 45 ++----------- 11 files changed, 86 insertions(+), 132 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00d470017bb7f..0d89ffb726435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3552,6 +3552,7 @@ dependencies = [ "rustc_errors", "rustc_hir", "rustc_index", + "rustc_query_system", "rustc_session", "rustc_span", "rustc_target", @@ -4333,6 +4334,7 @@ dependencies = [ "rustc_index", "rustc_metadata", "rustc_middle", + "rustc_query_system", "rustc_session", "rustc_span", "smallvec", diff --git a/compiler/rustc_ast_lowering/Cargo.toml b/compiler/rustc_ast_lowering/Cargo.toml index f4859ee4ae91f..7989af24d9986 100644 --- a/compiler/rustc_ast_lowering/Cargo.toml +++ b/compiler/rustc_ast_lowering/Cargo.toml @@ -14,6 +14,7 @@ rustc_hir = { path = "../rustc_hir" } rustc_target = { path = "../rustc_target" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } +rustc_query_system = { path = "../rustc_query_system" } rustc_span = { path = "../rustc_span" } rustc_errors = { path = "../rustc_errors" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 8375a37d32a48..80b95b99b165e 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -51,13 +51,14 @@ use rustc_hir::definitions::{DefKey, DefPathData, Definitions}; use rustc_hir::intravisit; use rustc_hir::{ConstArg, GenericArg, InferKind, ParamName}; use rustc_index::vec::{Idx, IndexVec}; +use rustc_query_system::ich::StableHashingContext; use rustc_session::lint::builtin::BARE_TRAIT_OBJECTS; use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; use rustc_session::utils::{FlattenNonterminals, NtToTokenstream}; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::hygiene::ExpnId; -use rustc_span::source_map::{respan, CachingSourceMapView, DesugaringKind}; +use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -179,6 +180,8 @@ pub trait ResolverAstLowering { /// This should only return `None` during testing. fn definitions(&mut self) -> &mut Definitions; + fn create_stable_hashing_context(&self) -> StableHashingContext<'_>; + fn lint_buffer(&mut self) -> &mut LintBuffer; fn next_node_id(&mut self) -> NodeId; @@ -201,37 +204,6 @@ pub trait ResolverAstLowering { ) -> LocalDefId; } -struct LoweringHasher<'a> { - source_map: CachingSourceMapView<'a>, - resolver: &'a dyn ResolverAstLowering, -} - -impl<'a> rustc_span::HashStableContext for LoweringHasher<'a> { - #[inline] - fn hash_spans(&self) -> bool { - true - } - - #[inline] - fn def_span(&self, id: LocalDefId) -> Span { - self.resolver.def_span(id) - } - - #[inline] - fn def_path_hash(&self, def_id: DefId) -> DefPathHash { - self.resolver.def_path_hash(def_id) - } - - #[inline] - fn span_data_to_lines_and_cols( - &mut self, - span: &rustc_span::SpanData, - ) -> Option<(Lrc, usize, rustc_span::BytePos, usize, rustc_span::BytePos)> - { - self.source_map.span_data_to_lines_and_cols(span) - } -} - /// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree, /// and if so, what meaning it has. #[derive(Debug)] @@ -440,13 +412,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.arena.alloc(krate) } - fn create_stable_hashing_context(&self) -> LoweringHasher<'_> { - LoweringHasher { - source_map: CachingSourceMapView::new(self.sess.source_map()), - resolver: self.resolver, - } - } - fn with_hir_id_owner( &mut self, owner: NodeId, @@ -566,7 +531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { allow_internal_unstable, reason, self.sess.edition(), - self.create_stable_hashing_context(), + self.resolver.create_stable_hashing_context(), ) } diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 868c1b7853e5e..80e48a4f74b4f 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -51,18 +51,21 @@ fn insert_vec_map(map: &mut IndexVec>, k: K, v: V map[k] = Some(v); } -fn hash_body( - hcx: &mut StableHashingContext<'_>, +fn hash_body<'s, 'hir: 's>( + hcx: &mut StableHashingContext<'s>, item_like: impl for<'a> HashStable>, + hash_bodies: bool, + owner: LocalDefId, + bodies: &'hir IndexVec>>, ) -> Fingerprint { let mut stable_hasher = StableHasher::new(); - hcx.while_hashing_hir_bodies(true, |hcx| { - item_like.hash_stable(hcx, &mut stable_hasher); + hcx.with_hir_bodies(hash_bodies, owner, bodies, |hcx| { + item_like.hash_stable(hcx, &mut stable_hasher) }); stable_hasher.finish() } -impl<'a, 'hir> NodeCollector<'a, 'hir> { +impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { pub(super) fn root( sess: &'a Session, arena: &'hir Arena<'hir>, @@ -91,15 +94,16 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } fn insert_owner(&mut self, owner: LocalDefId, node: OwnerNode<'hir>) { - let hash = hash_body(&mut self.hcx, node); - let mut nodes = IndexVec::new(); nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: node.into() })); let bodies = &self.krate.owners[owner].as_ref().unwrap().bodies; + let hash = hash_body(&mut self.hcx, node, true, owner, bodies); + let node_hash = hash_body(&mut self.hcx, node, false, owner, bodies); + debug_assert!(self.map[owner].is_none()); - self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, nodes, bodies })); + self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, node_hash, nodes, bodies })); } fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) { @@ -176,7 +180,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } } -impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { +impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { type Map = Map<'hir>; /// Because we want to track parent items and so forth, enable diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 66d4ec2eeb6da..8c11fd8a280fc 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -874,21 +874,21 @@ impl<'hir> Map<'hir> { pub fn expect_item(&self, id: HirId) -> &'hir Item<'hir> { match self.tcx.hir_owner(id.expect_owner()) { - Some(Owner { node: OwnerNode::Item(item) }) => item, + Some(Owner { node: OwnerNode::Item(item), .. }) => item, _ => bug!("expected item, found {}", self.node_to_string(id)), } } pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem<'hir> { match self.tcx.hir_owner(id.expect_owner()) { - Some(Owner { node: OwnerNode::ImplItem(item) }) => item, + Some(Owner { node: OwnerNode::ImplItem(item), .. }) => item, _ => bug!("expected impl item, found {}", self.node_to_string(id)), } } pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem<'hir> { match self.tcx.hir_owner(id.expect_owner()) { - Some(Owner { node: OwnerNode::TraitItem(item) }) => item, + Some(Owner { node: OwnerNode::TraitItem(item), .. }) => item, _ => bug!("expected trait item, found {}", self.node_to_string(id)), } } @@ -902,7 +902,7 @@ impl<'hir> Map<'hir> { pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem<'hir> { match self.tcx.hir_owner(id.expect_owner()) { - Some(Owner { node: OwnerNode::ForeignItem(item) }) => item, + Some(Owner { node: OwnerNode::ForeignItem(item), .. }) => item, _ => bug!("expected foreign item, found {}", self.node_to_string(id)), } } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 094198713cc21..6d24190eefb5c 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -39,12 +39,14 @@ pub struct IndexedHir<'hir> { #[derive(Copy, Clone, Debug)] pub struct Owner<'tcx> { node: OwnerNode<'tcx>, + node_hash: Fingerprint, } impl<'a, 'tcx> HashStable> for Owner<'tcx> { + #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let Owner { node } = self; - hcx.while_hashing_hir_bodies(false, |hcx| node.hash_stable(hcx, hasher)); + let Owner { node: _, node_hash } = self; + node_hash.hash_stable(hcx, hasher) } } @@ -61,6 +63,8 @@ pub struct ParentedNode<'tcx> { pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the full HIR. hash: Fingerprint, + /// Pre-computed hash of the top node. + node_hash: Fingerprint, /// Full HIR for the current owner. // The zeroth node's parent is trash, but is never accessed. nodes: IndexVec>>, @@ -69,10 +73,11 @@ pub struct OwnerNodes<'tcx> { } impl<'a, 'tcx> HashStable> for OwnerNodes<'tcx> { + #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { // We ignore the `nodes` and `bodies` fields since these refer to information included in // `hash` which is hashed in the collector and used for the crate hash. - let OwnerNodes { hash, nodes: _, bodies: _ } = *self; + let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self; hash.hash_stable(hcx, hasher); } } @@ -130,7 +135,7 @@ pub fn provide(providers: &mut Providers) { let owner = tcx.index_hir(()).map[id].as_ref()?; let node = owner.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode. - Some(Owner { node }) + Some(Owner { node, node_hash: owner.node_hash }) }; providers.hir_owner_nodes = |tcx, id| tcx.index_hir(()).map[id].as_deref(); providers.hir_owner_parent = |tcx, id| { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index cbbd89e903335..5dea574c48417 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1342,20 +1342,15 @@ impl<'tcx> TyCtxt<'tcx> { #[inline(always)] pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> { - let krate = self.gcx.untracked_crate; let resolutions = &self.gcx.untracked_resolutions; - - StableHashingContext::new(self.sess, krate, &resolutions.definitions, &*resolutions.cstore) + StableHashingContext::new(self.sess, &resolutions.definitions, &*resolutions.cstore) } #[inline(always)] pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> { - let krate = self.gcx.untracked_crate; let resolutions = &self.gcx.untracked_resolutions; - StableHashingContext::ignore_spans( self.sess, - krate, &resolutions.definitions, &*resolutions.cstore, ) diff --git a/compiler/rustc_query_system/src/ich/hcx.rs b/compiler/rustc_query_system/src/ich/hcx.rs index f2e935c59fce2..cfef2073373cc 100644 --- a/compiler/rustc_query_system/src/ich/hcx.rs +++ b/compiler/rustc_query_system/src/ich/hcx.rs @@ -6,6 +6,7 @@ use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::definitions::{DefPathHash, Definitions}; +use rustc_index::vec::IndexVec; use rustc_session::cstore::CrateStore; use rustc_session::Session; use rustc_span::source_map::SourceMap; @@ -27,7 +28,6 @@ pub struct StableHashingContext<'a> { cstore: &'a dyn CrateStore, pub(super) body_resolver: BodyResolver<'a>, hash_spans: bool, - hash_bodies: bool, pub(super) node_id_hashing_mode: NodeIdHashingMode, // Very often, we are hashing something that does not need the @@ -46,24 +46,19 @@ pub enum NodeIdHashingMode { /// We could also just store a plain reference to the `hir::Crate` but we want /// to avoid that the crate is used to get untracked access to all of the HIR. #[derive(Clone, Copy)] -pub(super) struct BodyResolver<'tcx>(&'tcx hir::Crate<'tcx>); - -impl<'tcx> BodyResolver<'tcx> { - /// Returns a reference to the `hir::Body` with the given `BodyId`. - /// **Does not do any tracking**; use carefully. - pub(super) fn body(self, id: hir::BodyId) -> &'tcx hir::Body<'tcx> { - self.0.body(id) - } +pub(super) enum BodyResolver<'tcx> { + Forbidden, + Traverse { + hash_bodies: bool, + owner: LocalDefId, + bodies: &'tcx IndexVec>>, + }, } impl<'a> StableHashingContext<'a> { - /// The `krate` here is only used for mapping `BodyId`s to `Body`s. - /// Don't use it for anything else or you'll run the risk of - /// leaking data out of the tracking system. #[inline] fn new_with_or_without_spans( sess: &'a Session, - krate: &'a hir::Crate<'a>, definitions: &'a Definitions, cstore: &'a dyn CrateStore, always_ignore_spans: bool, @@ -72,13 +67,12 @@ impl<'a> StableHashingContext<'a> { !always_ignore_spans && !sess.opts.debugging_opts.incremental_ignore_spans; StableHashingContext { - body_resolver: BodyResolver(krate), + body_resolver: BodyResolver::Forbidden, definitions, cstore, caching_source_map: None, raw_source_map: sess.source_map(), hash_spans: hash_spans_initial, - hash_bodies: true, node_id_hashing_mode: NodeIdHashingMode::HashDefPath, } } @@ -86,13 +80,11 @@ impl<'a> StableHashingContext<'a> { #[inline] pub fn new( sess: &'a Session, - krate: &'a hir::Crate<'a>, definitions: &'a Definitions, cstore: &'a dyn CrateStore, ) -> Self { Self::new_with_or_without_spans( sess, - krate, definitions, cstore, /*always_ignore_spans=*/ false, @@ -102,20 +94,41 @@ impl<'a> StableHashingContext<'a> { #[inline] pub fn ignore_spans( sess: &'a Session, - krate: &'a hir::Crate<'a>, definitions: &'a Definitions, cstore: &'a dyn CrateStore, ) -> Self { let always_ignore_spans = true; - Self::new_with_or_without_spans(sess, krate, definitions, cstore, always_ignore_spans) + Self::new_with_or_without_spans(sess, definitions, cstore, always_ignore_spans) } + /// Allow hashing #[inline] - pub fn while_hashing_hir_bodies(&mut self, hash_bodies: bool, f: F) { - let prev_hash_bodies = self.hash_bodies; - self.hash_bodies = hash_bodies; + pub fn while_hashing_hir_bodies(&mut self, hb: bool, f: impl FnOnce(&mut Self)) { + let prev = match &mut self.body_resolver { + BodyResolver::Forbidden => panic!("Hashing HIR bodies is forbidden."), + BodyResolver::Traverse { ref mut hash_bodies, .. } => { + std::mem::replace(hash_bodies, hb) + } + }; f(self); - self.hash_bodies = prev_hash_bodies; + match &mut self.body_resolver { + BodyResolver::Forbidden => unreachable!(), + BodyResolver::Traverse { ref mut hash_bodies, .. } => *hash_bodies = prev, + } + } + + #[inline] + pub fn with_hir_bodies( + &mut self, + hash_bodies: bool, + owner: LocalDefId, + bodies: &'a IndexVec>>, + f: impl FnOnce(&mut Self), + ) { + let prev = self.body_resolver; + self.body_resolver = BodyResolver::Traverse { hash_bodies, owner, bodies }; + f(self); + self.body_resolver = prev; } #[inline] @@ -152,11 +165,6 @@ impl<'a> StableHashingContext<'a> { self.definitions.def_path_hash(def_id) } - #[inline] - pub fn hash_bodies(&self) -> bool { - self.hash_bodies - } - #[inline] pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> { match self.caching_source_map { diff --git a/compiler/rustc_query_system/src/ich/impls_hir.rs b/compiler/rustc_query_system/src/ich/impls_hir.rs index 04eb263a97718..dc208b36f938e 100644 --- a/compiler/rustc_query_system/src/ich/impls_hir.rs +++ b/compiler/rustc_query_system/src/ich/impls_hir.rs @@ -1,6 +1,7 @@ //! This module contains `HashStable` implementations for various HIR data //! types in no particular order. +use crate::ich::hcx::BodyResolver; use crate::ich::{NodeIdHashingMode, StableHashingContext}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; @@ -29,8 +30,13 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { #[inline] fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) { let hcx = self; - if hcx.hash_bodies() { - hcx.body_resolver.body(id).hash_stable(hcx, hasher); + match hcx.body_resolver { + BodyResolver::Forbidden => panic!("Hashing HIR bodies is forbidden."), + BodyResolver::Traverse { hash_bodies: false, .. } => {} + BodyResolver::Traverse { hash_bodies: true, owner, bodies } => { + assert_eq!(id.hir_id.owner, owner); + bodies[id.hir_id.local_id].unwrap().hash_stable(hcx, hasher); + } } } diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index f1d3315d6e66a..bd27c16c732a9 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -23,6 +23,7 @@ rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_metadata = { path = "../rustc_metadata" } +rustc_query_system = { path = "../rustc_query_system" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 28fe365fb584b..f08878ea9255e 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -54,13 +54,14 @@ use rustc_middle::hir::exports::ExportMap; use rustc_middle::span_bug; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, DefIdTree, MainDefinition, ResolverOutputs}; +use rustc_query_system::ich::StableHashingContext; use rustc_session::cstore::{CrateStore, MetadataLoaderDyn}; use rustc_session::lint; use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer}; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext, Transparency}; -use rustc_span::source_map::{CachingSourceMapView, Spanned}; +use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -1177,6 +1178,10 @@ impl ResolverAstLowering for Resolver<'_> { &mut self.definitions } + fn create_stable_hashing_context(&self) -> StableHashingContext<'_> { + StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore()) + } + fn lint_buffer(&mut self) -> &mut LintBuffer { &mut self.lint_buffer } @@ -1245,37 +1250,6 @@ impl ResolverAstLowering for Resolver<'_> { } } -struct ExpandHasher<'a, 'b> { - source_map: CachingSourceMapView<'a>, - resolver: &'a Resolver<'b>, -} - -impl<'a, 'b> rustc_span::HashStableContext for ExpandHasher<'a, 'b> { - #[inline] - fn hash_spans(&self) -> bool { - true - } - - #[inline] - fn def_span(&self, id: LocalDefId) -> Span { - self.resolver.def_span(id) - } - - #[inline] - fn def_path_hash(&self, def_id: DefId) -> DefPathHash { - self.resolver.def_path_hash(def_id) - } - - #[inline] - fn span_data_to_lines_and_cols( - &mut self, - span: &rustc_span::SpanData, - ) -> Option<(Lrc, usize, rustc_span::BytePos, usize, rustc_span::BytePos)> - { - self.source_map.span_data_to_lines_and_cols(span) - } -} - impl<'a> Resolver<'a> { pub fn new( session: &'a Session, @@ -1456,13 +1430,6 @@ impl<'a> Resolver<'a> { self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude, module_map) } - fn create_stable_hashing_context(&self) -> ExpandHasher<'_, 'a> { - ExpandHasher { - source_map: CachingSourceMapView::new(self.session.source_map()), - resolver: self, - } - } - pub fn next_node_id(&mut self) -> NodeId { let next = self .next_node_id From ed3c8e86cbface5f050b8911b0de02c196d840eb Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 9 Oct 2021 19:44:55 +0200 Subject: [PATCH 027/181] Hash during lowering. --- compiler/rustc_ast_lowering/src/lib.rs | 27 ++++++++++++++++- compiler/rustc_hir/src/hir.rs | 5 ++++ .../rustc_middle/src/hir/map/collector.rs | 29 +++---------------- compiler/rustc_middle/src/hir/map/mod.rs | 2 -- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 80b95b99b165e..f95ad9f3a9bd6 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -41,7 +41,9 @@ use rustc_ast::visit; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust; use rustc_data_structures::captures::Captures; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; @@ -467,7 +469,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - hir::OwnerInfo { node, attrs, bodies, trait_map } + let (hash, node_hash) = self.hash_body(node, &bodies); + + hir::OwnerInfo { hash, node_hash, node, attrs, bodies, trait_map } + } + + /// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate + /// queries which depend on the full HIR tree and those which only depend on the item signature. + fn hash_body( + &mut self, + node: hir::OwnerNode<'hir>, + bodies: &IndexVec>>, + ) -> (Fingerprint, Fingerprint) { + let mut hcx = self.resolver.create_stable_hashing_context(); + let mut stable_hasher = StableHasher::new(); + hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| { + node.hash_stable(hcx, &mut stable_hasher) + }); + let full_hash = stable_hasher.finish(); + let mut stable_hasher = StableHasher::new(); + hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| { + node.hash_stable(hcx, &mut stable_hasher) + }); + let node_hash = stable_hasher.finish(); + (full_hash, node_hash) } /// This method allocates a new `HirId` for the given `NodeId` and stores it in diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 1d1c0a0de13d8..44652d0198fad 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -9,6 +9,7 @@ use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, TraitObject pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto}; pub use rustc_ast::{CaptureBy, Movability, Mutability}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; use rustc_macros::HashStable_Generic; @@ -670,6 +671,10 @@ pub struct OwnerInfo<'hir> { /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. pub trait_map: FxHashMap>, + /// Pre-computed hash of the full HIR. + pub hash: Fingerprint, + /// Pre-computed hash of the top node. + pub node_hash: Fingerprint, } /// The top-level data structure that stores the entire contents of diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 80e48a4f74b4f..2499ef8bc60d1 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -1,9 +1,7 @@ use crate::arena::Arena; use crate::hir::map::Map; use crate::hir::{IndexedHir, OwnerNodes, ParentedNode}; -use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::CRATE_DEF_ID; @@ -11,7 +9,6 @@ use rustc_hir::definitions; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_index::vec::{Idx, IndexVec}; -use rustc_query_system::ich::StableHashingContext; use rustc_session::Session; use rustc_span::source_map::SourceMap; use rustc_span::{Span, DUMMY_SP}; @@ -37,8 +34,6 @@ pub(super) struct NodeCollector<'a, 'hir> { current_dep_node_owner: LocalDefId, definitions: &'a definitions::Definitions, - - hcx: StableHashingContext<'a>, } fn insert_vec_map(map: &mut IndexVec>, k: K, v: V) { @@ -51,27 +46,12 @@ fn insert_vec_map(map: &mut IndexVec>, k: K, v: V map[k] = Some(v); } -fn hash_body<'s, 'hir: 's>( - hcx: &mut StableHashingContext<'s>, - item_like: impl for<'a> HashStable>, - hash_bodies: bool, - owner: LocalDefId, - bodies: &'hir IndexVec>>, -) -> Fingerprint { - let mut stable_hasher = StableHasher::new(); - hcx.with_hir_bodies(hash_bodies, owner, bodies, |hcx| { - item_like.hash_stable(hcx, &mut stable_hasher) - }); - stable_hasher.finish() -} - impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { pub(super) fn root( sess: &'a Session, arena: &'hir Arena<'hir>, krate: &'hir Crate<'hir>, definitions: &'a definitions::Definitions, - hcx: StableHashingContext<'a>, ) -> NodeCollector<'a, 'hir> { let mut collector = NodeCollector { arena, @@ -80,7 +60,6 @@ impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { parent_node: hir::CRATE_HIR_ID, current_dep_node_owner: CRATE_DEF_ID, definitions, - hcx, map: IndexVec::from_fn_n(|_| None, definitions.def_index_count()), parenting: FxHashMap::default(), }; @@ -97,10 +76,10 @@ impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { let mut nodes = IndexVec::new(); nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: node.into() })); - let bodies = &self.krate.owners[owner].as_ref().unwrap().bodies; - - let hash = hash_body(&mut self.hcx, node, true, owner, bodies); - let node_hash = hash_body(&mut self.hcx, node, false, owner, bodies); + let info = self.krate.owners[owner].as_ref().unwrap(); + let hash = info.hash; + let node_hash = info.node_hash; + let bodies = &info.bodies; debug_assert!(self.map[owner].is_none()); self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, node_hash, nodes, bodies })); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 8c11fd8a280fc..89f4ec4d9f61f 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1071,13 +1071,11 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tc let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map"); // We can access untracked state since we are an eval_always query. - let hcx = tcx.create_stable_hashing_context(); let mut collector = NodeCollector::root( tcx.sess, &**tcx.arena, tcx.untracked_crate, &tcx.untracked_resolutions.definitions, - hcx, ); let top_mod = tcx.untracked_crate.module(); collector.visit_mod(top_mod, top_mod.inner, CRATE_HIR_ID); From c09eaea484c8f7a01741188982447eec88b5caa8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 28 Feb 2021 20:23:10 +0100 Subject: [PATCH 028/181] Make index_hir incremental. --- compiler/rustc_hir/src/definitions.rs | 6 + compiler/rustc_middle/src/arena.rs | 5 +- .../rustc_middle/src/hir/map/collector.rs | 164 ++++++++---------- compiler/rustc_middle/src/hir/map/mod.rs | 43 ++--- compiler/rustc_middle/src/hir/mod.rs | 36 ++-- compiler/rustc_middle/src/query/mod.rs | 3 +- 6 files changed, 115 insertions(+), 142 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index ca29351455e62..b7bdc9a1414ac 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -92,6 +92,12 @@ impl DefPathTable { .iter_enumerated() .map(move |(index, key)| (index, key, &self.def_path_hashes[index])) } + + pub fn all_def_path_hashes_and_def_ids( + &self, + ) -> impl Iterator + '_ { + self.def_path_hashes.iter_enumerated().map(move |(index, hash)| (hash, index)) + } } /// The definition table containing node definitions. diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 962aea448b82c..2986e8c7a06db 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -93,10 +93,7 @@ macro_rules! arena_types { [] predicates: rustc_middle::ty::PredicateInner<$tcx>, // HIR query types - [few] indexed_hir: rustc_middle::hir::IndexedHir<$tcx>, - [few] hir_definitions: rustc_hir::definitions::Definitions, - [] hir_owner: rustc_middle::hir::Owner<$tcx>, - [] hir_owner_nodes: rustc_middle::hir::OwnerNodes<$tcx>, + [] indexed_hir: rustc_middle::hir::IndexedHir<$tcx>, // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 2499ef8bc60d1..a9e676b9e30f4 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -1,10 +1,8 @@ -use crate::arena::Arena; use crate::hir::map::Map; use crate::hir::{IndexedHir, OwnerNodes, ParentedNode}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; -use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::definitions; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::*; @@ -17,21 +15,19 @@ use std::iter::repeat; /// A visitor that walks over the HIR and collects `Node`s into a HIR map. pub(super) struct NodeCollector<'a, 'hir> { - arena: &'hir Arena<'hir>, - /// The crate krate: &'hir Crate<'hir>, /// Source map source_map: &'a SourceMap, - map: IndexVec>>, - parenting: FxHashMap, + nodes: OwnerNodes<'hir>, + parenting: FxHashMap, /// The parent of this node - parent_node: hir::HirId, + parent_node: hir::ItemLocalId, - current_dep_node_owner: LocalDefId, + owner: LocalDefId, definitions: &'a definitions::Definitions, } @@ -46,53 +42,51 @@ fn insert_vec_map(map: &mut IndexVec>, k: K, v: V map[k] = Some(v); } -impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { - pub(super) fn root( - sess: &'a Session, - arena: &'hir Arena<'hir>, - krate: &'hir Crate<'hir>, - definitions: &'a definitions::Definitions, - ) -> NodeCollector<'a, 'hir> { - let mut collector = NodeCollector { - arena, - krate, - source_map: sess.source_map(), - parent_node: hir::CRATE_HIR_ID, - current_dep_node_owner: CRATE_DEF_ID, - definitions, - map: IndexVec::from_fn_n(|_| None, definitions.def_index_count()), - parenting: FxHashMap::default(), - }; - collector.insert_owner(CRATE_DEF_ID, OwnerNode::Crate(krate.module())); - - collector - } - - pub(super) fn finalize_and_compute_crate_hash(self) -> IndexedHir<'hir> { - IndexedHir { map: self.map, parenting: self.parenting } - } - - fn insert_owner(&mut self, owner: LocalDefId, node: OwnerNode<'hir>) { - let mut nodes = IndexVec::new(); - nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: node.into() })); - - let info = self.krate.owners[owner].as_ref().unwrap(); - let hash = info.hash; - let node_hash = info.node_hash; - let bodies = &info.bodies; - - debug_assert!(self.map[owner].is_none()); - self.map[owner] = Some(self.arena.alloc(OwnerNodes { hash, node_hash, nodes, bodies })); - } +pub(super) fn collect<'a, 'hir: 'a>( + sess: &'a Session, + krate: &'hir Crate<'hir>, + definitions: &'a definitions::Definitions, + owner: LocalDefId, +) -> Option> { + let info = krate.owners.get(owner)?.as_ref()?; + let item = info.node; + let mut nodes = IndexVec::new(); + nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: item.into() })); + let mut collector = NodeCollector { + krate, + source_map: sess.source_map(), + owner, + parent_node: ItemLocalId::new(0), + definitions, + nodes: OwnerNodes { + hash: info.hash, + node_hash: info.node_hash, + nodes, + bodies: &info.bodies, + }, + parenting: FxHashMap::default(), + }; + + match item { + OwnerNode::Crate(citem) => collector.visit_mod(&citem, citem.inner, hir::CRATE_HIR_ID), + OwnerNode::Item(item) => collector.visit_item(item), + OwnerNode::TraitItem(item) => collector.visit_trait_item(item), + OwnerNode::ImplItem(item) => collector.visit_impl_item(item), + OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item), + }; + + Some(IndexedHir { nodes: collector.nodes, parenting: collector.parenting }) +} +impl<'a, 'hir> NodeCollector<'a, 'hir> { fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) { - debug_assert_eq!(self.current_dep_node_owner, hir_id.owner); + debug_assert_eq!(self.owner, hir_id.owner); debug_assert_ne!(hir_id.local_id.as_u32(), 0); // Make sure that the DepNode of some node coincides with the HirId // owner of that node. if cfg!(debug_assertions) { - if hir_id.owner != self.current_dep_node_owner { + if hir_id.owner != self.owner { let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) { Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate_verbose(), None => format!("{:?}", node), @@ -104,62 +98,41 @@ impl<'a, 'hir: 'a> NodeCollector<'a, 'hir> { current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", self.source_map.span_to_diagnostic_string(span), node_str, - self.definitions - .def_path(self.current_dep_node_owner) - .to_string_no_crate_verbose(), - self.current_dep_node_owner, + self.definitions.def_path(self.owner).to_string_no_crate_verbose(), + self.owner, self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(), hir_id.owner, ) } } - let nodes = self.map[hir_id.owner].as_mut().unwrap(); - - debug_assert_eq!(self.parent_node.owner, self.current_dep_node_owner); insert_vec_map( - &mut nodes.nodes, + &mut self.nodes.nodes, hir_id.local_id, - ParentedNode { parent: self.parent_node.local_id, node: node }, + ParentedNode { parent: self.parent_node, node: node }, ); } fn with_parent(&mut self, parent_node_id: HirId, f: F) { + debug_assert_eq!(parent_node_id.owner, self.owner); let parent_node = self.parent_node; - self.parent_node = parent_node_id; + self.parent_node = parent_node_id.local_id; f(self); self.parent_node = parent_node; } - fn with_dep_node_owner(&mut self, dep_node_owner: LocalDefId, f: impl FnOnce(&mut Self)) { - let prev_owner = self.current_dep_node_owner; - let prev_parent = self.parent_node; - - self.current_dep_node_owner = dep_node_owner; - self.parent_node = HirId::make_owner(dep_node_owner); - f(self); - self.current_dep_node_owner = prev_owner; - self.parent_node = prev_parent; - } - fn insert_nested(&mut self, item: LocalDefId) { - #[cfg(debug_assertions)] - { - let dk_parent = self.definitions.def_key(item).parent.unwrap(); - let dk_parent = LocalDefId { local_def_index: dk_parent }; - let dk_parent = self.definitions.local_def_id_to_hir_id(dk_parent); - debug_assert_eq!( - dk_parent.owner, self.parent_node.owner, - "Different parents for {:?}", - item - ) + let dk_parent = self.definitions.def_key(item).parent.unwrap(); + let dk_parent = LocalDefId { local_def_index: dk_parent }; + let dk_parent = self.definitions.local_def_id_to_hir_id(dk_parent); + debug_assert_eq!(dk_parent.owner, self.owner, "Different parents for {:?}", item); + if dk_parent.local_id != self.parent_node { + self.parenting.insert(item, self.parent_node); } - - assert_eq!(self.parenting.insert(item, self.parent_node), None); } } -impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { +impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { type Map = Map<'hir>; /// Because we want to track parent items and so forth, enable @@ -173,26 +146,24 @@ impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { fn visit_nested_item(&mut self, item: ItemId) { debug!("visit_nested_item: {:?}", item); self.insert_nested(item.def_id); - self.visit_item(self.krate.item(item)); } fn visit_nested_trait_item(&mut self, item_id: TraitItemId) { self.insert_nested(item_id.def_id); - self.visit_trait_item(self.krate.trait_item(item_id)); } fn visit_nested_impl_item(&mut self, item_id: ImplItemId) { self.insert_nested(item_id.def_id); - self.visit_impl_item(self.krate.impl_item(item_id)); } fn visit_nested_foreign_item(&mut self, foreign_id: ForeignItemId) { self.insert_nested(foreign_id.def_id); - self.visit_foreign_item(self.krate.foreign_item(foreign_id)); } fn visit_nested_body(&mut self, id: BodyId) { - self.visit_body(self.krate.body(id)); + let body = self.krate.body(id); + debug_assert_eq!(id.hir_id.owner, self.owner); + self.visit_body(body); } fn visit_param(&mut self, param: &'hir Param<'hir>) { @@ -205,8 +176,8 @@ impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { fn visit_item(&mut self, i: &'hir Item<'hir>) { debug!("visit_item: {:?}", i); - self.insert_owner(i.def_id, OwnerNode::Item(i)); - self.with_dep_node_owner(i.def_id, |this| { + debug_assert_eq!(i.def_id, self.owner); + self.with_parent(i.hir_id(), |this| { if let ItemKind::Struct(ref struct_def, _) = i.kind { // If this is a tuple or unit-like struct, register the constructor. if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { @@ -218,8 +189,8 @@ impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_foreign_item(&mut self, fi: &'hir ForeignItem<'hir>) { - self.insert_owner(fi.def_id, OwnerNode::ForeignItem(fi)); - self.with_dep_node_owner(fi.def_id, |this| { + debug_assert_eq!(fi.def_id, self.owner); + self.with_parent(fi.hir_id(), |this| { intravisit::walk_foreign_item(this, fi); }); } @@ -236,15 +207,15 @@ impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_trait_item(&mut self, ti: &'hir TraitItem<'hir>) { - self.insert_owner(ti.def_id, OwnerNode::TraitItem(ti)); - self.with_dep_node_owner(ti.def_id, |this| { + debug_assert_eq!(ti.def_id, self.owner); + self.with_parent(ti.hir_id(), |this| { intravisit::walk_trait_item(this, ti); }); } fn visit_impl_item(&mut self, ii: &'hir ImplItem<'hir>) { - self.insert_owner(ii.def_id, OwnerNode::ImplItem(ii)); - self.with_dep_node_owner(ii.def_id, |this| { + debug_assert_eq!(ii.def_id, self.owner); + self.with_parent(ii.hir_id(), |this| { intravisit::walk_impl_item(this, ii); }); } @@ -332,7 +303,8 @@ impl<'a, 'hir: 'a> Visitor<'hir> for NodeCollector<'a, 'hir> { s: Span, id: HirId, ) { - assert_eq!(self.parent_node, id); + assert_eq!(self.owner, id.owner); + assert_eq!(self.parent_node, id.local_id); intravisit::walk_fn(self, fk, fd, b, s, id); } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 89f4ec4d9f61f..1a63cc1d8fedd 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1,5 +1,3 @@ -use self::collector::NodeCollector; - use crate::hir::{IndexedHir, ModuleItems, Owner}; use crate::ty::TyCtxt; use rustc_ast as ast; @@ -318,7 +316,7 @@ impl<'hir> Map<'hir> { } pub fn get_parent_node(&self, hir_id: HirId) -> HirId { - self.find_parent_node(hir_id).unwrap_or(CRATE_HIR_ID) + self.find_parent_node(hir_id).unwrap() } /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. @@ -1067,36 +1065,30 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> { } } -pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tcx> { - let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map"); - - // We can access untracked state since we are an eval_always query. - let mut collector = NodeCollector::root( +pub(super) fn index_hir<'tcx>( + tcx: TyCtxt<'tcx>, + owner: LocalDefId, +) -> Option<&'tcx IndexedHir<'tcx>> { + let map = collector::collect( tcx.sess, - &**tcx.arena, tcx.untracked_crate, &tcx.untracked_resolutions.definitions, - ); - let top_mod = tcx.untracked_crate.module(); - collector.visit_mod(top_mod, top_mod.inner, CRATE_HIR_ID); + owner, + )?; - let map = collector.finalize_and_compute_crate_hash(); - tcx.arena.alloc(map) + Some(&*tcx.arena.alloc(map)) } pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { - assert_eq!(crate_num, LOCAL_CRATE); - - // We can access untracked state since we are an eval_always query. - let mut hcx = tcx.create_stable_hashing_context(); - + debug_assert_eq!(crate_num, LOCAL_CRATE); let mut hir_body_nodes: Vec<_> = tcx - .index_hir(()) - .map - .iter_enumerated() - .filter_map(|(def_id, hod)| { - let def_path_hash = tcx.untracked_resolutions.definitions.def_path_hash(def_id); - let hash = hod.as_ref()?.hash; + .untracked_resolutions + .definitions + .def_path_table() + .all_def_path_hashes_and_def_ids() + .filter_map(|(def_path_hash, local_def_index)| { + let def_id = LocalDefId { local_def_index }; + let hash = tcx.index_hir(def_id).as_ref()?.nodes.hash; Some((def_path_hash, hash, def_id)) }) .collect(); @@ -1120,6 +1112,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { source_file_names.sort_unstable(); + let mut hcx = tcx.create_stable_hashing_context(); let mut stable_hasher = StableHasher::new(); for (def_path_hash, fingerprint, def_id) in hir_body_nodes.iter() { def_path_hash.0.hash_stable(&mut hcx, &mut stable_hasher); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 6d24190eefb5c..2ac647307184e 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -19,16 +19,13 @@ use rustc_query_system::ich::StableHashingContext; use rustc_span::DUMMY_SP; use std::collections::BTreeMap; -/// Result of HIR indexing. -#[derive(Debug)] +/// Result of HIR indexing for a given HIR owner. +#[derive(Debug, HashStable)] pub struct IndexedHir<'hir> { - /// Contents of the HIR owned by each definition. None for definitions that are not HIR owners. - // The `mut` comes from construction time, and is harmless since we only ever hand out - // immutable refs to IndexedHir. - map: IndexVec>>, - /// Map from each owner to its parent's HirId inside another owner. - // This map is separate from `map` to eventually allow for per-owner indexing. - parenting: FxHashMap, + /// Contents of the HIR. + nodes: OwnerNodes<'hir>, + /// Map from each nested owner to its parent's local id. + parenting: FxHashMap, } /// Top-level HIR node for current owner. This only contains the node for which @@ -132,15 +129,24 @@ pub fn provide(providers: &mut Providers) { providers.crate_hash = map::crate_hash; providers.hir_module_items = map::hir_module_items; providers.hir_owner = |tcx, id| { - let owner = tcx.index_hir(()).map[id].as_ref()?; - let node = owner.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; + let owner = tcx.index_hir(id)?; + let node = owner.nodes.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode. - Some(Owner { node, node_hash: owner.node_hash }) + Some(Owner { node, node_hash: owner.nodes.node_hash }) }; - providers.hir_owner_nodes = |tcx, id| tcx.index_hir(()).map[id].as_deref(); + providers.hir_owner_nodes = |tcx, id| tcx.index_hir(id).map(|i| &i.nodes); providers.hir_owner_parent = |tcx, id| { - let index = tcx.index_hir(()); - index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID) + let parent = tcx.untracked_resolutions.definitions.def_key(id).parent; + let parent = parent.map_or(CRATE_HIR_ID, |local_def_index| { + let def_id = LocalDefId { local_def_index }; + let mut parent_hir_id = + tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id); + if let Some(local_id) = tcx.index_hir(parent_hir_id.owner).unwrap().parenting.get(&id) { + parent_hir_id.local_id = *local_id; + } + parent_hir_id + }); + parent }; providers.hir_attrs = |tcx, id| AttributeMap::new(&tcx.hir_crate(()).owners[id]); providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 7e9391b98f7ed..bfded8f710ac8 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -42,9 +42,8 @@ rustc_queries! { /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`. /// Avoid calling this query directly. - query index_hir(_: ()) -> &'tcx crate::hir::IndexedHir<'tcx> { + query index_hir(_: LocalDefId) -> Option<&'tcx crate::hir::IndexedHir<'tcx>> { eval_always - no_hash desc { "index HIR" } } From 1c7f85f17c0ddde890ced0ba4445e122c1ffc093 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Sep 2021 03:19:18 +0200 Subject: [PATCH 029/181] Perform indexing during lowering. Do not access DefId<->HirId maps before they are initialized. --- .../src/index.rs} | 65 ++++++---------- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 8 +- compiler/rustc_hir/src/arena.rs | 1 + compiler/rustc_hir/src/hir.rs | 78 +++++++++---------- compiler/rustc_hir/src/intravisit.rs | 22 ++++++ compiler/rustc_hir/src/lib.rs | 1 + compiler/rustc_hir/src/stable_hash_impls.rs | 13 +++- compiler/rustc_middle/src/arena.rs | 3 - compiler/rustc_middle/src/hir/map/mod.rs | 29 ++----- compiler/rustc_middle/src/hir/mod.rs | 55 ++----------- compiler/rustc_middle/src/query/mod.rs | 9 +-- 12 files changed, 117 insertions(+), 169 deletions(-) rename compiler/{rustc_middle/src/hir/map/collector.rs => rustc_ast_lowering/src/index.rs} (87%) diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_ast_lowering/src/index.rs similarity index 87% rename from compiler/rustc_middle/src/hir/map/collector.rs rename to compiler/rustc_ast_lowering/src/index.rs index a9e676b9e30f4..7b0f1caaee1e1 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -1,5 +1,3 @@ -use crate::hir::map::Map; -use crate::hir::{IndexedHir, OwnerNodes, ParentedNode}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; @@ -12,16 +10,16 @@ use rustc_span::source_map::SourceMap; use rustc_span::{Span, DUMMY_SP}; use std::iter::repeat; +use tracing::debug; /// A visitor that walks over the HIR and collects `Node`s into a HIR map. pub(super) struct NodeCollector<'a, 'hir> { - /// The crate - krate: &'hir Crate<'hir>, - /// Source map source_map: &'a SourceMap, + bodies: &'a IndexVec>>, - nodes: OwnerNodes<'hir>, + /// Outputs + nodes: IndexVec>>, parenting: FxHashMap, /// The parent of this node @@ -42,28 +40,21 @@ fn insert_vec_map(map: &mut IndexVec>, k: K, v: V map[k] = Some(v); } -pub(super) fn collect<'a, 'hir: 'a>( - sess: &'a Session, - krate: &'hir Crate<'hir>, - definitions: &'a definitions::Definitions, - owner: LocalDefId, -) -> Option> { - let info = krate.owners.get(owner)?.as_ref()?; - let item = info.node; +pub(super) fn index_hir<'hir>( + sess: &Session, + definitions: &definitions::Definitions, + item: hir::OwnerNode<'hir>, + bodies: &IndexVec>>, +) -> (IndexVec>>, FxHashMap) { let mut nodes = IndexVec::new(); nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: item.into() })); let mut collector = NodeCollector { - krate, source_map: sess.source_map(), - owner, - parent_node: ItemLocalId::new(0), definitions, - nodes: OwnerNodes { - hash: info.hash, - node_hash: info.node_hash, - nodes, - bodies: &info.bodies, - }, + owner: item.def_id(), + parent_node: ItemLocalId::new(0), + nodes, + bodies, parenting: FxHashMap::default(), }; @@ -75,7 +66,7 @@ pub(super) fn collect<'a, 'hir: 'a>( OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item), }; - Some(IndexedHir { nodes: collector.nodes, parenting: collector.parenting }) + (collector.nodes, collector.parenting) } impl<'a, 'hir> NodeCollector<'a, 'hir> { @@ -87,17 +78,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { // owner of that node. if cfg!(debug_assertions) { if hir_id.owner != self.owner { - let node_str = match self.definitions.opt_hir_id_to_local_def_id(hir_id) { - Some(def_id) => self.definitions.def_path(def_id).to_string_no_crate_verbose(), - None => format!("{:?}", node), - }; - - span_bug!( - span, - "inconsistent DepNode at `{:?}` for `{}`: \ + panic!( + "inconsistent DepNode at `{:?}` for `{:?}`: \ current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})", self.source_map.span_to_diagnostic_string(span), - node_str, + node, self.definitions.def_path(self.owner).to_string_no_crate_verbose(), self.owner, self.definitions.def_path(hir_id.owner).to_string_no_crate_verbose(), @@ -107,7 +92,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } insert_vec_map( - &mut self.nodes.nodes, + &mut self.nodes, hir_id.local_id, ParentedNode { parent: self.parent_node, node: node }, ); @@ -122,18 +107,12 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } fn insert_nested(&mut self, item: LocalDefId) { - let dk_parent = self.definitions.def_key(item).parent.unwrap(); - let dk_parent = LocalDefId { local_def_index: dk_parent }; - let dk_parent = self.definitions.local_def_id_to_hir_id(dk_parent); - debug_assert_eq!(dk_parent.owner, self.owner, "Different parents for {:?}", item); - if dk_parent.local_id != self.parent_node { - self.parenting.insert(item, self.parent_node); - } + self.parenting.insert(item, self.parent_node); } } impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { - type Map = Map<'hir>; + type Map = !; /// Because we want to track parent items and so forth, enable /// deep walking so that we walk nested items in the context of @@ -161,8 +140,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_nested_body(&mut self, id: BodyId) { - let body = self.krate.body(id); debug_assert_eq!(id.hir_id.owner, self.owner); + let body = self.bodies[id.hir_id.local_id].unwrap(); self.visit_body(body); } diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index cac5bb56c9f5f..d5fa52a341475 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -101,7 +101,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let old_len = self.in_scope_lifetimes.len(); let parent_generics = - match self.owners[parent_hir_id].as_ref().unwrap().node.expect_item().kind { + match self.owners[parent_hir_id].as_ref().unwrap().node().expect_item().kind { hir::ItemKind::Impl(hir::Impl { ref generics, .. }) | hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params, _ => &[], diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index f95ad9f3a9bd6..a7f1ba8b79198 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -33,6 +33,7 @@ #![feature(crate_visibility_modifier)] #![feature(box_patterns)] #![feature(iter_zip)] +#![feature(never_type)] #![recursion_limit = "256"] use rustc_ast::token::{self, Token}; @@ -78,6 +79,7 @@ macro_rules! arena_vec { mod asm; mod block; mod expr; +mod index; mod item; mod pat; mod path; @@ -434,6 +436,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.local_node_ids.push(owner); let item = f(self); + debug_assert_eq!(def_id, item.def_id()); let info = self.make_owner_info(item); self.attrs = current_attrs; @@ -470,8 +473,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } let (hash, node_hash) = self.hash_body(node, &bodies); + let (nodes, parenting) = + index::index_hir(self.sess, self.resolver.definitions(), node, &bodies); + let nodes = hir::OwnerNodes { hash, node_hash, nodes, bodies }; - hir::OwnerInfo { hash, node_hash, node, attrs, bodies, trait_map } + hir::OwnerInfo { nodes, parenting, attrs, trait_map } } /// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate diff --git a/compiler/rustc_hir/src/arena.rs b/compiler/rustc_hir/src/arena.rs index 5334f6d729dc5..1a34dd0442855 100644 --- a/compiler/rustc_hir/src/arena.rs +++ b/compiler/rustc_hir/src/arena.rs @@ -37,6 +37,7 @@ macro_rules! arena_types { [few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>, [] local: rustc_hir::Local<$tcx>, [few] mod_: rustc_hir::Mod<$tcx>, + [] owner_info: rustc_hir::OwnerInfo<$tcx>, [] param: rustc_hir::Param<$tcx>, [] pat: rustc_hir::Pat<$tcx>, [] path: rustc_hir::Path<$tcx>, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 44652d0198fad..4c8157fee3704 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1,5 +1,5 @@ use crate::def::{CtorKind, DefKind, Res}; -use crate::def_id::{DefId, CRATE_DEF_ID}; +use crate::def_id::DefId; crate use crate::hir_id::{HirId, ItemLocalId}; use crate::LangItem; @@ -663,18 +663,49 @@ pub struct WhereEqPredicate<'hir> { pub rhs_ty: &'hir Ty<'hir>, } +/// HIR node coupled with its parent's id in the same HIR owner. +/// +/// The parent is trash when the node is a HIR owner. +#[derive(Clone, Debug)] +pub struct ParentedNode<'tcx> { + pub parent: ItemLocalId, + pub node: Node<'tcx>, +} + +#[derive(Debug)] +pub struct OwnerNodes<'tcx> { + /// Pre-computed hash of the full HIR. + pub hash: Fingerprint, + /// Pre-computed hash of the top node. + pub node_hash: Fingerprint, + /// Full HIR for the current owner. + // The zeroth node's parent is trash, but is never accessed. + pub nodes: IndexVec>>, + /// Content of local bodies. + pub bodies: IndexVec>>, +} + #[derive(Debug)] pub struct OwnerInfo<'hir> { - pub node: OwnerNode<'hir>, + /// Contents of the HIR. + pub nodes: OwnerNodes<'hir>, + /// Map from each nested owner to its parent's local id. + pub parenting: FxHashMap, + pub attrs: BTreeMap, - pub bodies: IndexVec>>, /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. pub trait_map: FxHashMap>, - /// Pre-computed hash of the full HIR. - pub hash: Fingerprint, - /// Pre-computed hash of the top node. - pub node_hash: Fingerprint, +} + +impl<'tcx> OwnerInfo<'tcx> { + #[inline] + pub fn node(&self) -> OwnerNode<'tcx> { + use rustc_index::vec::Idx; + let node = self.nodes.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; + let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode. + node + } } /// The top-level data structure that stores the entire contents of @@ -688,39 +719,6 @@ pub struct Crate<'hir> { pub owners: IndexVec>>, } -impl Crate<'hir> { - pub fn module(&self) -> &'hir Mod<'hir> { - let i = self.owners[CRATE_DEF_ID].as_ref().unwrap().node; - if let OwnerNode::Crate(m) = i { m } else { panic!() } - } - - pub fn item(&self, id: ItemId) -> &'hir Item<'hir> { - self.owners[id.def_id].as_ref().unwrap().node.expect_item() - } - - pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().node.expect_trait_item() - } - - pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().node.expect_impl_item() - } - - pub fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { - self.owners[id.def_id].as_ref().unwrap().node.expect_foreign_item() - } - - pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { - let HirId { owner, local_id } = id.hir_id; - self.owners[owner].as_ref().unwrap().bodies[local_id].unwrap() - } - - pub fn attrs(&self, id: HirId) -> &'hir [Attribute] { - let HirId { owner, local_id } = id; - &self.owners[owner].as_ref().unwrap().attrs.get(&local_id).map(|la| *la).unwrap_or(&[]) - } -} - /// A block of statements `{ .. }`, which may have a label (in this case the /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// the `rules` being anything but `DefaultBlock`. diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 1ac2625dd4754..3e58af1f167aa 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -130,6 +130,28 @@ pub trait Map<'hir> { fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>; } +// Used when no map is actually available, forcing manual implementation of nested visitors. +impl Map<'hir> for ! { + fn find(&self, _: HirId) -> Option> { + unreachable!() + } + fn body(&self, _: BodyId) -> &'hir Body<'hir> { + unreachable!() + } + fn item(&self, _: ItemId) -> &'hir Item<'hir> { + unreachable!() + } + fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> { + unreachable!() + } + fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> { + unreachable!() + } + fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> { + unreachable!() + } +} + /// An erased version of `Map<'hir>`, using dynamic dispatch. /// NOTE: This type is effectively only usable with `NestedVisitorMap::None`. pub struct ErasedMap<'hir>(&'hir dyn Map<'hir>); diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index f5ea044e24865..af8421aeb89a7 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -6,6 +6,7 @@ #![feature(in_band_lifetimes)] #![feature(once_cell)] #![feature(min_specialization)] +#![feature(never_type)] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index 9d5ef279dd784..ad73e363d7f2e 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,8 +1,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use crate::hir::{ - BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, - TraitItemId, Ty, VisibilityKind, + BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, OwnerNodes, + TraitItem, TraitItemId, Ty, VisibilityKind, }; use crate::hir_id::{HirId, ItemLocalId}; use rustc_span::def_id::DefPathHash; @@ -209,3 +209,12 @@ impl HashStable for Item<'_> { }); } } + +impl HashStable for OwnerNodes<'tcx> { + fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + // We ignore the `nodes` and `bodies` fields since these refer to information included in + // `hash` which is hashed in the collector and used for the crate hash. + let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self; + hash.hash_stable(hcx, hasher); + } +} diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 2986e8c7a06db..4a027cb7ebe05 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -92,9 +92,6 @@ macro_rules! arena_types { [] tys: rustc_middle::ty::TyS<$tcx>, [] predicates: rustc_middle::ty::PredicateInner<$tcx>, - // HIR query types - [] indexed_hir: rustc_middle::hir::IndexedHir<$tcx>, - // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena // (during lowering) and the `librustc_middle` arena (for decoding MIR) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 1a63cc1d8fedd..834d5f964e187 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1,4 +1,4 @@ -use crate::hir::{IndexedHir, ModuleItems, Owner}; +use crate::hir::{ModuleItems, Owner}; use crate::ty::TyCtxt; use rustc_ast as ast; use rustc_data_structures::fingerprint::Fingerprint; @@ -21,7 +21,6 @@ use rustc_target::spec::abi::Abi; use std::collections::VecDeque; pub mod blocks; -mod collector; fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> { match node { @@ -164,7 +163,7 @@ impl<'hir> Map<'hir> { pub fn items(&self) -> impl Iterator> + 'hir { let krate = self.krate(); - krate.owners.iter().filter_map(|owner| match owner.as_ref()?.node { + krate.owners.iter().filter_map(|owner| match owner.as_ref()?.node() { OwnerNode::Item(item) => Some(item), _ => None, }) @@ -497,7 +496,7 @@ impl<'hir> Map<'hir> { .owners .iter_enumerated() .flat_map(move |(owner, owner_info)| { - let bodies = &owner_info.as_ref()?.bodies; + let bodies = &owner_info.as_ref()?.nodes.bodies; Some(bodies.iter_enumerated().filter_map(move |(local_id, body)| { if body.is_none() { return None; @@ -518,7 +517,7 @@ impl<'hir> Map<'hir> { par_iter(&self.krate().owners.raw).enumerate().for_each(|(owner, owner_info)| { let owner = LocalDefId::new(owner); if let Some(owner_info) = owner_info { - par_iter(&owner_info.bodies.raw).enumerate().for_each(|(local_id, body)| { + par_iter(&owner_info.nodes.bodies.raw).enumerate().for_each(|(local_id, body)| { if body.is_some() { let local_id = ItemLocalId::new(local_id); let hir_id = HirId { owner, local_id }; @@ -605,7 +604,7 @@ impl<'hir> Map<'hir> { { let krate = self.krate(); for owner in krate.owners.iter().filter_map(Option::as_ref) { - match owner.node { + match owner.node() { OwnerNode::Item(item) => visitor.visit_item(item), OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item), OwnerNode::ImplItem(item) => visitor.visit_impl_item(item), @@ -621,7 +620,7 @@ impl<'hir> Map<'hir> { V: itemlikevisit::ParItemLikeVisitor<'hir> + Sync + Send, { let krate = self.krate(); - par_for_each_in(&krate.owners.raw, |owner| match owner.as_ref().map(|o| o.node) { + par_for_each_in(&krate.owners.raw, |owner| match owner.as_ref().map(OwnerInfo::node) { Some(OwnerNode::Item(item)) => visitor.visit_item(item), Some(OwnerNode::ForeignItem(item)) => visitor.visit_foreign_item(item), Some(OwnerNode::ImplItem(item)) => visitor.visit_impl_item(item), @@ -1065,20 +1064,6 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> { } } -pub(super) fn index_hir<'tcx>( - tcx: TyCtxt<'tcx>, - owner: LocalDefId, -) -> Option<&'tcx IndexedHir<'tcx>> { - let map = collector::collect( - tcx.sess, - tcx.untracked_crate, - &tcx.untracked_resolutions.definitions, - owner, - )?; - - Some(&*tcx.arena.alloc(map)) -} - pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { debug_assert_eq!(crate_num, LOCAL_CRATE); let mut hir_body_nodes: Vec<_> = tcx @@ -1088,7 +1073,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { .all_def_path_hashes_and_def_ids() .filter_map(|(def_path_hash, local_def_index)| { let def_id = LocalDefId { local_def_index }; - let hash = tcx.index_hir(def_id).as_ref()?.nodes.hash; + let hash = tcx.hir_crate(()).owners[def_id].as_ref()?.nodes.hash; Some((def_path_hash, hash, def_id)) }) .collect(); diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 2ac647307184e..70179e73b1975 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -10,24 +10,13 @@ use crate::ty::query::Providers; use crate::ty::TyCtxt; use rustc_ast::Attribute; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::LocalDefId; use rustc_hir::*; -use rustc_index::vec::{Idx, IndexVec}; use rustc_query_system::ich::StableHashingContext; use rustc_span::DUMMY_SP; use std::collections::BTreeMap; -/// Result of HIR indexing for a given HIR owner. -#[derive(Debug, HashStable)] -pub struct IndexedHir<'hir> { - /// Contents of the HIR. - nodes: OwnerNodes<'hir>, - /// Map from each nested owner to its parent's local id. - parenting: FxHashMap, -} - /// Top-level HIR node for current owner. This only contains the node for which /// `HirId::local_id == 0`, and excludes bodies. /// @@ -47,38 +36,6 @@ impl<'a, 'tcx> HashStable> for Owner<'tcx> { } } -/// HIR node coupled with its parent's id in the same HIR owner. -/// -/// The parent is trash when the node is a HIR owner. -#[derive(Clone, Debug)] -pub struct ParentedNode<'tcx> { - parent: ItemLocalId, - node: Node<'tcx>, -} - -#[derive(Debug)] -pub struct OwnerNodes<'tcx> { - /// Pre-computed hash of the full HIR. - hash: Fingerprint, - /// Pre-computed hash of the top node. - node_hash: Fingerprint, - /// Full HIR for the current owner. - // The zeroth node's parent is trash, but is never accessed. - nodes: IndexVec>>, - /// Content of local bodies. - bodies: &'tcx IndexVec>>, -} - -impl<'a, 'tcx> HashStable> for OwnerNodes<'tcx> { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - // We ignore the `nodes` and `bodies` fields since these refer to information included in - // `hash` which is hashed in the collector and used for the crate hash. - let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self; - hash.hash_stable(hcx, hasher); - } -} - /// Attributes owner by a HIR owner. #[derive(Copy, Clone, Debug, HashStable)] pub struct AttributeMap<'tcx> { @@ -125,23 +82,23 @@ pub fn provide(providers: &mut Providers) { hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id))) }; providers.hir_crate = |tcx, ()| tcx.untracked_crate; - providers.index_hir = map::index_hir; providers.crate_hash = map::crate_hash; providers.hir_module_items = map::hir_module_items; providers.hir_owner = |tcx, id| { - let owner = tcx.index_hir(id)?; - let node = owner.nodes.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; - let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode. + let owner = tcx.hir_crate(()).owners[id].as_ref()?; + let node = owner.node(); Some(Owner { node, node_hash: owner.nodes.node_hash }) }; - providers.hir_owner_nodes = |tcx, id| tcx.index_hir(id).map(|i| &i.nodes); + providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes); providers.hir_owner_parent = |tcx, id| { let parent = tcx.untracked_resolutions.definitions.def_key(id).parent; let parent = parent.map_or(CRATE_HIR_ID, |local_def_index| { let def_id = LocalDefId { local_def_index }; let mut parent_hir_id = tcx.untracked_resolutions.definitions.local_def_id_to_hir_id(def_id); - if let Some(local_id) = tcx.index_hir(parent_hir_id.owner).unwrap().parenting.get(&id) { + if let Some(local_id) = + tcx.hir_crate(()).owners[parent_hir_id.owner].as_ref().unwrap().parenting.get(&id) + { parent_hir_id.local_id = *local_id; } parent_hir_id diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index bfded8f710ac8..e604f59175e8e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -40,13 +40,6 @@ rustc_queries! { desc { "get the crate HIR" } } - /// The indexed HIR. This can be conveniently accessed by `tcx.hir()`. - /// Avoid calling this query directly. - query index_hir(_: LocalDefId) -> Option<&'tcx crate::hir::IndexedHir<'tcx>> { - eval_always - desc { "index HIR" } - } - /// The items in a module. /// /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`. @@ -76,7 +69,7 @@ rustc_queries! { /// /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. - query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx crate::hir::OwnerNodes<'tcx>> { + query hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> { desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } } From 41e80b85cf05e6373b589b876d3ee65823196406 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 12 Sep 2021 11:41:35 +0200 Subject: [PATCH 030/181] Directly use AttributeMap inside OwnerInfo. --- compiler/rustc_ast_lowering/src/lib.rs | 7 +++++++ compiler/rustc_hir/src/hir.rs | 21 +++++++++++++++++-- compiler/rustc_hir/src/lib.rs | 1 + compiler/rustc_hir/src/stable_hash_impls.rs | 13 ++++++++++-- compiler/rustc_middle/src/hir/map/mod.rs | 2 +- compiler/rustc_middle/src/hir/mod.rs | 23 ++------------------- compiler/rustc_middle/src/lib.rs | 1 - compiler/rustc_middle/src/query/mod.rs | 2 +- 8 files changed, 42 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index a7f1ba8b79198..9ba3d0446dd1c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -476,6 +476,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let (nodes, parenting) = index::index_hir(self.sess, self.resolver.definitions(), node, &bodies); let nodes = hir::OwnerNodes { hash, node_hash, nodes, bodies }; + let attrs = { + let mut hcx = self.resolver.create_stable_hashing_context(); + let mut stable_hasher = StableHasher::new(); + attrs.hash_stable(&mut hcx, &mut stable_hasher); + let hash = stable_hasher.finish(); + hir::AttributeMap { map: attrs, hash } + }; hir::OwnerInfo { nodes, parenting, attrs, trait_map } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 4c8157fee3704..bb5c0bc1889bf 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -672,6 +672,23 @@ pub struct ParentedNode<'tcx> { pub node: Node<'tcx>, } +/// Attributes owner by a HIR owner. +#[derive(Debug)] +pub struct AttributeMap<'tcx> { + pub map: BTreeMap, + pub hash: Fingerprint, +} + +impl<'tcx> AttributeMap<'tcx> { + pub const EMPTY: &'static AttributeMap<'static> = + &AttributeMap { map: BTreeMap::new(), hash: Fingerprint::ZERO }; + + #[inline] + pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] { + self.map.get(&id).copied().unwrap_or(&[]) + } +} + #[derive(Debug)] pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the full HIR. @@ -691,8 +708,8 @@ pub struct OwnerInfo<'hir> { pub nodes: OwnerNodes<'hir>, /// Map from each nested owner to its parent's local id. pub parenting: FxHashMap, - - pub attrs: BTreeMap, + /// Collected attributes of the HIR nodes. + pub attrs: AttributeMap<'hir>, /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. pub trait_map: FxHashMap>, diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index af8421aeb89a7..93224d388c00f 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -2,6 +2,7 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html +#![feature(const_btree_new)] #![feature(crate_visibility_modifier)] #![feature(in_band_lifetimes)] #![feature(once_cell)] diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index ad73e363d7f2e..da2aeb9b311bb 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,8 +1,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use crate::hir::{ - BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, Mod, OwnerNodes, - TraitItem, TraitItemId, Ty, VisibilityKind, + AttributeMap, BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, + Mod, OwnerNodes, TraitItem, TraitItemId, Ty, VisibilityKind, }; use crate::hir_id::{HirId, ItemLocalId}; use rustc_span::def_id::DefPathHash; @@ -218,3 +218,12 @@ impl HashStable for OwnerNodes<'tcx> { hash.hash_stable(hcx, hasher); } } + +impl HashStable for AttributeMap<'tcx> { + fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + // We ignore the `map` since it refers to information included in `hash` which is hashed in + // the collector and used for the crate hash. + let AttributeMap { hash, map: _ } = *self; + hash.hash_stable(hcx, hasher); + } +} diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 834d5f964e187..af4c0e4843dca 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -580,7 +580,7 @@ impl<'hir> Map<'hir> { let krate = self.krate(); for (owner, info) in krate.owners.iter_enumerated() { if let Some(info) = info { - for (&local_id, attrs) in info.attrs.iter() { + for (&local_id, attrs) in info.attrs.map.iter() { let id = HirId { owner, local_id }; for a in *attrs { visitor.visit_attribute(id, a) diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 70179e73b1975..f941981be79b7 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -8,14 +8,12 @@ pub mod place; use crate::ty::query::Providers; use crate::ty::TyCtxt; -use rustc_ast::Attribute; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::LocalDefId; use rustc_hir::*; use rustc_query_system::ich::StableHashingContext; use rustc_span::DUMMY_SP; -use std::collections::BTreeMap; /// Top-level HIR node for current owner. This only contains the node for which /// `HirId::local_id == 0`, and excludes bodies. @@ -36,24 +34,6 @@ impl<'a, 'tcx> HashStable> for Owner<'tcx> { } } -/// Attributes owner by a HIR owner. -#[derive(Copy, Clone, Debug, HashStable)] -pub struct AttributeMap<'tcx> { - map: &'tcx BTreeMap, -} - -impl<'tcx> AttributeMap<'tcx> { - fn new(owner_info: &'tcx Option>) -> AttributeMap<'tcx> { - const FALLBACK: &'static BTreeMap = &BTreeMap::new(); - let map = owner_info.as_ref().map_or(FALLBACK, |info| &info.attrs); - AttributeMap { map } - } - - fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] { - self.map.get(&id).copied().unwrap_or(&[]) - } -} - /// Gather the LocalDefId for each item-like within a module, including items contained within /// bodies. The Ids are in visitor order. This is used to partition a pass between modules. #[derive(Debug, HashStable)] @@ -105,7 +85,8 @@ pub fn provide(providers: &mut Providers) { }); parent }; - providers.hir_attrs = |tcx, id| AttributeMap::new(&tcx.hir_crate(()).owners[id]); + providers.hir_attrs = + |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map_or(AttributeMap::EMPTY, |o| &o.attrs); providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id); providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); providers.fn_arg_names = |tcx, id| { diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index e7219cc58a18a..e41f5add457fb 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -30,7 +30,6 @@ #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(core_intrinsics)] -#![feature(const_btree_new)] #![feature(discriminant_kind)] #![feature(exhaustive_patterns)] #![feature(if_let_guard)] diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index e604f59175e8e..eb4cc7c750c11 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -77,7 +77,7 @@ rustc_queries! { /// /// This can be conveniently accessed by methods on `tcx.hir()`. /// Avoid calling this query directly. - query hir_attrs(key: LocalDefId) -> rustc_middle::hir::AttributeMap<'tcx> { + query hir_attrs(key: LocalDefId) -> &'tcx hir::AttributeMap<'tcx> { desc { |tcx| "HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) } } From 0431fdb11312ae324c73e4dab1e5be5c45164678 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 19 Sep 2021 22:07:12 +0200 Subject: [PATCH 031/181] Compute full HIR hash during lowering. --- compiler/rustc_ast_lowering/src/lib.rs | 23 +++++++++- compiler/rustc_hir/src/hir.rs | 3 +- compiler/rustc_hir/src/stable_hash_impls.rs | 18 +++++++- compiler/rustc_middle/src/hir/map/mod.rs | 45 ++++++++----------- compiler/rustc_middle/src/query/mod.rs | 1 - .../rustc_query_system/src/ich/impls_hir.rs | 36 +++++---------- 6 files changed, 69 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 9ba3d0446dd1c..84aeb78a0aa10 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -399,6 +399,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::OwnerNode::Crate(lctx.arena.alloc(module)) }); + let hir_hash = self.compute_hir_hash(); + let mut def_id_to_hir_id = IndexVec::default(); for (node_id, hir_id) in self.node_id_to_hir_id.into_iter_enumerated() { @@ -412,10 +414,29 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.resolver.definitions().init_def_id_to_hir_id_mapping(def_id_to_hir_id); - let krate = hir::Crate { owners: self.owners }; + let krate = hir::Crate { owners: self.owners, hir_hash }; self.arena.alloc(krate) } + fn compute_hir_hash(&mut self) -> Fingerprint { + let definitions = self.resolver.definitions(); + let mut hir_body_nodes: Vec<_> = self + .owners + .iter_enumerated() + .filter_map(|(def_id, info)| { + let info = info.as_ref()?; + let def_path_hash = definitions.def_path_hash(def_id); + Some((def_path_hash, info)) + }) + .collect(); + hir_body_nodes.sort_unstable_by_key(|bn| bn.0); + + let mut stable_hasher = StableHasher::new(); + let mut hcx = self.resolver.create_stable_hashing_context(); + hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher); + stable_hasher.finish() + } + fn with_hir_id_owner( &mut self, owner: NodeId, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index bb5c0bc1889bf..6cbea732c9938 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -702,7 +702,7 @@ pub struct OwnerNodes<'tcx> { pub bodies: IndexVec>>, } -#[derive(Debug)] +#[derive(Debug, HashStable_Generic)] pub struct OwnerInfo<'hir> { /// Contents of the HIR. pub nodes: OwnerNodes<'hir>, @@ -734,6 +734,7 @@ impl<'tcx> OwnerInfo<'tcx> { #[derive(Debug)] pub struct Crate<'hir> { pub owners: IndexVec>>, + pub hir_hash: Fingerprint, } /// A block of statements `{ .. }`, which may have a label (in this case the diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index da2aeb9b311bb..3c9fe93b67d3c 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -1,8 +1,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use crate::hir::{ - AttributeMap, BodyId, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, ItemId, - Mod, OwnerNodes, TraitItem, TraitItemId, Ty, VisibilityKind, + AttributeMap, BodyId, Crate, Expr, ForeignItem, ForeignItemId, ImplItem, ImplItemId, Item, + ItemId, Mod, OwnerNodes, TraitCandidate, TraitItem, TraitItemId, Ty, VisibilityKind, }; use crate::hir_id::{HirId, ItemLocalId}; use rustc_span::def_id::DefPathHash; @@ -21,6 +21,7 @@ pub trait HashStableContext: fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher); fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher); fn hash_hir_item_like(&mut self, f: F); + fn hash_hir_trait_candidate(&mut self, _: &TraitCandidate, hasher: &mut StableHasher); } impl ToStableHashKey for HirId { @@ -227,3 +228,16 @@ impl HashStable for AttributeMap<'tcx> hash.hash_stable(hcx, hasher); } } + +impl HashStable for Crate<'_> { + fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + let Crate { owners: _, hir_hash } = self; + hir_hash.hash_stable(hcx, hasher) + } +} + +impl HashStable for TraitCandidate { + fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { + hcx.hash_hir_trait_candidate(self, hasher) + } +} diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index af4c0e4843dca..c8d6ecf6940ed 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1066,18 +1066,8 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> { pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { debug_assert_eq!(crate_num, LOCAL_CRATE); - let mut hir_body_nodes: Vec<_> = tcx - .untracked_resolutions - .definitions - .def_path_table() - .all_def_path_hashes_and_def_ids() - .filter_map(|(def_path_hash, local_def_index)| { - let def_id = LocalDefId { local_def_index }; - let hash = tcx.hir_crate(()).owners[def_id].as_ref()?.nodes.hash; - Some((def_path_hash, hash, def_id)) - }) - .collect(); - hir_body_nodes.sort_unstable_by_key(|bn| bn.0); + let krate = tcx.hir_crate(()); + let hir_body_hash = krate.hir_hash; let upstream_crates = upstream_crates(tcx); @@ -1099,22 +1089,25 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { let mut hcx = tcx.create_stable_hashing_context(); let mut stable_hasher = StableHasher::new(); - for (def_path_hash, fingerprint, def_id) in hir_body_nodes.iter() { - def_path_hash.0.hash_stable(&mut hcx, &mut stable_hasher); - fingerprint.hash_stable(&mut hcx, &mut stable_hasher); - tcx.untracked_crate.owners[*def_id] - .as_ref() - .unwrap() - .attrs - .hash_stable(&mut hcx, &mut stable_hasher); - if tcx.sess.opts.debugging_opts.incremental_relative_spans { - let span = tcx.untracked_resolutions.definitions.def_span(*def_id); - debug_assert_eq!(span.parent(), None); - span.hash_stable(&mut hcx, &mut stable_hasher); - } - } + hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher); upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); source_file_names.hash_stable(&mut hcx, &mut stable_hasher); + if tcx.sess.opts.debugging_opts.incremental_relative_spans { + let definitions = &tcx.untracked_resolutions.definitions; + let mut owner_spans: Vec<_> = krate + .owners + .iter_enumerated() + .filter_map(|(def_id, info)| { + let _ = info.as_ref()?; + let def_path_hash = definitions.def_path_hash(def_id); + let span = definitions.def_span(def_id); + debug_assert_eq!(span.parent(), None); + Some((def_path_hash, span)) + }) + .collect(); + owner_spans.sort_unstable_by_key(|bn| bn.0); + owner_spans.hash_stable(&mut hcx, &mut stable_hasher); + } tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher); tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index eb4cc7c750c11..4ffe76fed1c47 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -36,7 +36,6 @@ rustc_queries! { /// prefer wrappers like `tcx.visit_all_items_in_krate()`. query hir_crate(key: ()) -> &'tcx Crate<'tcx> { eval_always - no_hash desc { "get the crate HIR" } } diff --git a/compiler/rustc_query_system/src/ich/impls_hir.rs b/compiler/rustc_query_system/src/ich/impls_hir.rs index dc208b36f938e..24f3a2e7de0a9 100644 --- a/compiler/rustc_query_system/src/ich/impls_hir.rs +++ b/compiler/rustc_query_system/src/ich/impls_hir.rs @@ -6,8 +6,6 @@ use crate::ich::{NodeIdHashingMode, StableHashingContext}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use rustc_hir as hir; -use rustc_hir::definitions::DefPathHash; -use smallvec::SmallVec; use std::mem; impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { @@ -121,6 +119,16 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { self.node_id_hashing_mode = prev_hash_node_ids; } + + #[inline] + fn hash_hir_trait_candidate(&mut self, tc: &hir::TraitCandidate, hasher: &mut StableHasher) { + self.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + let hir::TraitCandidate { def_id, import_ids } = tc; + + def_id.hash_stable(hcx, hasher); + import_ids.hash_stable(hcx, hasher); + }); + } } impl<'a> HashStable> for hir::Body<'_> { @@ -135,27 +143,3 @@ impl<'a> HashStable> for hir::Body<'_> { }); } } - -impl<'a> HashStable> for hir::TraitCandidate { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - let hir::TraitCandidate { def_id, import_ids } = self; - - def_id.hash_stable(hcx, hasher); - import_ids.hash_stable(hcx, hasher); - }); - } -} - -impl<'a> ToStableHashKey> for hir::TraitCandidate { - type KeyType = (DefPathHash, SmallVec<[DefPathHash; 1]>); - - fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Self::KeyType { - let hir::TraitCandidate { def_id, import_ids } = self; - - ( - hcx.def_path_hash(*def_id), - import_ids.iter().map(|def_id| hcx.local_def_path_hash(*def_id)).collect(), - ) - } -} From 04ed86757af86540e5797982f4e70fbf6be24513 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 21 Sep 2021 08:17:18 +0200 Subject: [PATCH 032/181] Bless ui tests. --- src/test/ui/privacy/privacy2.stderr | 8 +------- src/test/ui/privacy/privacy3.stderr | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/test/ui/privacy/privacy2.stderr b/src/test/ui/privacy/privacy2.stderr index 882f314655d83..c2a33ce1f59b3 100644 --- a/src/test/ui/privacy/privacy2.stderr +++ b/src/test/ui/privacy/privacy2.stderr @@ -23,13 +23,7 @@ LL | pub fn foo() {} error: requires `sized` lang_item -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0432, E0603. For more information about an error, try `rustc --explain E0432`. diff --git a/src/test/ui/privacy/privacy3.stderr b/src/test/ui/privacy/privacy3.stderr index 42ce456d962a1..22c1e48b07d94 100644 --- a/src/test/ui/privacy/privacy3.stderr +++ b/src/test/ui/privacy/privacy3.stderr @@ -6,12 +6,6 @@ LL | use bar::gpriv; error: requires `sized` lang_item -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: requires `sized` lang_item - -error: aborting due to 5 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0432`. From 152e40377aefe966486515c392d741f851510a8a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 10 Oct 2021 18:18:30 +0300 Subject: [PATCH 033/181] ty::pretty: document "dummy Span extern crate" special-case in `try_print_visible_def_path_recur`. --- compiler/rustc_middle/src/ty/print/pretty.rs | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 2610a76b2810b..ae0cc97c7044e 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -350,18 +350,19 @@ pub trait PrettyPrinter<'tcx>: match self.tcx().extern_crate(def_id) { Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) { (ExternCrateSource::Extern(def_id), LOCAL_CRATE) => { - debug!("try_print_visible_def_path: def_id={:?}", def_id); - return Ok(( - if !span.is_dummy() { - self.print_def_path(def_id, &[])? - } else { - self.path_crate(cnum)? - }, - true, - )); + // NOTE(eddyb) the only reason `span` might be dummy, + // that we're aware of, is that it's the `std`/`core` + // `extern crate` injected by default. + // FIXME(eddyb) find something better to key this on, + // or avoid ending up with `ExternCrateSource::Extern`, + // for the injected `std`/`core`. + if span.is_dummy() { + return Ok((self.path_crate(cnum)?, true)); + } + + return Ok((self.print_def_path(def_id, &[])?, true)); } (ExternCrateSource::Path, LOCAL_CRATE) => { - debug!("try_print_visible_def_path: def_id={:?}", def_id); return Ok((self.path_crate(cnum)?, true)); } _ => {} From f14e8dd4e719bd29c6f559ffffa9a17317f4af1e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 10 Oct 2021 18:50:44 +0300 Subject: [PATCH 034/181] ty::pretty: prevent infinite recursion for `extern crate` paths. --- compiler/rustc_middle/src/ty/print/pretty.rs | 9 +++++- .../auxiliary/issue-55779-extern-trait.rs | 1 + .../uniform-paths/auxiliary/issue-87932-a.rs | 3 ++ .../ui/rust-2018/uniform-paths/issue-55779.rs | 29 +++++++++++++++++++ .../ui/rust-2018/uniform-paths/issue-87932.rs | 15 ++++++++++ .../uniform-paths/issue-87932.stderr | 18 ++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rust-2018/uniform-paths/auxiliary/issue-55779-extern-trait.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/auxiliary/issue-87932-a.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/issue-55779.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/issue-87932.rs create mode 100644 src/test/ui/rust-2018/uniform-paths/issue-87932.stderr diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ae0cc97c7044e..b11a54d5dcb11 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -360,7 +360,14 @@ pub trait PrettyPrinter<'tcx>: return Ok((self.path_crate(cnum)?, true)); } - return Ok((self.print_def_path(def_id, &[])?, true)); + // Disable `try_print_trimmed_def_path` behavior within + // the `print_def_path` call, to avoid infinite recursion + // in cases where the `extern crate foo` has non-trivial + // parents, e.g. it's nested in `impl foo::Trait for Bar` + // (see also issues #55779 and #87932). + self = with_no_visible_paths(|| self.print_def_path(def_id, &[]))?; + + return Ok((self, true)); } (ExternCrateSource::Path, LOCAL_CRATE) => { return Ok((self.path_crate(cnum)?, true)); diff --git a/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-55779-extern-trait.rs b/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-55779-extern-trait.rs new file mode 100644 index 0000000000000..1ce9841c1a8c5 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-55779-extern-trait.rs @@ -0,0 +1 @@ +pub trait Trait { fn no_op(&self); } diff --git a/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-87932-a.rs b/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-87932-a.rs new file mode 100644 index 0000000000000..8fd2d77be3910 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-87932-a.rs @@ -0,0 +1,3 @@ +pub trait Deserialize { + fn deserialize(); +} diff --git a/src/test/ui/rust-2018/uniform-paths/issue-55779.rs b/src/test/ui/rust-2018/uniform-paths/issue-55779.rs new file mode 100644 index 0000000000000..0af17a89b17bf --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/issue-55779.rs @@ -0,0 +1,29 @@ +// run-pass +// edition:2018 +// aux-crate:issue_55779_extern_trait=issue-55779-extern-trait.rs + +use issue_55779_extern_trait::Trait; + +struct Local; +struct Helper; + +impl Trait for Local { + fn no_op(&self) + { + // (Unused) extern crate declaration necessary to reproduce bug + extern crate issue_55779_extern_trait; + + // This one works + // impl Trait for Helper { fn no_op(&self) { } } + + // This one infinite-loops + const _IMPL_SERIALIZE_FOR_HELPER: () = { + // (extern crate can also appear here to reproduce bug, + // as in originating example from serde) + impl Trait for Helper { fn no_op(&self) { } } + }; + + } +} + +fn main() { } diff --git a/src/test/ui/rust-2018/uniform-paths/issue-87932.rs b/src/test/ui/rust-2018/uniform-paths/issue-87932.rs new file mode 100644 index 0000000000000..70a641d8a47ad --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/issue-87932.rs @@ -0,0 +1,15 @@ +// edition:2018 +// aux-crate:issue_87932_a=issue-87932-a.rs + +pub struct A {} + +impl issue_87932_a::Deserialize for A { + fn deserialize() { + extern crate issue_87932_a as _a; + } +} + +fn main() { + A::deserialize(); + //~^ ERROR no function or associated item named `deserialize` found for struct `A` +} diff --git a/src/test/ui/rust-2018/uniform-paths/issue-87932.stderr b/src/test/ui/rust-2018/uniform-paths/issue-87932.stderr new file mode 100644 index 0000000000000..53272abccbbf0 --- /dev/null +++ b/src/test/ui/rust-2018/uniform-paths/issue-87932.stderr @@ -0,0 +1,18 @@ +error[E0599]: no function or associated item named `deserialize` found for struct `A` in the current scope + --> $DIR/issue-87932.rs:13:8 + | +LL | pub struct A {} + | ------------ function or associated item `deserialize` not found for this +... +LL | A::deserialize(); + | ^^^^^^^^^^^ function or associated item not found in `A` + | + = help: items from traits can only be used if the trait is in scope +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use ::deserialize::_a::Deserialize; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. From 63ebfc2c55af8b7581bea067f29276f73c7fa503 Mon Sep 17 00:00:00 2001 From: Milan Landaverde Date: Tue, 11 May 2021 15:41:32 -0400 Subject: [PATCH 035/181] Add abstract namespace support for Unix domain sockets --- library/std/src/os/unix/net/addr.rs | 84 +++++++++++++++- library/std/src/os/unix/net/datagram.rs | 94 +++++++++++++++++- library/std/src/os/unix/net/listener.rs | 34 +++++++ library/std/src/os/unix/net/stream.rs | 31 ++++++ library/std/src/os/unix/net/tests.rs | 125 +++++++++++++++++++++++- 5 files changed, 363 insertions(+), 5 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 62bfde8bfd436..5c985a28017aa 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -2,7 +2,7 @@ use crate::ffi::OsStr; use crate::os::unix::ffi::OsStrExt; use crate::path::Path; use crate::sys::cvt; -use crate::{ascii, fmt, io, iter, mem}; +use crate::{ascii, fmt, io, iter, mem, ptr}; // FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here? #[cfg(not(unix))] @@ -92,8 +92,8 @@ impl<'a> fmt::Display for AsciiEscaped<'a> { #[derive(Clone)] #[stable(feature = "unix_socket", since = "1.10.0")] pub struct SocketAddr { - addr: libc::sockaddr_un, - len: libc::socklen_t, + pub(super) addr: libc::sockaddr_un, + pub(super) len: libc::socklen_t, } impl SocketAddr { @@ -196,6 +196,30 @@ impl SocketAddr { if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None } } + /// Returns the contents of this address if it is an abstract namespace + /// without the leading null byte. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let namespace = b"hidden"; + /// let namespace_addr = SocketAddr::from_abstract_namespace(&namespace[..])?; + /// let socket = UnixListener::bind_addr(&namespace_addr)?; + /// let local_addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(local_addr.as_abstract_namespace(), Some(&namespace[..])); + /// Ok(()) + /// } + /// ``` + #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn as_abstract_namespace(&self) -> Option<&[u8]> { + if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None } + } + fn address(&self) -> AddressKind<'_> { let len = self.len as usize - sun_path_offset(&self.addr); let path = unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.addr.sun_path) }; @@ -212,6 +236,60 @@ impl SocketAddr { AddressKind::Pathname(OsStr::from_bytes(&path[..len - 1]).as_ref()) } } + + /// Creates an abstract domain socket address from a namespace + /// + /// An abstract address does not create a file unlike traditional path-based + /// Unix sockets. The advantage of this is that the address will disappear when + /// the socket bound to it is closed, so no filesystem clean up is required. + /// + /// The leading null byte for the abstract namespace is automatically added. + /// + /// This is a Linux-specific extension. See more at [`unix(7)`]. + /// + /// [`unix(7)`]: https://man7.org/linux/man-pages/man7/unix.7.html + /// + /// # Errors + /// + /// This will return an error if the given namespace is too long + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; + /// let listener = match UnixListener::bind_addr(&addr) { + /// Ok(sock) => sock, + /// Err(err) => { + /// println!("Couldn't bind: {:?}", err); + /// return Err(err); + /// } + /// }; + /// Ok(()) + /// } + /// ``` + #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn from_abstract_namespace(namespace: &[u8]) -> io::Result { + unsafe { + let mut addr: libc::sockaddr_un = mem::zeroed(); + addr.sun_family = libc::AF_UNIX as libc::sa_family_t; + + if namespace.len() + 1 > addr.sun_path.len() { + return Err(io::Error::new_const( + io::ErrorKind::InvalidInput, + &"namespace must be shorter than SUN_LEN", + )); + } + + ptr::copy_nonoverlapping(namespace.as_ptr(), addr.sun_path.as_mut_ptr().offset(1) as *mut u8, namespace.len()); + let len = (sun_path_offset(&addr) + 1 + namespace.len()) as libc::socklen_t; + SocketAddr::from_parts(addr, len) + } + } } #[stable(feature = "unix_socket", since = "1.10.0")] diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index f11eec18cc521..bae88af6d1f8e 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -112,6 +112,35 @@ impl UnixDatagram { } } + /// Creates a Unix datagram socket bound to an address. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only + /// let sock = match UnixDatagram::bind_addr(&addr) { + /// Ok(sock) => sock, + /// Err(err) => { + /// println!("Couldn't bind: {:?}", err); + /// return Err(err); + /// } + /// }; + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { + unsafe { + let socket = UnixDatagram::unbound()?; + cvt(libc::bind(*socket.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?; + Ok(socket) + } + } + /// Creates a Unix Datagram socket which is not bound to any address. /// /// # Examples @@ -156,7 +185,7 @@ impl UnixDatagram { Ok((UnixDatagram(i1), UnixDatagram(i2))) } - /// Connects the socket to the specified address. + /// Connects the socket to the specified path address. /// /// The [`send`] method may be used to send data to the specified address. /// [`recv`] and [`recv_from`] will only receive data from that address. @@ -192,6 +221,35 @@ impl UnixDatagram { Ok(()) } + /// Connects the socket to an address. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only + /// let sock = UnixDatagram::unbound()?; + /// match sock.connect_addr(&addr) { + /// Ok(sock) => sock, + /// Err(e) => { + /// println!("Couldn't connect: {:?}", e); + /// return Err(e) + /// } + /// }; + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> { + unsafe { + cvt(libc::connect(*self.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?; + } + Ok(()) + } + /// Creates a new independently owned handle to the underlying socket. /// /// The returned `UnixDatagram` is a reference to the same socket that this @@ -473,6 +531,40 @@ impl UnixDatagram { } } + /// Sends data on the socket to the specified [SocketAddr]. + /// + /// On success, returns the number of bytes written. + /// + /// [SocketAddr]: crate::os::unix::net::SocketAddr + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; + /// let sock = UnixDatagram::unbound()?; + /// sock.send_to_addr(b"bacon egg and cheese", &addr).expect("send_to_addr function failed"); + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn send_to_addr(&self, buf: &[u8], socket_addr: &SocketAddr) -> io::Result { + unsafe { + let count = cvt(libc::sendto( + *self.0.as_inner(), + buf.as_ptr() as *const _, + buf.len(), + MSG_NOSIGNAL, + &socket_addr.addr as *const _ as *const _, + socket_addr.len, + ))?; + Ok(count as usize) + } + } + /// Sends data on the socket to the socket's peer. /// /// The peer address may be set by the `connect` method, and this method diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index f08bd252e46fa..3077632764e51 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -81,6 +81,40 @@ impl UnixListener { } } + /// Creates a new `UnixListener` bound to the specified [`socket address`]. + /// + /// [`socket address`]: crate::os::unix::net::SocketAddr + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only + /// let listener = match UnixListener::bind_addr(&addr) { + /// Ok(sock) => sock, + /// Err(err) => { + /// println!("Couldn't bind: {:?}", err); + /// return Err(err); + /// } + /// }; + /// Ok(()) + /// } + /// ``` + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { + unsafe { + let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; + cvt(libc::bind(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?; + cvt(libc::listen(*inner.as_inner(), 128))?; + + Ok(UnixListener(inner)) + } + } + + /// Accepts a new incoming connection to this listener. /// /// This function will block the calling thread until a new Unix connection diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 4119de3c03cbe..00a713f0732f0 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -106,6 +106,37 @@ impl UnixStream { } } + /// Connects to the socket specified by [`address`]. + /// + /// [`address`]: crate::os::unix::net::SocketAddr + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// use std::os::unix::net::{UnixStream, SocketAddr}; + /// + /// fn main() -> std::io::Result<()> { + /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only + /// match UnixStream::connect_addr(&addr) { + /// Ok(sock) => sock, + /// Err(e) => { + /// println!("Couldn't connect: {:?}", e); + /// return Err(e) + /// } + /// }; + /// Ok(()) + /// } + /// ```` + #[unstable(feature = "unix_socket_abstract", issue = "42048")] + pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result { + unsafe { + let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; + cvt(libc::connect(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?; + Ok(UnixStream(inner)) + } + } + /// Creates an unnamed pair of connected sockets. /// /// Returns two `UnixStream`s which are connected to each other. diff --git a/library/std/src/os/unix/net/tests.rs b/library/std/src/os/unix/net/tests.rs index bd9b6dd727b96..b13ce0e252adb 100644 --- a/library/std/src/os/unix/net/tests.rs +++ b/library/std/src/os/unix/net/tests.rs @@ -388,10 +388,133 @@ fn test_unix_datagram_timeout_zero_duration() { } #[test] -fn abstract_namespace_not_allowed() { +fn abstract_namespace_not_allowed_connect() { assert!(UnixStream::connect("\0asdf").is_err()); } +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_stream_connect() { + let msg1 = b"hello"; + let msg2 = b"world"; + + let socket_addr = or_panic!(SocketAddr::from_abstract_namespace(b"namespace")); + let listener = or_panic!(UnixListener::bind_addr(&socket_addr)); + + let thread = thread::spawn(move || { + let mut stream = or_panic!(listener.accept()).0; + let mut buf = [0; 5]; + or_panic!(stream.read(&mut buf)); + assert_eq!(&msg1[..], &buf[..]); + or_panic!(stream.write_all(msg2)); + }); + + let mut stream = or_panic!(UnixStream::connect_addr(&socket_addr)); + + let peer = or_panic!(stream.peer_addr()); + assert_eq!(peer.as_abstract_namespace().unwrap(), b"namespace"); + + or_panic!(stream.write_all(msg1)); + let mut buf = vec![]; + or_panic!(stream.read_to_end(&mut buf)); + assert_eq!(&msg2[..], &buf[..]); + drop(stream); + + thread.join().unwrap(); +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_stream_iter() { + let addr = or_panic!(SocketAddr::from_abstract_namespace(b"hidden")); + let listener = or_panic!(UnixListener::bind_addr(&addr)); + + let thread = thread::spawn(move || { + for stream in listener.incoming().take(2) { + let mut stream = or_panic!(stream); + let mut buf = [0]; + or_panic!(stream.read(&mut buf)); + } + }); + + for _ in 0..2 { + let mut stream = or_panic!(UnixStream::connect_addr(&addr)); + or_panic!(stream.write_all(&[0])); + } + + thread.join().unwrap(); +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_datagram_bind_send_to_addr() { + let addr1 = or_panic!(SocketAddr::from_abstract_namespace(b"ns1")); + let sock1 = or_panic!(UnixDatagram::bind_addr(&addr1)); + + let local = or_panic!(sock1.local_addr()); + assert_eq!(local.as_abstract_namespace().unwrap(), b"ns1"); + + let addr2 = or_panic!(SocketAddr::from_abstract_namespace(b"ns2")); + let sock2 = or_panic!(UnixDatagram::bind_addr(&addr2)); + + let msg = b"hello world"; + or_panic!(sock1.send_to_addr(msg, &addr2)); + let mut buf = [0; 11]; + let (len, addr) = or_panic!(sock2.recv_from(&mut buf)); + assert_eq!(msg, &buf[..]); + assert_eq!(len, 11); + assert_eq!(addr.as_abstract_namespace().unwrap(), b"ns1"); +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_datagram_connect_addr() { + let addr1 = or_panic!(SocketAddr::from_abstract_namespace(b"ns3")); + let bsock1 = or_panic!(UnixDatagram::bind_addr(&addr1)); + + let sock = or_panic!(UnixDatagram::unbound()); + or_panic!(sock.connect_addr(&addr1)); + + let msg = b"hello world"; + or_panic!(sock.send(msg)); + let mut buf = [0; 11]; + let (len, addr) = or_panic!(bsock1.recv_from(&mut buf)); + assert_eq!(len, 11); + assert_eq!(addr.is_unnamed(), true); + assert_eq!(msg, &buf[..]); + + let addr2 = or_panic!(SocketAddr::from_abstract_namespace(b"ns4")); + let bsock2 = or_panic!(UnixDatagram::bind_addr(&addr2)); + + or_panic!(sock.connect_addr(&addr2)); + or_panic!(sock.send(msg)); + or_panic!(bsock2.recv_from(&mut buf)); +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_namespace_too_long() { + match SocketAddr::from_abstract_namespace( + b"abcdefghijklmnopqrstuvwxyzabcdefghijklmn\ + opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi\ + jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", + ) { + Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {} + Err(e) => panic!("unexpected error {}", e), + Ok(_) => panic!("unexpected success"), + } +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn test_abstract_namespace_no_pathname_and_not_unnamed() { + let namespace = b"local"; + let addr = or_panic!(SocketAddr::from_abstract_namespace(&namespace[..])); + assert_eq!(addr.as_pathname(), None); + assert_eq!(addr.as_abstract_namespace(), Some(&namespace[..])); + assert_eq!(addr.is_unnamed(), false); +} + #[test] fn test_unix_stream_peek() { let (txdone, rxdone) = crate::sync::mpsc::channel(); From 1c2143193fb4394bb5dd20eefd192c2908775271 Mon Sep 17 00:00:00 2001 From: Milan Landaverde Date: Sun, 16 May 2021 17:49:54 -0400 Subject: [PATCH 036/181] rustfmt --- library/std/src/os/unix/net/addr.rs | 6 +++++- library/std/src/os/unix/net/datagram.rs | 12 ++++++++++-- library/std/src/os/unix/net/listener.rs | 7 +++++-- library/std/src/os/unix/net/stream.rs | 6 +++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 5c985a28017aa..1cef5a3256c61 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -285,7 +285,11 @@ impl SocketAddr { )); } - ptr::copy_nonoverlapping(namespace.as_ptr(), addr.sun_path.as_mut_ptr().offset(1) as *mut u8, namespace.len()); + ptr::copy_nonoverlapping( + namespace.as_ptr(), + addr.sun_path.as_mut_ptr().offset(1) as *mut u8, + namespace.len(), + ); let len = (sun_path_offset(&addr) + 1 + namespace.len()) as libc::socklen_t; SocketAddr::from_parts(addr, len) } diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index bae88af6d1f8e..d0eb7f68ec6c2 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -136,7 +136,11 @@ impl UnixDatagram { pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let socket = UnixDatagram::unbound()?; - cvt(libc::bind(*socket.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?; + cvt(libc::bind( + *socket.0.as_inner(), + &socket_addr.addr as *const _ as *const _, + socket_addr.len as _, + ))?; Ok(socket) } } @@ -245,7 +249,11 @@ impl UnixDatagram { #[unstable(feature = "unix_socket_abstract", issue = "42048")] pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> { unsafe { - cvt(libc::connect(*self.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?; + cvt(libc::connect( + *self.0.as_inner(), + &socket_addr.addr as *const _ as *const _, + socket_addr.len, + ))?; } Ok(()) } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 3077632764e51..d55ea054539b5 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -107,14 +107,17 @@ impl UnixListener { pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; - cvt(libc::bind(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?; + cvt(libc::bind( + *inner.as_inner(), + &socket_addr.addr as *const _ as *const _, + socket_addr.len as _, + ))?; cvt(libc::listen(*inner.as_inner(), 128))?; Ok(UnixListener(inner)) } } - /// Accepts a new incoming connection to this listener. /// /// This function will block the calling thread until a new Unix connection diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 00a713f0732f0..5b482e13823c5 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -132,7 +132,11 @@ impl UnixStream { pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; - cvt(libc::connect(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?; + cvt(libc::connect( + *inner.as_inner(), + &socket_addr.addr as *const _ as *const _, + socket_addr.len, + ))?; Ok(UnixStream(inner)) } } From 565e349c799cd0703dfa1829c9b331276494230c Mon Sep 17 00:00:00 2001 From: Milan Landaverde Date: Mon, 17 May 2021 08:29:49 -0400 Subject: [PATCH 037/181] Update tracking issue in stability refs --- library/std/src/os/unix/net/addr.rs | 4 ++-- library/std/src/os/unix/net/datagram.rs | 6 +++--- library/std/src/os/unix/net/listener.rs | 2 +- library/std/src/os/unix/net/stream.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 1cef5a3256c61..8d988cc71dc07 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -215,7 +215,7 @@ impl SocketAddr { /// } /// ``` #[cfg(any(doc, target_os = "android", target_os = "linux",))] - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn as_abstract_namespace(&self) -> Option<&[u8]> { if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None } } @@ -272,7 +272,7 @@ impl SocketAddr { /// } /// ``` #[cfg(any(doc, target_os = "android", target_os = "linux",))] - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn from_abstract_namespace(namespace: &[u8]) -> io::Result { unsafe { let mut addr: libc::sockaddr_un = mem::zeroed(); diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index d0eb7f68ec6c2..c4625b90e78bc 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -132,7 +132,7 @@ impl UnixDatagram { /// Ok(()) /// } /// ``` - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let socket = UnixDatagram::unbound()?; @@ -246,7 +246,7 @@ impl UnixDatagram { /// Ok(()) /// } /// ``` - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> { unsafe { cvt(libc::connect( @@ -558,7 +558,7 @@ impl UnixDatagram { /// Ok(()) /// } /// ``` - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn send_to_addr(&self, buf: &[u8], socket_addr: &SocketAddr) -> io::Result { unsafe { let count = cvt(libc::sendto( diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index d55ea054539b5..5e88f9acb8705 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -103,7 +103,7 @@ impl UnixListener { /// Ok(()) /// } /// ``` - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 5b482e13823c5..765a040a24671 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -128,7 +128,7 @@ impl UnixStream { /// Ok(()) /// } /// ```` - #[unstable(feature = "unix_socket_abstract", issue = "42048")] + #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; From d68a8d987069227c7aab32b088e163195af142e4 Mon Sep 17 00:00:00 2001 From: Milan Landaverde Date: Tue, 18 May 2021 09:27:53 -0400 Subject: [PATCH 038/181] moves use ptr within from_abstract_namespace fn --- library/std/src/os/unix/net/addr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 8d988cc71dc07..a414b6eff43dd 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -2,7 +2,7 @@ use crate::ffi::OsStr; use crate::os::unix::ffi::OsStrExt; use crate::path::Path; use crate::sys::cvt; -use crate::{ascii, fmt, io, iter, mem, ptr}; +use crate::{ascii, fmt, io, iter, mem}; // FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here? #[cfg(not(unix))] @@ -285,7 +285,7 @@ impl SocketAddr { )); } - ptr::copy_nonoverlapping( + crate::ptr::copy_nonoverlapping( namespace.as_ptr(), addr.sun_path.as_mut_ptr().offset(1) as *mut u8, namespace.len(), From 92d680589c1e7c9a21a7e31ce98b7a7f09bcc65f Mon Sep 17 00:00:00 2001 From: Milan Landaverde Date: Fri, 21 May 2021 14:47:17 -0400 Subject: [PATCH 039/181] cross-platform doctests --- library/std/src/os/unix/net/addr.rs | 2 ++ library/std/src/os/unix/net/datagram.rs | 20 +++++++++++++------- library/std/src/os/unix/net/listener.rs | 8 +++++--- library/std/src/os/unix/net/stream.rs | 8 +++++--- library/std/src/os/unix/net/tests.rs | 24 ++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index a414b6eff43dd..fd8d1d7acf8c4 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -214,6 +214,7 @@ impl SocketAddr { /// Ok(()) /// } /// ``` + #[doc(cfg(any(target_os = "android", target_os = "linux")))] #[cfg(any(doc, target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn as_abstract_namespace(&self) -> Option<&[u8]> { @@ -271,6 +272,7 @@ impl SocketAddr { /// Ok(()) /// } /// ``` + #[doc(cfg(any(target_os = "android", target_os = "linux")))] #[cfg(any(doc, target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn from_abstract_namespace(namespace: &[u8]) -> io::Result { diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index c4625b90e78bc..87be4d3f57a84 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -118,11 +118,13 @@ impl UnixDatagram { /// /// ```no_run /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only - /// let sock = match UnixDatagram::bind_addr(&addr) { + /// let sock1 = UnixDatagram::bind("path/to/socket")?; + /// let addr = sock1.local_addr()?; + /// + /// let sock2 = match UnixDatagram::bind_addr(&addr) { /// Ok(sock) => sock, /// Err(err) => { /// println!("Couldn't bind: {:?}", err); @@ -231,10 +233,12 @@ impl UnixDatagram { /// /// ```no_run /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only + /// let bound = UnixDatagram::bind("/path/to/socket")?; + /// let addr = bound.local_addr()?; + /// /// let sock = UnixDatagram::unbound()?; /// match sock.connect_addr(&addr) { /// Ok(sock) => sock, @@ -549,10 +553,12 @@ impl UnixDatagram { /// /// ```no_run /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixDatagram, SocketAddr}; + /// use std::os::unix::net::{UnixDatagram}; /// /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; + /// let bound = UnixDatagram::bind("/path/to/socket")?; + /// let addr = bound.local_addr()?; + /// /// let sock = UnixDatagram::unbound()?; /// sock.send_to_addr(b"bacon egg and cheese", &addr).expect("send_to_addr function failed"); /// Ok(()) diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 5e88f9acb8705..7fba7543ec297 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -89,11 +89,13 @@ impl UnixListener { /// /// ```no_run /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixListener, SocketAddr}; + /// use std::os::unix::net::{UnixListener}; /// /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only - /// let listener = match UnixListener::bind_addr(&addr) { + /// let listener1 = UnixListener::bind("path/to/socket")?; + /// let addr = listener1.local_addr()?; + /// + /// let listener2 = match UnixListener::bind_addr(&addr) { /// Ok(sock) => sock, /// Err(err) => { /// println!("Couldn't bind: {:?}", err); diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 765a040a24671..e3eef7c761487 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -114,11 +114,13 @@ impl UnixStream { /// /// ```no_run /// #![feature(unix_socket_abstract)] - /// use std::os::unix::net::{UnixStream, SocketAddr}; + /// use std::os::unix::net::{UnixListener, UnixStream}; /// /// fn main() -> std::io::Result<()> { - /// let addr = SocketAddr::from_abstract_namespace(b"hidden")?; // Linux only - /// match UnixStream::connect_addr(&addr) { + /// let listener = UnixListener::bind("/path/to/the/socket")?; + /// let addr = listener.local_addr()?; + /// + /// let sock = match UnixStream::connect_addr(&addr) { /// Ok(sock) => sock, /// Err(e) => { /// println!("Couldn't connect: {:?}", e); diff --git a/library/std/src/os/unix/net/tests.rs b/library/std/src/os/unix/net/tests.rs index b13ce0e252adb..7ad4a02611e07 100644 --- a/library/std/src/os/unix/net/tests.rs +++ b/library/std/src/os/unix/net/tests.rs @@ -303,6 +303,30 @@ fn test_unnamed_unix_datagram() { assert_eq!(msg, &buf[..]); } +#[test] +fn test_unix_datagram_connect_to_recv_addr() { + let dir = tmpdir(); + let path1 = dir.path().join("sock1"); + let path2 = dir.path().join("sock2"); + + let sock1 = or_panic!(UnixDatagram::bind(&path1)); + let sock2 = or_panic!(UnixDatagram::bind(&path2)); + + let msg = b"hello world"; + let sock1_addr = or_panic!(sock1.local_addr()); + or_panic!(sock2.send_to_addr(msg, &sock1_addr)); + let mut buf = [0; 11]; + let (_, addr) = or_panic!(sock1.recv_from(&mut buf)); + + let new_msg = b"hello back"; + let mut new_buf = [0; 10]; + or_panic!(sock2.connect_addr(&addr)); + or_panic!(sock2.send(new_msg)); // set by connect_addr + let usize = or_panic!(sock2.recv(&mut new_buf)); + assert_eq!(usize, 10); + assert_eq!(new_msg, &new_buf[..]); +} + #[test] fn test_connect_unix_datagram() { let dir = tmpdir(); From 15b119897c40cbc76f5e1c65370930773dfdc741 Mon Sep 17 00:00:00 2001 From: Milan Date: Thu, 7 Oct 2021 10:19:45 -0400 Subject: [PATCH 040/181] integrate I/O safety changes --- library/std/src/os/unix/net/datagram.rs | 6 +++--- library/std/src/os/unix/net/listener.rs | 5 ++--- library/std/src/os/unix/net/stream.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 87be4d3f57a84..a2caccc784917 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -139,7 +139,7 @@ impl UnixDatagram { unsafe { let socket = UnixDatagram::unbound()?; cvt(libc::bind( - *socket.0.as_inner(), + socket.as_raw_fd(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _, ))?; @@ -254,7 +254,7 @@ impl UnixDatagram { pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> { unsafe { cvt(libc::connect( - *self.0.as_inner(), + self.as_raw_fd(), &socket_addr.addr as *const _ as *const _, socket_addr.len, ))?; @@ -568,7 +568,7 @@ impl UnixDatagram { pub fn send_to_addr(&self, buf: &[u8], socket_addr: &SocketAddr) -> io::Result { unsafe { let count = cvt(libc::sendto( - *self.0.as_inner(), + self.as_raw_fd(), buf.as_ptr() as *const _, buf.len(), MSG_NOSIGNAL, diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 7fba7543ec297..97348afe7de12 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -110,12 +110,11 @@ impl UnixListener { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; cvt(libc::bind( - *inner.as_inner(), + inner.as_raw_fd(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _, ))?; - cvt(libc::listen(*inner.as_inner(), 128))?; - + cvt(libc::listen(inner.as_raw_fd(), 128))?; Ok(UnixListener(inner)) } } diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index e3eef7c761487..6120d557227af 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -135,7 +135,7 @@ impl UnixStream { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; cvt(libc::connect( - *inner.as_inner(), + inner.as_raw_fd(), &socket_addr.addr as *const _ as *const _, socket_addr.len, ))?; From 9177fa3dd23945a8add858cfce893bb25194e0fe Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 10 Oct 2021 22:34:10 -0500 Subject: [PATCH 041/181] Use shallow clones for submodules This reduces the amount of git history downloaded from ~67M to ~11M. --- src/bootstrap/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 05d7b0f611f72..9d64a254f619b 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -990,7 +990,7 @@ def update_submodule(self, module, checked_out, recorded_submodules): run(["git", "submodule", "-q", "sync", module], cwd=self.rust_root, verbose=self.verbose) - update_args = ["git", "submodule", "update", "--init", "--recursive"] + update_args = ["git", "submodule", "update", "--init", "--recursive", "--depth=1"] if self.git_version >= distutils.version.LooseVersion("2.11.0"): update_args.append("--progress") update_args.append(module) From 1afe14ceedaad19bc3e10dda28ce3f52c69e287a Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Tue, 31 Aug 2021 12:59:44 -0400 Subject: [PATCH 042/181] add `slice::swap_unchecked` --- library/core/src/slice/mod.rs | 46 +++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 53b8b343238d5..2624df78a7612 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -560,15 +560,45 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn swap(&mut self, a: usize, b: usize) { - // Can't take two mutable loans from one vector, so instead use raw pointers. - let pa = ptr::addr_of_mut!(self[a]); - let pb = ptr::addr_of_mut!(self[b]); - // SAFETY: `pa` and `pb` have been created from safe mutable references and refer - // to elements in the slice and therefore are guaranteed to be valid and aligned. - // Note that accessing the elements behind `a` and `b` is checked and will - // panic when out of bounds. + assert!(a < self.len()); + assert!(b < self.len()); + // SAFETY: we just checked that both `a` and `b` are in bounds + unsafe { self.swap_unchecked(a, b) } + } + + /// Swaps two elements in the slice, without doing bounds checking. + /// + /// For a safe alternative see [`swap`]. + /// + /// # Arguments + /// + /// * a - The index of the first element + /// * b - The index of the second element + /// + /// # Safety + /// + /// Calling this method with an out-of-bounds index is *[undefined behavior]*. + /// The caller has to ensure that `a < self.len()` and `b < self.len()`. + /// + /// # Examples + /// + /// ``` + /// let mut v = ["a", "b", "c", "d"]; + /// // SAFETY: we know that 1 and 3 are both indices of the slice + /// unsafe { v.swap_unchecked(1, 3) }; + /// assert!(v == ["a", "d", "c", "b"]); + /// ``` + /// + /// [`swap`]: slice::swap + /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html + #[unstable(feature = "slice_swap_unchecked", issue = "88539")] + pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { + debug_assert!(a < self.len()); + debug_assert!(b < self.len()); + let ptr = self.as_mut_ptr(); + // SAFETY: caller has to guarantee that `a < self.len()` and `b < self.len()` unsafe { - ptr::swap(pa, pb); + ptr::swap(ptr.add(a), ptr.add(b)); } } From 14769ce96f53553c9f61b9d5ef950cfbe85d7e51 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Tue, 31 Aug 2021 13:25:09 -0400 Subject: [PATCH 043/181] enable `slice_swap_unchecked` feature in doc test --- library/core/src/slice/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 2624df78a7612..16e3c9e52fa9e 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -583,6 +583,8 @@ impl [T] { /// # Examples /// /// ``` + /// #![feature(slice_swap_unchecked)] + /// /// let mut v = ["a", "b", "c", "d"]; /// // SAFETY: we know that 1 and 3 are both indices of the slice /// unsafe { v.swap_unchecked(1, 3) }; From 33ecc33268c1cda372c90c203cead2721a822363 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Tue, 31 Aug 2021 21:00:30 -0400 Subject: [PATCH 044/181] use `swap_unchecked` in `slice::reverse` --- library/core/src/slice/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 16e3c9e52fa9e..496cc359c19f9 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -707,11 +707,7 @@ impl [T] { // The resulting pointers `pa` and `pb` are therefore valid and // aligned, and can be read from and written to. unsafe { - // Unsafe swap to avoid the bounds check in safe swap. - let ptr = self.as_mut_ptr(); - let pa = ptr.add(i); - let pb = ptr.add(ln - i - 1); - ptr::swap(pa, pb); + self.swap_unchecked(i, ln - i - 1); } i += 1; } From 2a8ff8df54d5effdfd0154009eea2d50bdd5e598 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 11 Oct 2021 16:12:43 -0400 Subject: [PATCH 045/181] improve slice::swap panic message --- library/core/src/slice/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 496cc359c19f9..8108d52071b26 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -560,8 +560,9 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn swap(&mut self, a: usize, b: usize) { - assert!(a < self.len()); - assert!(b < self.len()); + assert_in_bounds(self.len(), a); + assert_in_bounds(self.len(), b); + // SAFETY: we just checked that both `a` and `b` are in bounds unsafe { self.swap_unchecked(a, b) } } @@ -595,8 +596,12 @@ impl [T] { /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html #[unstable(feature = "slice_swap_unchecked", issue = "88539")] pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { - debug_assert!(a < self.len()); - debug_assert!(b < self.len()); + #[cfg(debug_assertions)] + { + assert_in_bounds(self.len(), a); + assert_in_bounds(self.len(), b); + } + let ptr = self.as_mut_ptr(); // SAFETY: caller has to guarantee that `a < self.len()` and `b < self.len()` unsafe { @@ -3497,6 +3502,12 @@ impl [T] { } } +fn assert_in_bounds(len: usize, idx: usize) { + if idx >= len { + panic!("index out of bounds: the len is {} but the index is {}", len, idx); + } +} + trait CloneFromSpec { fn spec_clone_from(&mut self, src: &[T]); } From c517a0de3e8d7d6a85b6f47f0ae8c8988311e288 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Mon, 11 Oct 2021 16:13:17 -0400 Subject: [PATCH 046/181] add slice::swap tests --- library/core/tests/slice.rs | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index c591dd3e1a6db..b6a326f3d7368 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -2152,3 +2152,42 @@ fn test_slice_fill_with_uninit() { let mut a = [MaybeUninit::::uninit(); 10]; a.fill(MaybeUninit::uninit()); } + +#[test] +fn test_swap() { + let mut x = ["a", "b", "c", "d"]; + x.swap(1, 3); + assert_eq!(x, ["a", "d", "c", "b"]); + x.swap(0, 3); + assert_eq!(x, ["b", "d", "c", "a"]); +} + +mod swap_panics { + #[test] + #[should_panic(expected = "index out of bounds: the len is 4 but the index is 4")] + fn index_a_equals_len() { + let mut x = ["a", "b", "c", "d"]; + x.swap(4, 2); + } + + #[test] + #[should_panic(expected = "index out of bounds: the len is 4 but the index is 4")] + fn index_b_equals_len() { + let mut x = ["a", "b", "c", "d"]; + x.swap(2, 4); + } + + #[test] + #[should_panic(expected = "index out of bounds: the len is 4 but the index is 5")] + fn index_a_greater_than_len() { + let mut x = ["a", "b", "c", "d"]; + x.swap(5, 2); + } + + #[test] + #[should_panic(expected = "index out of bounds: the len is 4 but the index is 5")] + fn index_b_greater_than_len() { + let mut x = ["a", "b", "c", "d"]; + x.swap(2, 5); + } +} From 12b39e59127468b77632cadd2908c7e0f8ed2fea Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 11 Oct 2021 22:36:37 +0200 Subject: [PATCH 047/181] Make naming more explicit. --- compiler/rustc_ast_lowering/src/lib.rs | 16 ++++++++++------ compiler/rustc_hir/src/hir.rs | 6 +++--- compiler/rustc_hir/src/stable_hash_impls.rs | 5 +++-- compiler/rustc_middle/src/hir/mod.rs | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 84aeb78a0aa10..19037abdd22e9 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -102,7 +102,9 @@ struct LoweringContext<'a, 'hir: 'a> { /// The items being lowered are collected here. owners: IndexVec>>, + /// Bodies inside the owner being lowered. bodies: IndexVec>>, + /// Attributes inside the owner being lowered. attrs: BTreeMap, generator_kind: Option, @@ -418,6 +420,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.arena.alloc(krate) } + /// Compute the hash for the HIR of the full crate. + /// This hash will then be part of the crate_hash which is stored in the metadata. fn compute_hir_hash(&mut self) -> Fingerprint { let definitions = self.resolver.definitions(); let mut hir_body_nodes: Vec<_> = self @@ -493,10 +497,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - let (hash, node_hash) = self.hash_body(node, &bodies); + let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies); let (nodes, parenting) = index::index_hir(self.sess, self.resolver.definitions(), node, &bodies); - let nodes = hir::OwnerNodes { hash, node_hash, nodes, bodies }; + let nodes = hir::OwnerNodes { hash_including_bodies, hash_without_bodies, nodes, bodies }; let attrs = { let mut hcx = self.resolver.create_stable_hashing_context(); let mut stable_hasher = StableHasher::new(); @@ -510,7 +514,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate /// queries which depend on the full HIR tree and those which only depend on the item signature. - fn hash_body( + fn hash_owner( &mut self, node: hir::OwnerNode<'hir>, bodies: &IndexVec>>, @@ -520,13 +524,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| { node.hash_stable(hcx, &mut stable_hasher) }); - let full_hash = stable_hasher.finish(); + let hash_including_bodies = stable_hasher.finish(); let mut stable_hasher = StableHasher::new(); hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| { node.hash_stable(hcx, &mut stable_hasher) }); - let node_hash = stable_hasher.finish(); - (full_hash, node_hash) + let hash_without_bodies = stable_hasher.finish(); + (hash_including_bodies, hash_without_bodies) } /// This method allocates a new `HirId` for the given `NodeId` and stores it in diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 6cbea732c9938..0530a69102038 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -692,9 +692,9 @@ impl<'tcx> AttributeMap<'tcx> { #[derive(Debug)] pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the full HIR. - pub hash: Fingerprint, - /// Pre-computed hash of the top node. - pub node_hash: Fingerprint, + pub hash_including_bodies: Fingerprint, + /// Pre-computed hash of the item signature, sithout recursing into the body. + pub hash_without_bodies: Fingerprint, /// Full HIR for the current owner. // The zeroth node's parent is trash, but is never accessed. pub nodes: IndexVec>>, diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index 3c9fe93b67d3c..6e7b765a0c441 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -215,8 +215,9 @@ impl HashStable for OwnerNodes<'tcx> { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { // We ignore the `nodes` and `bodies` fields since these refer to information included in // `hash` which is hashed in the collector and used for the crate hash. - let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self; - hash.hash_stable(hcx, hasher); + let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } = + *self; + hash_including_bodies.hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index f941981be79b7..1648d0d3ac172 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -23,14 +23,14 @@ use rustc_span::DUMMY_SP; #[derive(Copy, Clone, Debug)] pub struct Owner<'tcx> { node: OwnerNode<'tcx>, - node_hash: Fingerprint, + hash_without_bodies: Fingerprint, } impl<'a, 'tcx> HashStable> for Owner<'tcx> { #[inline] fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let Owner { node: _, node_hash } = self; - node_hash.hash_stable(hcx, hasher) + let Owner { node: _, hash_without_bodies } = self; + hash_without_bodies.hash_stable(hcx, hasher) } } @@ -67,7 +67,7 @@ pub fn provide(providers: &mut Providers) { providers.hir_owner = |tcx, id| { let owner = tcx.hir_crate(()).owners[id].as_ref()?; let node = owner.node(); - Some(Owner { node, node_hash: owner.nodes.node_hash }) + Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies }) }; providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes); providers.hir_owner_parent = |tcx, id| { From 6b7995195a7d89ee3d5b669ca7424d0f412ad7bb Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 11 Oct 2021 22:36:46 +0200 Subject: [PATCH 048/181] Remove unused function. --- compiler/rustc_hir/src/definitions.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index b7bdc9a1414ac..ca29351455e62 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -92,12 +92,6 @@ impl DefPathTable { .iter_enumerated() .map(move |(index, key)| (index, key, &self.def_path_hashes[index])) } - - pub fn all_def_path_hashes_and_def_ids( - &self, - ) -> impl Iterator + '_ { - self.def_path_hashes.iter_enumerated().map(move |(index, hash)| (hash, index)) - } } /// The definition table containing node definitions. From 5387b6542f1d72d332c84e8325309f0c9de7b6a0 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 12 Oct 2021 05:06:37 +0000 Subject: [PATCH 049/181] Add const_eval_select intrinsic --- .../rustc_codegen_cranelift/src/abi/mod.rs | 4 +- .../src/intrinsics/mod.rs | 4 +- .../src/const_eval/machine.rs | 59 +++++++++++----- .../src/interpret/terminator.rs | 2 +- .../src/transform/check_consts/check.rs | 8 ++- .../src/transform/check_consts/mod.rs | 12 +++- .../check_consts/post_drop_elaboration.rs | 6 +- .../src/transform/promote_consts.rs | 4 +- compiler/rustc_feature/src/builtin_attrs.rs | 2 + compiler/rustc_hir/src/lang_items.rs | 2 + compiler/rustc_span/src/symbol.rs | 3 + .../src/traits/select/candidate_assembly.rs | 8 ++- compiler/rustc_typeck/src/check/callee.rs | 6 +- compiler/rustc_typeck/src/check/intrinsic.rs | 2 + library/core/src/intrinsics.rs | 69 +++++++++++++++++++ .../codegen/intrinsics/const_eval_select.rs | 17 +++++ .../ui/intrinsics/const-eval-select-bad.rs | 36 ++++++++++ .../intrinsics/const-eval-select-bad.stderr | 63 +++++++++++++++++ .../ui/intrinsics/const-eval-select-x86_64.rs | 39 +++++++++++ src/test/ui/intrinsics/const-eval-select.rs | 26 +++++++ 20 files changed, 334 insertions(+), 38 deletions(-) create mode 100644 src/test/codegen/intrinsics/const_eval_select.rs create mode 100644 src/test/ui/intrinsics/const-eval-select-bad.rs create mode 100644 src/test/ui/intrinsics/const-eval-select-bad.stderr create mode 100644 src/test/ui/intrinsics/const-eval-select-x86_64.rs create mode 100644 src/test/ui/intrinsics/const-eval-select.rs diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 15bb90678059d..78fdf9c02d06a 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -309,13 +309,13 @@ pub(crate) fn codegen_terminator_call<'tcx>( span: Span, func: &Operand<'tcx>, args: &[Operand<'tcx>], - destination: Option<(Place<'tcx>, BasicBlock)>, + mir_dest: Option<(Place<'tcx>, BasicBlock)>, ) { let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx)); let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx)); - let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb)); + let destination = mir_dest.map(|(place, bb)| (codegen_place(fx, place), bb)); // Handle special calls like instrinsics and empty drop glue. let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() { diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index 48183b2d4f634..313b62c5770b6 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -407,11 +407,9 @@ pub(crate) fn codegen_intrinsic_call<'tcx>( destination: Option<(CPlace<'tcx>, BasicBlock)>, span: Span, ) { - let def_id = instance.def_id(); + let intrinsic = fx.tcx.item_name(instance.def_id()); let substs = instance.substs; - let intrinsic = fx.tcx.item_name(def_id); - let ret = match destination { Some((place, _)) => place, None => { diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index ae20f6f97b212..202c9cad8eb53 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -26,14 +26,35 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> { /// "Intercept" a function call to a panic-related function /// because we have something special to do for it. /// If this returns successfully (`Ok`), the function should just be evaluated normally. - fn hook_panic_fn( + fn hook_special_const_fn( &mut self, instance: ty::Instance<'tcx>, args: &[OpTy<'tcx>], + is_const_fn: bool, ) -> InterpResult<'tcx, Option>> { // The list of functions we handle here must be in sync with - // `is_lang_panic_fn` in `transform/check_consts/mod.rs`. + // `is_lang_special_const_fn` in `transform/check_consts/mod.rs`. let def_id = instance.def_id(); + + if is_const_fn { + if Some(def_id) == self.tcx.lang_items().const_eval_select() { + // redirect to const_eval_select_ct + if let Some(const_eval_select) = self.tcx.lang_items().const_eval_select_ct() { + return Ok(Some( + ty::Instance::resolve( + *self.tcx, + ty::ParamEnv::reveal_all(), + const_eval_select, + instance.substs, + ) + .unwrap() + .unwrap(), + )); + } + } + return Ok(None); + } + if Some(def_id) == self.tcx.lang_items().panic_fn() || Some(def_id) == self.tcx.lang_items().panic_str() || Some(def_id) == self.tcx.lang_items().panic_display() @@ -255,31 +276,31 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, // Only check non-glue functions if let ty::InstanceDef::Item(def) = instance.def { + let mut is_const_fn = true; + // Execution might have wandered off into other crates, so we cannot do a stability- // sensitive check here. But we can at least rule out functions that are not const // at all. if !ecx.tcx.is_const_fn_raw(def.did) { // allow calling functions marked with #[default_method_body_is_const]. if !ecx.tcx.has_attr(def.did, sym::default_method_body_is_const) { - // Some functions we support even if they are non-const -- but avoid testing - // that for const fn! - if let Some(new_instance) = ecx.hook_panic_fn(instance, args)? { - // We call another const fn instead. - return Self::find_mir_or_eval_fn( - ecx, - new_instance, - _abi, - args, - _ret, - _unwind, - ); - } else { - // We certainly do *not* want to actually call the fn - // though, so be sure we return here. - throw_unsup_format!("calling non-const function `{}`", instance) - } + is_const_fn = false; } } + + // Some functions we support even if they are non-const -- but avoid testing + // that for const fn! + // `const_eval_select` is a const fn because it must use const trait bounds. + if let Some(new_instance) = ecx.hook_special_const_fn(instance, args, is_const_fn)? { + // We call another const fn instead. + return Self::find_mir_or_eval_fn(ecx, new_instance, _abi, args, _ret, _unwind); + } + + if !is_const_fn { + // We certainly do *not* want to actually call the fn + // though, so be sure we return here. + throw_unsup_format!("calling non-const function `{}`", instance) + } } // This is a const fn. Call it. Ok(Some(ecx.load_mir(instance.def, None)?)) diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index a06903aedf649..8d3544d434acf 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -231,7 +231,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } /// Call this function -- pushing the stack frame and initializing the arguments. - fn eval_fn_call( + pub(crate) fn eval_fn_call( &mut self, fn_val: FnVal<'tcx, M::ExtraFnVal>, caller_abi: Abi, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index fd5cd269a3a9e..22f14ffbd583a 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -24,7 +24,7 @@ use std::ops::Deref; use super::ops::{self, NonConstOp, Status}; use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop}; use super::resolver::FlowSensitiveAnalysis; -use super::{is_lang_panic_fn, ConstCx, Qualif}; +use super::{is_lang_special_const_fn, ConstCx, Qualif}; use crate::const_eval::is_unstable_const_fn; // We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated @@ -259,7 +259,9 @@ impl Checker<'mir, 'tcx> { self.check_local_or_return_ty(return_ty.skip_binder(), RETURN_PLACE); } - self.visit_body(&body); + if !tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) { + self.visit_body(&body); + } // Ensure that the end result is `Sync` in a non-thread local `static`. let should_check_for_sync = self.const_kind() @@ -886,7 +888,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { } // At this point, we are calling a function, `callee`, whose `DefId` is known... - if is_lang_panic_fn(tcx, callee) { + if is_lang_special_const_fn(tcx, callee) { // `begin_panic` and `panic_display` are generic functions that accept // types other than str. Check to enforce that only str can be used in // const-eval. diff --git a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs index d1fd3ceaa589a..0a852282f8f26 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs @@ -74,9 +74,6 @@ impl ConstCx<'mir, 'tcx> { /// Returns `true` if this `DefId` points to one of the official `panic` lang items. pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { - // We can allow calls to these functions because `hook_panic_fn` in - // `const_eval/machine.rs` ensures the calls are handled specially. - // Keep in sync with what that function handles! Some(def_id) == tcx.lang_items().panic_fn() || Some(def_id) == tcx.lang_items().panic_str() || Some(def_id) == tcx.lang_items().panic_display() @@ -85,6 +82,15 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { || Some(def_id) == tcx.lang_items().begin_panic_fmt() } +/// Returns `true` if this `DefId` points to one of the lang items that will be handled differently +/// in const_eval. +pub fn is_lang_special_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + // We can allow calls to these functions because `hook_special_const_fn` in + // `const_eval/machine.rs` ensures the calls are handled specially. + // Keep in sync with what that function handles! + is_lang_panic_fn(tcx, def_id) || Some(def_id) == tcx.lang_items().const_eval_select() +} + pub fn rustc_allow_const_fn_unstable( tcx: TyCtxt<'tcx>, def_id: DefId, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs index f2ba5a1ebb19b..1a8c8b1c78d08 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs @@ -1,7 +1,7 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{self, BasicBlock, Location}; use rustc_middle::ty::TyCtxt; -use rustc_span::Span; +use rustc_span::{symbol::sym, Span}; use super::check::Qualifs; use super::ops::{self, NonConstOp}; @@ -30,6 +30,10 @@ pub fn check_live_drops(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) { return; } + if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) { + return; + } + let ccx = ConstCx { body, tcx, const_kind, param_env: tcx.param_env(def_id) }; if !checking_enabled(&ccx) { return; diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index be1b827f2356f..7cfe3d7f809e9 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -26,7 +26,7 @@ use rustc_index::vec::{Idx, IndexVec}; use std::cell::Cell; use std::{cmp, iter, mem}; -use crate::transform::check_consts::{is_lang_panic_fn, qualifs, ConstCx}; +use crate::transform::check_consts::{is_lang_special_const_fn, qualifs, ConstCx}; use crate::transform::MirPass; /// A `MirPass` for promotion. @@ -657,7 +657,7 @@ impl<'tcx> Validator<'_, 'tcx> { let is_const_fn = match *fn_ty.kind() { ty::FnDef(def_id, _) => { - self.tcx.is_const_fn_raw(def_id) || is_lang_panic_fn(self.tcx, def_id) + self.tcx.is_const_fn_raw(def_id) || is_lang_special_const_fn(self.tcx, def_id) } _ => false, }; diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index f3eaf2645f50a..85b0db468d125 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -467,6 +467,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!(rustc_promotable, Normal, template!(Word), IMPL_DETAIL), rustc_attr!(rustc_legacy_const_generics, Normal, template!(List: "N"), INTERNAL_UNSTABLE), + // Do not const-check this function's body. It will always get replaced during CTFE. + rustc_attr!(rustc_do_not_const_check, Normal, template!(Word), INTERNAL_UNSTABLE), // ========================================================================== // Internal attributes, Layout related: diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 814054c551878..f35353dbfb581 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -299,6 +299,8 @@ language_item_table! { DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1); Oom, sym::oom, oom, Target::Fn, GenericRequirement::None; AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None; + ConstEvalSelect, sym::const_eval_select, const_eval_select, Target::Fn, GenericRequirement::Exact(4); + ConstConstEvalSelect, sym::const_eval_select_ct,const_eval_select_ct, Target::Fn, GenericRequirement::Exact(4); Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0e30e154ee57c..63bd58a3bec38 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -441,6 +441,8 @@ symbols! { const_compare_raw_pointers, const_constructor, const_eval_limit, + const_eval_select, + const_eval_select_ct, const_evaluatable_checked, const_extern_fn, const_fn, @@ -1095,6 +1097,7 @@ symbols! { rustc_diagnostic_item, rustc_diagnostic_macros, rustc_dirty, + rustc_do_not_const_check, rustc_dummy, rustc_dump_env_program_clauses, rustc_dump_program_clauses, diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index d68ae07907734..b78c227c364c1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -973,12 +973,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Tuple(_) => stack.extend(ty.tuple_fields().map(|t| (t, depth + 1))), ty::Closure(_, substs) => { - stack.extend(substs.as_closure().upvar_tys().map(|t| (t, depth + 1))) + let substs = substs.as_closure(); + let ty = self.infcx.shallow_resolve(substs.tupled_upvars_ty()); + stack.push((ty, depth + 1)); } ty::Generator(_, substs, _) => { let substs = substs.as_generator(); - stack.extend(substs.upvar_tys().map(|t| (t, depth + 1))); + let ty = self.infcx.shallow_resolve(substs.tupled_upvars_ty()); + + stack.push((ty, depth + 1)); stack.push((substs.witness(), depth + 1)); } diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 51bbcbebcdc0b..06c42098791ef 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -17,7 +17,7 @@ use rustc_infer::{ use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; -use rustc_middle::ty::subst::SubstsRef; +use rustc_middle::ty::subst::{Subst, SubstsRef}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; @@ -317,6 +317,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { let (fn_sig, def_id) = match *callee_ty.kind() { ty::FnDef(def_id, subst) => { + let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, subst); + // Unit testing: function items annotated with // `#[rustc_evaluate_where_clauses]` trigger special output // to let us test the trait evaluation system. @@ -342,7 +344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .emit(); } } - (callee_ty.fn_sig(self.tcx), Some(def_id)) + (fn_sig, Some(def_id)) } ty::FnPtr(sig) => (sig, None), ref t => { diff --git a/compiler/rustc_typeck/src/check/intrinsic.rs b/compiler/rustc_typeck/src/check/intrinsic.rs index ff7a26853b188..b0cb8443bfbc1 100644 --- a/compiler/rustc_typeck/src/check/intrinsic.rs +++ b/compiler/rustc_typeck/src/check/intrinsic.rs @@ -390,6 +390,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { sym::black_box => (1, vec![param(0)], param(0)), + sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)), + other => { tcx.sess.emit_err(UnrecognizedIntrinsicFunction { span: it.span, name: other }); return; diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 3e26d46ddcaf9..da0591418f072 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2221,3 +2221,72 @@ pub unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { // SAFETY: the safety contract for `write_bytes` must be upheld by the caller. unsafe { write_bytes(dst, val, count) } } + +/// Selects which function to call depending on the context. +/// +/// If this function is evaluated at compile-time, then a call to this +/// intrinsic will be replaced with a call to `called_in_const`. It gets +/// replaced with a call to `called_at_rt` otherwise. +/// +/// # Type Requirements +/// +/// The two functions must be both function items. They cannot be function +/// pointers or closures. +/// +/// `arg` will be the arguments that will be passed to either one of the +/// two functions, therefore, both functions must accept the same type of +/// arguments. Both functions must return RET. +/// +/// # Safety +/// +/// This intrinsic allows breaking [referential transparency] in `const fn` +/// and is therefore `unsafe`. +/// +/// Code that uses this intrinsic must be extremely careful to ensure that +/// `const fn`s remain referentially-transparent independently of when they +/// are evaluated. +/// +/// The Rust compiler assumes that it is sound to replace a call to a `const +/// fn` with the result produced by evaluating it at compile-time. If +/// evaluating the function at run-time were to produce a different result, +/// or have any other observable side-effects, the behavior is undefined. +/// +/// [referential transparency]: https://en.wikipedia.org/wiki/Referential_transparency +#[cfg(not(bootstrap))] +#[unstable( + feature = "const_eval_select", + issue = "none", + reason = "const_eval_select will never be stable" +)] +#[lang = "const_eval_select"] +#[rustc_do_not_const_check] +pub const unsafe fn const_eval_select( + arg: ARG, + _called_in_const: F, + called_at_rt: G, +) -> RET +where + F: ~const FnOnce(ARG) -> RET, + G: FnOnce(ARG) -> RET + ~const Drop, +{ + called_at_rt(arg) +} + +#[cfg(not(bootstrap))] +#[unstable( + feature = "const_eval_select", + issue = "none", + reason = "const_eval_select will never be stable" +)] +#[lang = "const_eval_select_ct"] +pub const unsafe fn const_eval_select_ct( + arg: ARG, + called_in_const: F, + _called_at_rt: G, +) -> RET +where + F: ~const FnOnce(ARG) -> RET, + G: FnOnce(ARG) -> RET + ~const Drop, +{ + called_in_const(arg) +} diff --git a/src/test/codegen/intrinsics/const_eval_select.rs b/src/test/codegen/intrinsics/const_eval_select.rs new file mode 100644 index 0000000000000..84777cac7c390 --- /dev/null +++ b/src/test/codegen/intrinsics/const_eval_select.rs @@ -0,0 +1,17 @@ +// compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(const_eval_select)] + +use std::intrinsics::const_eval_select; + +const fn foo(_: (i32,)) -> i32 { 1 } + +#[no_mangle] +pub fn hi((n,): (i32,)) -> i32 { n } + +#[no_mangle] +pub unsafe fn hey() { + // CHECK: call i32 @hi(i32 + const_eval_select((42,), foo, hi); +} diff --git a/src/test/ui/intrinsics/const-eval-select-bad.rs b/src/test/ui/intrinsics/const-eval-select-bad.rs new file mode 100644 index 0000000000000..1e5bf7a70b8c4 --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select-bad.rs @@ -0,0 +1,36 @@ +#![feature(const_eval_select)] + +use std::intrinsics::const_eval_select; + +const fn not_fn_items() { + const_eval_select((), |()| {}, |()| {}); + //~^ ERROR expected a `FnOnce<((),)>` closure + const_eval_select((), 42, 0xDEADBEEF); + //~^ ERROR expected a `FnOnce<((),)>` closure +} + +const fn foo((n,): (i32,)) -> i32 { + n +} + +fn bar((n,): (i32,)) -> bool { + assert_eq!(n, 0, "{} must be equal to {}", n, 0); + n == 0 +} + +fn baz((n,): (bool,)) -> i32 { + assert!(n, "{} must be true", n); + n as i32 +} + +const fn return_ty_mismatch() { + const_eval_select((1,), foo, bar); + //~^ ERROR type mismatch +} + +const fn args_ty_mismatch() { + const_eval_select((true,), foo, baz); + //~^ ERROR type mismatch +} + +fn main() {} diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr new file mode 100644 index 0000000000000..a38eb627e341d --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -0,0 +1,63 @@ +error[E0277]: expected a `FnOnce<((),)>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` + --> $DIR/const-eval-select-bad.rs:6:36 + | +LL | const_eval_select((), |()| {}, |()| {}); + | ----------------- ^^^^^^^ expected an `FnOnce<((),)>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` + | | + | required by a bound introduced by this call + | + = help: the trait `FnOnce<((),)>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` +note: required by a bound in `const_eval_select` + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | F: ~const FnOnce(ARG) -> RET, + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` + +error[E0277]: expected a `FnOnce<((),)>` closure, found `{integer}` + --> $DIR/const-eval-select-bad.rs:8:31 + | +LL | const_eval_select((), 42, 0xDEADBEEF); + | ----------------- ^^^^^^^^^^ expected an `FnOnce<((),)>` closure, found `{integer}` + | | + | required by a bound introduced by this call + | + = help: the trait `FnOnce<((),)>` is not implemented for `{integer}` +note: required by a bound in `const_eval_select` + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | F: ~const FnOnce(ARG) -> RET, + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` + +error[E0271]: type mismatch resolving ` bool {bar} as FnOnce<((i32,),)>>::Output == i32` + --> $DIR/const-eval-select-bad.rs:27:5 + | +LL | const_eval_select((1,), foo, bar); + | ^^^^^^^^^^^^^^^^^ expected `i32`, found `bool` + | +note: required by a bound in `const_eval_select` + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | G: FnOnce(ARG) -> RET + ~const Drop, + | ^^^ required by this bound in `const_eval_select` + +error[E0631]: type mismatch in function arguments + --> $DIR/const-eval-select-bad.rs:32:37 + | +LL | const fn foo((n,): (i32,)) -> i32 { + | --------------------------------- found signature of `fn((i32,)) -> _` +... +LL | const_eval_select((true,), foo, baz); + | ----------------- ^^^ expected signature of `fn((bool,)) -> _` + | | + | required by a bound introduced by this call + | +note: required by a bound in `const_eval_select` + --> $SRC_DIR/core/src/intrinsics.rs:LL:COL + | +LL | F: ~const FnOnce(ARG) -> RET, + | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0271, E0277, E0631. +For more information about an error, try `rustc --explain E0271`. diff --git a/src/test/ui/intrinsics/const-eval-select-x86_64.rs b/src/test/ui/intrinsics/const-eval-select-x86_64.rs new file mode 100644 index 0000000000000..807db65bc72d9 --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select-x86_64.rs @@ -0,0 +1,39 @@ +// run-pass +// only-x86_64 + +#![feature(const_eval_select)] +use std::intrinsics::const_eval_select; +use std::arch::x86_64::*; +use std::mem::transmute; + +const fn eq_ct((x, y): ([i32; 4], [i32; 4])) -> bool { + x[0] == y[0] && x[1] == y[1] && x[2] == y[2] && x[3] == y[3] +} + +fn eq_rt((x, y): ([i32; 4], [i32; 4])) -> bool { + unsafe { + let x = _mm_loadu_si128(&x as *const _ as *const _); + let y = _mm_loadu_si128(&y as *const _ as *const _); + let r = _mm_cmpeq_epi32(x, y); + let r = _mm_movemask_ps(transmute(r) ); + r == 0b1111 + } +} + +const fn eq(x: [i32; 4], y: [i32; 4]) -> bool { + unsafe { + const_eval_select((x, y), eq_ct, eq_rt) + } +} + +fn main() { + const X: bool = eq([0, 1, 2, 3], [0, 1, 2, 3]); + assert_eq!(X, true); + let x = eq([0, 1, 2, 3], [0, 1, 2, 3]); + assert_eq!(x, true); + + const Y: bool = eq([0, 1, 2, 3], [0, 1, 3, 2]); + assert_eq!(Y, false); + let y = eq([0, 1, 2, 3], [0, 1, 3, 2]); + assert_eq!(y, false); +} diff --git a/src/test/ui/intrinsics/const-eval-select.rs b/src/test/ui/intrinsics/const-eval-select.rs new file mode 100644 index 0000000000000..0b2c2f6ed4f06 --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select.rs @@ -0,0 +1,26 @@ +// run-pass + +#![feature(const_eval_select)] + +use std::intrinsics::const_eval_select; + +const fn yes(_: ()) -> bool { + true +} + +fn no(_: ()) -> bool { + false +} + +// not a sound use case; testing only +const fn is_const_eval() -> bool { + unsafe { const_eval_select((), yes, no) } +} + +fn main() { + const YES: bool = is_const_eval(); + let no = is_const_eval(); + + assert_eq!(true, YES); + assert_eq!(false, no); +} From c5628a5e656073bd3bceacb7824c2f66845d99f3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 12 Oct 2021 08:34:38 +0200 Subject: [PATCH 050/181] Use invalid local id for zeroth node parent. --- compiler/rustc_ast_lowering/src/index.rs | 5 ++++- compiler/rustc_hir/src/hir.rs | 4 +++- compiler/rustc_hir/src/hir_id.rs | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 7b0f1caaee1e1..dc2b1a730fbd6 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -47,7 +47,10 @@ pub(super) fn index_hir<'hir>( bodies: &IndexVec>>, ) -> (IndexVec>>, FxHashMap) { let mut nodes = IndexVec::new(); - nodes.push(Some(ParentedNode { parent: ItemLocalId::new(0), node: item.into() })); + // This node's parent should never be accessed: the owner's parent is computed by the + // hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is + // used. + nodes.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() })); let mut collector = NodeCollector { source_map: sess.source_map(), definitions, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 0530a69102038..1ec37566faba8 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -696,7 +696,9 @@ pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the item signature, sithout recursing into the body. pub hash_without_bodies: Fingerprint, /// Full HIR for the current owner. - // The zeroth node's parent is trash, but is never accessed. + // The zeroth node's parent should never be accessed: the owner's parent is computed by the + // hir_owner_parent query. It is set to `ItemLocalId::INVALID` to force an ICE if accidentally + // used. pub nodes: IndexVec>>, /// Content of local bodies. pub bodies: IndexVec>>, diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index 0b25ebc27bd3f..877871f7c3d80 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -56,6 +56,10 @@ rustc_index::newtype_index! { pub struct ItemLocalId { .. } } rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId); +impl ItemLocalId { + /// Signal local id which should never be used. + pub const INVALID: ItemLocalId = ItemLocalId::MAX; +} /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`. pub const CRATE_HIR_ID: HirId = HirId { From 129af049fef9a9de3ffba1f6b26246b02a360de3 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 12 Oct 2021 14:50:46 +0200 Subject: [PATCH 051/181] Mention Rust version in Vec::leak docs. --- library/alloc/src/vec/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 30cd95d695989..546cd1f631083 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1952,10 +1952,11 @@ impl Vec { /// `'a`. If the type has only static references, or none at all, then this /// may be chosen to be `'static`. /// - /// This method does not reallocate or shrink the `Vec`, so the leaked - /// allocation may include unused capacity that is not part of the returned - /// slice. Unsafe code that later reconstructs or deallocates the `Vec` - /// (for example, by calling [`Vec::from_raw_parts`]) must keep track of the + /// As of Rust 1.57, this method does not reallocate or shrink the `Vec`, + /// so the leaked allocation may include unused capacity that is not part + /// of the returned slice. + /// Unsafe code that later reconstructs or deallocates the `Vec` (for + /// example, by calling [`Vec::from_raw_parts`]) must keep track of the /// original capacity. /// /// This function is mainly useful for data that lives for the remainder of From df15b289f39c497d16fac694c6982fbdfa2e6fe2 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Tue, 12 Oct 2021 15:02:52 +0200 Subject: [PATCH 052/181] Remove potentially unsound note on reconstructing a leaked Vec. --- library/alloc/src/vec/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 546cd1f631083..632297196caf5 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1955,9 +1955,6 @@ impl Vec { /// As of Rust 1.57, this method does not reallocate or shrink the `Vec`, /// so the leaked allocation may include unused capacity that is not part /// of the returned slice. - /// Unsafe code that later reconstructs or deallocates the `Vec` (for - /// example, by calling [`Vec::from_raw_parts`]) must keep track of the - /// original capacity. /// /// This function is mainly useful for data that lives for the remainder of /// the program's life. Dropping the returned reference will cause a memory From d6dbff56e4789dc92c053881a8fe4d20f3bc28cd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Oct 2021 15:06:52 +0200 Subject: [PATCH 053/181] List associated constants in the sidebar --- src/librustdoc/html/render/mod.rs | 45 ++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index dc5aec3b084f5..71b9deca9d647 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1837,6 +1837,20 @@ fn get_methods( .collect::>() } +fn get_associated_constants(i: &clean::Impl, used_links: &mut FxHashSet) -> Vec { + i.items + .iter() + .filter_map(|item| match item.name { + Some(ref name) if !name.is_empty() && item.is_associated_const() => Some(format!( + "{}", + get_next_url(used_links, format!("associatedconstant.{}", name)), + name + )), + _ => None, + }) + .collect::>() +} + // The point is to url encode any potential character from a type with genericity. fn small_url_encode(s: String) -> String { let mut st = String::new(); @@ -1881,22 +1895,39 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { { let used_links_bor = &mut used_links; - let mut ret = v + let mut assoc_consts = v + .iter() + .flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)) + .collect::>(); + if !assoc_consts.is_empty() { + // We want links' order to be reproducible so we don't use unstable sort. + assoc_consts.sort(); + + out.push_str( + "

\ + Associated Constants\ +

\ +
", + ); + for line in assoc_consts { + out.push_str(&line); + } + out.push_str("
"); + } + let mut methods = v .iter() .filter(|i| i.inner_impl().trait_.is_none()) - .flat_map(move |i| { - get_methods(i.inner_impl(), false, used_links_bor, false, cx.tcx()) - }) + .flat_map(|i| get_methods(i.inner_impl(), false, used_links_bor, false, cx.tcx())) .collect::>(); - if !ret.is_empty() { + if !methods.is_empty() { // We want links' order to be reproducible so we don't use unstable sort. - ret.sort(); + methods.sort(); out.push_str( "

Methods

\
", ); - for line in ret { + for line in methods { out.push_str(&line); } out.push_str("
"); From 51a993f4a6f70765b2def104e9f1ba9549b37eb5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 12 Oct 2021 15:07:11 +0200 Subject: [PATCH 054/181] Add test for associated constants in the sidebar --- src/test/rustdoc/associated-consts.rs | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/rustdoc/associated-consts.rs diff --git a/src/test/rustdoc/associated-consts.rs b/src/test/rustdoc/associated-consts.rs new file mode 100644 index 0000000000000..6ae5e20632e52 --- /dev/null +++ b/src/test/rustdoc/associated-consts.rs @@ -0,0 +1,31 @@ +#![crate_name = "foo"] + +pub trait Trait { + const FOO: u32 = 12; + + fn foo(); +} + +pub struct Bar; + +// @has 'foo/struct.Bar.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//div[@class="sidebar-links"]/a' 'FOO' +impl Trait for Bar { + const FOO: u32 = 1; + + fn foo() {} +} + +pub enum Foo { + A, +} + +// @has 'foo/enum.Foo.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//div[@class="sidebar-links"]/a' 'FOO' +impl Trait for Foo { + const FOO: u32 = 1; + + fn foo() {} +} From 9855e7dc7bdafaafde22d9642eaea43638cf0a8a Mon Sep 17 00:00:00 2001 From: jackh726 Date: Tue, 12 Oct 2021 11:14:31 -0400 Subject: [PATCH 055/181] Switch order of terms to prevent overflow --- compiler/rustc_trait_selection/src/traits/project.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 47b006985ec56..db8a6d9620495 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -558,7 +558,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { fn universe_for(&mut self, debruijn: ty::DebruijnIndex) -> ty::UniverseIndex { let infcx = self.infcx; let index = - self.universe_indices.len() - debruijn.as_usize() + self.current_index.as_usize() - 1; + self.universe_indices.len() + self.current_index.as_usize() - debruijn.as_usize() - 1; let universe = self.universe_indices[index].unwrap_or_else(|| { for i in self.universe_indices.iter_mut().take(index + 1) { *i = i.or_else(|| Some(infcx.create_next_universe())) From 7a209bb7a55580076ce77ae859330875f6e2f18c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 12 Oct 2021 20:53:29 +0200 Subject: [PATCH 056/181] Justify untracked access. --- compiler/rustc_middle/src/hir/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 1648d0d3ac172..95d7273b17b44 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -71,6 +71,7 @@ pub fn provide(providers: &mut Providers) { }; providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes); providers.hir_owner_parent = |tcx, id| { + // Accessing the def_key is ok since its value is hashed as part of `id`'s DefPathHash. let parent = tcx.untracked_resolutions.definitions.def_key(id).parent; let parent = parent.map_or(CRATE_HIR_ID, |local_def_index| { let def_id = LocalDefId { local_def_index }; From f819e6d59c41b6bb3db2810c5c8e340b2fb2a88d Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 29 Sep 2021 13:55:24 +0900 Subject: [PATCH 057/181] suggestion for typoed crate or module avoid suggesting the same name sort candidates fix a message use `opt_def_id` instead of `def_id` move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs --- compiler/rustc_resolve/src/diagnostics.rs | 28 ++++++++++++ compiler/rustc_resolve/src/lib.rs | 17 +++++++- .../ui/macros/macro-inner-attributes.stderr | 5 +++ .../ui/suggestions/crate-or-module-typo.rs | 17 ++++++++ .../suggestions/crate-or-module-typo.stderr | 43 +++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/crate-or-module-typo.rs create mode 100644 src/test/ui/suggestions/crate-or-module-typo.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index dea47c25a8e0a..e3970038a33b0 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1277,6 +1277,34 @@ impl<'a> Resolver<'a> { err.emit(); } + + crate fn find_similarly_named_module_or_crate( + &mut self, + ident: Symbol, + current_module: &Module<'a>, + ) -> Option { + let mut candidates = self + .extern_prelude + .iter() + .map(|(ident, _)| ident.name) + .chain( + self.module_map + .iter() + .filter(|(_, module)| { + current_module.is_ancestor_of(module) && !ptr::eq(current_module, *module) + }) + .map(|(_, module)| module.kind.name()) + .flatten(), + ) + .filter(|c| !c.to_string().is_empty()) + .collect::>(); + candidates.sort(); + candidates.dedup(); + match find_best_match_for_name(&candidates, ident, None) { + Some(sugg) if sugg == ident => None, + sugg => sugg, + } + } } impl<'a, 'b> ImportResolver<'a, 'b> { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 3e7783033efa5..9652c483686f0 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2555,7 +2555,22 @@ impl<'a> Resolver<'a> { (format!("use of undeclared type `{}`", ident), suggestion) } else { - (format!("use of undeclared crate or module `{}`", ident), None) + ( + format!("use of undeclared crate or module `{}`", ident), + self.find_similarly_named_module_or_crate( + ident.name, + &parent_scope.module, + ) + .map(|sugg| { + ( + vec![(ident.span, sugg.to_string())], + String::from( + "there is a crate or module with a similar name", + ), + Applicability::MaybeIncorrect, + ) + }), + ) } } else { let parent = path[i - 1].ident.name; diff --git a/src/test/ui/macros/macro-inner-attributes.stderr b/src/test/ui/macros/macro-inner-attributes.stderr index 8223220d9a4e2..77b6486155cd2 100644 --- a/src/test/ui/macros/macro-inner-attributes.stderr +++ b/src/test/ui/macros/macro-inner-attributes.stderr @@ -3,6 +3,11 @@ error[E0433]: failed to resolve: use of undeclared crate or module `a` | LL | a::bar(); | ^ use of undeclared crate or module `a` + | +help: there is a crate or module with a similar name + | +LL | b::bar(); + | ~ error: aborting due to previous error diff --git a/src/test/ui/suggestions/crate-or-module-typo.rs b/src/test/ui/suggestions/crate-or-module-typo.rs new file mode 100644 index 0000000000000..2471b11c61efd --- /dev/null +++ b/src/test/ui/suggestions/crate-or-module-typo.rs @@ -0,0 +1,17 @@ +// edition:2018 + +use st::cell::Cell; //~ ERROR failed to resolve: use of undeclared crate or module `st` + +mod bar { + pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: use of undeclared crate or module `bar` + + fn baz() {} +} + +use bas::bar; //~ ERROR unresolved import `bas` + +struct Foo { + bar: st::cell::Cell //~ ERROR failed to resolve: use of undeclared crate or module `st` +} + +fn main() {} diff --git a/src/test/ui/suggestions/crate-or-module-typo.stderr b/src/test/ui/suggestions/crate-or-module-typo.stderr new file mode 100644 index 0000000000000..e8250c9fa5ff4 --- /dev/null +++ b/src/test/ui/suggestions/crate-or-module-typo.stderr @@ -0,0 +1,43 @@ +error[E0433]: failed to resolve: use of undeclared crate or module `st` + --> $DIR/crate-or-module-typo.rs:3:5 + | +LL | use st::cell::Cell; + | ^^ use of undeclared crate or module `st` + | +help: there is a crate or module with a similar name + | +LL | use std::cell::Cell; + | ~~~ + +error[E0432]: unresolved import `bas` + --> $DIR/crate-or-module-typo.rs:11:5 + | +LL | use bas::bar; + | ^^^ use of undeclared crate or module `bas` + | +help: there is a crate or module with a similar name + | +LL | use bar::bar; + | ~~~ + +error[E0433]: failed to resolve: use of undeclared crate or module `bar` + --> $DIR/crate-or-module-typo.rs:6:20 + | +LL | pub fn bar() { bar::baz(); } + | ^^^ use of undeclared crate or module `bar` + +error[E0433]: failed to resolve: use of undeclared crate or module `st` + --> $DIR/crate-or-module-typo.rs:14:10 + | +LL | bar: st::cell::Cell + | ^^ use of undeclared crate or module `st` + | +help: there is a crate or module with a similar name + | +LL | bar: std::cell::Cell + | ~~~ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0432, E0433. +For more information about an error, try `rustc --explain E0432`. From 31265c6ca3a2d404b7dbda0e3529f0be7c38cde7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 11 Oct 2021 04:09:15 +0000 Subject: [PATCH 058/181] Assemble the compiler when running `x.py build` Previously, there was no way to actually get binaries in `build/$TARGET/stage1/bin` without building the standard library. This makes it possible to build just the compiler. This can be useful when the standard library isn't actually necessary for trying out your tests (e.g. a bug that can be reproduced with only a `no_core` crate). --- src/bootstrap/builder.rs | 2 +- src/bootstrap/compile.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 0a6ed2f49b787..b55e7d8d50e36 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -370,7 +370,7 @@ impl<'a> Builder<'a> { match kind { Kind::Build => describe!( compile::Std, - compile::Rustc, + compile::Assemble, compile::CodegenBackend, compile::StartupObjects, tool::BuildManifest, diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index ae234fb1dc729..6a4d57a36b71c 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -528,7 +528,7 @@ impl Step for Rustc { const DEFAULT: bool = false; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("compiler/rustc") + run.never() } fn make_run(run: RunConfig<'_>) { @@ -1023,9 +1023,16 @@ pub struct Assemble { impl Step for Assemble { type Output = Compiler; + const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.never() + run.path("compiler/rustc") + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(Assemble { + target_compiler: run.builder.compiler(run.builder.top_stage + 1, run.target), + }); } /// Prepare a new compiler from the artifacts in `stage` From 15f93473f1db46d12cf0dd959c06b006c0847023 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Oct 2021 12:11:51 +0000 Subject: [PATCH 059/181] Remove textual span from diagnostic string --- .../src/infer/error_reporting/mod.rs | 67 +++---------------- ...ssociated-const-impl-wrong-lifetime.stderr | 2 +- ...regions-bound-missing-bound-in-impl.stderr | 8 +-- src/test/ui/c-variadic/issue-86053-1.stderr | 4 +- src/test/ui/c-variadic/issue-86053-2.stderr | 2 +- .../expect-fn-supply-fn.stderr | 8 +-- .../expect-region-supply-region-2.stderr | 8 +-- .../reject-specialized-drops-8142.stderr | 6 +- src/test/ui/error-codes/E0308-2.stderr | 2 +- src/test/ui/error-codes/E0478.stderr | 4 +- src/test/ui/error-codes/E0490.stderr | 12 ++-- .../explicit-self-lifetime-mismatch.stderr | 8 +-- .../ui/generator/resume-arg-late-bound.stderr | 4 +- .../impl_bounds.stderr | 4 +- ...113-lifetime-mismatch-dyn-trait-box.stderr | 6 +- .../unsatified-item-lifetime-bound.stderr | 6 +- .../unsatisfied-outlives-bound.stderr | 2 +- ...hr-subtype.free_inv_x_vs_free_inv_y.stderr | 8 +-- .../hr-subtype.free_x_vs_free_y.stderr | 4 +- .../ui/impl-trait/hidden-lifetimes.stderr | 4 +- .../error-handling-2.stderr | 2 +- .../ordinary-bounds-unrelated.nll.stderr | 2 +- .../ordinary-bounds-unsuited.nll.stderr | 2 +- .../impl-trait/region-escape-via-bound.stderr | 2 +- src/test/ui/issues/issue-10291.stderr | 4 +- src/test/ui/issues/issue-16683.stderr | 4 +- src/test/ui/issues/issue-17740.stderr | 8 +-- src/test/ui/issues/issue-17758.stderr | 4 +- src/test/ui/issues/issue-17905-2.stderr | 8 +-- .../ui/issues/issue-20831-debruijn.stderr | 4 +- src/test/ui/issues/issue-27942.stderr | 8 +-- src/test/ui/issues/issue-37884.stderr | 4 +- src/test/ui/issues/issue-52213.stderr | 4 +- src/test/ui/issues/issue-52533-1.stderr | 4 +- src/test/ui/issues/issue-52533.stderr | 4 +- src/test/ui/issues/issue-55796.stderr | 4 +- src/test/ui/issues/issue-65230.stderr | 2 +- src/test/ui/issues/issue-75777.stderr | 2 +- src/test/ui/lifetimes/issue-79187-2.stderr | 4 +- .../lifetime-bound-will-change-warning.stderr | 4 +- src/test/ui/lub-if.stderr | 4 +- src/test/ui/lub-match.stderr | 4 +- .../ui/match/match-ref-mut-invariance.stderr | 4 +- .../match/match-ref-mut-let-invariance.stderr | 4 +- .../closure-arg-type-mismatch.stderr | 4 +- src/test/ui/nll/issue-50716.stderr | 2 +- src/test/ui/nll/issue-52742.stderr | 4 +- src/test/ui/nll/issue-55394.stderr | 4 +- src/test/ui/nll/issue-55401.stderr | 2 +- .../ui/nll/normalization-bounds-error.stderr | 4 +- .../ui/nll/trait-associated-constant.stderr | 4 +- .../ui/nll/type-alias-free-regions.stderr | 8 +-- .../constant-in-expr-normalize.stderr | 2 +- .../constant-in-expr-trait-item-1.stderr | 2 +- .../constant-in-expr-trait-item-2.stderr | 2 +- .../constant-in-expr-trait-item-3.stderr | 2 +- .../object-lifetime-default-elision.stderr | 8 +-- ...ifetime-default-from-rptr-box-error.stderr | 2 +- ...time-default-from-rptr-struct-error.stderr | 2 +- .../object-lifetime-default-mybox.stderr | 2 +- src/test/ui/regions/issue-28848.stderr | 4 +- .../ui/regions/issue-78262.default.stderr | 2 +- ...unds-on-objects-and-type-parameters.stderr | 4 +- ...on-invariant-static-error-reporting.stderr | 2 +- .../regions/region-object-lifetime-2.stderr | 4 +- .../regions/region-object-lifetime-4.stderr | 4 +- .../region-object-lifetime-in-coercion.stderr | 4 +- .../regions/regions-addr-of-upvar-self.stderr | 2 +- ...pertrait-outlives-container.migrate.stderr | 4 +- ...-type-region-bound-in-trait-not-met.stderr | 2 +- src/test/ui/regions/regions-bounds.stderr | 8 +-- ...-close-over-type-parameter-multiple.stderr | 4 +- .../ui/regions/regions-creating-enums4.stderr | 4 +- .../regions-early-bound-error-method.stderr | 4 +- .../regions/regions-early-bound-error.stderr | 4 +- ...gions-free-region-ordering-callee-4.stderr | 4 +- ...free-region-ordering-caller.migrate.stderr | 12 ++-- ...ions-free-region-ordering-incorrect.stderr | 4 +- ...egions-infer-invariance-due-to-decl.stderr | 2 +- ...nfer-invariance-due-to-mutability-3.stderr | 2 +- ...nfer-invariance-due-to-mutability-4.stderr | 2 +- .../ui/regions/regions-infer-not-param.stderr | 12 ++-- .../regions-infer-paramd-indirect.stderr | 4 +- src/test/ui/regions/regions-nested-fns.stderr | 8 +-- ...ions-normalize-in-where-clause-list.stderr | 8 +-- ...s-projection-container-hrtb.migrate.stderr | 8 +-- ...ves-projection-container-wc.migrate.stderr | 4 +- ...gions-outlives-projection-container.stderr | 16 ++--- .../ui/regions/regions-ret-borrowed-1.stderr | 4 +- .../ui/regions/regions-ret-borrowed.stderr | 4 +- .../regions-static-bound.migrate.stderr | 2 +- .../regions-trait-object-subtyping.stderr | 12 ++-- ...ns-variance-invariant-use-covariant.stderr | 2 +- .../ui/regions/regions-wf-trait-object.stderr | 4 +- ...ns-outlives-nominal-type-region-rev.stderr | 4 +- ...egions-outlives-nominal-type-region.stderr | 4 +- ...ions-outlives-nominal-type-type-rev.stderr | 4 +- .../regions-outlives-nominal-type-type.stderr | 4 +- .../regions-struct-not-wf.stderr | 4 +- src/test/ui/static/static-lifetime.stderr | 2 +- ...issing-lifetimes-in-signature-2.nll.stderr | 2 +- .../missing-lifetimes-in-signature-2.stderr | 2 +- ...trait-has-wrong-lifetime-parameters.stderr | 4 +- src/test/ui/traits/matching-lifetimes.stderr | 8 +-- .../type-checking-test-3.stderr | 4 +- .../type-checking-test-4.stderr | 4 +- .../bounds-are-checked.stderr | 2 +- .../ui/ufcs/ufcs-explicit-self-bad.stderr | 16 ++--- ...-argument-types-two-region-pointers.stderr | 4 +- .../variance-associated-types2.stderr | 2 +- .../variance-btree-invariant-types.stderr | 32 ++++----- .../variance-contravariant-arg-object.stderr | 8 +-- ...iance-contravariant-arg-trait-match.stderr | 8 +-- ...ance-contravariant-self-trait-match.stderr | 8 +-- .../variance-covariant-arg-object.stderr | 8 +-- .../variance-covariant-arg-trait-match.stderr | 8 +-- ...variance-covariant-self-trait-match.stderr | 8 +-- .../variance-invariant-arg-object.stderr | 8 +-- .../variance-invariant-arg-trait-match.stderr | 8 +-- ...variance-invariant-self-trait-match.stderr | 8 +-- ...variance-use-contravariant-struct-1.stderr | 4 +- .../variance-use-covariant-struct-1.stderr | 4 +- .../variance-use-invariant-struct-1.stderr | 8 +-- .../wf-in-foreign-fn-decls-issue-80468.stderr | 2 +- src/test/ui/wf/wf-static-method.stderr | 24 +++---- 125 files changed, 329 insertions(+), 376 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 056709cd314d1..f94a86af04b67 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -135,7 +135,8 @@ fn msg_span_from_free_region( ) -> (String, Option) { match *region { ty::ReEarlyBound(_) | ty::ReFree(_) => { - msg_span_from_early_bound_and_free_regions(tcx, region) + let (msg, span) = msg_span_from_early_bound_and_free_regions(tcx, region); + (msg, Some(span)) } ty::ReStatic => ("the static lifetime".to_owned(), alt_span), ty::ReEmpty(ty::UniverseIndex::ROOT) => ("an empty lifetime".to_owned(), alt_span), @@ -147,20 +148,12 @@ fn msg_span_from_free_region( fn msg_span_from_early_bound_and_free_regions( tcx: TyCtxt<'tcx>, region: ty::Region<'tcx>, -) -> (String, Option) { +) -> (String, Span) { let sm = tcx.sess.source_map(); let scope = region.free_region_binding_scope(tcx); let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local()); - let tag = match tcx.hir().find(node) { - Some(Node::Block(_) | Node::Expr(_)) => "body", - Some(Node::Item(it)) => item_scope_tag(&it), - Some(Node::TraitItem(it)) => trait_item_scope_tag(&it), - Some(Node::ImplItem(it)) => impl_item_scope_tag(&it), - Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it), - _ => unreachable!(), - }; - let (prefix, span) = match *region { + match *region { ty::ReEarlyBound(ref br) => { let mut sp = sm.guess_head_span(tcx.hir().span(node)); if let Some(param) = @@ -168,7 +161,7 @@ fn msg_span_from_early_bound_and_free_regions( { sp = param.span; } - (format!("the lifetime `{}` as defined on", br.name), sp) + (format!("the lifetime `{}` as defined here", br.name), sp) } ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegionKind::BrNamed(_, name), .. @@ -179,28 +172,26 @@ fn msg_span_from_early_bound_and_free_regions( { sp = param.span; } - (format!("the lifetime `{}` as defined on", name), sp) + (format!("the lifetime `{}` as defined here", name), sp) } ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => { if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) { - ("the anonymous lifetime defined on".to_string(), ty.span) + ("the anonymous lifetime defined here".to_string(), ty.span) } else { ( - format!("the anonymous lifetime #{} defined on", idx + 1), + format!("the anonymous lifetime #{} defined here", idx + 1), tcx.hir().span(node), ) } } _ => ( - format!("the lifetime `{}` as defined on", region), + format!("the lifetime `{}` as defined here", region), sm.guess_head_span(tcx.hir().span(node)), ), }, _ => bug!(), - }; - let (msg, opt_span) = explain_span(tcx, tag, span); - (format!("{} {}", prefix, msg), opt_span) + } } fn emit_msg_span( @@ -219,44 +210,6 @@ fn emit_msg_span( } } -fn item_scope_tag(item: &hir::Item<'_>) -> &'static str { - match item.kind { - hir::ItemKind::Impl { .. } => "impl", - hir::ItemKind::Struct(..) => "struct", - hir::ItemKind::Union(..) => "union", - hir::ItemKind::Enum(..) => "enum", - hir::ItemKind::Trait(..) => "trait", - hir::ItemKind::Fn(..) => "function body", - _ => "item", - } -} - -fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str { - match item.kind { - hir::TraitItemKind::Fn(..) => "method body", - hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item", - } -} - -fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str { - match item.kind { - hir::ImplItemKind::Fn(..) => "method body", - hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(..) => "associated item", - } -} - -fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str { - match item.kind { - hir::ForeignItemKind::Fn(..) => "method body", - hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item", - } -} - -fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option) { - let lo = tcx.sess.source_map().lookup_char_pos(span.lo()); - (format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span)) -} - pub fn unexpected_hidden_region_diagnostic( tcx: TyCtxt<'tcx>, span: Span, diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr index 0cce10b54a4a9..f71fb2ee18aa1 100644 --- a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr +++ b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr @@ -6,7 +6,7 @@ LL | const NAME: &'a str = "unit"; | = note: expected reference `&'static str` found reference `&'a str` -note: the lifetime `'a` as defined on the impl at 6:6... +note: the lifetime `'a` as defined here... --> $DIR/associated-const-impl-wrong-lifetime.rs:6:6 | LL | impl<'a> Foo for &'a () { diff --git a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr index ad39b3601bffb..536fd43ef75e8 100644 --- a/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr +++ b/src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr @@ -24,12 +24,12 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d | = note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)` found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)` -note: the lifetime `'c` as defined on the method body at 27:24... +note: the lifetime `'c` as defined here... --> $DIR/regions-bound-missing-bound-in-impl.rs:27:24 | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { | ^^ -note: ...does not necessarily outlive the lifetime `'c` as defined on the method body at 27:24 +note: ...does not necessarily outlive the lifetime `'c` as defined here --> $DIR/regions-bound-missing-bound-in-impl.rs:27:24 | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { @@ -43,12 +43,12 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d | = note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)` found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)` -note: the lifetime `'c` as defined on the method body at 27:24... +note: the lifetime `'c` as defined here... --> $DIR/regions-bound-missing-bound-in-impl.rs:27:24 | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { | ^^ -note: ...does not necessarily outlive the lifetime `'c` as defined on the method body at 27:24 +note: ...does not necessarily outlive the lifetime `'c` as defined here --> $DIR/regions-bound-missing-bound-in-impl.rs:27:24 | LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { diff --git a/src/test/ui/c-variadic/issue-86053-1.stderr b/src/test/ui/c-variadic/issue-86053-1.stderr index 793068138a9ac..5d119bb8557a4 100644 --- a/src/test/ui/c-variadic/issue-86053-1.stderr +++ b/src/test/ui/c-variadic/issue-86053-1.stderr @@ -84,12 +84,12 @@ error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 10:16 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/issue-86053-1.rs:10:16 | LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 10:21 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/issue-86053-1.rs:10:21 | LL | fn ordering4 < 'a , 'b > ( a : , self , self , self , diff --git a/src/test/ui/c-variadic/issue-86053-2.stderr b/src/test/ui/c-variadic/issue-86053-2.stderr index 4fc5e6315e45b..815b06e770890 100644 --- a/src/test/ui/c-variadic/issue-86053-2.stderr +++ b/src/test/ui/c-variadic/issue-86053-2.stderr @@ -5,7 +5,7 @@ LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} | ^^^^^^^^^^^^^^^^^^ | = note: the pointer is valid for the static lifetime -note: but the referenced data is only valid for the lifetime `'a` as defined on the function body at 8:32 +note: but the referenced data is only valid for the lifetime `'a` as defined here --> $DIR/issue-86053-2.rs:8:32 | LL | unsafe extern "C" fn ordering4<'a, F: H<&'static &'a ()>>(_: (), ...) {} diff --git a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr index 7a4ff77941052..b25a7ab3dc6c7 100644 --- a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr +++ b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr @@ -6,12 +6,12 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); | = note: expected fn pointer `fn(&u32)` found fn pointer `fn(&'x u32)` -note: the anonymous lifetime #1 defined on the body at 16:48... +note: the anonymous lifetime #1 defined here... --> $DIR/expect-fn-supply-fn.rs:16:48 | LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); | ^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 13:36 +note: ...does not necessarily outlive the lifetime `'x` as defined here --> $DIR/expect-fn-supply-fn.rs:13:36 | LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) { @@ -25,12 +25,12 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); | = note: expected fn pointer `fn(&u32)` found fn pointer `fn(&'x u32)` -note: the lifetime `'x` as defined on the function body at 13:36... +note: the lifetime `'x` as defined here... --> $DIR/expect-fn-supply-fn.rs:13:36 | LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 16:48 +note: ...does not necessarily outlive the anonymous lifetime #1 defined here --> $DIR/expect-fn-supply-fn.rs:16:48 | LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); diff --git a/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr b/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr index 07a67a6183462..f584b0c8382d0 100644 --- a/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr +++ b/src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr @@ -6,7 +6,7 @@ LL | closure_expecting_bound(|x: &'x u32| { | = note: expected reference `&u32` found reference `&'x u32` -note: the anonymous lifetime #1 defined on the body at 14:29... +note: the anonymous lifetime #1 defined here... --> $DIR/expect-region-supply-region-2.rs:14:29 | LL | closure_expecting_bound(|x: &'x u32| { @@ -18,7 +18,7 @@ LL | | LL | | f = Some(x); LL | | }); | |_____^ -note: ...does not necessarily outlive the lifetime `'x` as defined on the function body at 9:30 +note: ...does not necessarily outlive the lifetime `'x` as defined here --> $DIR/expect-region-supply-region-2.rs:9:30 | LL | fn expect_bound_supply_named<'x>() { @@ -32,12 +32,12 @@ LL | closure_expecting_bound(|x: &'x u32| { | = note: expected reference `&u32` found reference `&'x u32` -note: the lifetime `'x` as defined on the function body at 9:30... +note: the lifetime `'x` as defined here... --> $DIR/expect-region-supply-region-2.rs:9:30 | LL | fn expect_bound_supply_named<'x>() { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 14:29 +note: ...does not necessarily outlive the anonymous lifetime #1 defined here --> $DIR/expect-region-supply-region-2.rs:14:29 | LL | closure_expecting_bound(|x: &'x u32| { diff --git a/src/test/ui/dropck/reject-specialized-drops-8142.stderr b/src/test/ui/dropck/reject-specialized-drops-8142.stderr index cb4d97a8b2023..8dbde9d417df0 100644 --- a/src/test/ui/dropck/reject-specialized-drops-8142.stderr +++ b/src/test/ui/dropck/reject-specialized-drops-8142.stderr @@ -30,7 +30,7 @@ LL | impl Drop for N<'static> { fn drop(&mut self) { } } | = note: expected struct `N<'n>` found struct `N<'static>` -note: the lifetime `'n` as defined on the struct at 7:10... +note: the lifetime `'n` as defined here... --> $DIR/reject-specialized-drops-8142.rs:7:10 | LL | struct N<'n> { x: &'n i8 } @@ -91,12 +91,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'lw` LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 16:10... +note: first, the lifetime cannot outlive the lifetime `'l1` as defined here... --> $DIR/reject-specialized-drops-8142.rs:16:10 | LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 } | ^^^ -note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 16:15... +note: ...but the lifetime must also be valid for the lifetime `'l2` as defined here... --> $DIR/reject-specialized-drops-8142.rs:16:15 | LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 } diff --git a/src/test/ui/error-codes/E0308-2.stderr b/src/test/ui/error-codes/E0308-2.stderr index 0ac03195fa341..5c1dcb4d4f9b3 100644 --- a/src/test/ui/error-codes/E0308-2.stderr +++ b/src/test/ui/error-codes/E0308-2.stderr @@ -6,7 +6,7 @@ LL | impl Eq for &dyn DynEq {} | = note: expected trait `<&dyn DynEq as PartialEq>` found trait `<&(dyn DynEq + 'static) as PartialEq>` -note: the lifetime `'_` as defined on the impl at 9:13... +note: the lifetime `'_` as defined here... --> $DIR/E0308-2.rs:9:13 | LL | impl Eq for &dyn DynEq {} diff --git a/src/test/ui/error-codes/E0478.stderr b/src/test/ui/error-codes/E0478.stderr index 38736de8d9ac7..ec650085a2b9d 100644 --- a/src/test/ui/error-codes/E0478.stderr +++ b/src/test/ui/error-codes/E0478.stderr @@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied LL | child: Box + 'SnowWhite>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'SnowWhite` as defined on the struct at 3:22 +note: lifetime parameter instantiated with the lifetime `'SnowWhite` as defined here --> $DIR/E0478.rs:3:22 | LL | struct Prince<'kiss, 'SnowWhite> { | ^^^^^^^^^^ -note: but lifetime parameter must outlive the lifetime `'kiss` as defined on the struct at 3:15 +note: but lifetime parameter must outlive the lifetime `'kiss` as defined here --> $DIR/E0478.rs:3:15 | LL | struct Prince<'kiss, 'SnowWhite> { diff --git a/src/test/ui/error-codes/E0490.stderr b/src/test/ui/error-codes/E0490.stderr index 9ba5bc330ea93..96e99bd88a497 100644 --- a/src/test/ui/error-codes/E0490.stderr +++ b/src/test/ui/error-codes/E0490.stderr @@ -4,12 +4,12 @@ error[E0490]: a value of type `&'b ()` is borrowed for too long LL | let x: &'a _ = &y; | ^^ | -note: the type is valid for the lifetime `'a` as defined on the function body at 1:6 +note: the type is valid for the lifetime `'a` as defined here --> $DIR/E0490.rs:1:6 | LL | fn f<'a, 'b>(y: &'b ()) { | ^^ -note: but the borrow lasts for the lifetime `'b` as defined on the function body at 1:10 +note: but the borrow lasts for the lifetime `'b` as defined here --> $DIR/E0490.rs:1:10 | LL | fn f<'a, 'b>(y: &'b ()) { @@ -21,7 +21,7 @@ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to LL | let x: &'a _ = &y; | ^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/E0490.rs:1:10 | LL | fn f<'a, 'b>(y: &'b ()) { @@ -31,7 +31,7 @@ note: ...so that the type `&'b ()` is not borrowed for too long | LL | let x: &'a _ = &y; | ^^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/E0490.rs:1:6 | LL | fn f<'a, 'b>(y: &'b ()) { @@ -48,7 +48,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | let x: &'a _ = &y; | ^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 1:10... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/E0490.rs:1:10 | LL | fn f<'a, 'b>(y: &'b ()) { @@ -60,7 +60,7 @@ LL | let x: &'a _ = &y; | ^^ = note: expected `&'a &()` found `&'a &'b ()` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 1:6... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/E0490.rs:1:6 | LL | fn f<'a, 'b>(y: &'b ()) { diff --git a/src/test/ui/explicit/explicit-self-lifetime-mismatch.stderr b/src/test/ui/explicit/explicit-self-lifetime-mismatch.stderr index 5c976098ae3bc..d5ffa8f1b2fb1 100644 --- a/src/test/ui/explicit/explicit-self-lifetime-mismatch.stderr +++ b/src/test/ui/explicit/explicit-self-lifetime-mismatch.stderr @@ -6,12 +6,12 @@ LL | Foo<'b,'a> | = note: expected struct `Foo<'a, 'b>` found struct `Foo<'b, 'a>` -note: the lifetime `'b` as defined on the impl at 6:9... +note: the lifetime `'b` as defined here... --> $DIR/explicit-self-lifetime-mismatch.rs:6:9 | LL | impl<'a,'b> Foo<'a,'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 6:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/explicit-self-lifetime-mismatch.rs:6:6 | LL | impl<'a,'b> Foo<'a,'b> { @@ -25,12 +25,12 @@ LL | Foo<'b,'a> | = note: expected struct `Foo<'a, 'b>` found struct `Foo<'b, 'a>` -note: the lifetime `'a` as defined on the impl at 6:6... +note: the lifetime `'a` as defined here... --> $DIR/explicit-self-lifetime-mismatch.rs:6:6 | LL | impl<'a,'b> Foo<'a,'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 6:9 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/explicit-self-lifetime-mismatch.rs:6:9 | LL | impl<'a,'b> Foo<'a,'b> { diff --git a/src/test/ui/generator/resume-arg-late-bound.stderr b/src/test/ui/generator/resume-arg-late-bound.stderr index 63411b59280bb..5e60e33584e10 100644 --- a/src/test/ui/generator/resume-arg-late-bound.stderr +++ b/src/test/ui/generator/resume-arg-late-bound.stderr @@ -6,7 +6,7 @@ LL | test(gen); | = note: expected type `for<'a> Generator<&'a mut bool>` found type `Generator<&mut bool>` -note: the required lifetime does not necessarily outlive the anonymous lifetime #1 defined on the body at 11:15 +note: the required lifetime does not necessarily outlive the anonymous lifetime #1 defined here --> $DIR/resume-arg-late-bound.rs:11:15 | LL | let gen = |arg: &mut bool| { @@ -29,7 +29,7 @@ LL | test(gen); | = note: expected type `for<'a> Generator<&'a mut bool>` found type `Generator<&mut bool>` -note: the anonymous lifetime #1 defined on the body at 11:15 doesn't meet the lifetime requirements +note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements --> $DIR/resume-arg-late-bound.rs:11:15 | LL | let gen = |arg: &mut bool| { diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 73415e0faac88..649eadec515d0 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -22,12 +22,12 @@ error[E0478]: lifetime bound not satisfied LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the associated item at 17:12 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/impl_bounds.rs:17:12 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); | ^^ -note: but lifetime parameter must outlive the lifetime `'b` as defined on the associated item at 17:16 +note: but lifetime parameter must outlive the lifetime `'b` as defined here --> $DIR/impl_bounds.rs:17:16 | LL | type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); diff --git a/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr index 8ff6cb569b060..24be83024b458 100644 --- a/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr +++ b/src/test/ui/generic-associated-types/issue-78113-lifetime-mismatch-dyn-trait-box.stderr @@ -9,7 +9,7 @@ note: because this has an unmet lifetime requirement | LL | type T<'a>: A; | ^ introduces a `'static` lifetime requirement -note: the lifetime `'a` as defined on the associated item at 17:12... +note: the lifetime `'a` as defined here... --> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:17:12 | LL | type T<'a> = Box; @@ -36,7 +36,7 @@ note: because this has an unmet lifetime requirement | LL | type T<'a>: C; | ^ introduces a `'static` lifetime requirement -note: the lifetime `'a` as defined on the associated item at 27:12... +note: the lifetime `'a` as defined here... --> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:27:12 | LL | type T<'a> = Box; @@ -58,7 +58,7 @@ note: because this has an unmet lifetime requirement | LL | type T<'a>: E; | ^ introduces a `'static` lifetime requirement -note: the lifetime `'a` as defined on the associated item at 37:12... +note: the lifetime `'a` as defined here... --> $DIR/issue-78113-lifetime-mismatch-dyn-trait-box.rs:37:12 | LL | type T<'a> = (Box, Box); diff --git a/src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.stderr b/src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.stderr index 772d027685d08..4f0a023ee39c3 100644 --- a/src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.stderr +++ b/src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.stderr @@ -12,7 +12,7 @@ error[E0478]: lifetime bound not satisfied LL | f: ::Y<'a>, | ^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 12:10 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/unsatified-item-lifetime-bound.rs:12:10 | LL | struct B<'a, T: for<'r> X = &'r ()>> { @@ -25,7 +25,7 @@ error[E0478]: lifetime bound not satisfied LL | f: ::Y<'a>, | ^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 17:10 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/unsatified-item-lifetime-bound.rs:17:10 | LL | struct C<'a, T: X> { @@ -38,7 +38,7 @@ error[E0478]: lifetime bound not satisfied LL | f: <() as X>::Y<'a>, | ^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 22:10 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/unsatified-item-lifetime-bound.rs:22:10 | LL | struct D<'a> { diff --git a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr index 8237d3718c298..ebb4789345733 100644 --- a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr +++ b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr @@ -4,7 +4,7 @@ error[E0477]: the type `&'b ()` does not fulfill the required lifetime LL | type Item<'a> = &'b (); | ^^^^^^^^^^^^^^^^^^^^^^^ | -note: type must outlive the lifetime `'a` as defined on the associated item at 8:15 as required by this binding +note: type must outlive the lifetime `'a` as defined here as required by this binding --> $DIR/unsatisfied-outlives-bound.rs:8:15 | LL | type Item<'a> = &'b (); diff --git a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr index 8b0e36ab5f6b1..9f200357222ab 100644 --- a/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr +++ b/src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr @@ -10,7 +10,7 @@ LL | | fn(Inv<'y>)) } | = note: expected enum `Option)>` found enum `Option)>` -note: the lifetime `'x` as defined on the function body at 38:20... +note: the lifetime `'x` as defined here... --> $DIR/hr-subtype.rs:38:20 | LL | fn subtype<'x, 'y: 'x, 'z: 'y>() { @@ -19,7 +19,7 @@ LL | fn subtype<'x, 'y: 'x, 'z: 'y>() { LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>), LL | | fn(Inv<'y>)) } | |______________- in this macro invocation -note: ...does not necessarily outlive the lifetime `'y` as defined on the function body at 38:24 +note: ...does not necessarily outlive the lifetime `'y` as defined here --> $DIR/hr-subtype.rs:38:24 | LL | fn subtype<'x, 'y: 'x, 'z: 'y>() { @@ -42,7 +42,7 @@ LL | | fn(Inv<'y>)) } | = note: expected enum `Option)>` found enum `Option)>` -note: the lifetime `'x` as defined on the function body at 44:22... +note: the lifetime `'x` as defined here... --> $DIR/hr-subtype.rs:44:22 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { @@ -51,7 +51,7 @@ LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>), LL | | fn(Inv<'y>)) } | |______________- in this macro invocation -note: ...does not necessarily outlive the lifetime `'y` as defined on the function body at 44:26 +note: ...does not necessarily outlive the lifetime `'y` as defined here --> $DIR/hr-subtype.rs:44:26 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { diff --git a/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr b/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr index fb1127f7f402c..07add3d91a018 100644 --- a/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr +++ b/src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr @@ -10,7 +10,7 @@ LL | | fn(&'y u32)) } | = note: expected enum `Option` found enum `Option` -note: the lifetime `'x` as defined on the function body at 44:22... +note: the lifetime `'x` as defined here... --> $DIR/hr-subtype.rs:44:22 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { @@ -19,7 +19,7 @@ LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { LL | / check! { free_x_vs_free_y: (fn(&'x u32), LL | | fn(&'y u32)) } | |______________- in this macro invocation -note: ...does not necessarily outlive the lifetime `'y` as defined on the function body at 44:26 +note: ...does not necessarily outlive the lifetime `'y` as defined here --> $DIR/hr-subtype.rs:44:26 | LL | fn supertype<'x, 'y: 'x, 'z: 'y>() { diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index 7cea4fb93d929..c8ea98f147f91 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | ^^^^^^^^^^^^^^ | -note: hidden type `&'a mut &'b T` captures the lifetime `'b` as defined on the function body at 28:17 +note: hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here --> $DIR/hidden-lifetimes.rs:28:17 | LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { @@ -16,7 +16,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { | ^^^^^^^^^^^^^^ | -note: hidden type `Rc>` captures the lifetime `'b` as defined on the function body at 45:24 +note: hidden type `Rc>` captures the lifetime `'b` as defined here --> $DIR/hidden-lifetimes.rs:45:24 | LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr index 59105f11805cd..64f89812fffce 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | ^^^^^^^^^ | -note: hidden type `*mut &'a i32` captures the lifetime `'a` as defined on the function body at 13:8 +note: hidden type `*mut &'a i32` captures the lifetime `'a` as defined here --> $DIR/error-handling-2.rs:13:8 | LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr index 0fe9b06355f0b..784e840a7055b 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> | ^^^^^^^^^^^^^^^^^^ | -note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined on the function body at 16:21 +note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here --> $DIR/ordinary-bounds-unrelated.rs:16:21 | LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr index 6de77523db577..4287d00361419 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> | ^^^^^^^^^^^^^^^^^^ | -note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined on the function body at 18:21 +note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here --> $DIR/ordinary-bounds-unsuited.rs:18:21 | LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr index 969ddc57af882..ddf8939d21d8a 100644 --- a/src/test/ui/impl-trait/region-escape-via-bound.stderr +++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> | ^^^^^^^^^^^^^^ | -note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined on the function body at 17:7 +note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here --> $DIR/region-escape-via-bound.rs:17:7 | LL | where 'x: 'y diff --git a/src/test/ui/issues/issue-10291.stderr b/src/test/ui/issues/issue-10291.stderr index ff51aa3acf4d4..a80b0ba5e9151 100644 --- a/src/test/ui/issues/issue-10291.stderr +++ b/src/test/ui/issues/issue-10291.stderr @@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | x | ^ | -note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 2:69... +note: ...the reference is valid for the anonymous lifetime #1 defined here... --> $DIR/issue-10291.rs:2:69 | LL | drop:: FnMut(&'z isize) -> &'z isize>>(Box::new(|z| { @@ -12,7 +12,7 @@ LL | drop:: FnMut(&'z isize) -> &'z isize>>(Box::new(|z| { LL | | x LL | | })); | |_____^ -note: ...but the borrowed content is only valid for the lifetime `'x` as defined on the function body at 1:9 +note: ...but the borrowed content is only valid for the lifetime `'x` as defined here --> $DIR/issue-10291.rs:1:9 | LL | fn test<'x>(x: &'x isize) { diff --git a/src/test/ui/issues/issue-16683.stderr b/src/test/ui/issues/issue-16683.stderr index 35bcf286c440f..d4e18df8de324 100644 --- a/src/test/ui/issues/issue-16683.stderr +++ b/src/test/ui/issues/issue-16683.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.a(); | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 3:10... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/issue-16683.rs:3:10 | LL | fn b(&self) { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | self.a(); | ^^^^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the trait at 1:9... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/issue-16683.rs:1:9 | LL | trait T<'a> { diff --git a/src/test/ui/issues/issue-17740.stderr b/src/test/ui/issues/issue-17740.stderr index 995f5f1fc3de3..d177380415591 100644 --- a/src/test/ui/issues/issue-17740.stderr +++ b/src/test/ui/issues/issue-17740.stderr @@ -6,12 +6,12 @@ LL | fn bar(self: &mut Foo) { | = note: expected struct `Foo<'a>` found struct `Foo<'_>` -note: the anonymous lifetime defined on the method body at 6:23... +note: the anonymous lifetime defined here... --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { | ^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 5:7 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/issue-17740.rs:5:7 | LL | impl <'a> Foo<'a>{ @@ -25,12 +25,12 @@ LL | fn bar(self: &mut Foo) { | = note: expected struct `Foo<'a>` found struct `Foo<'_>` -note: the lifetime `'a` as defined on the impl at 5:7... +note: the lifetime `'a` as defined here... --> $DIR/issue-17740.rs:5:7 | LL | impl <'a> Foo<'a>{ | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 6:23 +note: ...does not necessarily outlive the anonymous lifetime defined here --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { diff --git a/src/test/ui/issues/issue-17758.stderr b/src/test/ui/issues/issue-17758.stderr index 846e8939b53b8..711217033a1f7 100644 --- a/src/test/ui/issues/issue-17758.stderr +++ b/src/test/ui/issues/issue-17758.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.foo(); | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 6:12... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/issue-17758.rs:6:12 | LL | fn bar(&self) { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | self.foo(); | ^^^^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the trait at 4:11... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/issue-17758.rs:4:11 | LL | trait Foo<'a> { diff --git a/src/test/ui/issues/issue-17905-2.stderr b/src/test/ui/issues/issue-17905-2.stderr index 3c27f7058591c..c68265f71f259 100644 --- a/src/test/ui/issues/issue-17905-2.stderr +++ b/src/test/ui/issues/issue-17905-2.stderr @@ -6,12 +6,12 @@ LL | fn say(self: &Pair<&str, isize>) { | = note: expected struct `Pair<&str, _>` found struct `Pair<&str, _>` -note: the anonymous lifetime defined on the method body at 8:24... +note: the anonymous lifetime defined here... --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { | ^^^^ -note: ...does not necessarily outlive the lifetime `'_` as defined on the impl at 5:5 +note: ...does not necessarily outlive the lifetime `'_` as defined here --> $DIR/issue-17905-2.rs:5:5 | LL | &str, @@ -25,12 +25,12 @@ LL | fn say(self: &Pair<&str, isize>) { | = note: expected struct `Pair<&str, _>` found struct `Pair<&str, _>` -note: the lifetime `'_` as defined on the impl at 5:5... +note: the lifetime `'_` as defined here... --> $DIR/issue-17905-2.rs:5:5 | LL | &str, | ^ -note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 8:24 +note: ...does not necessarily outlive the anonymous lifetime defined here --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { diff --git a/src/test/ui/issues/issue-20831-debruijn.stderr b/src/test/ui/issues/issue-20831-debruijn.stderr index 02c80c2940824..57f9575bdbd29 100644 --- a/src/test/ui/issues/issue-20831-debruijn.stderr +++ b/src/test/ui/issues/issue-20831-debruijn.stderr @@ -4,12 +4,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 28:58... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/issue-20831-debruijn.rs:28:58 | LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the impl at 26:6... +note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... --> $DIR/issue-20831-debruijn.rs:26:6 | LL | impl<'a> Publisher<'a> for MyStruct<'a> { diff --git a/src/test/ui/issues/issue-27942.stderr b/src/test/ui/issues/issue-27942.stderr index 80eecb42d1cef..a0126b68fdcd6 100644 --- a/src/test/ui/issues/issue-27942.stderr +++ b/src/test/ui/issues/issue-27942.stderr @@ -6,12 +6,12 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected type `Resources<'_>` found type `Resources<'a>` -note: the anonymous lifetime defined on the method body at 5:15... +note: the anonymous lifetime defined here... --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; | ^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the trait at 3:18 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/issue-27942.rs:3:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { @@ -25,12 +25,12 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected type `Resources<'_>` found type `Resources<'a>` -note: the lifetime `'a` as defined on the trait at 3:18... +note: the lifetime `'a` as defined here... --> $DIR/issue-27942.rs:3:18 | LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 5:15 +note: ...does not necessarily outlive the anonymous lifetime defined here --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; diff --git a/src/test/ui/issues/issue-37884.stderr b/src/test/ui/issues/issue-37884.stderr index d741d42685232..cd84b6ef48471 100644 --- a/src/test/ui/issues/issue-37884.stderr +++ b/src/test/ui/issues/issue-37884.stderr @@ -11,12 +11,12 @@ LL | | } | = note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> Option<_>` found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> Option<_>` -note: the anonymous lifetime #1 defined on the method body at 6:5... +note: the anonymous lifetime #1 defined here... --> $DIR/issue-37884.rs:6:5 | LL | fn next(&'a mut self) -> Option | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 3:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/issue-37884.rs:3:6 | LL | impl<'a, T: 'a> Iterator for RepeatMut<'a, T> { diff --git a/src/test/ui/issues/issue-52213.stderr b/src/test/ui/issues/issue-52213.stderr index 7463af9332a76..aef5e258a1b06 100644 --- a/src/test/ui/issues/issue-52213.stderr +++ b/src/test/ui/issues/issue-52213.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | match (&t,) { | ^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 1:23... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/issue-52213.rs:1:23 | LL | fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T { @@ -16,7 +16,7 @@ LL | match (&t,) { | ^^^^^ = note: expected `(&&(T,),)` found `(&&'a (T,),)` -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 1:27... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/issue-52213.rs:1:27 | LL | fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T { diff --git a/src/test/ui/issues/issue-52533-1.stderr b/src/test/ui/issues/issue-52533-1.stderr index 4247d551565c8..475c7d0b48bfb 100644 --- a/src/test/ui/issues/issue-52533-1.stderr +++ b/src/test/ui/issues/issue-52533-1.stderr @@ -6,12 +6,12 @@ LL | gimme(|x, y| y) | = note: expected reference `&Foo<'_, '_, u32>` found reference `&Foo<'_, '_, u32>` -note: the anonymous lifetime #3 defined on the body at 9:11... +note: the anonymous lifetime #3 defined here... --> $DIR/issue-52533-1.rs:9:11 | LL | gimme(|x, y| y) | ^^^^^^^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 9:11 +note: ...does not necessarily outlive the anonymous lifetime #2 defined here --> $DIR/issue-52533-1.rs:9:11 | LL | gimme(|x, y| y) diff --git a/src/test/ui/issues/issue-52533.stderr b/src/test/ui/issues/issue-52533.stderr index 4e41620eecfdd..ccedbcfec7a28 100644 --- a/src/test/ui/issues/issue-52533.stderr +++ b/src/test/ui/issues/issue-52533.stderr @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | foo(|a, b| b) | ^ | -note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 5:9... +note: ...the reference is valid for the anonymous lifetime #1 defined here... --> $DIR/issue-52533.rs:5:9 | LL | foo(|a, b| b) | ^^^^^^^^ -note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the body at 5:9 +note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined here --> $DIR/issue-52533.rs:5:9 | LL | foo(|a, b| b) diff --git a/src/test/ui/issues/issue-55796.stderr b/src/test/ui/issues/issue-55796.stderr index 952159ffc3bfe..304339657f0a9 100644 --- a/src/test/ui/issues/issue-55796.stderr +++ b/src/test/ui/issues/issue-55796.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | Box::new(self.out_edges(u).map(|e| e.target())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the trait at 7:17... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/issue-55796.rs:7:17 | LL | pub trait Graph<'a> { @@ -29,7 +29,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | Box::new(self.in_edges(u).map(|e| e.target())) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the trait at 7:17... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/issue-55796.rs:7:17 | LL | pub trait Graph<'a> { diff --git a/src/test/ui/issues/issue-65230.stderr b/src/test/ui/issues/issue-65230.stderr index d75428f3d531d..bfeb38d6471e4 100644 --- a/src/test/ui/issues/issue-65230.stderr +++ b/src/test/ui/issues/issue-65230.stderr @@ -6,7 +6,7 @@ LL | impl T1 for &dyn T2 {} | = note: expected trait `<&dyn T2 as T0>` found trait `<&(dyn T2 + 'static) as T0>` -note: the lifetime `'_` as defined on the impl at 8:13... +note: the lifetime `'_` as defined here... --> $DIR/issue-65230.rs:8:13 | LL | impl T1 for &dyn T2 {} diff --git a/src/test/ui/issues/issue-75777.stderr b/src/test/ui/issues/issue-75777.stderr index 25562f6347e67..bf271ab78f7ee 100644 --- a/src/test/ui/issues/issue-75777.stderr +++ b/src/test/ui/issues/issue-75777.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | Box::new(move |_| fut) | ^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 11:11... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/issue-75777.rs:11:11 | LL | fn inject<'a, Env: 'a, A: 'a + Send>(v: A) -> Box BoxFuture<'a, A>> { diff --git a/src/test/ui/lifetimes/issue-79187-2.stderr b/src/test/ui/lifetimes/issue-79187-2.stderr index a156c74fb3304..2aca8faff9f2c 100644 --- a/src/test/ui/lifetimes/issue-79187-2.stderr +++ b/src/test/ui/lifetimes/issue-79187-2.stderr @@ -25,7 +25,7 @@ LL | take_foo(|a: &i32| a); | = note: expected reference `&i32` found reference `&i32` -note: the anonymous lifetime #1 defined on the body at 9:14 doesn't meet the lifetime requirements +note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements --> $DIR/issue-79187-2.rs:9:14 | LL | take_foo(|a: &i32| a); @@ -44,7 +44,7 @@ LL | take_foo(|a: &i32| -> &i32 { a }); | = note: expected reference `&i32` found reference `&i32` -note: the anonymous lifetime #1 defined on the body at 10:14 doesn't meet the lifetime requirements +note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements --> $DIR/issue-79187-2.rs:10:14 | LL | take_foo(|a: &i32| -> &i32 { a }); diff --git a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.stderr b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.stderr index 91cdc0205d841..bb691fc072b5a 100644 --- a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.stderr +++ b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.stderr @@ -6,7 +6,7 @@ LL | ref_obj(x) | = note: expected reference `&Box<(dyn Fn() + 'static)>` found reference `&Box<(dyn Fn() + 'a)>` -note: the lifetime `'a` as defined on the function body at 32:10... +note: the lifetime `'a` as defined here... --> $DIR/lifetime-bound-will-change-warning.rs:32:10 | LL | fn test2<'a>(x: &'a Box) { @@ -21,7 +21,7 @@ LL | lib::ref_obj(x) | = note: expected reference `&Box<(dyn Fn() + 'static)>` found reference `&Box<(dyn Fn() + 'a)>` -note: the lifetime `'a` as defined on the function body at 37:12... +note: the lifetime `'a` as defined here... --> $DIR/lifetime-bound-will-change-warning.rs:37:12 | LL | fn test2cc<'a>(x: &'a Box) { diff --git a/src/test/ui/lub-if.stderr b/src/test/ui/lub-if.stderr index 0a4744013a62c..a12c48582c79e 100644 --- a/src/test/ui/lub-if.stderr +++ b/src/test/ui/lub-if.stderr @@ -5,7 +5,7 @@ LL | s | ^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 23:17 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/lub-if.rs:23:17 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { @@ -18,7 +18,7 @@ LL | s | ^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 32:17 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/lub-if.rs:32:17 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { diff --git a/src/test/ui/lub-match.stderr b/src/test/ui/lub-match.stderr index 168a389446921..04d50f5ebf471 100644 --- a/src/test/ui/lub-match.stderr +++ b/src/test/ui/lub-match.stderr @@ -5,7 +5,7 @@ LL | s | ^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 25:17 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/lub-match.rs:25:17 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { @@ -18,7 +18,7 @@ LL | s | ^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 35:17 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/lub-match.rs:35:17 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { diff --git a/src/test/ui/match/match-ref-mut-invariance.stderr b/src/test/ui/match/match-ref-mut-invariance.stderr index 3e9f729dc09f5..f9271cb3d068c 100644 --- a/src/test/ui/match/match-ref-mut-invariance.stderr +++ b/src/test/ui/match/match-ref-mut-invariance.stderr @@ -6,12 +6,12 @@ LL | match self.0 { ref mut x => x } | = note: expected mutable reference `&'a mut &'a i32` found mutable reference `&'a mut &'b i32` -note: the lifetime `'a` as defined on the method body at 9:12... +note: the lifetime `'a` as defined here... --> $DIR/match-ref-mut-invariance.rs:9:12 | LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 8:6 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/match-ref-mut-invariance.rs:8:6 | LL | impl<'b> S<'b> { diff --git a/src/test/ui/match/match-ref-mut-let-invariance.stderr b/src/test/ui/match/match-ref-mut-let-invariance.stderr index 303aba3422cec..c021a5a91f5c0 100644 --- a/src/test/ui/match/match-ref-mut-let-invariance.stderr +++ b/src/test/ui/match/match-ref-mut-let-invariance.stderr @@ -6,12 +6,12 @@ LL | x | = note: expected mutable reference `&'a mut &'a i32` found mutable reference `&'a mut &'b i32` -note: the lifetime `'a` as defined on the method body at 9:12... +note: the lifetime `'a` as defined here... --> $DIR/match-ref-mut-let-invariance.rs:9:12 | LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 8:6 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/match-ref-mut-let-invariance.rs:8:6 | LL | impl<'b> S<'b> { diff --git a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr index 521de3742b03f..0ec282dac45e2 100644 --- a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr +++ b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr @@ -30,7 +30,7 @@ LL | baz(f); | = note: expected type `for<'r> Fn<(*mut &'r u32,)>` found type `Fn<(*mut &'a u32,)>` -note: the required lifetime does not necessarily outlive the lifetime `'a` as defined on the function body at 9:10 +note: the required lifetime does not necessarily outlive the lifetime `'a` as defined here --> $DIR/closure-arg-type-mismatch.rs:9:10 | LL | fn _test<'a>(f: fn(*mut &'a u32)) { @@ -58,7 +58,7 @@ LL | baz(f); | = note: expected type `for<'r> Fn<(*mut &'r u32,)>` found type `Fn<(*mut &'a u32,)>` -note: the lifetime `'a` as defined on the function body at 9:10 doesn't meet the lifetime requirements +note: the lifetime `'a` as defined here doesn't meet the lifetime requirements --> $DIR/closure-arg-type-mismatch.rs:9:10 | LL | fn _test<'a>(f: fn(*mut &'a u32)) { diff --git a/src/test/ui/nll/issue-50716.stderr b/src/test/ui/nll/issue-50716.stderr index 4e69dda8721d6..be68d252f32f0 100644 --- a/src/test/ui/nll/issue-50716.stderr +++ b/src/test/ui/nll/issue-50716.stderr @@ -6,7 +6,7 @@ LL | let _x = *s; | = note: expected type `<<&'a T as A>::X as Sized>` found type `<<&'static T as A>::X as Sized>` -note: the lifetime `'a` as defined on the function body at 9:8... +note: the lifetime `'a` as defined here... --> $DIR/issue-50716.rs:9:8 | LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) diff --git a/src/test/ui/nll/issue-52742.stderr b/src/test/ui/nll/issue-52742.stderr index 23bb12f942075..3f8481219a9ad 100644 --- a/src/test/ui/nll/issue-52742.stderr +++ b/src/test/ui/nll/issue-52742.stderr @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | self.y = b.z | ^^^ | -note: ...the reference is valid for the lifetime `'_` as defined on the impl at 12:10... +note: ...the reference is valid for the lifetime `'_` as defined here... --> $DIR/issue-52742.rs:12:10 | LL | impl Foo<'_, '_> { | ^^ -note: ...but the borrowed content is only valid for the anonymous lifetime defined on the method body at 13:31 +note: ...but the borrowed content is only valid for the anonymous lifetime defined here --> $DIR/issue-52742.rs:13:31 | LL | fn take_bar(&mut self, b: Bar<'_>) { diff --git a/src/test/ui/nll/issue-55394.stderr b/src/test/ui/nll/issue-55394.stderr index dbc478e5b4c87..197f8dfa2abe7 100644 --- a/src/test/ui/nll/issue-55394.stderr +++ b/src/test/ui/nll/issue-55394.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` d LL | Foo { bar } | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 8:17... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/issue-55394.rs:8:17 | LL | fn new(bar: &mut Bar) -> Self { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | Foo { bar } | ^^^ -note: but, the lifetime must be valid for the lifetime `'_` as defined on the impl at 7:10... +note: but, the lifetime must be valid for the lifetime `'_` as defined here... --> $DIR/issue-55394.rs:7:10 | LL | impl Foo<'_> { diff --git a/src/test/ui/nll/issue-55401.stderr b/src/test/ui/nll/issue-55401.stderr index 2dc7236cbc274..55c51d532e779 100644 --- a/src/test/ui/nll/issue-55401.stderr +++ b/src/test/ui/nll/issue-55401.stderr @@ -5,7 +5,7 @@ LL | *y | ^^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 1:47 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/issue-55401.rs:1:47 | LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 { diff --git a/src/test/ui/nll/normalization-bounds-error.stderr b/src/test/ui/nll/normalization-bounds-error.stderr index 8c7c8918f3fc6..6da3d5d96925d 100644 --- a/src/test/ui/nll/normalization-bounds-error.stderr +++ b/src/test/ui/nll/normalization-bounds-error.stderr @@ -4,12 +4,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'d` d LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'d` as defined on the function body at 12:14... +note: first, the lifetime cannot outlive the lifetime `'d` as defined here... --> $DIR/normalization-bounds-error.rs:12:14 | LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} | ^^ -note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the function body at 12:18... +note: ...but the lifetime must also be valid for the lifetime `'a` as defined here... --> $DIR/normalization-bounds-error.rs:12:18 | LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {} diff --git a/src/test/ui/nll/trait-associated-constant.stderr b/src/test/ui/nll/trait-associated-constant.stderr index 2af5b2a2e0095..000ebc716572a 100644 --- a/src/test/ui/nll/trait-associated-constant.stderr +++ b/src/test/ui/nll/trait-associated-constant.stderr @@ -6,12 +6,12 @@ LL | const AC: Option<&'c str> = None; | = note: expected enum `Option<&'b str>` found enum `Option<&'c str>` -note: the lifetime `'c` as defined on the impl at 20:18... +note: the lifetime `'c` as defined here... --> $DIR/trait-associated-constant.rs:20:18 | LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 20:14 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/trait-associated-constant.rs:20:14 | LL | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct { diff --git a/src/test/ui/nll/type-alias-free-regions.stderr b/src/test/ui/nll/type-alias-free-regions.stderr index dbb63b71af8a2..71f5f8fb17668 100644 --- a/src/test/ui/nll/type-alias-free-regions.stderr +++ b/src/test/ui/nll/type-alias-free-regions.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | C { f: b } | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 16:24... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/type-alias-free-regions.rs:16:24 | LL | fn from_box(b: Box) -> Self { @@ -16,7 +16,7 @@ LL | C { f: b } | ^ = note: expected `Box>` found `Box>` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 15:6... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/type-alias-free-regions.rs:15:6 | LL | impl<'a> FromBox<'a> for C<'a> { @@ -35,7 +35,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | C { f: Box::new(b.0) } | ^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 26:23... +note: first, the lifetime cannot outlive the anonymous lifetime defined here... --> $DIR/type-alias-free-regions.rs:26:23 | LL | fn from_tuple(b: (B,)) -> Self { @@ -47,7 +47,7 @@ LL | C { f: Box::new(b.0) } | ^^^ = note: expected `Box<&isize>` found `Box<&isize>` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 25:6... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/type-alias-free-regions.rs:25:6 | LL | impl<'a> FromTuple<'a> for C<'a> { diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr index 4c7adf75d2fd7..d33c458421406 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr @@ -5,7 +5,7 @@ LL | <() as Foo<'a>>::C | ^^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 17:8 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/constant-in-expr-normalize.rs:17:8 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr index d01d022cba796..3ec3a2af8cab3 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr @@ -5,7 +5,7 @@ LL | <() as Foo<'a>>::C | ^^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 9:8 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/constant-in-expr-trait-item-1.rs:9:8 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr index dd294280b903a..b36bc3bdd9cdb 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr @@ -5,7 +5,7 @@ LL | >::C | ^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 9:8 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/constant-in-expr-trait-item-2.rs:9:8 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr index ba0a1748c5e9f..806492b71f449 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | T::C | ^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 9:8... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/constant-in-expr-trait-item-3.rs:9:8 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr b/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr index ee1a461257228..5af4c5bdfaed3 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-elision.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for automatic coercion due to LL | ss | ^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 54:10... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/object-lifetime-default-elision.rs:54:10 | LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | ss | ^^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 54:13... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/object-lifetime-default-elision.rs:54:13 | LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { @@ -33,7 +33,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | ss | ^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 54:10... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/object-lifetime-default-elision.rs:54:10 | LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { @@ -43,7 +43,7 @@ note: ...so that the declared lifetime parameter bounds are satisfied | LL | ss | ^^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 54:13... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/object-lifetime-default-elision.rs:54:13 | LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr index a789c4906ef4f..e7fab9ecefcd1 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-box-error.stderr @@ -6,7 +6,7 @@ LL | ss.t = t; | = note: expected reference `&'a Box<(dyn Test + 'static)>` found reference `&'a Box<(dyn Test + 'a)>` -note: the lifetime `'a` as defined on the function body at 14:6... +note: the lifetime `'a` as defined here... --> $DIR/object-lifetime-default-from-rptr-box-error.rs:14:6 | LL | fn c<'a>(t: &'a Box, mut ss: SomeStruct<'a>) { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr index 65f8a32f06dd2..07c321ed8c344 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-from-rptr-struct-error.stderr @@ -6,7 +6,7 @@ LL | ss.t = t; | = note: expected reference `&'a MyBox<(dyn Test + 'static)>` found reference `&'a MyBox<(dyn Test + 'a)>` -note: the lifetime `'a` as defined on the function body at 20:6... +note: the lifetime `'a` as defined here... --> $DIR/object-lifetime-default-from-rptr-struct-error.rs:20:6 | LL | fn c<'a>(t: &'a MyBox, mut ss: SomeStruct<'a>) { diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr b/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr index 404717ff55e5e..4c5fb452ebe42 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.stderr @@ -18,7 +18,7 @@ LL | load0(ss) | = note: expected reference `&MyBox<(dyn SomeTrait + 'static)>` found reference `&MyBox<(dyn SomeTrait + 'a)>` -note: the lifetime `'a` as defined on the function body at 30:10... +note: the lifetime `'a` as defined here... --> $DIR/object-lifetime-default-mybox.rs:30:10 | LL | fn load2<'a>(ss: &MyBox) -> MyBox { diff --git a/src/test/ui/regions/issue-28848.stderr b/src/test/ui/regions/issue-28848.stderr index 83313b34316b4..afa0c9c76b2c5 100644 --- a/src/test/ui/regions/issue-28848.stderr +++ b/src/test/ui/regions/issue-28848.stderr @@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied LL | Foo::<'a, 'b>::xmute(u) | ^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'b` as defined on the function body at 9:16 +note: lifetime parameter instantiated with the lifetime `'b` as defined here --> $DIR/issue-28848.rs:9:16 | LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () { | ^^ -note: but lifetime parameter must outlive the lifetime `'a` as defined on the function body at 9:12 +note: but lifetime parameter must outlive the lifetime `'a` as defined here --> $DIR/issue-28848.rs:9:12 | LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () { diff --git a/src/test/ui/regions/issue-78262.default.stderr b/src/test/ui/regions/issue-78262.default.stderr index 5250848a65cc3..dcb67e6a65492 100644 --- a/src/test/ui/regions/issue-78262.default.stderr +++ b/src/test/ui/regions/issue-78262.default.stderr @@ -6,7 +6,7 @@ LL | let f = |x: &dyn TT| x.func(); | = note: expected reference `&(dyn TT + 'static)` found reference `&dyn TT` -note: the anonymous lifetime #1 defined on the body at 14:13... +note: the anonymous lifetime #1 defined here... --> $DIR/issue-78262.rs:14:13 | LL | let f = |x: &dyn TT| x.func(); diff --git a/src/test/ui/regions/region-bounds-on-objects-and-type-parameters.stderr b/src/test/ui/regions/region-bounds-on-objects-and-type-parameters.stderr index 1fff85e766428..2ec2ca49b1142 100644 --- a/src/test/ui/regions/region-bounds-on-objects-and-type-parameters.stderr +++ b/src/test/ui/regions/region-bounds-on-objects-and-type-parameters.stderr @@ -10,12 +10,12 @@ error[E0478]: lifetime bound not satisfied LL | z: Box+'b+'c>, | ^^^^^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'b` as defined on the struct at 11:15 +note: lifetime parameter instantiated with the lifetime `'b` as defined here --> $DIR/region-bounds-on-objects-and-type-parameters.rs:11:15 | LL | struct Foo<'a,'b,'c> { | ^^ -note: but lifetime parameter must outlive the lifetime `'a` as defined on the struct at 11:12 +note: but lifetime parameter must outlive the lifetime `'a` as defined here --> $DIR/region-bounds-on-objects-and-type-parameters.rs:11:12 | LL | struct Foo<'a,'b,'c> { diff --git a/src/test/ui/regions/region-invariant-static-error-reporting.stderr b/src/test/ui/regions/region-invariant-static-error-reporting.stderr index 750cc3566e032..34287070eec77 100644 --- a/src/test/ui/regions/region-invariant-static-error-reporting.stderr +++ b/src/test/ui/regions/region-invariant-static-error-reporting.stderr @@ -13,7 +13,7 @@ LL | | }; | = note: expected struct `Invariant<'a>` found struct `Invariant<'static>` -note: the lifetime `'a` as defined on the function body at 13:10... +note: the lifetime `'a` as defined here... --> $DIR/region-invariant-static-error-reporting.rs:13:10 | LL | fn unify<'a>(x: Option>, f: fn(Invariant<'a>)) { diff --git a/src/test/ui/regions/region-object-lifetime-2.stderr b/src/test/ui/regions/region-object-lifetime-2.stderr index 74ea1b731e9ac..380e27ab0e011 100644 --- a/src/test/ui/regions/region-object-lifetime-2.stderr +++ b/src/test/ui/regions/region-object-lifetime-2.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | x.borrowed() | ^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 9:42... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/region-object-lifetime-2.rs:9:42 | LL | fn borrowed_receiver_different_lifetimes<'a,'b>(x: &'a dyn Foo) -> &'b () { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | x.borrowed() | ^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 9:45... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/region-object-lifetime-2.rs:9:45 | LL | fn borrowed_receiver_different_lifetimes<'a,'b>(x: &'a dyn Foo) -> &'b () { diff --git a/src/test/ui/regions/region-object-lifetime-4.stderr b/src/test/ui/regions/region-object-lifetime-4.stderr index 1053218290588..b59163ef13b31 100644 --- a/src/test/ui/regions/region-object-lifetime-4.stderr +++ b/src/test/ui/regions/region-object-lifetime-4.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | x.borrowed() | ^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 11:41... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/region-object-lifetime-4.rs:11:41 | LL | fn borrowed_receiver_related_lifetimes2<'a,'b>(x: &'a (dyn Foo + 'b)) -> &'b () { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | x.borrowed() | ^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 11:44... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/region-object-lifetime-4.rs:11:44 | LL | fn borrowed_receiver_related_lifetimes2<'a,'b>(x: &'a (dyn Foo + 'b)) -> &'b () { diff --git a/src/test/ui/regions/region-object-lifetime-in-coercion.stderr b/src/test/ui/regions/region-object-lifetime-in-coercion.stderr index 852ca0f21b166..04d22e58a1dc5 100644 --- a/src/test/ui/regions/region-object-lifetime-in-coercion.stderr +++ b/src/test/ui/regions/region-object-lifetime-in-coercion.stderr @@ -52,7 +52,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | Box::new(v) | ^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 22:6... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/region-object-lifetime-in-coercion.rs:22:6 | LL | fn d<'a,'b>(v: &'a [u8]) -> Box { @@ -64,7 +64,7 @@ LL | Box::new(v) | ^ = note: expected `&[u8]` found `&'a [u8]` -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 22:9... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/region-object-lifetime-in-coercion.rs:22:9 | LL | fn d<'a,'b>(v: &'a [u8]) -> Box { diff --git a/src/test/ui/regions/regions-addr-of-upvar-self.stderr b/src/test/ui/regions/regions-addr-of-upvar-self.stderr index 62e9058365f11..f638064ef8378 100644 --- a/src/test/ui/regions/regions-addr-of-upvar-self.stderr +++ b/src/test/ui/regions/regions-addr-of-upvar-self.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to LL | let p: &'static mut usize = &mut self.food; | ^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'_` as defined on the body at 7:18... +note: first, the lifetime cannot outlive the lifetime `'_` as defined here... --> $DIR/regions-addr-of-upvar-self.rs:7:18 | LL | let _f = || { diff --git a/src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.migrate.stderr b/src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.migrate.stderr index c0401780b8f5b..6ae70ec672ce1 100644 --- a/src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.migrate.stderr +++ b/src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.migrate.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a WithAssoc>`, reference has a longer lifet LL | let _: &'a WithAssoc> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 33:15 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:33:15 | LL | fn with_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 33:18 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-assoc-type-in-supertrait-outlives-container.rs:33:18 | LL | fn with_assoc<'a,'b>() { diff --git a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr index 52802848d563c..f4153b2a8166d 100644 --- a/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr +++ b/src/test/ui/regions/regions-assoc-type-region-bound-in-trait-not-met.stderr @@ -16,7 +16,7 @@ error[E0477]: the type `&'a i32` does not fulfill the required lifetime LL | type Value = &'a i32; | ^^^^^^^^^^^^^^^^^^^^^ | -note: type must outlive the lifetime `'b` as defined on the impl at 19:10 as required by this binding +note: type must outlive the lifetime `'b` as defined here as required by this binding --> $DIR/regions-assoc-type-region-bound-in-trait-not-met.rs:19:10 | LL | impl<'a, 'b> Foo<'b> for &'a i64 { diff --git a/src/test/ui/regions/regions-bounds.stderr b/src/test/ui/regions/regions-bounds.stderr index a4eebab38639e..90227e574ad47 100644 --- a/src/test/ui/regions/regions-bounds.stderr +++ b/src/test/ui/regions/regions-bounds.stderr @@ -6,12 +6,12 @@ LL | return e; | = note: expected struct `TupleStruct<'b>` found struct `TupleStruct<'a>` -note: the lifetime `'a` as defined on the function body at 8:10... +note: the lifetime `'a` as defined here... --> $DIR/regions-bounds.rs:8:10 | LL | fn a_fn1<'a,'b>(e: TupleStruct<'a>) -> TupleStruct<'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the function body at 8:13 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/regions-bounds.rs:8:13 | LL | fn a_fn1<'a,'b>(e: TupleStruct<'a>) -> TupleStruct<'b> { @@ -25,12 +25,12 @@ LL | return e; | = note: expected struct `Struct<'b>` found struct `Struct<'a>` -note: the lifetime `'a` as defined on the function body at 12:10... +note: the lifetime `'a` as defined here... --> $DIR/regions-bounds.rs:12:10 | LL | fn a_fn3<'a,'b>(e: Struct<'a>) -> Struct<'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the function body at 12:13 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/regions-bounds.rs:12:13 | LL | fn a_fn3<'a,'b>(e: Struct<'a>) -> Struct<'b> { diff --git a/src/test/ui/regions/regions-close-over-type-parameter-multiple.stderr b/src/test/ui/regions/regions-close-over-type-parameter-multiple.stderr index 0cb0b24f108b0..aa22fd96deb64 100644 --- a/src/test/ui/regions/regions-close-over-type-parameter-multiple.stderr +++ b/src/test/ui/regions/regions-close-over-type-parameter-multiple.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | Box::new(v) as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 18:20... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-close-over-type-parameter-multiple.rs:18:20 | LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box { @@ -14,7 +14,7 @@ note: ...so that the declared lifetime parameter bounds are satisfied | LL | Box::new(v) as Box | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: but, the lifetime must be valid for the lifetime `'c` as defined on the function body at 18:26... +note: but, the lifetime must be valid for the lifetime `'c` as defined here... --> $DIR/regions-close-over-type-parameter-multiple.rs:18:26 | LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box { diff --git a/src/test/ui/regions/regions-creating-enums4.stderr b/src/test/ui/regions/regions-creating-enums4.stderr index 44bd88e01a267..8b1b90f5b1a84 100644 --- a/src/test/ui/regions/regions-creating-enums4.stderr +++ b/src/test/ui/regions/regions-creating-enums4.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | Ast::Add(x, y) | ^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 6:16... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-creating-enums4.rs:6:16 | LL | fn mk_add_bad2<'a,'b>(x: &'a Ast<'a>, y: &'a Ast<'a>, z: &Ast) -> Ast<'b> { @@ -16,7 +16,7 @@ LL | Ast::Add(x, y) | ^ = note: expected `&Ast<'_>` found `&Ast<'a>` -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 6:19... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/regions-creating-enums4.rs:6:19 | LL | fn mk_add_bad2<'a,'b>(x: &'a Ast<'a>, y: &'a Ast<'a>, z: &Ast) -> Ast<'b> { diff --git a/src/test/ui/regions/regions-early-bound-error-method.stderr b/src/test/ui/regions/regions-early-bound-error-method.stderr index 9095451da0522..99a5f0ce4cd80 100644 --- a/src/test/ui/regions/regions-early-bound-error-method.stderr +++ b/src/test/ui/regions/regions-early-bound-error-method.stderr @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | g2.get() | ^^^^^^^^ | -note: ...the reference is valid for the lifetime `'a` as defined on the impl at 18:6... +note: ...the reference is valid for the lifetime `'a` as defined here... --> $DIR/regions-early-bound-error-method.rs:18:6 | LL | impl<'a> Box<'a> { | ^^ -note: ...but the borrowed content is only valid for the lifetime `'b` as defined on the method body at 19:11 +note: ...but the borrowed content is only valid for the lifetime `'b` as defined here --> $DIR/regions-early-bound-error-method.rs:19:11 | LL | fn or<'b,G:GetRef<'b>>(&self, g2: G) -> &'a isize { diff --git a/src/test/ui/regions/regions-early-bound-error.stderr b/src/test/ui/regions/regions-early-bound-error.stderr index 162d573362d45..df9e979eacf0f 100644 --- a/src/test/ui/regions/regions-early-bound-error.stderr +++ b/src/test/ui/regions/regions-early-bound-error.stderr @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | g1.get() | ^^^^^^^^ | -note: ...the reference is valid for the lifetime `'b` as defined on the function body at 18:11... +note: ...the reference is valid for the lifetime `'b` as defined here... --> $DIR/regions-early-bound-error.rs:18:11 | LL | fn get<'a,'b,G:GetRef<'a, isize>>(g1: G, b: &'b isize) -> &'b isize { | ^^ -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 18:8 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/regions-early-bound-error.rs:18:8 | LL | fn get<'a,'b,G:GetRef<'a, isize>>(g1: G, b: &'b isize) -> &'b isize { diff --git a/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr b/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr index 5ab423d9e2077..1df7ca0e3e900 100644 --- a/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr +++ b/src/test/ui/regions/regions-free-region-ordering-callee-4.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the LL | fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { | ^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 5:14 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-free-region-ordering-callee-4.rs:5:14 | LL | fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 5:18 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-free-region-ordering-callee-4.rs:5:18 | LL | fn ordering4<'a, 'b, F>(a: &'a usize, b: &'b usize, x: F) where F: FnOnce(&'a &'b usize) { diff --git a/src/test/ui/regions/regions-free-region-ordering-caller.migrate.stderr b/src/test/ui/regions/regions-free-region-ordering-caller.migrate.stderr index 06e1b0f1ac262..c0f3b24f68cfe 100644 --- a/src/test/ui/regions/regions-free-region-ordering-caller.migrate.stderr +++ b/src/test/ui/regions/regions-free-region-ordering-caller.migrate.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'b &'a usize`, reference has a longer lifetime than the LL | let z: Option<&'b &'a usize> = None; | ^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'b` as defined on the function body at 10:14 +note: the pointer is valid for the lifetime `'b` as defined here --> $DIR/regions-free-region-ordering-caller.rs:10:14 | LL | fn call2<'a, 'b>(a: &'a usize, b: &'b usize) { | ^^ -note: but the referenced data is only valid for the lifetime `'a` as defined on the function body at 10:10 +note: but the referenced data is only valid for the lifetime `'a` as defined here --> $DIR/regions-free-region-ordering-caller.rs:10:10 | LL | fn call2<'a, 'b>(a: &'a usize, b: &'b usize) { @@ -21,12 +21,12 @@ error[E0491]: in type `&'b Paramd<'a>`, reference has a longer lifetime than the LL | let z: Option<&'b Paramd<'a>> = None; | ^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'b` as defined on the function body at 15:14 +note: the pointer is valid for the lifetime `'b` as defined here --> $DIR/regions-free-region-ordering-caller.rs:15:14 | LL | fn call3<'a, 'b>(a: &'a usize, b: &'b usize) { | ^^ -note: but the referenced data is only valid for the lifetime `'a` as defined on the function body at 15:10 +note: but the referenced data is only valid for the lifetime `'a` as defined here --> $DIR/regions-free-region-ordering-caller.rs:15:10 | LL | fn call3<'a, 'b>(a: &'a usize, b: &'b usize) { @@ -38,12 +38,12 @@ error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the LL | let z: Option<&'a &'b usize> = None; | ^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 21:10 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-free-region-ordering-caller.rs:21:10 | LL | fn call4<'a, 'b>(a: &'a usize, b: &'b usize) { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 21:14 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-free-region-ordering-caller.rs:21:14 | LL | fn call4<'a, 'b>(a: &'a usize, b: &'b usize) { diff --git a/src/test/ui/regions/regions-free-region-ordering-incorrect.stderr b/src/test/ui/regions/regions-free-region-ordering-incorrect.stderr index 10644174b9bc4..b0a8f4af3973d 100644 --- a/src/test/ui/regions/regions-free-region-ordering-incorrect.stderr +++ b/src/test/ui/regions/regions-free-region-ordering-incorrect.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to LL | None => &self.val | ^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the method body at 14:12... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-free-region-ordering-incorrect.rs:14:12 | LL | fn get<'a>(&'a self) -> &'b T { @@ -14,7 +14,7 @@ note: ...so that reference does not outlive borrowed content | LL | None => &self.val | ^^^^^^^^^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the impl at 13:6... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/regions-free-region-ordering-incorrect.rs:13:6 | LL | impl<'b, T> Node<'b, T> { diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-decl.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-decl.stderr index 4de380ad03b5b..afd522aa00316 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-decl.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-decl.stderr @@ -6,7 +6,7 @@ LL | b_isize | = note: expected struct `Invariant<'static>` found struct `Invariant<'r>` -note: the lifetime `'r` as defined on the function body at 11:23... +note: the lifetime `'r` as defined here... --> $DIR/regions-infer-invariance-due-to-decl.rs:11:23 | LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.stderr index a98d2f0222e65..bb594f3676e37 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-3.stderr @@ -6,7 +6,7 @@ LL | b_isize | = note: expected struct `Invariant<'static>` found struct `Invariant<'r>` -note: the lifetime `'r` as defined on the function body at 9:23... +note: the lifetime `'r` as defined here... --> $DIR/regions-infer-invariance-due-to-mutability-3.rs:9:23 | LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { diff --git a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.stderr b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.stderr index deb08ff862cc2..04d11b5b7c71c 100644 --- a/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.stderr +++ b/src/test/ui/regions/regions-infer-invariance-due-to-mutability-4.stderr @@ -6,7 +6,7 @@ LL | b_isize | = note: expected struct `Invariant<'static>` found struct `Invariant<'r>` -note: the lifetime `'r` as defined on the function body at 9:23... +note: the lifetime `'r` as defined here... --> $DIR/regions-infer-invariance-due-to-mutability-4.rs:9:23 | LL | fn to_longer_lifetime<'r>(b_isize: Invariant<'r>) -> Invariant<'static> { diff --git a/src/test/ui/regions/regions-infer-not-param.stderr b/src/test/ui/regions/regions-infer-not-param.stderr index a6e2047559cce..a23bdeb834fad 100644 --- a/src/test/ui/regions/regions-infer-not-param.stderr +++ b/src/test/ui/regions/regions-infer-not-param.stderr @@ -6,12 +6,12 @@ LL | fn take_direct<'a,'b>(p: Direct<'a>) -> Direct<'b> { p } | = note: expected struct `Direct<'b>` found struct `Direct<'a>` -note: the lifetime `'a` as defined on the function body at 15:16... +note: the lifetime `'a` as defined here... --> $DIR/regions-infer-not-param.rs:15:16 | LL | fn take_direct<'a,'b>(p: Direct<'a>) -> Direct<'b> { p } | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the function body at 15:19 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/regions-infer-not-param.rs:15:19 | LL | fn take_direct<'a,'b>(p: Direct<'a>) -> Direct<'b> { p } @@ -25,12 +25,12 @@ LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | = note: expected struct `Indirect2<'b>` found struct `Indirect2<'a>` -note: the lifetime `'a` as defined on the function body at 19:19... +note: the lifetime `'a` as defined here... --> $DIR/regions-infer-not-param.rs:19:19 | LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the function body at 19:22 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/regions-infer-not-param.rs:19:22 | LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } @@ -44,12 +44,12 @@ LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | = note: expected struct `Indirect2<'b>` found struct `Indirect2<'a>` -note: the lifetime `'b` as defined on the function body at 19:22... +note: the lifetime `'b` as defined here... --> $DIR/regions-infer-not-param.rs:19:22 | LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the function body at 19:19 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/regions-infer-not-param.rs:19:19 | LL | fn take_indirect2<'a,'b>(p: Indirect2<'a>) -> Indirect2<'b> { p } diff --git a/src/test/ui/regions/regions-infer-paramd-indirect.stderr b/src/test/ui/regions/regions-infer-paramd-indirect.stderr index 95eb4d1f75b72..d2b369fb07b9c 100644 --- a/src/test/ui/regions/regions-infer-paramd-indirect.stderr +++ b/src/test/ui/regions/regions-infer-paramd-indirect.stderr @@ -6,12 +6,12 @@ LL | self.f = b; | = note: expected struct `Box>` found struct `Box>` -note: the anonymous lifetime defined on the method body at 21:36... +note: the anonymous lifetime defined here... --> $DIR/regions-infer-paramd-indirect.rs:21:36 | LL | fn set_f_bad(&mut self, b: Box) { | ^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 16:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/regions-infer-paramd-indirect.rs:16:6 | LL | impl<'a> SetF<'a> for C<'a> { diff --git a/src/test/ui/regions/regions-nested-fns.stderr b/src/test/ui/regions/regions-nested-fns.stderr index eeec0cc786267..11affcaaa79ca 100644 --- a/src/test/ui/regions/regions-nested-fns.stderr +++ b/src/test/ui/regions/regions-nested-fns.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | let mut ay = &y; | ^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 7:58... +note: first, the lifetime cannot outlive the anonymous lifetime #1 defined here... --> $DIR/regions-nested-fns.rs:7:58 | LL | ignore:: FnMut(&'z isize)>>(Box::new(|z| { @@ -19,7 +19,7 @@ note: ...so that reference does not outlive borrowed content | LL | ay = z; | ^ -note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the body at 13:72... +note: but, the lifetime must be valid for the anonymous lifetime #1 defined here... --> $DIR/regions-nested-fns.rs:13:72 | LL | ignore::< Box FnMut(&'z isize) -> &'z isize>>(Box::new(|z| { @@ -48,7 +48,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | if false { return x; } | ^ | -note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 13:72... +note: ...the reference is valid for the anonymous lifetime #1 defined here... --> $DIR/regions-nested-fns.rs:13:72 | LL | ignore::< Box FnMut(&'z isize) -> &'z isize>>(Box::new(|z| { @@ -58,7 +58,7 @@ LL | | if false { return ay; } LL | | return z; LL | | })); | |_____^ -note: ...but the borrowed content is only valid for the lifetime `'x` as defined on the function body at 3:11 +note: ...but the borrowed content is only valid for the lifetime `'x` as defined here --> $DIR/regions-nested-fns.rs:3:11 | LL | fn nested<'x>(x: &'x isize) { diff --git a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr index ddb2b31ce1095..2bb58b5ec2df5 100644 --- a/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr +++ b/src/test/ui/regions/regions-normalize-in-where-clause-list.stderr @@ -8,12 +8,12 @@ LL | | where LL | | <() as Project<'a, 'b>>::Item: Eq, | |______________________________________^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 24:8... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-normalize-in-where-clause-list.rs:24:8 | LL | fn bar<'a, 'b>() | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 24:12... +note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... --> $DIR/regions-normalize-in-where-clause-list.rs:24:12 | LL | fn bar<'a, 'b>() @@ -36,12 +36,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | fn bar<'a, 'b>() | ^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 24:8... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-normalize-in-where-clause-list.rs:24:8 | LL | fn bar<'a, 'b>() | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the function body at 24:12... +note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... --> $DIR/regions-normalize-in-where-clause-list.rs:24:12 | LL | fn bar<'a, 'b>() diff --git a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr index 0992d9bf295c1..60c115b3f5939 100644 --- a/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr +++ b/src/test/ui/regions/regions-outlives-projection-container-hrtb.migrate.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a WithHrAssoc>`, reference has a longer lif LL | let _: &'a WithHrAssoc> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 27:15 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container-hrtb.rs:27:15 | LL | fn with_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 27:18 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container-hrtb.rs:27:18 | LL | fn with_assoc<'a,'b>() { @@ -21,12 +21,12 @@ error[E0491]: in type `&'a WithHrAssocSub>`, reference has a longer LL | let _: &'a WithHrAssocSub> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 46:19 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container-hrtb.rs:46:19 | LL | fn with_assoc_sub<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 46:22 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container-hrtb.rs:46:22 | LL | fn with_assoc_sub<'a,'b>() { diff --git a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr index 49e28a14d8a4e..8430b69f99832 100644 --- a/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr +++ b/src/test/ui/regions/regions-outlives-projection-container-wc.migrate.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a WithAssoc>`, reference has a longer lifet LL | let _: &'a WithAssoc> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 27:15 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container-wc.rs:27:15 | LL | fn with_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 27:18 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container-wc.rs:27:18 | LL | fn with_assoc<'a,'b>() { diff --git a/src/test/ui/regions/regions-outlives-projection-container.stderr b/src/test/ui/regions/regions-outlives-projection-container.stderr index dba15fb0576ee..8c2b2c1e24ae1 100644 --- a/src/test/ui/regions/regions-outlives-projection-container.stderr +++ b/src/test/ui/regions/regions-outlives-projection-container.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a WithAssoc>`, reference has a longer lifet LL | let _x: &'a WithAssoc> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 28:15 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container.rs:28:15 | LL | fn with_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 28:18 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container.rs:28:18 | LL | fn with_assoc<'a,'b>() { @@ -21,12 +21,12 @@ error[E0491]: in type `&'a WithoutAssoc>`, reference has a longer li LL | let _x: &'a WithoutAssoc> = loop { }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 50:18 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container.rs:50:18 | LL | fn without_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 50:21 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container.rs:50:21 | LL | fn without_assoc<'a,'b>() { @@ -38,12 +38,12 @@ error[E0491]: in type `&'a WithAssoc>`, reference has a longer lifet LL | call::<&'a WithAssoc>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 58:20 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container.rs:58:20 | LL | fn call_with_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 58:23 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container.rs:58:23 | LL | fn call_with_assoc<'a,'b>() { @@ -55,12 +55,12 @@ error[E0491]: in type `&'a WithoutAssoc>`, reference has a longer li LL | call::<&'a WithoutAssoc>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the function body at 67:23 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-projection-container.rs:67:23 | LL | fn call_without_assoc<'a,'b>() { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the function body at 67:26 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-projection-container.rs:67:26 | LL | fn call_without_assoc<'a,'b>() { diff --git a/src/test/ui/regions/regions-ret-borrowed-1.stderr b/src/test/ui/regions/regions-ret-borrowed-1.stderr index b5b54bc3c8b73..86df7bfeb7062 100644 --- a/src/test/ui/regions/regions-ret-borrowed-1.stderr +++ b/src/test/ui/regions/regions-ret-borrowed-1.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | with(|o| o) | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 10:10... +note: first, the lifetime cannot outlive the anonymous lifetime #1 defined here... --> $DIR/regions-ret-borrowed-1.rs:10:10 | LL | with(|o| o) @@ -16,7 +16,7 @@ LL | with(|o| o) | ^ = note: expected `&isize` found `&isize` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 9:14... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/regions-ret-borrowed-1.rs:9:14 | LL | fn return_it<'a>() -> &'a isize { diff --git a/src/test/ui/regions/regions-ret-borrowed.stderr b/src/test/ui/regions/regions-ret-borrowed.stderr index debae47d16d0b..b9a06d974334c 100644 --- a/src/test/ui/regions/regions-ret-borrowed.stderr +++ b/src/test/ui/regions/regions-ret-borrowed.stderr @@ -4,7 +4,7 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | with(|o| o) | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 13:10... +note: first, the lifetime cannot outlive the anonymous lifetime #1 defined here... --> $DIR/regions-ret-borrowed.rs:13:10 | LL | with(|o| o) @@ -16,7 +16,7 @@ LL | with(|o| o) | ^ = note: expected `&isize` found `&isize` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 12:14... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/regions-ret-borrowed.rs:12:14 | LL | fn return_it<'a>() -> &'a isize { diff --git a/src/test/ui/regions/regions-static-bound.migrate.stderr b/src/test/ui/regions/regions-static-bound.migrate.stderr index 644458e2063ce..8f11e148220d6 100644 --- a/src/test/ui/regions/regions-static-bound.migrate.stderr +++ b/src/test/ui/regions/regions-static-bound.migrate.stderr @@ -5,7 +5,7 @@ LL | t | ^ | = note: ...the reference is valid for the static lifetime... -note: ...but the borrowed content is only valid for the lifetime `'a` as defined on the function body at 8:24 +note: ...but the borrowed content is only valid for the lifetime `'a` as defined here --> $DIR/regions-static-bound.rs:8:24 | LL | fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { diff --git a/src/test/ui/regions/regions-trait-object-subtyping.stderr b/src/test/ui/regions/regions-trait-object-subtyping.stderr index f16dfdd6e8c77..d45ca94ad27fa 100644 --- a/src/test/ui/regions/regions-trait-object-subtyping.stderr +++ b/src/test/ui/regions/regions-trait-object-subtyping.stderr @@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied LL | x | ^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the function body at 13:9 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/regions-trait-object-subtyping.rs:13:9 | LL | fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy { | ^^ -note: but lifetime parameter must outlive the lifetime `'b` as defined on the function body at 13:12 +note: but lifetime parameter must outlive the lifetime `'b` as defined here --> $DIR/regions-trait-object-subtyping.rs:13:12 | LL | fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy { @@ -21,7 +21,7 @@ error[E0495]: cannot infer an appropriate lifetime for automatic coercion due to LL | x | ^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 13:9... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/regions-trait-object-subtyping.rs:13:9 | LL | fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy { @@ -31,7 +31,7 @@ note: ...so that reference does not outlive borrowed content | LL | x | ^ -note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 13:12... +note: but, the lifetime must be valid for the lifetime `'b` as defined here... --> $DIR/regions-trait-object-subtyping.rs:13:12 | LL | fn foo3<'a,'b>(x: &'a mut dyn Dummy) -> &'b mut dyn Dummy { @@ -52,12 +52,12 @@ LL | x | = note: expected struct `Wrapper<&'b mut (dyn Dummy + 'b)>` found struct `Wrapper<&'a mut (dyn Dummy + 'a)>` -note: the lifetime `'b` as defined on the function body at 20:15... +note: the lifetime `'b` as defined here... --> $DIR/regions-trait-object-subtyping.rs:20:15 | LL | fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dummy> { | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the function body at 20:9 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/regions-trait-object-subtyping.rs:20:9 | LL | fn foo4<'a:'b,'b>(x: Wrapper<&'a mut dyn Dummy>) -> Wrapper<&'b mut dyn Dummy> { diff --git a/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr b/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr index e7a5db671bf6b..7801517595d33 100644 --- a/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr +++ b/src/test/ui/regions/regions-variance-invariant-use-covariant.stderr @@ -6,7 +6,7 @@ LL | let _: Invariant<'static> = c; | = note: expected struct `Invariant<'static>` found struct `Invariant<'b>` -note: the lifetime `'b` as defined on the function body at 11:9... +note: the lifetime `'b` as defined here... --> $DIR/regions-variance-invariant-use-covariant.rs:11:9 | LL | fn use_<'b>(c: Invariant<'b>) { diff --git a/src/test/ui/regions/regions-wf-trait-object.stderr b/src/test/ui/regions/regions-wf-trait-object.stderr index 1ddbf73a46372..f6006ca046a88 100644 --- a/src/test/ui/regions/regions-wf-trait-object.stderr +++ b/src/test/ui/regions/regions-wf-trait-object.stderr @@ -4,12 +4,12 @@ error[E0478]: lifetime bound not satisfied LL | x: Box+'b> | ^^^^^^^^^^^^^^^^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'b` as defined on the struct at 6:15 +note: lifetime parameter instantiated with the lifetime `'b` as defined here --> $DIR/regions-wf-trait-object.rs:6:15 | LL | struct Foo<'a,'b> { | ^^ -note: but lifetime parameter must outlive the lifetime `'a` as defined on the struct at 6:12 +note: but lifetime parameter must outlive the lifetime `'a` as defined here --> $DIR/regions-wf-trait-object.rs:6:12 | LL | struct Foo<'a,'b> { diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region-rev.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region-rev.stderr index 09b51fe056870..5dff4c8fffcaf 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region-rev.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region-rev.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the da LL | type Out = &'a Foo<'b>; | ^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-nominal-type-region-rev.rs:16:10 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the impl at 16:14 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-nominal-type-region-rev.rs:16:14 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region.stderr index 957a9d6dd3c12..975776cddffb4 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-region.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a Foo<'b>`, reference has a longer lifetime than the da LL | type Out = &'a Foo<'b>; | ^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-nominal-type-region.rs:16:10 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the impl at 16:14 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-nominal-type-region.rs:16:14 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type-rev.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type-rev.stderr index 1589f93d90c8e..be05ecec0c9b0 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type-rev.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type-rev.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than t LL | type Out = &'a Foo<&'b i32>; | ^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-nominal-type-type-rev.rs:16:10 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the impl at 16:14 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-nominal-type-type-rev.rs:16:14 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type.stderr index 4bfaa1aac782a..4ba1778d6443f 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-outlives-nominal-type-type.stderr @@ -4,12 +4,12 @@ error[E0491]: in type `&'a Foo<&'b i32>`, reference has a longer lifetime than t LL | type Out = &'a Foo<&'b i32>; | ^^^^^^^^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the impl at 16:10 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-outlives-nominal-type-type.rs:16:10 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the impl at 16:14 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-outlives-nominal-type-type.rs:16:14 | LL | impl<'a, 'b> Trait<'a, 'b> for usize { diff --git a/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr b/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr index 1b1a2f7b043b7..f886126299120 100644 --- a/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr +++ b/src/test/ui/rfc-2093-infer-outlives/regions-struct-not-wf.stderr @@ -26,12 +26,12 @@ error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data LL | type Out = &'a &'b T; | ^^^^^^^^^ | -note: the pointer is valid for the lifetime `'a` as defined on the impl at 24:6 +note: the pointer is valid for the lifetime `'a` as defined here --> $DIR/regions-struct-not-wf.rs:24:6 | LL | impl<'a, 'b, T> Trait1<'a, 'b, T> for u32 { | ^^ -note: but the referenced data is only valid for the lifetime `'b` as defined on the impl at 24:10 +note: but the referenced data is only valid for the lifetime `'b` as defined here --> $DIR/regions-struct-not-wf.rs:24:10 | LL | impl<'a, 'b, T> Trait1<'a, 'b, T> for u32 { diff --git a/src/test/ui/static/static-lifetime.stderr b/src/test/ui/static/static-lifetime.stderr index bda325dc01160..4af3370c79944 100644 --- a/src/test/ui/static/static-lifetime.stderr +++ b/src/test/ui/static/static-lifetime.stderr @@ -4,7 +4,7 @@ error[E0478]: lifetime bound not satisfied LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} | ^^^^^^^^^ | -note: lifetime parameter instantiated with the lifetime `'a` as defined on the impl at 3:6 +note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/static-lifetime.rs:3:6 | LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr index 7e07a5775bb12..536494c73445c 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr @@ -7,7 +7,7 @@ LL | | t.test(); LL | | }); | |______^ | -note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... +note: the parameter type `T` must be valid for the anonymous lifetime defined here... --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr index 4e7d52978400f..0cf0074dc3d25 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr @@ -6,7 +6,7 @@ LL | fn func(foo: &Foo, t: T) { LL | foo.bar(move |_| { | ^^^ | -note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... +note: the parameter type `T` must be valid for the anonymous lifetime defined here... --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { diff --git a/src/test/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr b/src/test/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr index 539a56f010a84..5572c6515ff92 100644 --- a/src/test/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr +++ b/src/test/ui/traits/impl-of-supertrait-has-wrong-lifetime-parameters.stderr @@ -4,12 +4,12 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 24:6... +note: first, the lifetime cannot outlive the lifetime `'a` as defined here... --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6 | LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { | ^^ -note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the impl at 24:9... +note: ...but the lifetime must also be valid for the lifetime `'b` as defined here... --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9 | LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { diff --git a/src/test/ui/traits/matching-lifetimes.stderr b/src/test/ui/traits/matching-lifetimes.stderr index 5c28d40160d0c..de1c878a51311 100644 --- a/src/test/ui/traits/matching-lifetimes.stderr +++ b/src/test/ui/traits/matching-lifetimes.stderr @@ -6,12 +6,12 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected fn pointer `fn(Foo<'a, 'b>)` found fn pointer `fn(Foo<'b, 'a>)` -note: the lifetime `'b` as defined on the impl at 13:9... +note: the lifetime `'b` as defined here... --> $DIR/matching-lifetimes.rs:13:9 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 13:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/matching-lifetimes.rs:13:6 | LL | impl<'a,'b> Tr for Foo<'a,'b> { @@ -25,12 +25,12 @@ LL | fn foo(x: Foo<'b,'a>) { | = note: expected fn pointer `fn(Foo<'a, 'b>)` found fn pointer `fn(Foo<'b, 'a>)` -note: the lifetime `'a` as defined on the impl at 13:6... +note: the lifetime `'a` as defined here... --> $DIR/matching-lifetimes.rs:13:6 | LL | impl<'a,'b> Tr for Foo<'a,'b> { | ^^ -note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 13:9 +note: ...does not necessarily outlive the lifetime `'b` as defined here --> $DIR/matching-lifetimes.rs:13:9 | LL | impl<'a,'b> Tr for Foo<'a,'b> { diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-3.stderr b/src/test/ui/traits/trait-upcasting/type-checking-test-3.stderr index 593ee0a34300a..641e5c97c10fb 100644 --- a/src/test/ui/traits/trait-upcasting/type-checking-test-3.stderr +++ b/src/test/ui/traits/trait-upcasting/type-checking-test-3.stderr @@ -6,7 +6,7 @@ LL | let _ = x as &dyn Bar<'a>; // Error | = note: expected trait object `dyn Bar<'a>` found trait object `dyn Bar<'static>` -note: the lifetime `'a` as defined on the function body at 12:16... +note: the lifetime `'a` as defined here... --> $DIR/type-checking-test-3.rs:12:16 | LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { @@ -21,7 +21,7 @@ LL | let _ = x as &dyn Bar<'static>; // Error | = note: expected trait object `dyn Bar<'static>` found trait object `dyn Bar<'a>` -note: the lifetime `'a` as defined on the function body at 17:16... +note: the lifetime `'a` as defined here... --> $DIR/type-checking-test-3.rs:17:16 | LL | fn test_wrong2<'a>(x: &dyn Foo<'a>) { diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr b/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr index 811e524eda78b..4967f3dc2c8cf 100644 --- a/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr +++ b/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr @@ -6,7 +6,7 @@ LL | let _ = x as &dyn Bar<'static, 'a>; // Error | = note: expected trait object `dyn Bar<'static, 'a>` found trait object `dyn Bar<'static, 'static>` -note: the lifetime `'a` as defined on the function body at 16:16... +note: the lifetime `'a` as defined here... --> $DIR/type-checking-test-4.rs:16:16 | LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { @@ -21,7 +21,7 @@ LL | let _ = x as &dyn Bar<'a, 'static>; // Error | = note: expected trait object `dyn Bar<'a, 'static>` found trait object `dyn Bar<'static, 'static>` -note: the lifetime `'a` as defined on the function body at 21:16... +note: the lifetime `'a` as defined here... --> $DIR/type-checking-test-4.rs:21:16 | LL | fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) { diff --git a/src/test/ui/type-alias-impl-trait/bounds-are-checked.stderr b/src/test/ui/type-alias-impl-trait/bounds-are-checked.stderr index d5fafe05887b9..da9f81d6bd370 100644 --- a/src/test/ui/type-alias-impl-trait/bounds-are-checked.stderr +++ b/src/test/ui/type-alias-impl-trait/bounds-are-checked.stderr @@ -14,7 +14,7 @@ LL | type X<'a> = impl Into<&'static str> + From<&'a str>; | = note: expected trait `From<&'a str>` found trait `From<&'static str>` -note: the lifetime `'a` as defined on the item at 6:8... +note: the lifetime `'a` as defined here... --> $DIR/bounds-are-checked.rs:6:8 | LL | type X<'a> = impl Into<&'static str> + From<&'a str>; diff --git a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr index 133ecab2296b7..f325d1d8182f1 100644 --- a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr +++ b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr @@ -33,12 +33,12 @@ LL | fn dummy2(self: &Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime defined on the method body at 37:21... +note: the anonymous lifetime defined here... --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} | ^^^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/ufcs-explicit-self-bad.rs:35:6 | LL | impl<'a, T> SomeTrait for &'a Bar { @@ -52,12 +52,12 @@ LL | fn dummy2(self: &Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the lifetime `'a` as defined on the impl at 35:6... +note: the lifetime `'a` as defined here... --> $DIR/ufcs-explicit-self-bad.rs:35:6 | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 37:21 +note: ...does not necessarily outlive the anonymous lifetime defined here --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} @@ -71,12 +71,12 @@ LL | fn dummy3(self: &&Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime defined on the method body at 39:22... +note: the anonymous lifetime defined here... --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} | ^^^^^^^ -note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 +note: ...does not necessarily outlive the lifetime `'a` as defined here --> $DIR/ufcs-explicit-self-bad.rs:35:6 | LL | impl<'a, T> SomeTrait for &'a Bar { @@ -90,12 +90,12 @@ LL | fn dummy3(self: &&Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the lifetime `'a` as defined on the impl at 35:6... +note: the lifetime `'a` as defined here... --> $DIR/ufcs-explicit-self-bad.rs:35:6 | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 39:22 +note: ...does not necessarily outlive the anonymous lifetime defined here --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} diff --git a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr index bd20fd26180cb..d7813338f68cb 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr @@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | x.set(y); | ^ | -note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 16:14... +note: ...the reference is valid for the anonymous lifetime #2 defined here... --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14 | LL | doit(0, &|x, y| { @@ -12,7 +12,7 @@ LL | doit(0, &|x, y| { LL | | x.set(y); LL | | }); | |_____^ -note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined on the body at 16:14 +note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined here --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14 | LL | doit(0, &|x, y| { diff --git a/src/test/ui/variance/variance-associated-types2.stderr b/src/test/ui/variance/variance-associated-types2.stderr index 52cdd6493b06d..af4f2a7c2a066 100644 --- a/src/test/ui/variance/variance-associated-types2.stderr +++ b/src/test/ui/variance/variance-associated-types2.stderr @@ -6,7 +6,7 @@ LL | let _: Box> = make(); | = note: expected trait object `dyn Foo` found trait object `dyn Foo` -note: the lifetime `'a` as defined on the function body at 12:9... +note: the lifetime `'a` as defined here... --> $DIR/variance-associated-types2.rs:12:9 | LL | fn take<'a>(_: &'a u32) { diff --git a/src/test/ui/variance/variance-btree-invariant-types.stderr b/src/test/ui/variance/variance-btree-invariant-types.stderr index ba47bdff281a2..df519e25641c3 100644 --- a/src/test/ui/variance/variance-btree-invariant-types.stderr +++ b/src/test/ui/variance/variance-btree-invariant-types.stderr @@ -6,7 +6,7 @@ LL | v | = note: expected struct `std::collections::btree_map::IterMut<'_, &'new (), _>` found struct `std::collections::btree_map::IterMut<'_, &'static (), _>` -note: the lifetime `'new` as defined on the function body at 3:21... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:3:21 | LL | fn iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, &'new (), ()> { @@ -21,7 +21,7 @@ LL | v | = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` found struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` -note: the lifetime `'new` as defined on the function body at 6:21... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:6:21 | LL | fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> { @@ -36,7 +36,7 @@ LL | v | = note: expected struct `std::collections::btree_map::IterMut<'_, &'static (), _>` found struct `std::collections::btree_map::IterMut<'_, &'new (), _>` -note: the lifetime `'new` as defined on the function body at 9:24... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:9:24 | LL | fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> { @@ -51,7 +51,7 @@ LL | v | = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` found struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` -note: the lifetime `'new` as defined on the function body at 12:24... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:12:24 | LL | fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> { @@ -66,7 +66,7 @@ LL | v | = note: expected struct `RangeMut<'_, &'new (), _>` found struct `RangeMut<'_, &'static (), _>` -note: the lifetime `'new` as defined on the function body at 16:22... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:16:22 | LL | fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a, &'new (), ()> { @@ -81,7 +81,7 @@ LL | v | = note: expected struct `RangeMut<'_, _, &'new ()>` found struct `RangeMut<'_, _, &'static ()>` -note: the lifetime `'new` as defined on the function body at 19:22... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:19:22 | LL | fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a, (), &'new ()> { @@ -96,7 +96,7 @@ LL | v | = note: expected struct `RangeMut<'_, &'static (), _>` found struct `RangeMut<'_, &'new (), _>` -note: the lifetime `'new` as defined on the function body at 22:25... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:22:25 | LL | fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a, &'static (), ()> { @@ -111,7 +111,7 @@ LL | v | = note: expected struct `RangeMut<'_, _, &'static ()>` found struct `RangeMut<'_, _, &'new ()>` -note: the lifetime `'new` as defined on the function body at 25:25... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:25:25 | LL | fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a, (), &'static ()> { @@ -126,7 +126,7 @@ LL | v | = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, &'new (), _>` found struct `std::collections::btree_map::OccupiedEntry<'_, &'static (), _>` -note: the lifetime `'new` as defined on the function body at 29:20... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:29:20 | LL | fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>) @@ -141,7 +141,7 @@ LL | v | = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, _, &'new ()>` found struct `std::collections::btree_map::OccupiedEntry<'_, _, &'static ()>` -note: the lifetime `'new` as defined on the function body at 33:20... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:33:20 | LL | fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>) @@ -156,7 +156,7 @@ LL | v | = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, &'static (), _>` found struct `std::collections::btree_map::OccupiedEntry<'_, &'new (), _>` -note: the lifetime `'new` as defined on the function body at 37:23... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:37:23 | LL | fn occ_contra_key<'a, 'new>(v: OccupiedEntry<'a, &'new (), ()>) @@ -171,7 +171,7 @@ LL | v | = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, _, &'static ()>` found struct `std::collections::btree_map::OccupiedEntry<'_, _, &'new ()>` -note: the lifetime `'new` as defined on the function body at 41:23... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:41:23 | LL | fn occ_contra_val<'a, 'new>(v: OccupiedEntry<'a, (), &'new ()>) @@ -186,7 +186,7 @@ LL | v | = note: expected struct `std::collections::btree_map::VacantEntry<'_, &'new (), _>` found struct `std::collections::btree_map::VacantEntry<'_, &'static (), _>` -note: the lifetime `'new` as defined on the function body at 46:20... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:46:20 | LL | fn vac_cov_key<'a, 'new>(v: VacantEntry<'a, &'static (), ()>) @@ -201,7 +201,7 @@ LL | v | = note: expected struct `std::collections::btree_map::VacantEntry<'_, _, &'new ()>` found struct `std::collections::btree_map::VacantEntry<'_, _, &'static ()>` -note: the lifetime `'new` as defined on the function body at 50:20... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:50:20 | LL | fn vac_cov_val<'a, 'new>(v: VacantEntry<'a, (), &'static ()>) @@ -216,7 +216,7 @@ LL | v | = note: expected struct `std::collections::btree_map::VacantEntry<'_, &'static (), _>` found struct `std::collections::btree_map::VacantEntry<'_, &'new (), _>` -note: the lifetime `'new` as defined on the function body at 54:23... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:54:23 | LL | fn vac_contra_key<'a, 'new>(v: VacantEntry<'a, &'new (), ()>) @@ -231,7 +231,7 @@ LL | v | = note: expected struct `std::collections::btree_map::VacantEntry<'_, _, &'static ()>` found struct `std::collections::btree_map::VacantEntry<'_, _, &'new ()>` -note: the lifetime `'new` as defined on the function body at 58:23... +note: the lifetime `'new` as defined here... --> $DIR/variance-btree-invariant-types.rs:58:23 | LL | fn vac_contra_val<'a, 'new>(v: VacantEntry<'a, (), &'new ()>) diff --git a/src/test/ui/variance/variance-contravariant-arg-object.stderr b/src/test/ui/variance/variance-contravariant-arg-object.stderr index a512a60aa42d9..16583fa793109 100644 --- a/src/test/ui/variance/variance-contravariant-arg-object.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-object.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-arg-object.rs:10:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-arg-object.rs:10:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) @@ -25,12 +25,12 @@ LL | v | = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 17:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-arg-object.rs:17:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 17:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-arg-object.rs:17:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) diff --git a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr b/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr index 1752b3b36a484..370e57f73df10 100644 --- a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::() | = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-arg-trait-match.rs:10:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-arg-trait-match.rs:10:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::() | = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 16:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-arg-trait-match.rs:16:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 16:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-arg-trait-match.rs:16:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr b/src/test/ui/variance/variance-contravariant-self-trait-match.stderr index 9455162732b73..ab14faaa50728 100644 --- a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-self-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::<&'min G>(); | = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-self-trait-match.rs:10:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-self-trait-match.rs:10:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::<&'max G>(); | = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` -note: the lifetime `'min` as defined on the function body at 16:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-contravariant-self-trait-match.rs:16:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 16:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-contravariant-self-trait-match.rs:16:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-covariant-arg-object.stderr b/src/test/ui/variance/variance-covariant-arg-object.stderr index 75b6d588c1593..d590a4dc2d9d5 100644 --- a/src/test/ui/variance/variance-covariant-arg-object.stderr +++ b/src/test/ui/variance/variance-covariant-arg-object.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-arg-object.rs:10:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-arg-object.rs:10:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) @@ -25,12 +25,12 @@ LL | v | = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 18:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-arg-object.rs:18:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 18:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-arg-object.rs:18:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) diff --git a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr b/src/test/ui/variance/variance-covariant-arg-trait-match.stderr index aa383fcc26280..eb1766b096c07 100644 --- a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-arg-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::() | = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-arg-trait-match.rs:10:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-arg-trait-match.rs:10:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::() | = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 17:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-arg-trait-match.rs:17:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 17:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-arg-trait-match.rs:17:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-covariant-self-trait-match.stderr b/src/test/ui/variance/variance-covariant-self-trait-match.stderr index 3f3a69dde5210..b0bcb2e8422e4 100644 --- a/src/test/ui/variance/variance-covariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-self-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::<&'min G>(); | = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` -note: the lifetime `'min` as defined on the function body at 10:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-self-trait-match.rs:10:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 10:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-self-trait-match.rs:10:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::<&'max G>(); | = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` -note: the lifetime `'min` as defined on the function body at 17:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-covariant-self-trait-match.rs:17:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 17:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-covariant-self-trait-match.rs:17:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-invariant-arg-object.stderr b/src/test/ui/variance/variance-invariant-arg-object.stderr index 13ee9b9da3c98..6c1b07e6677e3 100644 --- a/src/test/ui/variance/variance-invariant-arg-object.stderr +++ b/src/test/ui/variance/variance-invariant-arg-object.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 7:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-arg-object.rs:7:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 7:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-arg-object.rs:7:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) @@ -25,12 +25,12 @@ LL | v | = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 14:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-arg-object.rs:14:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 14:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-arg-object.rs:14:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) diff --git a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr b/src/test/ui/variance/variance-invariant-arg-trait-match.stderr index b58993737c783..0328496546eb7 100644 --- a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-arg-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::() | = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` -note: the lifetime `'min` as defined on the function body at 7:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-arg-trait-match.rs:7:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 7:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-arg-trait-match.rs:7:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::() | = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` -note: the lifetime `'min` as defined on the function body at 13:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-arg-trait-match.rs:13:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 13:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-arg-trait-match.rs:13:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-invariant-self-trait-match.stderr b/src/test/ui/variance/variance-invariant-self-trait-match.stderr index a80a5e41d0314..c553581b564a0 100644 --- a/src/test/ui/variance/variance-invariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-self-trait-match.stderr @@ -6,12 +6,12 @@ LL | impls_get::<&'min G>(); | = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` -note: the lifetime `'min` as defined on the function body at 7:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-self-trait-match.rs:7:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 7:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-self-trait-match.rs:7:27 | LL | fn get_min_from_max<'min, 'max, G>() @@ -25,12 +25,12 @@ LL | impls_get::<&'max G>(); | = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` -note: the lifetime `'min` as defined on the function body at 13:21... +note: the lifetime `'min` as defined here... --> $DIR/variance-invariant-self-trait-match.rs:13:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 13:27 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-invariant-self-trait-match.rs:13:27 | LL | fn get_max_from_min<'min, 'max, G>() diff --git a/src/test/ui/variance/variance-use-contravariant-struct-1.stderr b/src/test/ui/variance/variance-use-contravariant-struct-1.stderr index 423c9a601f456..ec0cb22cdb6ba 100644 --- a/src/test/ui/variance/variance-use-contravariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-contravariant-struct-1.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected struct `SomeStruct<&'min ()>` found struct `SomeStruct<&'max ()>` -note: the lifetime `'min` as defined on the function body at 8:8... +note: the lifetime `'min` as defined here... --> $DIR/variance-use-contravariant-struct-1.rs:8:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 8:13 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-use-contravariant-struct-1.rs:8:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) diff --git a/src/test/ui/variance/variance-use-covariant-struct-1.stderr b/src/test/ui/variance/variance-use-covariant-struct-1.stderr index 3f9224804bdd0..0c0071cf9e16f 100644 --- a/src/test/ui/variance/variance-use-covariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-covariant-struct-1.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected struct `SomeStruct<&'max ()>` found struct `SomeStruct<&'min ()>` -note: the lifetime `'min` as defined on the function body at 6:8... +note: the lifetime `'min` as defined here... --> $DIR/variance-use-covariant-struct-1.rs:6:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 6:13 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-use-covariant-struct-1.rs:6:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'min ()>) diff --git a/src/test/ui/variance/variance-use-invariant-struct-1.stderr b/src/test/ui/variance/variance-use-invariant-struct-1.stderr index 7063f1c9c8f97..76e4bd76b998f 100644 --- a/src/test/ui/variance/variance-use-invariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-invariant-struct-1.stderr @@ -6,12 +6,12 @@ LL | v | = note: expected struct `SomeStruct<&'min ()>` found struct `SomeStruct<&'max ()>` -note: the lifetime `'min` as defined on the function body at 8:8... +note: the lifetime `'min` as defined here... --> $DIR/variance-use-invariant-struct-1.rs:8:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 8:13 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-use-invariant-struct-1.rs:8:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) @@ -25,12 +25,12 @@ LL | v | = note: expected struct `SomeStruct<&'max ()>` found struct `SomeStruct<&'min ()>` -note: the lifetime `'min` as defined on the function body at 15:8... +note: the lifetime `'min` as defined here... --> $DIR/variance-use-invariant-struct-1.rs:15:8 | LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ -note: ...does not necessarily outlive the lifetime `'max` as defined on the function body at 15:13 +note: ...does not necessarily outlive the lifetime `'max` as defined here --> $DIR/variance-use-invariant-struct-1.rs:15:13 | LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>) diff --git a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr index 4e927cd983d0d..d3593d8c1eb67 100644 --- a/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr +++ b/src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr @@ -17,7 +17,7 @@ note: because this has an unmet lifetime requirement | LL | pub struct Wrapper(T); | ^^^^^ introduces a `'static` lifetime requirement -note: the anonymous lifetime #1 defined on the method body at 16:5... +note: the anonymous lifetime #1 defined here... --> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5 | LL | pub fn repro(_: Wrapper); diff --git a/src/test/ui/wf/wf-static-method.stderr b/src/test/ui/wf/wf-static-method.stderr index c02a8fe4aaff6..c663931c5d605 100644 --- a/src/test/ui/wf/wf-static-method.stderr +++ b/src/test/ui/wf/wf-static-method.stderr @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | u | ^ | -note: ...the reference is valid for the lifetime `'a` as defined on the impl at 14:6... +note: ...the reference is valid for the lifetime `'a` as defined here... --> $DIR/wf-static-method.rs:14:6 | LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { | ^^ -note: ...but the borrowed content is only valid for the lifetime `'b` as defined on the impl at 14:10 +note: ...but the borrowed content is only valid for the lifetime `'b` as defined here --> $DIR/wf-static-method.rs:14:10 | LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { @@ -21,12 +21,12 @@ error[E0478]: lifetime bound not satisfied LL | let me = Self::make_me(); | ^^^^ | -note: lifetime parameter instantiated with the lifetime `'b` as defined on the impl at 23:10 +note: lifetime parameter instantiated with the lifetime `'b` as defined here --> $DIR/wf-static-method.rs:23:10 | LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | ^^ -note: but lifetime parameter must outlive the lifetime `'a` as defined on the impl at 23:6 +note: but lifetime parameter must outlive the lifetime `'a` as defined here --> $DIR/wf-static-method.rs:23:6 | LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { @@ -38,12 +38,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... LL | u | ^ | -note: ...the reference is valid for the lifetime `'a` as defined on the impl at 31:6... +note: ...the reference is valid for the lifetime `'a` as defined here... --> $DIR/wf-static-method.rs:31:6 | LL | impl<'a, 'b> Evil<'a, 'b> { | ^^ -note: ...but the borrowed content is only valid for the lifetime `'b` as defined on the impl at 31:10 +note: ...but the borrowed content is only valid for the lifetime `'b` as defined here --> $DIR/wf-static-method.rs:31:10 | LL | impl<'a, 'b> Evil<'a, 'b> { @@ -55,7 +55,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | <()>::static_evil(b) | ^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 40:13... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/wf-static-method.rs:40:13 | LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { @@ -65,7 +65,7 @@ note: ...so that reference does not outlive borrowed content | LL | <()>::static_evil(b) | ^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 40:9... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/wf-static-method.rs:40:9 | LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { @@ -82,7 +82,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | ::static_evil(b) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 44:22... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/wf-static-method.rs:44:22 | LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { @@ -92,7 +92,7 @@ note: ...so that reference does not outlive borrowed content | LL | ::static_evil(b) | ^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 44:18... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/wf-static-method.rs:44:18 | LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { @@ -109,7 +109,7 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` d LL | ::inherent_evil(b) | ^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the function body at 49:22... +note: first, the lifetime cannot outlive the lifetime `'b` as defined here... --> $DIR/wf-static-method.rs:49:22 | LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { @@ -119,7 +119,7 @@ note: ...so that reference does not outlive borrowed content | LL | ::inherent_evil(b) | ^ -note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 49:18... +note: but, the lifetime must be valid for the lifetime `'a` as defined here... --> $DIR/wf-static-method.rs:49:18 | LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { From d4351015378886fd7204cad5b0c74d176bf9151c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Oct 2021 12:32:08 +0000 Subject: [PATCH 060/181] Use a label instead of a note for member constraint errors --- .../src/infer/error_reporting/mod.rs | 22 ++++++++++++++++--- .../ui/impl-trait/hidden-lifetimes.stderr | 20 +++++------------ .../error-handling-2.stderr | 10 +++------ .../impl-trait/region-escape-via-bound.stderr | 7 ++---- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index f94a86af04b67..a48e01b1da2df 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -116,7 +116,7 @@ pub(super) fn note_and_explain_region( emit_msg_span(err, prefix, description, span, suffix); } -pub(super) fn note_and_explain_free_region( +fn explain_free_region( tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_>, prefix: &str, @@ -125,7 +125,7 @@ pub(super) fn note_and_explain_free_region( ) { let (description, span) = msg_span_from_free_region(tcx, region, None); - emit_msg_span(err, prefix, description, span, suffix); + label_msg_span(err, prefix, description, span, suffix); } fn msg_span_from_free_region( @@ -210,6 +210,22 @@ fn emit_msg_span( } } +fn label_msg_span( + err: &mut DiagnosticBuilder<'_>, + prefix: &str, + description: String, + span: Option, + suffix: &str, +) { + let message = format!("{}{}{}", prefix, description, suffix); + + if let Some(span) = span { + err.span_label(span, &message); + } else { + err.note(&message); + } +} + pub fn unexpected_hidden_region_diagnostic( tcx: TyCtxt<'tcx>, span: Span, @@ -244,7 +260,7 @@ pub fn unexpected_hidden_region_diagnostic( // // (*) if not, the `tainted_by_errors` field would be set to // `Some(ErrorReported)` in any case, so we wouldn't be here at all. - note_and_explain_free_region( + explain_free_region( tcx, &mut err, &format!("hidden type `{}` captures ", hidden_ty), diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index c8ea98f147f91..ba192aa4ab231 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -2,25 +2,17 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/hidden-lifetimes.rs:28:54 | LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { - | ^^^^^^^^^^^^^^ - | -note: hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here - --> $DIR/hidden-lifetimes.rs:28:17 - | -LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { - | ^^ + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:45:70 | LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { - | ^^^^^^^^^^^^^^ - | -note: hidden type `Rc>` captures the lifetime `'b` as defined here - --> $DIR/hidden-lifetimes.rs:45:24 - | -LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { - | ^^ + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `Rc>` captures the lifetime `'b` as defined here error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr index 64f89812fffce..cee71400094af 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr @@ -2,13 +2,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/error-handling-2.rs:13:60 | LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { - | ^^^^^^^^^ - | -note: hidden type `*mut &'a i32` captures the lifetime `'a` as defined here - --> $DIR/error-handling-2.rs:13:8 - | -LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { - | ^^ + | -- ^^^^^^^^^ + | | + | hidden type `*mut &'a i32` captures the lifetime `'a` as defined here error: aborting due to previous error diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr index ddf8939d21d8a..b935945527857 100644 --- a/src/test/ui/impl-trait/region-escape-via-bound.stderr +++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr @@ -3,12 +3,9 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea | LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> | ^^^^^^^^^^^^^^ - | -note: hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here - --> $DIR/region-escape-via-bound.rs:17:7 - | +LL | LL | where 'x: 'y - | ^^ + | -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here error: aborting due to previous error From 56e79e6ce2cc018919c3e6665d7aae87d6b92089 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Oct 2021 12:32:57 +0000 Subject: [PATCH 061/181] Remove a feature attribute for an accepted feature --- src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs | 1 - .../ui/impl-trait/multiple-lifetimes/error-handling-2.stderr | 2 +- src/test/ui/type-alias-impl-trait/issue-74761-2.rs | 1 - src/test/ui/type-alias-impl-trait/issue-74761-2.stderr | 4 ++-- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs index 96d891b2cf1d7..763ec7290c040 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs @@ -1,6 +1,5 @@ // compile-flags:-Zborrowck=mir -#![feature(member_constraints)] #![feature(type_alias_impl_trait)] #[derive(Clone)] diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr index cee71400094af..46bd75ea7c8df 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr @@ -1,5 +1,5 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/error-handling-2.rs:13:60 + --> $DIR/error-handling-2.rs:12:60 | LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- ^^^^^^^^^ diff --git a/src/test/ui/type-alias-impl-trait/issue-74761-2.rs b/src/test/ui/type-alias-impl-trait/issue-74761-2.rs index 4345b5d886ee2..d26ca5c3ead38 100644 --- a/src/test/ui/type-alias-impl-trait/issue-74761-2.rs +++ b/src/test/ui/type-alias-impl-trait/issue-74761-2.rs @@ -1,4 +1,3 @@ -#![feature(member_constraints)] #![feature(type_alias_impl_trait)] pub trait A { diff --git a/src/test/ui/type-alias-impl-trait/issue-74761-2.stderr b/src/test/ui/type-alias-impl-trait/issue-74761-2.stderr index 7a321458b0bf1..f15d0a069ca8a 100644 --- a/src/test/ui/type-alias-impl-trait/issue-74761-2.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-74761-2.stderr @@ -1,11 +1,11 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-74761-2.rs:8:6 + --> $DIR/issue-74761-2.rs:7:6 | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter error[E0207]: the lifetime parameter `'b` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-74761-2.rs:8:10 + --> $DIR/issue-74761-2.rs:7:10 | LL | impl<'a, 'b> A for () { | ^^ unconstrained lifetime parameter From be399635a2618660d62fa7ce207d747ac56eae95 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Oct 2021 12:35:24 +0000 Subject: [PATCH 062/181] Remove explicit -Zborrowck=mir which does not affect test anymore --- src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs | 2 -- .../ui/impl-trait/multiple-lifetimes/error-handling-2.stderr | 2 +- src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs | 2 -- src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs index 763ec7290c040..72e9d96da3677 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs @@ -1,5 +1,3 @@ -// compile-flags:-Zborrowck=mir - #![feature(type_alias_impl_trait)] #[derive(Clone)] diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr index 46bd75ea7c8df..40bec0da2707d 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr @@ -1,5 +1,5 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/error-handling-2.rs:12:60 + --> $DIR/error-handling-2.rs:10:60 | LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- ^^^^^^^^^ diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs index 6d88f16ea8abb..367e7f4e6eafb 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs @@ -1,5 +1,3 @@ -// compile-flags:-Zborrowck=mir - #![feature(type_alias_impl_trait)] #[derive(Clone)] diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index ccd0040030da2..01d9f506a0c58 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/error-handling.rs:22:16 + --> $DIR/error-handling.rs:20:16 | LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- -- lifetime `'b` defined here From 888ba509eaf9791ea35c16c04305bdb106a65dfa Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 5 Oct 2021 13:32:03 +0000 Subject: [PATCH 063/181] Re-use logic for adding a suggestion when a lifetime bound is missing on an impl trait --- compiler/rustc_hir/src/hir.rs | 3 +- .../src/infer/error_reporting/mod.rs | 12 + .../error_reporting/nice_region_error/mod.rs | 2 + .../nice_region_error/static_impl_trait.rs | 209 ++++++++++-------- .../ui/impl-trait/hidden-lifetimes.stderr | 10 + .../impl-trait/region-escape-via-bound.stderr | 5 + 6 files changed, 150 insertions(+), 91 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5264f7cc32612..11d0178e93ba4 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2235,8 +2235,7 @@ pub enum TyKind<'hir> { /// /// Type parameters may be stored in each `PathSegment`. Path(QPath<'hir>), - /// An opaque type definition itself. This is currently only used for the - /// `opaque type Foo: Trait` item that `impl Trait` in desugars to. + /// An opaque type definition itself. This is only used for `impl Trait`. /// /// The generic argument list contains the lifetimes (and in the future /// possibly parameters) that are actually bound on the `impl Trait`. diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index a48e01b1da2df..126c25f0c38c7 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -267,6 +267,18 @@ pub fn unexpected_hidden_region_diagnostic( hidden_region, "", ); + if let Some(reg_info) = tcx.is_suitable_region(hidden_region) { + let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id); + nice_region_error::suggest_new_region_bound( + tcx, + &mut err, + fn_returns, + hidden_region.to_string(), + None, + format!("captures {}", hidden_region), + None, + ) + } } _ => { // Ugh. This is a painful case: the hidden region is not one diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 3f27bf67b59a9..6a3309770028f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -14,6 +14,8 @@ mod static_impl_trait; mod trait_impl_difference; mod util; +pub use static_impl_trait::suggest_new_region_bound; + impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { pub fn try_report_nice_region_error(&self, error: &RegionResolutionError<'tcx>) -> bool { NiceRegionError::new(self, error.clone()).try_report().is_some() diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 2d47e72780ebe..7fba6a823d75e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -217,128 +217,159 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { )); } - debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns); - // FIXME: account for the need of parens in `&(dyn Trait + '_)` - let consider = "consider changing the"; - let declare = "to declare that the"; let arg = match param.param.pat.simple_ident() { Some(simple_ident) => format!("argument `{}`", simple_ident), None => "the argument".to_string(), }; - let explicit = format!("you can add an explicit `{}` lifetime bound", lifetime_name); - let explicit_static = format!("explicit `'static` bound to the lifetime of {}", arg); let captures = format!("captures data from {}", arg); - let add_static_bound = "alternatively, add an explicit `'static` bound to this reference"; - let plus_lt = format!(" + {}", lifetime_name); - for fn_return in fn_returns { - if fn_return.span.desugaring_kind().is_some() { - // Skip `async` desugaring `impl Future`. - continue; - } - match fn_return.kind { - TyKind::OpaqueDef(item_id, _) => { - let item = tcx.hir().item(item_id); - let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { - opaque - } else { - err.emit(); - return Some(ErrorReported); - }; + suggest_new_region_bound( + tcx, + &mut err, + fn_returns, + lifetime_name, + Some(arg), + captures, + Some((param.param_ty_span, param.param_ty.to_string())), + ); - if let Some(span) = opaque - .bounds - .iter() - .filter_map(|arg| match arg { - GenericBound::Outlives(Lifetime { - name: LifetimeName::Static, - span, - .. - }) => Some(*span), - _ => None, - }) - .next() - { + err.emit(); + Some(ErrorReported) + } +} + +pub fn suggest_new_region_bound( + tcx: TyCtxt<'tcx>, + err: &mut DiagnosticBuilder<'_>, + fn_returns: Vec<&rustc_hir::Ty<'_>>, + lifetime_name: String, + arg: Option, + captures: String, + param: Option<(Span, String)>, +) { + debug!("try_report_static_impl_trait: fn_return={:?}", fn_returns); + // FIXME: account for the need of parens in `&(dyn Trait + '_)` + let consider = "consider changing the"; + let declare = "to declare that the"; + let explicit = format!("you can add an explicit `{}` lifetime bound", lifetime_name); + let explicit_static = + arg.map(|arg| format!("explicit `'static` bound to the lifetime of {}", arg)); + let add_static_bound = "alternatively, add an explicit `'static` bound to this reference"; + let plus_lt = format!(" + {}", lifetime_name); + for fn_return in fn_returns { + if fn_return.span.desugaring_kind().is_some() { + // Skip `async` desugaring `impl Future`. + continue; + } + match fn_return.kind { + TyKind::OpaqueDef(item_id, _) => { + let item = tcx.hir().item(item_id); + let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { + opaque + } else { + return; + }; + + if let Some(span) = opaque + .bounds + .iter() + .filter_map(|arg| match arg { + GenericBound::Outlives(Lifetime { + name: LifetimeName::Static, + span, + .. + }) => Some(*span), + _ => None, + }) + .next() + { + if let Some(explicit_static) = &explicit_static { err.span_suggestion_verbose( span, &format!("{} `impl Trait`'s {}", consider, explicit_static), lifetime_name.clone(), Applicability::MaybeIncorrect, ); + } + if let Some((param_span, param_ty)) = param.clone() { err.span_suggestion_verbose( - param.param_ty_span, + param_span, add_static_bound, - param.param_ty.to_string(), - Applicability::MaybeIncorrect, - ); - } else if opaque - .bounds - .iter() - .filter_map(|arg| match arg { - GenericBound::Outlives(Lifetime { name, span, .. }) - if name.ident().to_string() == lifetime_name => - { - Some(*span) - } - _ => None, - }) - .next() - .is_some() - { - } else { - err.span_suggestion_verbose( - fn_return.span.shrink_to_hi(), - &format!( - "{declare} `impl Trait` {captures}, {explicit}", - declare = declare, - captures = captures, - explicit = explicit, - ), - plus_lt.clone(), + param_ty, Applicability::MaybeIncorrect, ); } + } else if opaque + .bounds + .iter() + .filter_map(|arg| match arg { + GenericBound::Outlives(Lifetime { name, span, .. }) + if name.ident().to_string() == lifetime_name => + { + Some(*span) + } + _ => None, + }) + .next() + .is_some() + { + } else { + err.span_suggestion_verbose( + fn_return.span.shrink_to_hi(), + &format!( + "{declare} `impl Trait` {captures}, {explicit}", + declare = declare, + captures = captures, + explicit = explicit, + ), + plus_lt.clone(), + Applicability::MaybeIncorrect, + ); } - TyKind::TraitObject(_, lt, _) => match lt.name { - LifetimeName::ImplicitObjectLifetimeDefault => { - err.span_suggestion_verbose( - fn_return.span.shrink_to_hi(), - &format!( - "{declare} trait object {captures}, {explicit}", - declare = declare, - captures = captures, - explicit = explicit, - ), - plus_lt.clone(), - Applicability::MaybeIncorrect, - ); - } - name if name.ident().to_string() != lifetime_name => { - // With this check we avoid suggesting redundant bounds. This - // would happen if there are nested impl/dyn traits and only - // one of them has the bound we'd suggest already there, like - // in `impl Foo + '_`. + } + TyKind::TraitObject(_, lt, _) => match lt.name { + LifetimeName::ImplicitObjectLifetimeDefault => { + err.span_suggestion_verbose( + fn_return.span.shrink_to_hi(), + &format!( + "{declare} trait object {captures}, {explicit}", + declare = declare, + captures = captures, + explicit = explicit, + ), + plus_lt.clone(), + Applicability::MaybeIncorrect, + ); + } + name if name.ident().to_string() != lifetime_name => { + // With this check we avoid suggesting redundant bounds. This + // would happen if there are nested impl/dyn traits and only + // one of them has the bound we'd suggest already there, like + // in `impl Foo + '_`. + if let Some(explicit_static) = &explicit_static { err.span_suggestion_verbose( lt.span, &format!("{} trait object's {}", consider, explicit_static), lifetime_name.clone(), Applicability::MaybeIncorrect, ); + } + if let Some((param_span, param_ty)) = param.clone() { err.span_suggestion_verbose( - param.param_ty_span, + param_span, add_static_bound, - param.param_ty.to_string(), + param_ty, Applicability::MaybeIncorrect, ); } - _ => {} - }, + } _ => {} - } + }, + _ => {} } - err.emit(); - Some(ErrorReported) } +} +impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { fn get_impl_ident_and_self_ty_from_trait( &self, def_id: DefId, diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index ba192aa4ab231..60d3409a8accf 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -5,6 +5,11 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | -- ^^^^^^^^^^^^^^ | | | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { + | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/hidden-lifetimes.rs:45:70 @@ -13,6 +18,11 @@ LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl S | -- ^^^^^^^^^^^^^^ | | | hidden type `Rc>` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a + 'b { + | ++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr index b935945527857..9dc2ea5bc82a1 100644 --- a/src/test/ui/impl-trait/region-escape-via-bound.stderr +++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr @@ -6,6 +6,11 @@ LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> LL | LL | where 'x: 'y | -- hidden type `Cell<&'x u32>` captures the lifetime `'x` as defined here + | +help: to declare that the `impl Trait` captures 'x, you can add an explicit `'x` lifetime bound + | +LL | fn foo(x: Cell<&'x u32>) -> impl Trait<'y> + 'x + | ++++ error: aborting due to previous error From ab7721d69430dc697f07eb748135cf2c2d95ffff Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 8 Oct 2021 18:30:58 +0000 Subject: [PATCH 064/181] Bless nll tests --- .../ordinary-bounds-unrelated.nll.stderr | 11 ++++++----- .../ordinary-bounds-unsuited.nll.stderr | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr index 784e840a7055b..bfe656c7e2b49 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr @@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/ordinary-bounds-unrelated.rs:16:74 | LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | ^^^^^^^^^^^^^^^^^^ + | -- ^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here - --> $DIR/ordinary-bounds-unrelated.rs:16:21 +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | ^^ +LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b + | ++++ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr index 4287d00361419..75c2dd8e9d39e 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr @@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/ordinary-bounds-unsuited.rs:18:62 | LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | ^^^^^^^^^^^^^^^^^^ + | -- ^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -note: hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here - --> $DIR/ordinary-bounds-unsuited.rs:18:21 +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | -LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | ^^ +LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b + | ++++ error: aborting due to previous error From 20d6aadff7148cdce8d453b8d87b47610b1d0e41 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 13 Oct 2021 11:06:14 +0000 Subject: [PATCH 065/181] Update clippy ui output --- src/tools/clippy/tests/ui/crashes/ice-6256.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy/tests/ui/crashes/ice-6256.stderr b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr index d35d459168f23..ae4e6cad3328b 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6256.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6256.stderr @@ -6,7 +6,7 @@ LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types | = note: expected reference `&(dyn TT + 'static)` found reference `&dyn TT` -note: the anonymous lifetime #1 defined on the body at 13:13... +note: the anonymous lifetime #1 defined here... --> $DIR/ice-6256.rs:13:13 | LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types From cf905ed72f75918597fec46080e31dfca7eaddd4 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 13 Oct 2021 13:13:08 +0100 Subject: [PATCH 066/181] Add `riscv32imc-esp-espidf` to changelog --- RELEASES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 269740c171cfb..ae09de5e3fca1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -22,6 +22,7 @@ Compiler This feature is primarily intended for usage by `cargo fix`, rather than end users. - [Promote `aarch64-apple-ios-sim` to Tier 2\*.][rust#87760] - [Add `powerpc-unknown-freebsd` at Tier 3\*.][rust#87370] +- [Add `riscv32imc-esp-espidf` at Tier 3\*.][rust#87666] \* Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support. @@ -180,6 +181,7 @@ and related tools. [rust#87619]: https://github.com/rust-lang/rust/pull/87619 [rust#81825]: https://github.com/rust-lang/rust/pull/81825#issuecomment-808406918 [rust#88019]: https://github.com/rust-lang/rust/pull/88019 +[rust#87666]: https://github.com/rust-lang/rust/pull/87666 Version 1.55.0 (2021-09-09) ============================ From 21429eda2de59327881359b083e97f5fef58f17a Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 8 Oct 2021 17:17:50 +0200 Subject: [PATCH 067/181] Improve `std::thread::available_parallelism` docs --- library/std/src/thread/mod.rs | 77 ++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 707a55b625814..944defa0f817a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1427,39 +1427,76 @@ fn _assert_sync_and_send() { _assert_both::(); } -/// Returns the number of hardware threads available to the program. -/// -/// This value should be considered only a hint. -/// -/// # Platform-specific behavior -/// -/// If interpreted as the number of actual hardware threads, it may undercount on -/// Windows systems with more than 64 hardware threads. If interpreted as the -/// available concurrency for that process, it may overcount on Windows systems -/// when limited by a process wide affinity mask or job object limitations, and -/// it may overcount on Linux systems when limited by a process wide affinity -/// mask or affected by cgroups limits. +/// Returns an estimate of the default amount of parallelism a program should use. +/// +/// Parallelism is a resource. A given machine provides a certain capacity for +/// parallelism, i.e., a bound on the number of computations it can perform +/// simultaneously. This number often corresponds to the amount of CPUs or +/// computer has, but it may diverge in various cases. +/// +/// Host environments such as VMs or container orchestrators may want to +/// restrict the amount of parallelism made available to programs in them. This +/// is often done to limit the potential impact of (unintentionally) +/// resource-intensive programs on other programs running on the same machine. +/// +/// # Limitations +/// +/// The purpose of this API is to provide an easy and portable way to query +/// the default amount of parallelism the program should use. Among other things it +/// does not expose information on NUMA regions, does not account for +/// differences in (co)processor capabilities, and will not modify the program's +/// global state in order to more accurately query the amount of available +/// parallelism. +/// +/// The value returned by this function should be considered a simplified +/// approximation of the actual amount of parallelism available at any given +/// time. To get a more detailed or precise overview of the amount of +/// parallelism available to the program, you may wish to use +/// platform-specific APIs as well. The following platform limitations currently +/// apply to `available_parallelism`: +/// +/// On Windows: +/// - It may undercount the amount of parallelism available on systems with more +/// than 64 logical CPUs. However, programs typically need specific support to +/// take advantage of more than 64 logical CPUs, and in the absence of such +/// support, the number returned by this function accurately reflects the +/// number of logical CPUs the program can use by default. +/// - It may overcount the amount of parallelism available on systems limited by +/// process-wide affinity masks, or job object limitations. +/// +/// On Linux: +/// - It may overcount the amount of parallelism available when limited by a +/// process-wide affinity mask, or when affected by cgroup limits. +/// +/// On all targets: +/// - It may overcount the amount of parallelism available when running in a VM +/// with CPU usage limits (e.g. an overcommitted host). /// /// # Errors /// -/// This function will return an error in the following situations, but is not -/// limited to just these cases: +/// This function will, but is not limited to, return errors in the following +/// cases: /// -/// - If the number of hardware threads is not known for the target platform. -/// - The process lacks permissions to view the number of hardware threads -/// available. +/// - If the amount of parallelism is not known for the target platform. +/// - If the program lacks permission to query the amount of parallelism made +/// available to it. /// /// # Examples /// /// ``` /// # #![allow(dead_code)] /// #![feature(available_parallelism)] -/// use std::thread; +/// use std::{io, thread}; /// -/// let count = thread::available_parallelism().map(|n| n.get()).unwrap_or(1); +/// fn main() -> io::Result<()> { +/// let count = thread::available_parallelism()?.get(); +/// assert!(count >= 1_usize); +/// Ok(()) +/// } /// ``` +#[doc(alias = "available_concurrency")] // Alias for a previous name we gave this API on unstable. #[doc(alias = "hardware_concurrency")] // Alias for C++ `std::thread::hardware_concurrency`. -#[doc(alias = "available_concurrency")] // Alias for a name we gave this API on unstable. +#[doc(alias = "num_cpus")] // Alias for a popular ecosystem crate which provides similar functionality. #[unstable(feature = "available_parallelism", issue = "74479")] pub fn available_parallelism() -> io::Result { imp::available_parallelism() From a0cc8725e95793891e21f4211492abb0da800d3e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 13 Oct 2021 11:10:00 -0700 Subject: [PATCH 068/181] Update the 1.56.0 release header for consistency --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 269740c171cfb..94cfb4563af37 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,4 +1,4 @@ -Rust 1.56.0 (2021-10-21) +Version 1.56.0 (2021-10-21) ======================== Language From 38f6c07b112ce2c17cc60bc497d84d0268da3580 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 13 Oct 2021 17:09:48 +0200 Subject: [PATCH 069/181] Improve code readability for sidebar links --- src/librustdoc/html/render/mod.rs | 64 +++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 71b9deca9d647..69c5c2c4abc2a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1811,23 +1811,53 @@ fn get_next_url(used_links: &mut FxHashSet, url: String) -> String { format!("{}-{}", url, add) } +struct SidebarLink { + name: Symbol, + url: String, +} + +impl fmt::Display for SidebarLink { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.url, self.name) + } +} + +impl PartialEq for SidebarLink { + fn eq(&self, other: &Self) -> bool { + self.url == other.url + } +} + +impl Eq for SidebarLink {} + +impl PartialOrd for SidebarLink { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for SidebarLink { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.url.cmp(&other.url) + } +} + fn get_methods( i: &clean::Impl, for_deref: bool, used_links: &mut FxHashSet, deref_mut: bool, tcx: TyCtxt<'_>, -) -> Vec { +) -> Vec { i.items .iter() .filter_map(|item| match item.name { - Some(ref name) if !name.is_empty() && item.is_method() => { + Some(name) if !name.is_empty() && item.is_method() => { if !for_deref || should_render_item(item, deref_mut, tcx) { - Some(format!( - "{}", - get_next_url(used_links, format!("method.{}", name)), - name - )) + Some(SidebarLink { + name, + url: get_next_url(used_links, format!("method.{}", name)), + }) } else { None } @@ -1837,15 +1867,17 @@ fn get_methods( .collect::>() } -fn get_associated_constants(i: &clean::Impl, used_links: &mut FxHashSet) -> Vec { +fn get_associated_constants( + i: &clean::Impl, + used_links: &mut FxHashSet, +) -> Vec { i.items .iter() .filter_map(|item| match item.name { - Some(ref name) if !name.is_empty() && item.is_associated_const() => Some(format!( - "{}", - get_next_url(used_links, format!("associatedconstant.{}", name)), - name - )), + Some(name) if !name.is_empty() && item.is_associated_const() => Some(SidebarLink { + name, + url: get_next_url(used_links, format!("associatedconstant.{}", name)), + }), _ => None, }) .collect::>() @@ -1910,7 +1942,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
", ); for line in assoc_consts { - out.push_str(&line); + write!(out, "{}", line); } out.push_str("
"); } @@ -1928,7 +1960,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
", ); for line in methods { - out.push_str(&line); + write!(out, "{}", line); } out.push_str("
"); } @@ -2063,7 +2095,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V ret.sort(); out.push_str("
"); for link in ret { - out.push_str(&link); + write!(out, "{}", link); } out.push_str("
"); } From c9af192690d52818e83acb8b591d23dbab856f77 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Wed, 13 Oct 2021 22:56:26 +0000 Subject: [PATCH 070/181] Allow static linking LLVM with ThinLTO --- src/bootstrap/config.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 5706b8f9e7cc6..46843dac42f28 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -824,15 +824,10 @@ impl Config { }; } - if config.llvm_thin_lto { - // If we're building with ThinLTO on, we want to link to LLVM - // shared, to avoid re-doing ThinLTO (which happens in the link - // step) with each stage. - assert_ne!( - llvm.link_shared, - Some(false), - "setting link-shared=false is incompatible with thin-lto=true" - ); + if config.llvm_thin_lto && llvm.link_shared.is_none() { + // If we're building with ThinLTO on, by default we want to link + // to LLVM shared, to avoid re-doing ThinLTO (which happens in + // the link step) with each stage. config.llvm_link_shared = true; } } From 2c31c31bb87092fec3da6eefe6d5a3a836c6c5ba Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Fri, 24 Sep 2021 22:14:06 +0000 Subject: [PATCH 071/181] Fix line length --- compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index da8b863e2dbe6..4d25399a12387 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -341,7 +341,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (sp, label) in spans_and_labels { multi_span.push_span_label(sp, label); } - err.span_note(multi_span, "closures can only be coerced to `fn` types if they do not capture any variables"); + err.span_note( + multi_span, + "closures can only be coerced to `fn` types if they do not capture any variables" + ); } } } From 5c14433c00b29fb2065af0eb664e2040f88b4429 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 30 Sep 2021 01:06:56 +0000 Subject: [PATCH 072/181] Fix incorrect Box::pin suggestion The suggestion checked if Pin> could be coeerced to the expected type, but did not check predicates created by the coercion. We now look for predicates that definitely cannot be satisfied before giving the suggestion. The suggestion is marked MaybeIncorrect because we allow predicates that are still ambiguous and can't be proven. --- compiler/rustc_typeck/src/check/coercion.rs | 24 ++++++++++++++++++- .../src/check/fn_ctxt/suggestions.rs | 18 ++++++++++---- .../ui/suggestions/box-future-wrong-output.rs | 22 +++++++++++++++++ .../box-future-wrong-output.stderr | 14 +++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/suggestions/box-future-wrong-output.rs create mode 100644 src/test/ui/suggestions/box-future-wrong-output.stderr diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 07e542b70b90c..556c5d152df30 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -42,7 +42,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{Coercion, InferOk, InferResult}; -use rustc_infer::traits::Obligation; +use rustc_infer::traits::{Obligation, TraitEngine, TraitEngineExt}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast, @@ -146,6 +146,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { .and_then(|InferOk { value: ty, obligations }| success(f(ty), ty, obligations)) } + #[instrument(skip(self))] fn coerce(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> { // First, remove any resolved type variables (at the top level, at least): let a = self.shallow_resolve(a); @@ -943,6 +944,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.probe(|_| coerce.coerce(source, target)).is_ok() } + /// Same as `try_coerce()`, but without side-effects and attempts to select + /// all predicates created by the coercion. This is useful for e.g. checking + /// that associated types are correct. + pub fn can_coerce_and_satisfy_predicates(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { + let source = self.resolve_vars_with_obligations(expr_ty); + debug!("coercion::can_with_predicates({:?} -> {:?})", source, target); + + let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable); + // We don't ever need two-phase here since we throw out the result of the coercion + let coerce = Coerce::new(self, cause, AllowTwoPhase::No); + self.probe(|_| { + let ok = match coerce.coerce(source, target) { + Ok(ok) => ok, + _ => return false, + }; + let mut fcx = traits::FulfillmentContext::new_in_snapshot(); + fcx.register_predicate_obligations(self, ok.obligations); + fcx.select_where_possible(&self).is_ok() + }) + } + /// Given a type and a target type, this function will calculate and return /// how many dereference steps needed to achieve `expr_ty <: target`. If /// it's not possible, return `None`. diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 4d25399a12387..62cacdbbce34d 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -370,9 +370,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() => return false, _ => {} } - let boxed_found = self.tcx.mk_box(found); - let new_found = self.tcx.mk_lang_item(boxed_found, LangItem::Pin).unwrap(); - if self.can_coerce(new_found, expected) { + let box_found = self.tcx.mk_box(found); + let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); + let pin_found = self.tcx.mk_lang_item(found, LangItem::Pin).unwrap(); + if self.can_coerce_and_satisfy_predicates(pin_box_found, expected) { + debug!("can coerce {:?} to {:?}, suggesting Box::pin", pin_box_found, expected); match found.kind() { ty::Adt(def, _) if def.is_box() => { err.help("use `Box::pin`"); @@ -384,11 +386,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (expr.span.shrink_to_lo(), "Box::pin(".to_string()), (expr.span.shrink_to_hi(), ")".to_string()), ], - Applicability::MachineApplicable, + Applicability::MaybeIncorrect, ); } } true + } else if self.can_coerce_and_satisfy_predicates(pin_found, expected) { + match found.kind() { + ty::Adt(def, _) if def.is_box() => { + err.help("use `Box::pin`"); + true + } + _ => false, + } } else { false } diff --git a/src/test/ui/suggestions/box-future-wrong-output.rs b/src/test/ui/suggestions/box-future-wrong-output.rs new file mode 100644 index 0000000000000..d49819fcb14cf --- /dev/null +++ b/src/test/ui/suggestions/box-future-wrong-output.rs @@ -0,0 +1,22 @@ +// Issue #72117 +// edition:2018 + +use core::future::Future; +use core::pin::Pin; + +pub type BoxFuture<'a, T> = Pin + Send + 'a>>; + +impl FutureExt for T where T: Future {} +trait FutureExt: Future { + fn boxed<'a>(self) -> BoxFuture<'a, Self::Output> + where + Self: Sized + Send + 'a, + { + Box::pin(self) + } +} + +fn main() { + let _: BoxFuture<'static, bool> = async {}.boxed(); + //~^ ERROR: mismatched types +} diff --git a/src/test/ui/suggestions/box-future-wrong-output.stderr b/src/test/ui/suggestions/box-future-wrong-output.stderr new file mode 100644 index 0000000000000..e0c57af25b3d2 --- /dev/null +++ b/src/test/ui/suggestions/box-future-wrong-output.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/box-future-wrong-output.rs:20:39 + | +LL | let _: BoxFuture<'static, bool> = async {}.boxed(); + | ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | | + | expected due to this + | + = note: expected struct `Pin + Send + 'static)>>` + found struct `Pin + Send>>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 485ae9f2c077511f7e2838919c948f9b9b0f0f4f Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 30 Sep 2021 01:22:17 +0000 Subject: [PATCH 073/181] Always check predicates in can_coerce This only changed two tests and I consider both changes an improvement. --- compiler/rustc_typeck/src/check/coercion.rs | 16 +++------------- .../src/check/fn_ctxt/suggestions.rs | 4 ++-- src/test/ui/cross/cross-borrow-trait.stderr | 6 ++---- src/test/ui/dst/dst-bad-coercions.stderr | 12 ++++-------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 556c5d152df30..a87318ff34e6d 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -934,20 +934,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// Same as `try_coerce()`, but without side-effects. + /// + /// Returns false if the coercion creates any obligations that result in + /// errors. pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { - let source = self.resolve_vars_with_obligations(expr_ty); - debug!("coercion::can({:?} -> {:?})", source, target); - - let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable); - // We don't ever need two-phase here since we throw out the result of the coercion - let coerce = Coerce::new(self, cause, AllowTwoPhase::No); - self.probe(|_| coerce.coerce(source, target)).is_ok() - } - - /// Same as `try_coerce()`, but without side-effects and attempts to select - /// all predicates created by the coercion. This is useful for e.g. checking - /// that associated types are correct. - pub fn can_coerce_and_satisfy_predicates(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { let source = self.resolve_vars_with_obligations(expr_ty); debug!("coercion::can_with_predicates({:?} -> {:?})", source, target); diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 62cacdbbce34d..7fe841c381562 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -373,7 +373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let box_found = self.tcx.mk_box(found); let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); let pin_found = self.tcx.mk_lang_item(found, LangItem::Pin).unwrap(); - if self.can_coerce_and_satisfy_predicates(pin_box_found, expected) { + if self.can_coerce(pin_box_found, expected) { debug!("can coerce {:?} to {:?}, suggesting Box::pin", pin_box_found, expected); match found.kind() { ty::Adt(def, _) if def.is_box() => { @@ -391,7 +391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } true - } else if self.can_coerce_and_satisfy_predicates(pin_found, expected) { + } else if self.can_coerce(pin_found, expected) { match found.kind() { ty::Adt(def, _) if def.is_box() => { err.help("use `Box::pin`"); diff --git a/src/test/ui/cross/cross-borrow-trait.stderr b/src/test/ui/cross/cross-borrow-trait.stderr index f693a3149b2a1..81f309eae087c 100644 --- a/src/test/ui/cross/cross-borrow-trait.stderr +++ b/src/test/ui/cross/cross-borrow-trait.stderr @@ -2,10 +2,8 @@ error[E0308]: mismatched types --> $DIR/cross-borrow-trait.rs:10:26 | LL | let _y: &dyn Trait = x; - | ---------- ^ - | | | - | | expected `&dyn Trait`, found struct `Box` - | | help: consider borrowing here: `&x` + | ---------- ^ expected `&dyn Trait`, found struct `Box` + | | | expected due to this | = note: expected reference `&dyn Trait` diff --git a/src/test/ui/dst/dst-bad-coercions.stderr b/src/test/ui/dst/dst-bad-coercions.stderr index 3e23c5f5c7443..01f862ed516e9 100644 --- a/src/test/ui/dst/dst-bad-coercions.stderr +++ b/src/test/ui/dst/dst-bad-coercions.stderr @@ -13,10 +13,8 @@ error[E0308]: mismatched types --> $DIR/dst-bad-coercions.rs:15:21 | LL | let y: &dyn T = x; - | ------ ^ - | | | - | | expected `&dyn T`, found *-ptr - | | help: consider borrowing here: `&x` + | ------ ^ expected `&dyn T`, found *-ptr + | | | expected due to this | = note: expected reference `&dyn T` @@ -37,10 +35,8 @@ error[E0308]: mismatched types --> $DIR/dst-bad-coercions.rs:20:21 | LL | let y: &dyn T = x; - | ------ ^ - | | | - | | expected `&dyn T`, found *-ptr - | | help: consider borrowing here: `&x` + | ------ ^ expected `&dyn T`, found *-ptr + | | | expected due to this | = note: expected reference `&dyn T` From 156c9222f52acb1a842ffc2d6e814fca8937cbf0 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 30 Sep 2021 01:29:24 +0000 Subject: [PATCH 074/181] Move misplaced comment --- .../ui/suggestions/expected-boxed-future-isnt-pinned.rs | 6 +++--- .../ui/suggestions/expected-boxed-future-isnt-pinned.stderr | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs index 5dee0f5dae0b0..89a36e89b0acf 100644 --- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs +++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs @@ -11,13 +11,13 @@ fn foo + Send + 'static>(x: F) -> BoxFuture<'static, i32> x //~ ERROR mismatched types } -// This case is still subpar: -// `Pin::new(x)`: store this in the heap by calling `Box::new`: `Box::new(x)` -// Should suggest changing the code from `Pin::new` to `Box::pin`. fn bar + Send + 'static>(x: F) -> BoxFuture<'static, i32> { Box::new(x) //~ ERROR mismatched types } +// This case is still subpar: +// `Pin::new(x)`: store this in the heap by calling `Box::new`: `Box::new(x)` +// Should suggest changing the code from `Pin::new` to `Box::pin`. fn baz + Send + 'static>(x: F) -> BoxFuture<'static, i32> { Pin::new(x) //~ ERROR mismatched types //~^ ERROR E0277 diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr index ff08178cb7470..f0af37e0cbe8a 100644 --- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr +++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr @@ -15,7 +15,7 @@ LL | Box::pin(x) | +++++++++ + error[E0308]: mismatched types - --> $DIR/expected-boxed-future-isnt-pinned.rs:18:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:15:5 | LL | fn bar + Send + 'static>(x: F) -> BoxFuture<'static, i32> { | ----------------------- expected `Pin + Send + 'static)>>` because of return type From a8558e9efabc6640e8c1b1c353e62c233624f616 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 30 Sep 2021 03:33:12 +0000 Subject: [PATCH 075/181] Exit early if expected type is not an adt --- compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 7fe841c381562..339c46616a590 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -364,11 +364,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return false; } let pin_did = self.tcx.lang_items().pin_type(); + // This guards the `unwrap` and `mk_box` below. + if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() { + return false; + } match expected.kind() { - ty::Adt(def, _) if Some(def.did) != pin_did => return false, - // This guards the `unwrap` and `mk_box` below. - _ if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() => return false, - _ => {} + ty::Adt(def, _) if Some(def.did) == pin_did => (), + _ => return false, } let box_found = self.tcx.mk_box(found); let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); From 15c876db9ce32922c331b9dab5e9dafc3d81387b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Oct 2021 01:50:37 +0200 Subject: [PATCH 076/181] Deduplicate macro_rules! from module_exports when documenting them This can append if within the same module a `#[macro_export] macro_rules!` is declared but also a reexport of itself producing two export of the same macro in the same module. In that case we only want to document it once. --- src/librustdoc/visit_ast.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 36b1a14f6c1ea..3e38ac822f50a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -87,13 +87,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { // the rexport defines the path that a user will actually see. Accordingly, // we add the rexport as an item here, and then skip over the original // definition in `visit_item()` below. + // + // We also skip `#[macro_export] macro_rules!` that have alredy been inserted, + // this can append if within the same module a `#[macro_export] macro_rules!` + // is declared but also a reexport of itself producing two export of the same + // macro in the same module. + let mut inserted = FxHashSet::default(); for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) { if let Res::Def(DefKind::Macro(_), def_id) = export.res { if let Some(local_def_id) = def_id.as_local() { if self.cx.tcx.has_attr(def_id, sym::macro_export) { - let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id); - let item = self.cx.tcx.hir().expect_item(hir_id); - top_level_module.items.push((item, None)); + if !inserted.insert(def_id) { + let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id); + let item = self.cx.tcx.hir().expect_item(hir_id); + top_level_module.items.push((item, None)); + } } } } From e252274fb1ebcb2c83bc3b1ebb35456d34e942f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Oct 2021 02:12:18 +0200 Subject: [PATCH 077/181] Add regression test for #89852 --- src/test/rustdoc-json/reexport/macro.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/rustdoc-json/reexport/macro.rs diff --git a/src/test/rustdoc-json/reexport/macro.rs b/src/test/rustdoc-json/reexport/macro.rs new file mode 100644 index 0000000000000..b86614ffbad68 --- /dev/null +++ b/src/test/rustdoc-json/reexport/macro.rs @@ -0,0 +1,17 @@ +// edition:2018 + +#![no_core] +#![feature(no_core)] + +// @count macro.json "$.index[*][?(@.name=='macro')].inner.items[*]" 2 + +// @set repro_id = macro.json "$.index[*][?(@.name=='repro')].id" +// @has - "$.index[*][?(@.name=='macro')].inner.items[*]" $repro_id +#[macro_export] +macro_rules! repro { + () => {}; +} + +// @set repro2_id = macro.json "$.index[*][?(@.inner.name=='repro2')].id" +// @has - "$.index[*][?(@.name=='macro')].inner.items[*]" $repro2_id +pub use crate::repro as repro2; From d18502d6b347732a16dd45811d55111277802611 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Wed, 13 Oct 2021 23:24:48 +0000 Subject: [PATCH 078/181] Suggest Box::pin when Pin::new is used instead --- .../src/check/fn_ctxt/suggestions.rs | 90 ++++++++++++------- .../expected-boxed-future-isnt-pinned.rs | 3 - .../expected-boxed-future-isnt-pinned.stderr | 17 ++-- 3 files changed, 67 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 339c46616a590..babc06822ac52 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -8,11 +8,11 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::lang_items::LangItem; -use rustc_hir::{Expr, ExprKind, ItemKind, Node, Stmt, StmtKind}; +use rustc_hir::{Expr, ExprKind, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind}; use rustc_infer::infer; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{self, Binder, Ty}; -use rustc_span::symbol::kw; +use rustc_span::symbol::{kw, sym}; use std::iter; @@ -350,6 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// When encountering an `impl Future` where `BoxFuture` is expected, suggest `Box::pin`. + #[instrument(skip(self, err))] pub(in super::super) fn suggest_calling_boxed_future_when_appropriate( &self, err: &mut DiagnosticBuilder<'_>, @@ -368,41 +369,70 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() { return false; } - match expected.kind() { - ty::Adt(def, _) if Some(def.did) == pin_did => (), - _ => return false, - } let box_found = self.tcx.mk_box(found); let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); let pin_found = self.tcx.mk_lang_item(found, LangItem::Pin).unwrap(); - if self.can_coerce(pin_box_found, expected) { - debug!("can coerce {:?} to {:?}, suggesting Box::pin", pin_box_found, expected); - match found.kind() { - ty::Adt(def, _) if def.is_box() => { - err.help("use `Box::pin`"); - } - _ => { - err.multipart_suggestion( - "you need to pin and box this expression", - vec![ - (expr.span.shrink_to_lo(), "Box::pin(".to_string()), - (expr.span.shrink_to_hi(), ")".to_string()), - ], - Applicability::MaybeIncorrect, - ); + match expected.kind() { + ty::Adt(def, _) if Some(def.did) == pin_did => { + if self.can_coerce(pin_box_found, expected) { + debug!("can coerce {:?} to {:?}, suggesting Box::pin", pin_box_found, expected); + match found.kind() { + ty::Adt(def, _) if def.is_box() => { + err.help("use `Box::pin`"); + } + _ => { + err.multipart_suggestion( + "you need to pin and box this expression", + vec![ + (expr.span.shrink_to_lo(), "Box::pin(".to_string()), + (expr.span.shrink_to_hi(), ")".to_string()), + ], + Applicability::MaybeIncorrect, + ); + } + } + true + } else if self.can_coerce(pin_found, expected) { + match found.kind() { + ty::Adt(def, _) if def.is_box() => { + err.help("use `Box::pin`"); + true + } + _ => false, + } + } else { + false } } - true - } else if self.can_coerce(pin_found, expected) { - match found.kind() { - ty::Adt(def, _) if def.is_box() => { - err.help("use `Box::pin`"); - true + ty::Adt(def, _) if def.is_box() && self.can_coerce(box_found, expected) => { + // Check if the parent expression is a call to Pin::new. If it + // is and we were expecting a Box, ergo Pin>, we + // can suggest Box::pin. + let parent = self.tcx.hir().get_parent_node(expr.hir_id); + let fn_name = match self.tcx.hir().find(parent) { + Some(Node::Expr(Expr { kind: ExprKind::Call(fn_name, _), .. })) => fn_name, + _ => return false, + }; + match fn_name.kind { + ExprKind::Path(QPath::TypeRelative( + hir::Ty { + kind: TyKind::Path(QPath::Resolved(_, Path { res: recv_ty, .. })), + .. + }, + method, + )) if Some(recv_ty.def_id()) == pin_did && method.ident.name == sym::new => { + err.span_suggestion( + fn_name.span, + "use `Box::pin` to pin and box this expression", + "Box::pin".to_string(), + Applicability::MachineApplicable, + ); + true + } + _ => false, } - _ => false, } - } else { - false + _ => false, } } diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs index 89a36e89b0acf..7e9c5492d1a6b 100644 --- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs +++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs @@ -15,9 +15,6 @@ fn bar + Send + 'static>(x: F) -> BoxFuture<'static, i32> Box::new(x) //~ ERROR mismatched types } -// This case is still subpar: -// `Pin::new(x)`: store this in the heap by calling `Box::new`: `Box::new(x)` -// Should suggest changing the code from `Pin::new` to `Box::pin`. fn baz + Send + 'static>(x: F) -> BoxFuture<'static, i32> { Pin::new(x) //~ ERROR mismatched types //~^ ERROR E0277 diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr index f0af37e0cbe8a..aa3175dae2e66 100644 --- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr +++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr @@ -27,23 +27,20 @@ LL | Box::new(x) = help: use `Box::pin` error[E0308]: mismatched types - --> $DIR/expected-boxed-future-isnt-pinned.rs:22:14 + --> $DIR/expected-boxed-future-isnt-pinned.rs:19:14 | LL | fn baz + Send + 'static>(x: F) -> BoxFuture<'static, i32> { | - this type parameter LL | Pin::new(x) - | ^ expected struct `Box`, found type parameter `F` + | -------- ^ expected struct `Box`, found type parameter `F` + | | + | help: use `Box::pin` to pin and box this expression: `Box::pin` | = note: expected struct `Box + Send>` found type parameter `F` - = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html -help: store this in the heap by calling `Box::new` - | -LL | Pin::new(Box::new(x)) - | +++++++++ + error[E0277]: `dyn Future + Send` cannot be unpinned - --> $DIR/expected-boxed-future-isnt-pinned.rs:22:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:19:5 | LL | Pin::new(x) | ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future + Send` @@ -56,7 +53,7 @@ LL | pub const fn new(pointer: P) -> Pin

{ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: `dyn Future + Send` cannot be unpinned - --> $DIR/expected-boxed-future-isnt-pinned.rs:27:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:24:5 | LL | Pin::new(Box::new(x)) | ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future + Send` @@ -69,7 +66,7 @@ LL | pub const fn new(pointer: P) -> Pin

{ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/expected-boxed-future-isnt-pinned.rs:31:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:28:5 | LL | fn zap() -> BoxFuture<'static, i32> { | ----------------------- expected `Pin + Send + 'static)>>` because of return type From 4b59b35b76e9d14205f8b11f26bbf5920f8f936b Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Thu, 14 Oct 2021 13:47:54 +1100 Subject: [PATCH 079/181] Add missing word to `FromStr` trait docs --- library/core/src/str/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index 12d79a56a527c..e225776bc647f 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -536,7 +536,7 @@ pub trait FromStr: Sized { /// /// If parsing succeeds, return the value inside [`Ok`], otherwise /// when the string is ill-formatted return an error specific to the - /// inside [`Err`]. The error type is specific to implementation of the trait. + /// inside [`Err`]. The error type is specific to the implementation of the trait. /// /// # Examples /// From 8514b0097b28f84ee5cfead059a5771c6a693fb0 Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Wed, 13 Oct 2021 17:44:39 +0200 Subject: [PATCH 080/181] Selecting the Xcode version no longer needed with the macos-11 runners. --- .github/workflows/ci.yml | 10 ---------- src/ci/github-actions/ci.yml | 5 ----- src/ci/scripts/select-xcode.sh | 13 ------------- 3 files changed, 28 deletions(-) delete mode 100755 src/ci/scripts/select-xcode.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78ff874e75501..d921286ba3489 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,9 +92,6 @@ jobs: - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - if: success() && !env.SKIP_JOB - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB @@ -322,7 +319,6 @@ jobs: SCRIPT: "./x.py dist --stage 2" RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --host=aarch64-apple-darwin --target=aarch64-apple-darwin --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false" RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 - SELECT_XCODE: /Applications/Xcode_12.2.app USE_XCODE_CLANG: 1 MACOSX_DEPLOYMENT_TARGET: 11.0 MACOSX_STD_DEPLOYMENT_TARGET: 11.0 @@ -467,9 +463,6 @@ jobs: - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - if: success() && !env.SKIP_JOB - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB @@ -580,9 +573,6 @@ jobs: - name: install sccache run: src/ci/scripts/install-sccache.sh if: success() && !env.SKIP_JOB - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - if: success() && !env.SKIP_JOB - name: install clang run: src/ci/scripts/install-clang.sh if: success() && !env.SKIP_JOB diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index c9f8692d41887..eb16cf3c7620a 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -153,10 +153,6 @@ x--expand-yaml-anchors--remove: run: src/ci/scripts/install-sccache.sh <<: *step - - name: select Xcode - run: src/ci/scripts/select-xcode.sh - <<: *step - - name: install clang run: src/ci/scripts/install-clang.sh <<: *step @@ -498,7 +494,6 @@ jobs: --set rust.jemalloc --set llvm.ninja=false RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 - SELECT_XCODE: /Applications/Xcode_12.2.app USE_XCODE_CLANG: 1 MACOSX_DEPLOYMENT_TARGET: 11.0 MACOSX_STD_DEPLOYMENT_TARGET: 11.0 diff --git a/src/ci/scripts/select-xcode.sh b/src/ci/scripts/select-xcode.sh deleted file mode 100755 index 3b9c77d42ba5f..0000000000000 --- a/src/ci/scripts/select-xcode.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# This script selects the Xcode instance to use. - -set -euo pipefail -IFS=$'\n\t' - -source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" - -if isMacOS; then - if [[ -s "${SELECT_XCODE-}" ]]; then - sudo xcode-select -s "${SELECT_XCODE}" - fi -fi From 6770dbd4b5729677bcca6a4c73d3335e523a7ac9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 14 Oct 2021 06:18:53 +0000 Subject: [PATCH 081/181] Avoid tupling at the callee --- library/core/src/intrinsics.rs | 12 +++--- .../ui/intrinsics/const-eval-select-bad.rs | 12 +++--- .../intrinsics/const-eval-select-bad.stderr | 42 ++++++++++--------- .../ui/intrinsics/const-eval-select-x86_64.rs | 4 +- src/test/ui/intrinsics/const-eval-select.rs | 4 +- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index da0591418f072..54d0805550ac5 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2266,10 +2266,10 @@ pub const unsafe fn const_eval_select( called_at_rt: G, ) -> RET where - F: ~const FnOnce(ARG) -> RET, - G: FnOnce(ARG) -> RET + ~const Drop, + F: ~const FnOnce, + G: FnOnce + ~const Drop, { - called_at_rt(arg) + called_at_rt.call_once(arg) } #[cfg(not(bootstrap))] @@ -2285,8 +2285,8 @@ pub const unsafe fn const_eval_select_ct( _called_at_rt: G, ) -> RET where - F: ~const FnOnce(ARG) -> RET, - G: FnOnce(ARG) -> RET + ~const Drop, + F: ~const FnOnce, + G: FnOnce + ~const Drop, { - called_in_const(arg) + called_in_const.call_once(arg) } diff --git a/src/test/ui/intrinsics/const-eval-select-bad.rs b/src/test/ui/intrinsics/const-eval-select-bad.rs index 1e5bf7a70b8c4..8fbdc0c39c6aa 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.rs +++ b/src/test/ui/intrinsics/const-eval-select-bad.rs @@ -3,22 +3,22 @@ use std::intrinsics::const_eval_select; const fn not_fn_items() { - const_eval_select((), |()| {}, |()| {}); - //~^ ERROR expected a `FnOnce<((),)>` closure + const_eval_select((), || {}, || {}); + //~^ ERROR expected a `FnOnce<()>` closure const_eval_select((), 42, 0xDEADBEEF); - //~^ ERROR expected a `FnOnce<((),)>` closure + //~^ ERROR expected a `FnOnce<()>` closure } -const fn foo((n,): (i32,)) -> i32 { +const fn foo(n: i32) -> i32 { n } -fn bar((n,): (i32,)) -> bool { +fn bar(n: i32) -> bool { assert_eq!(n, 0, "{} must be equal to {}", n, 0); n == 0 } -fn baz((n,): (bool,)) -> i32 { +fn baz(n: bool) -> i32 { assert!(n, "{} must be true", n); n as i32 } diff --git a/src/test/ui/intrinsics/const-eval-select-bad.stderr b/src/test/ui/intrinsics/const-eval-select-bad.stderr index a38eb627e341d..78647e92138c2 100644 --- a/src/test/ui/intrinsics/const-eval-select-bad.stderr +++ b/src/test/ui/intrinsics/const-eval-select-bad.stderr @@ -1,34 +1,36 @@ -error[E0277]: expected a `FnOnce<((),)>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` - --> $DIR/const-eval-select-bad.rs:6:36 +error[E0277]: expected a `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` + --> $DIR/const-eval-select-bad.rs:6:34 | -LL | const_eval_select((), |()| {}, |()| {}); - | ----------------- ^^^^^^^ expected an `FnOnce<((),)>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` +LL | const_eval_select((), || {}, || {}); + | ----------------- ^^^^^ expected an `FnOnce<()>` closure, found `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` | | | required by a bound introduced by this call | - = help: the trait `FnOnce<((),)>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:34]` + = help: the trait `FnOnce<()>` is not implemented for `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` + = note: wrap the `[closure@$DIR/const-eval-select-bad.rs:6:27: 6:32]` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | -LL | F: ~const FnOnce(ARG) -> RET, - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` +LL | F: ~const FnOnce, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` -error[E0277]: expected a `FnOnce<((),)>` closure, found `{integer}` +error[E0277]: expected a `FnOnce<()>` closure, found `{integer}` --> $DIR/const-eval-select-bad.rs:8:31 | LL | const_eval_select((), 42, 0xDEADBEEF); - | ----------------- ^^^^^^^^^^ expected an `FnOnce<((),)>` closure, found `{integer}` + | ----------------- ^^^^^^^^^^ expected an `FnOnce<()>` closure, found `{integer}` | | | required by a bound introduced by this call | - = help: the trait `FnOnce<((),)>` is not implemented for `{integer}` + = help: the trait `FnOnce<()>` is not implemented for `{integer}` + = note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | -LL | F: ~const FnOnce(ARG) -> RET, - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` +LL | F: ~const FnOnce, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` -error[E0271]: type mismatch resolving ` bool {bar} as FnOnce<((i32,),)>>::Output == i32` +error[E0271]: type mismatch resolving ` bool {bar} as FnOnce<(i32,)>>::Output == i32` --> $DIR/const-eval-select-bad.rs:27:5 | LL | const_eval_select((1,), foo, bar); @@ -37,25 +39,25 @@ LL | const_eval_select((1,), foo, bar); note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | -LL | G: FnOnce(ARG) -> RET + ~const Drop, - | ^^^ required by this bound in `const_eval_select` +LL | G: FnOnce + ~const Drop, + | ^^^^^^^^^^^^ required by this bound in `const_eval_select` error[E0631]: type mismatch in function arguments --> $DIR/const-eval-select-bad.rs:32:37 | -LL | const fn foo((n,): (i32,)) -> i32 { - | --------------------------------- found signature of `fn((i32,)) -> _` +LL | const fn foo(n: i32) -> i32 { + | --------------------------- found signature of `fn(i32) -> _` ... LL | const_eval_select((true,), foo, baz); - | ----------------- ^^^ expected signature of `fn((bool,)) -> _` + | ----------------- ^^^ expected signature of `fn(bool) -> _` | | | required by a bound introduced by this call | note: required by a bound in `const_eval_select` --> $SRC_DIR/core/src/intrinsics.rs:LL:COL | -LL | F: ~const FnOnce(ARG) -> RET, - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` +LL | F: ~const FnOnce, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `const_eval_select` error: aborting due to 4 previous errors diff --git a/src/test/ui/intrinsics/const-eval-select-x86_64.rs b/src/test/ui/intrinsics/const-eval-select-x86_64.rs index 807db65bc72d9..afec8e054bb76 100644 --- a/src/test/ui/intrinsics/const-eval-select-x86_64.rs +++ b/src/test/ui/intrinsics/const-eval-select-x86_64.rs @@ -6,11 +6,11 @@ use std::intrinsics::const_eval_select; use std::arch::x86_64::*; use std::mem::transmute; -const fn eq_ct((x, y): ([i32; 4], [i32; 4])) -> bool { +const fn eq_ct(x: [i32; 4], y: [i32; 4]) -> bool { x[0] == y[0] && x[1] == y[1] && x[2] == y[2] && x[3] == y[3] } -fn eq_rt((x, y): ([i32; 4], [i32; 4])) -> bool { +fn eq_rt(x: [i32; 4], y: [i32; 4]) -> bool { unsafe { let x = _mm_loadu_si128(&x as *const _ as *const _); let y = _mm_loadu_si128(&y as *const _ as *const _); diff --git a/src/test/ui/intrinsics/const-eval-select.rs b/src/test/ui/intrinsics/const-eval-select.rs index 0b2c2f6ed4f06..744db2f15b056 100644 --- a/src/test/ui/intrinsics/const-eval-select.rs +++ b/src/test/ui/intrinsics/const-eval-select.rs @@ -4,11 +4,11 @@ use std::intrinsics::const_eval_select; -const fn yes(_: ()) -> bool { +const fn yes() -> bool { true } -fn no(_: ()) -> bool { +fn no() -> bool { false } From 26b78ccd317d7950e0aa9861c7c8e643d92d77cf Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 14 Oct 2021 06:53:20 +0000 Subject: [PATCH 082/181] Fix const stability --- .../src/transform/check_consts/check.rs | 7 +++++-- library/core/src/intrinsics.rs | 2 ++ .../intrinsics/const-eval-select-stability.rs | 20 +++++++++++++++++++ .../const-eval-select-stability.stderr | 10 ++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/intrinsics/const-eval-select-stability.rs create mode 100644 src/test/ui/intrinsics/const-eval-select-stability.stderr diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 22f14ffbd583a..d704c4335c754 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -24,7 +24,7 @@ use std::ops::Deref; use super::ops::{self, NonConstOp, Status}; use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop}; use super::resolver::FlowSensitiveAnalysis; -use super::{is_lang_special_const_fn, ConstCx, Qualif}; +use super::{is_lang_panic_fn, is_lang_special_const_fn, ConstCx, Qualif}; use crate::const_eval::is_unstable_const_fn; // We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated @@ -910,7 +910,10 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> { } } - return; + if is_lang_panic_fn(tcx, callee) { + // run stability check on non-panic special const fns. + return; + } } if Some(callee) == tcx.lang_items().exchange_malloc_fn() { diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 54d0805550ac5..886ace193c428 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2258,6 +2258,7 @@ pub unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { issue = "none", reason = "const_eval_select will never be stable" )] +#[rustc_const_unstable(feature = "const_eval_select", issue = "none")] #[lang = "const_eval_select"] #[rustc_do_not_const_check] pub const unsafe fn const_eval_select( @@ -2278,6 +2279,7 @@ where issue = "none", reason = "const_eval_select will never be stable" )] +#[rustc_const_unstable(feature = "const_eval_select", issue = "none")] #[lang = "const_eval_select_ct"] pub const unsafe fn const_eval_select_ct( arg: ARG, diff --git a/src/test/ui/intrinsics/const-eval-select-stability.rs b/src/test/ui/intrinsics/const-eval-select-stability.rs new file mode 100644 index 0000000000000..db2462aee5922 --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select-stability.rs @@ -0,0 +1,20 @@ +#![feature(staged_api)] +#![feature(const_eval_select)] +#![stable(since = "1.0", feature = "ui_test")] + +use std::intrinsics::const_eval_select; + +fn log() { + println!("HEY HEY HEY") +} + +const fn nothing(){} + +#[stable(since = "1.0", feature = "hey")] +#[rustc_const_stable(since = "1.0", feature = "const_hey")] +pub const unsafe fn hey() { + const_eval_select((), nothing, log); + //~^ ERROR `const_eval_select` is not yet stable as a const fn +} + +fn main() {} diff --git a/src/test/ui/intrinsics/const-eval-select-stability.stderr b/src/test/ui/intrinsics/const-eval-select-stability.stderr new file mode 100644 index 0000000000000..79641bbb46abe --- /dev/null +++ b/src/test/ui/intrinsics/const-eval-select-stability.stderr @@ -0,0 +1,10 @@ +error: `const_eval_select` is not yet stable as a const fn + --> $DIR/const-eval-select-stability.rs:16:5 + | +LL | const_eval_select((), nothing, log); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: const-stable functions can only call other const-stable functions + +error: aborting due to previous error + From 11fac09eadc3a60982e46e2fed177d6b0a686041 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 14 Oct 2021 07:35:35 +0000 Subject: [PATCH 083/181] fix codegen test --- src/test/codegen/intrinsics/const_eval_select.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/codegen/intrinsics/const_eval_select.rs b/src/test/codegen/intrinsics/const_eval_select.rs index 84777cac7c390..34e653b4b9dd4 100644 --- a/src/test/codegen/intrinsics/const_eval_select.rs +++ b/src/test/codegen/intrinsics/const_eval_select.rs @@ -5,10 +5,10 @@ use std::intrinsics::const_eval_select; -const fn foo(_: (i32,)) -> i32 { 1 } +const fn foo(_: i32) -> i32 { 1 } #[no_mangle] -pub fn hi((n,): (i32,)) -> i32 { n } +pub fn hi(n: i32) -> i32 { n } #[no_mangle] pub unsafe fn hey() { From 7d6cfb7754988b95f05a7dec8a26bc41c47ca5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Oct 2021 10:50:46 +0200 Subject: [PATCH 084/181] Oops, inverted condition, fix that --- src/librustdoc/visit_ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 3e38ac822f50a..f60d4e1f29537 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -97,7 +97,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { if let Res::Def(DefKind::Macro(_), def_id) = export.res { if let Some(local_def_id) = def_id.as_local() { if self.cx.tcx.has_attr(def_id, sym::macro_export) { - if !inserted.insert(def_id) { + if inserted.insert(def_id) { let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id); let item = self.cx.tcx.hir().expect_item(hir_id); top_level_module.items.push((item, None)); From 30a20f8c83161b17be9d550b1d4fd458c05117a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 14 Oct 2021 11:39:30 +0200 Subject: [PATCH 085/181] Fix missing remaining compiler specific cfg information --- library/alloc/src/lib.rs | 1 + library/std/src/lib.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 89ab11fb97e10..e86c41b1ff887 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -74,6 +74,7 @@ not(any(test, bootstrap)), any(not(feature = "miri-test-libstd"), test, doctest), no_global_oom_handling, + not(no_global_oom_handling), target_has_atomic = "ptr" )) )] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index b16436a18f0af..1d2d26b8f0046 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -195,7 +195,15 @@ test(no_crate_inject, attr(deny(warnings))), test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) )] -#![cfg_attr(not(bootstrap), doc(cfg_hide(not(test), not(any(test, bootstrap)))))] +#![cfg_attr( + not(bootstrap), + doc(cfg_hide( + not(test), + not(any(test, bootstrap)), + no_global_oom_handling, + not(no_global_oom_handling) + )) +)] // Don't link to std. We are std. #![no_std] #![warn(deprecated_in_future)] From af5b146324e2a20a432649723cf8d22487b1e499 Mon Sep 17 00:00:00 2001 From: Adam Gemmell Date: Wed, 13 Oct 2021 10:44:02 +0100 Subject: [PATCH 086/181] Use non-checking TLS relocation in aarch64 asm! sym test. The checking variant ensures that the offset required is not larger than 12 bits - hence we wouldn't ever need the upper 12 bits. --- src/test/ui/asm/aarch64/sym.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/asm/aarch64/sym.rs b/src/test/ui/asm/aarch64/sym.rs index db732e96b80b6..6fd1192eec6e0 100644 --- a/src/test/ui/asm/aarch64/sym.rs +++ b/src/test/ui/asm/aarch64/sym.rs @@ -55,7 +55,7 @@ macro_rules! static_tls_addr { // Add the top 12 bits of the symbol's offset "add {out}, {out}, :tprel_hi12:{sym}", // And the bottom 12 bits - "add {out}, {out}, :tprel_lo12:{sym}", + "add {out}, {out}, :tprel_lo12_nc:{sym}", out = out(reg) result, sym = sym $s ); From cf12732a38a2c038c8cbd5e0266cb38c43cb0c5d Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Thu, 14 Oct 2021 09:31:34 -0400 Subject: [PATCH 087/181] don't duplicate slice `panic_bounds_check` --- library/core/src/slice/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 8108d52071b26..c0e0589d5edee 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -560,8 +560,8 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn swap(&mut self, a: usize, b: usize) { - assert_in_bounds(self.len(), a); - assert_in_bounds(self.len(), b); + let _ = &self[a]; + let _ = &self[b]; // SAFETY: we just checked that both `a` and `b` are in bounds unsafe { self.swap_unchecked(a, b) } @@ -598,8 +598,8 @@ impl [T] { pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { #[cfg(debug_assertions)] { - assert_in_bounds(self.len(), a); - assert_in_bounds(self.len(), b); + let _ = &self[a]; + let _ = &self[b]; } let ptr = self.as_mut_ptr(); @@ -3502,12 +3502,6 @@ impl [T] { } } -fn assert_in_bounds(len: usize, idx: usize) { - if idx >= len { - panic!("index out of bounds: the len is {} but the index is {}", len, idx); - } -} - trait CloneFromSpec { fn spec_clone_from(&mut self, src: &[T]); } From c5a68cf0a65fe94022f5c5fd0fc47ccfcda81929 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Oct 2021 16:53:09 -0400 Subject: [PATCH 088/181] add dedicated error variant for writing the discriminant of an uninhabited enum variant --- .../rustc_const_eval/src/interpret/operand.rs | 1 + compiler/rustc_const_eval/src/interpret/place.rs | 15 ++++++++++++++- compiler/rustc_middle/src/mir/interpret/error.rs | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index de870bd5c6cf1..b6682b13ed216 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -618,6 +618,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } /// Read discriminant, return the runtime value as well as the variant index. + /// Can also legally be called on non-enums (e.g. through the discriminant_value intrinsic)! pub fn read_discriminant( &self, op: &OpTy<'tcx, M::PointerTag>, diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 0da6d8169bd3a..d425b84bdaf26 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -988,10 +988,23 @@ where variant_index: VariantIdx, dest: &PlaceTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx> { + // This must be an enum or generator. + match dest.layout.ty.kind() { + ty::Adt(adt, _) => assert!(adt.is_enum()), + ty::Generator(..) => {} + _ => span_bug!( + self.cur_span(), + "write_discriminant called on non-variant-type (neither enum nor generator)" + ), + } // Layout computation excludes uninhabited variants from consideration // therefore there's no way to represent those variants in the given layout. + // Essentially, uninhabited variants do not have a tag that corresponds to their + // discriminant, so we cannot do anything here. + // When evaluating we will always error before even getting here, but ConstProp 'executes' + // dead code, so we cannot ICE here. if dest.layout.for_variant(self, variant_index).abi.is_uninhabited() { - throw_ub!(Unreachable); + throw_ub!(UninhabitedEnumVariantWritten) } match dest.layout.variants { diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index 5d17bb9b15f4b..9472a287e5a41 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -287,6 +287,8 @@ pub enum UndefinedBehaviorInfo<'tcx> { target_size: u64, data_size: u64, }, + /// A discriminant of an uninhabited enum variant is written. + UninhabitedEnumVariantWritten, } impl fmt::Display for UndefinedBehaviorInfo<'_> { @@ -391,6 +393,9 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> { "scalar size mismatch: expected {} bytes but got {} bytes instead", target_size, data_size ), + UninhabitedEnumVariantWritten => { + write!(f, "writing discriminant of an uninhabited enum") + } } } } From 8485e6fdece723152c024228284ca76592108f72 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Oct 2021 10:57:56 -0400 Subject: [PATCH 089/181] Revert "Stabilize `arbitrary_enum_discriminant`" This reverts commit 7a62f29f3171767090949778ce0f161e930706b9. --- compiler/rustc_ast_passes/src/feature_gate.rs | 64 ++++++++++++++++++- .../src/error_codes/E0732.md | 4 ++ compiler/rustc_feature/src/accepted.rs | 2 - compiler/rustc_feature/src/active.rs | 3 + compiler/rustc_typeck/src/check/check.rs | 2 +- .../arbitrary-enum-discriminant.md | 37 +++++++++++ .../arbitrary_enum_discriminant-no-repr.rs | 1 + ...arbitrary_enum_discriminant-no-repr.stderr | 2 +- .../arbitrary_enum_discriminant.rs | 2 +- .../enum-discriminant/discriminant_value.rs | 2 +- ...eature-gate-arbitrary_enum_discriminant.rs | 10 +++ ...re-gate-arbitrary_enum_discriminant.stderr | 36 +++++++++++ .../issue-70453-generics-in-discr-ice-2.rs | 2 +- .../issue-70453-polymorphic-ctfe.rs | 2 +- .../issue-70509-partial_eq.rs | 2 +- .../issue-70509-partial_eq.stderr | 2 +- .../intrinsics/panic-uninitialized-zeroed.rs | 2 +- src/test/ui/parser/issue-17383.rs | 7 ++ src/test/ui/parser/issue-17383.stderr | 15 +++++ .../ui/parser/tag-variant-disr-non-nullary.rs | 12 ++++ .../tag-variant-disr-non-nullary.stderr | 25 ++++++++ 21 files changed, 221 insertions(+), 13 deletions(-) create mode 100644 src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md create mode 100644 src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs create mode 100644 src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr create mode 100644 src/test/ui/parser/issue-17383.rs create mode 100644 src/test/ui/parser/issue-17383.stderr create mode 100644 src/test/ui/parser/tag-variant-disr-non-nullary.rs create mode 100644 src/test/ui/parser/tag-variant-disr-non-nullary.stderr diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index bce5cd8174d08..91b4597a9bb1f 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -1,11 +1,11 @@ use rustc_ast as ast; use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId}; -use rustc_ast::{PatKind, RangeEnd}; +use rustc_ast::{PatKind, RangeEnd, VariantData}; use rustc_errors::struct_span_err; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; use rustc_feature::{Features, GateIssue}; -use rustc_session::parse::feature_err_issue; +use rustc_session::parse::{feature_err, feature_err_issue}; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; @@ -218,6 +218,46 @@ impl<'a> PostExpansionVisitor<'a> { } } + fn maybe_report_invalid_custom_discriminants(&self, variants: &[ast::Variant]) { + let has_fields = variants.iter().any(|variant| match variant.data { + VariantData::Tuple(..) | VariantData::Struct(..) => true, + VariantData::Unit(..) => false, + }); + + let discriminant_spans = variants + .iter() + .filter(|variant| match variant.data { + VariantData::Tuple(..) | VariantData::Struct(..) => false, + VariantData::Unit(..) => true, + }) + .filter_map(|variant| variant.disr_expr.as_ref().map(|c| c.value.span)) + .collect::>(); + + if !discriminant_spans.is_empty() && has_fields { + let mut err = feature_err( + &self.sess.parse_sess, + sym::arbitrary_enum_discriminant, + discriminant_spans.clone(), + "custom discriminant values are not allowed in enums with tuple or struct variants", + ); + for sp in discriminant_spans { + err.span_label(sp, "disallowed custom discriminant"); + } + for variant in variants.iter() { + match &variant.data { + VariantData::Struct(..) => { + err.span_label(variant.span, "struct variant defined here"); + } + VariantData::Tuple(..) => { + err.span_label(variant.span, "tuple variant defined here"); + } + VariantData::Unit(..) => {} + } + } + err.emit(); + } + } + fn check_gat(&self, generics: &ast::Generics, span: Span) { if !generics.params.is_empty() { gate_feature_post!( @@ -363,6 +403,26 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } + ast::ItemKind::Enum(ast::EnumDef { ref variants, .. }, ..) => { + for variant in variants { + match (&variant.data, &variant.disr_expr) { + (ast::VariantData::Unit(..), _) => {} + (_, Some(disr_expr)) => gate_feature_post!( + &self, + arbitrary_enum_discriminant, + disr_expr.value.span, + "discriminants on non-unit variants are experimental" + ), + _ => {} + } + } + + let has_feature = self.features.arbitrary_enum_discriminant; + if !has_feature && !i.span.allows_unstable(sym::arbitrary_enum_discriminant) { + self.maybe_report_invalid_custom_discriminants(&variants); + } + } + ast::ItemKind::Impl(box ast::ImplKind { polarity, defaultness, ref of_trait, .. }) => { diff --git a/compiler/rustc_error_codes/src/error_codes/E0732.md b/compiler/rustc_error_codes/src/error_codes/E0732.md index 9536fdbf0df87..7347e6654c5b3 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0732.md +++ b/compiler/rustc_error_codes/src/error_codes/E0732.md @@ -3,6 +3,8 @@ An `enum` with a discriminant must specify a `#[repr(inttype)]`. Erroneous code example: ```compile_fail,E0732 +#![feature(arbitrary_enum_discriminant)] + enum Enum { // error! Unit = 1, Tuple() = 2, @@ -18,6 +20,8 @@ is a well-defined way to extract a variant's discriminant from a value; for instance: ``` +#![feature(arbitrary_enum_discriminant)] + #[repr(u8)] enum Enum { Unit = 3, diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 55ec3703df8f8..0d7a2afb6367d 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -293,8 +293,6 @@ declare_features! ( (accepted, const_fn_transmute, "1.56.0", Some(53605), None), /// Allows accessing fields of unions inside `const` functions. (accepted, const_fn_union, "1.56.0", Some(51909), None), - /// Allows explicit discriminants on non-unit enum variants. - (accepted, arbitrary_enum_discriminant, "1.56.0", Some(60553), None), /// Allows macro attributes to observe output of `#[derive]`. (accepted, macro_attributes_in_derive_output, "1.57.0", Some(81119), None), /// Allows panicking during const eval (producing compile-time errors). diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index a2fadb13a5741..f7c0597909e8b 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -464,6 +464,9 @@ declare_features! ( /// Allows #[repr(transparent)] on unions (RFC 2645). (active, transparent_unions, "1.37.0", Some(60405), None), + /// Allows explicit discriminants on non-unit enum variants. + (active, arbitrary_enum_discriminant, "1.37.0", Some(60553), None), + /// Allows `async || body` closures. (active, async_closure, "1.37.0", Some(62290), None), diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index db50c5d891e13..66316214e5e66 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -1374,7 +1374,7 @@ fn check_enum<'tcx>( } } - if tcx.adt_def(def_id).repr.int.is_none() { + if tcx.adt_def(def_id).repr.int.is_none() && tcx.features().arbitrary_enum_discriminant { let is_unit = |var: &hir::Variant<'_>| matches!(var.data, hir::VariantData::Unit(..)); let has_disr = |var: &hir::Variant<'_>| var.disr_expr.is_some(); diff --git a/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md b/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md new file mode 100644 index 0000000000000..e0bb782270e22 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md @@ -0,0 +1,37 @@ +# `arbitrary_enum_discriminant` + +The tracking issue for this feature is: [#60553] + +[#60553]: https://github.com/rust-lang/rust/issues/60553 + +------------------------ + +The `arbitrary_enum_discriminant` feature permits tuple-like and +struct-like enum variants with `#[repr()]` to have explicit discriminants. + +## Examples + +```rust +#![feature(arbitrary_enum_discriminant)] + +#[allow(dead_code)] +#[repr(u8)] +enum Enum { + Unit = 3, + Tuple(u16) = 2, + Struct { + a: u8, + b: u16, + } = 1, +} + +impl Enum { + fn tag(&self) -> u8 { + unsafe { *(self as *const Self as *const u8) } + } +} + +assert_eq!(3, Enum::Unit.tag()); +assert_eq!(2, Enum::Tuple(5).tag()); +assert_eq!(1, Enum::Struct{a: 7, b: 11}.tag()); +``` diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs index a6e5f70fdefa6..4da7b5ab24b29 100644 --- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs +++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs @@ -1,4 +1,5 @@ #![crate_type="lib"] +#![feature(arbitrary_enum_discriminant)] enum Enum { //~^ ERROR `#[repr(inttype)]` must be specified diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr index 7af063c591d56..2db5372da0c6e 100644 --- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr +++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr @@ -1,5 +1,5 @@ error[E0732]: `#[repr(inttype)]` must be specified - --> $DIR/arbitrary_enum_discriminant-no-repr.rs:3:1 + --> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1 | LL | / enum Enum { LL | | diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs index 360bddb7bd1e4..f2270602d87eb 100644 --- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs +++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(const_raw_ptr_deref, test)] +#![feature(arbitrary_enum_discriminant, const_raw_ptr_deref, test)] extern crate test; diff --git a/src/test/ui/enum-discriminant/discriminant_value.rs b/src/test/ui/enum-discriminant/discriminant_value.rs index 7ed1d9660a69c..eb60aaf4b2d04 100644 --- a/src/test/ui/enum-discriminant/discriminant_value.rs +++ b/src/test/ui/enum-discriminant/discriminant_value.rs @@ -1,6 +1,6 @@ // run-pass #![allow(stable_features)] -#![feature(core, core_intrinsics)] +#![feature(arbitrary_enum_discriminant, core, core_intrinsics)] extern crate core; use core::intrinsics::discriminant_value; diff --git a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs new file mode 100644 index 0000000000000..3e90af4d36af3 --- /dev/null +++ b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs @@ -0,0 +1,10 @@ +#![crate_type="lib"] + +enum Enum { + Unit = 1, + //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants + Tuple() = 2, + //~^ ERROR discriminants on non-unit variants are experimental + Struct{} = 3, + //~^ ERROR discriminants on non-unit variants are experimental +} diff --git a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr new file mode 100644 index 0000000000000..b5f61e6e991d8 --- /dev/null +++ b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr @@ -0,0 +1,36 @@ +error[E0658]: discriminants on non-unit variants are experimental + --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:6:13 + | +LL | Tuple() = 2, + | ^ + | + = note: see issue #60553 for more information + = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable + +error[E0658]: discriminants on non-unit variants are experimental + --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:8:14 + | +LL | Struct{} = 3, + | ^ + | + = note: see issue #60553 for more information + = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable + +error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants + --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:4:10 + | +LL | Unit = 1, + | ^ disallowed custom discriminant +LL | +LL | Tuple() = 2, + | ----------- tuple variant defined here +LL | +LL | Struct{} = 3, + | ------------ struct variant defined here + | + = note: see issue #60553 for more information + = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs index ad9fcc25b4127..f927dd189038a 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs @@ -1,4 +1,4 @@ -#![feature(core_intrinsics)] +#![feature(arbitrary_enum_discriminant, core_intrinsics)] extern crate core; use core::intrinsics::discriminant_value; diff --git a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs index 42a062239d34a..e62582fb5161a 100644 --- a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs +++ b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs @@ -1,4 +1,4 @@ -#![feature(core_intrinsics)] +#![feature(arbitrary_enum_discriminant, core_intrinsics)] extern crate core; use core::intrinsics::discriminant_value; diff --git a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs index 3adac7b72621c..ae389e1146645 100644 --- a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs +++ b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs @@ -1,5 +1,5 @@ // run-pass -#![feature(repr128)] +#![feature(repr128, arbitrary_enum_discriminant)] //~^ WARN the feature `repr128` is incomplete #[derive(PartialEq, Debug)] diff --git a/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr b/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr index 04fb13f37a006..5bf6ea56ebc77 100644 --- a/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr +++ b/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr @@ -1,7 +1,7 @@ warning: the feature `repr128` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/issue-70509-partial_eq.rs:2:12 | -LL | #![feature(repr128)] +LL | #![feature(repr128, arbitrary_enum_discriminant)] | ^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs index 50f1a2f25b95d..324bba15e4350 100644 --- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs +++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs @@ -6,7 +6,7 @@ // This test checks panic emitted from `mem::{uninitialized,zeroed}`. -#![feature(never_type)] +#![feature(never_type, arbitrary_enum_discriminant)] #![allow(deprecated, invalid_value)] use std::{ diff --git a/src/test/ui/parser/issue-17383.rs b/src/test/ui/parser/issue-17383.rs new file mode 100644 index 0000000000000..7bf0e64f2c0a3 --- /dev/null +++ b/src/test/ui/parser/issue-17383.rs @@ -0,0 +1,7 @@ +enum X { + A = 3, + //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants + B(usize) +} + +fn main() {} diff --git a/src/test/ui/parser/issue-17383.stderr b/src/test/ui/parser/issue-17383.stderr new file mode 100644 index 0000000000000..265d6e1486614 --- /dev/null +++ b/src/test/ui/parser/issue-17383.stderr @@ -0,0 +1,15 @@ +error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants + --> $DIR/issue-17383.rs:2:9 + | +LL | A = 3, + | ^ disallowed custom discriminant +LL | +LL | B(usize) + | -------- tuple variant defined here + | + = note: see issue #60553 for more information + = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/parser/tag-variant-disr-non-nullary.rs b/src/test/ui/parser/tag-variant-disr-non-nullary.rs new file mode 100644 index 0000000000000..a9cfdd549c752 --- /dev/null +++ b/src/test/ui/parser/tag-variant-disr-non-nullary.rs @@ -0,0 +1,12 @@ +enum Color { + Red = 0xff0000, + //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants + Green = 0x00ff00, + Blue = 0x0000ff, + Black = 0x000000, + White = 0xffffff, + Other(usize), + Other2(usize, usize), +} + +fn main() {} diff --git a/src/test/ui/parser/tag-variant-disr-non-nullary.stderr b/src/test/ui/parser/tag-variant-disr-non-nullary.stderr new file mode 100644 index 0000000000000..79f044a0675b7 --- /dev/null +++ b/src/test/ui/parser/tag-variant-disr-non-nullary.stderr @@ -0,0 +1,25 @@ +error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants + --> $DIR/tag-variant-disr-non-nullary.rs:2:11 + | +LL | Red = 0xff0000, + | ^^^^^^^^ disallowed custom discriminant +LL | +LL | Green = 0x00ff00, + | ^^^^^^^^ disallowed custom discriminant +LL | Blue = 0x0000ff, + | ^^^^^^^^ disallowed custom discriminant +LL | Black = 0x000000, + | ^^^^^^^^ disallowed custom discriminant +LL | White = 0xffffff, + | ^^^^^^^^ disallowed custom discriminant +LL | Other(usize), + | ------------ tuple variant defined here +LL | Other2(usize, usize), + | -------------------- tuple variant defined here + | + = note: see issue #60553 for more information + = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From 2284082ae8e9d422fdacfa7c229d2676d61470a5 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Oct 2021 10:58:16 -0400 Subject: [PATCH 090/181] Drop reverted stabilizations from release notes --- RELEASES.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 63af8ebac195a..52d823d8acac4 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -6,7 +6,6 @@ Language - [The 2021 Edition is now stable.][rust#88100] See [the edition guide][rust-2021-edition-guide] for more details. -- [You can now specify explicit discriminant values on any Rust enum.][rust#86860] - [The pattern in `binding @ pattern` can now also introduce new bindings.][rust#85305] - [Union field access is permitted in `const fn`.][rust#85769] @@ -51,8 +50,6 @@ Stabilised APIs --------------- - [`std::os::unix::fs::chroot`] -- [`Iterator::intersperse`] -- [`Iterator::intersperse_with`] - [`UnsafeCell::raw_get`] - [`BufWriter::into_parts`] - [`core::panic::{UnwindSafe, RefUnwindSafe, AssertUnwindSafe}`] From cca39148f3dc8d3daee7736b4b68231e26f36711 Mon Sep 17 00:00:00 2001 From: cameron1024 Date: Thu, 14 Oct 2021 17:44:04 +0100 Subject: [PATCH 091/181] add long explanation for E0183 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0183.md | 39 +++++++++++++++++++ ...-gate-unboxed-closures-manual-impls.stderr | 4 +- .../feature-gate-unboxed-closures.stderr | 3 +- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0183.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 1b4b58314b356..cd846d63de88b 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -92,6 +92,7 @@ E0164: include_str!("./error_codes/E0164.md"), E0165: include_str!("./error_codes/E0165.md"), E0170: include_str!("./error_codes/E0170.md"), E0178: include_str!("./error_codes/E0178.md"), +E0183: include_str!("./error_codes/E0183.md"), E0184: include_str!("./error_codes/E0184.md"), E0185: include_str!("./error_codes/E0185.md"), E0186: include_str!("./error_codes/E0186.md"), @@ -512,7 +513,6 @@ E0785: include_str!("./error_codes/E0785.md"), // E0173, // manual implementations of unboxed closure traits are experimental // E0174, // E0182, // merged into E0229 - E0183, // E0187, // cannot infer the kind of the closure // E0188, // can not cast an immutable reference to a mutable pointer // E0189, // deprecated: can only cast a boxed pointer to a boxed object diff --git a/compiler/rustc_error_codes/src/error_codes/E0183.md b/compiler/rustc_error_codes/src/error_codes/E0183.md new file mode 100644 index 0000000000000..7e1d08daae1f2 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0183.md @@ -0,0 +1,39 @@ +Manual implemetation of a `Fn*` trait. + +Erroneous code example: + +```compile_fail,E0183 +struct MyClosure { + foo: i32 +} + +impl FnOnce<()> for MyClosure { // error + type Output = (); + extern "rust-call" fn call_once(self, args: ()) -> Self::Output { + println!("{}", self.foo); + } +} +``` + +Manually implementing `Fn`, `FnMut` or `FnOnce` is unstable +and requires `#![feature(fn_traits, unboxed_closures)]`. + +``` +#![feature(fn_traits, unboxed_closures)] + +struct MyClosure { + foo: i32 +} + +impl FnOnce<()> for MyClosure { // ok! + type Output = (); + extern "rust-call" fn call_once(self, args: ()) -> Self::Output { + println!("{}", self.foo); + } +} +``` + +The argumements must be a tuple representing the argument list. +For more info, see the [tracking issue][iss29625]: + +[iss29625]: https://github.com/rust-lang/rust/issues/29625 diff --git a/src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr b/src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr index 22a1ce3061889..e0e0acadb3776 100644 --- a/src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr +++ b/src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr @@ -101,5 +101,5 @@ LL | impl FnOnce<()> for Baz { error: aborting due to 12 previous errors -Some errors have detailed explanations: E0229, E0658. -For more information about an error, try `rustc --explain E0229`. +Some errors have detailed explanations: E0183, E0229, E0658. +For more information about an error, try `rustc --explain E0183`. diff --git a/src/test/ui/feature-gates/feature-gate-unboxed-closures.stderr b/src/test/ui/feature-gates/feature-gate-unboxed-closures.stderr index 2c8915d0ac334..8c5f87964561f 100644 --- a/src/test/ui/feature-gates/feature-gate-unboxed-closures.stderr +++ b/src/test/ui/feature-gates/feature-gate-unboxed-closures.stderr @@ -26,4 +26,5 @@ LL | impl FnOnce<(u32, u32)> for Test { error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0183, E0658. +For more information about an error, try `rustc --explain E0183`. From 5125b1a5c0a661f13a408e7864c05a97d1c40ce5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 14 Oct 2021 10:12:15 -0700 Subject: [PATCH 092/181] Update the wasi-libc built with the wasm32-wasi target This commit updates the wasi-libc that we include with the wasm32-wasi target, which brings in various misc fixes such as musl updates and some math tweaks. --- .../docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh index 82d0f7dc471e8..9bd56394eafc6 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh @@ -10,7 +10,7 @@ export PATH=`pwd`/clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04/bin:$PATH git clone https://github.com/WebAssembly/wasi-libc cd wasi-libc -git reset --hard 58795582905e08fa7748846c1971b4ab911d1e16 +git reset --hard ad5133410f66b93a2381db5b542aad5e0964db96 make -j$(nproc) INSTALL_DIR=/wasm32-wasi install cd .. From c76c620e4ec7d504fe42c9ca66bb55511fc9b23f Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Tue, 12 Oct 2021 22:34:53 +0800 Subject: [PATCH 093/181] Add a test for `unsafe_code` lint. --- .../unsafe_code/auxiliary/forge_unsafe_block.rs | 16 ++++++++++++++++ .../ui/lint/unsafe_code/forge_unsafe_block.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs create mode 100644 src/test/ui/lint/unsafe_code/forge_unsafe_block.rs diff --git a/src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs b/src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs new file mode 100644 index 0000000000000..26871c98dbef4 --- /dev/null +++ b/src/test/ui/lint/unsafe_code/auxiliary/forge_unsafe_block.rs @@ -0,0 +1,16 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; + +#[proc_macro] +pub fn forge_unsafe_block(input: TokenStream) -> TokenStream { + let mut output = TokenStream::new(); + output.extend(Some(TokenTree::from(Ident::new("unsafe", Span::call_site())))); + output.extend(Some(TokenTree::from(Group::new(Delimiter::Brace, input)))); + output +} diff --git a/src/test/ui/lint/unsafe_code/forge_unsafe_block.rs b/src/test/ui/lint/unsafe_code/forge_unsafe_block.rs new file mode 100644 index 0000000000000..a1bd7b4131984 --- /dev/null +++ b/src/test/ui/lint/unsafe_code/forge_unsafe_block.rs @@ -0,0 +1,16 @@ +// check-pass +// aux-build:forge_unsafe_block.rs + +#[macro_use] +extern crate forge_unsafe_block; + +unsafe fn foo() {} + +#[forbid(unsafe_code)] +fn main() { + // `forbid` doesn't work for non-user-provided unsafe blocks. + // see `UnsafeCode::check_expr`. + forge_unsafe_block! { + foo(); + } +} From f70232f81ac164d87195e31a157f52d0681f967c Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Oct 2021 10:19:03 -0400 Subject: [PATCH 094/181] Move LLVM profiling to a separate phase of compilation --- src/ci/pgo.sh | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/ci/pgo.sh b/src/ci/pgo.sh index e35e3e670cc64..29ef13a60fbc4 100755 --- a/src/ci/pgo.sh +++ b/src/ci/pgo.sh @@ -4,9 +4,13 @@ set -euxo pipefail rm -rf /tmp/rustc-pgo +# We collect LLVM profiling information and rustc profiling information in +# separate phases. This increases build time -- though not by a huge amount -- +# but prevents any problems from arising due to different profiling runtimes +# being simultaneously linked in. + python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \ --stage 2 library/std \ - --rust-profile-generate=/tmp/rustc-pgo \ --llvm-profile-generate # Profile libcore compilation in opt-level=0 and opt-level=3 @@ -15,6 +19,29 @@ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs +# Merge the profile data we gathered for LLVM +# Note that this uses the profdata from the clang we used to build LLVM, +# which likely has a different version than our in-tree clang. +/rustroot/bin/llvm-profdata \ + merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST/llvm/build/profiles + +# Rustbuild currently doesn't support rebuilding LLVM when PGO options +# change (or any other llvm-related options); so just clear out the relevant +# directories ourselves. +rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld + +# Okay, LLVM profiling is done, switch to rustc PGO. + +python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \ + --stage 2 library/std \ + --rust-profile-generate=/tmp/rustc-pgo + +# Profile libcore compilation in opt-level=0 and opt-level=3 +RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ + --crate-type=lib ../library/core/src/lib.rs +RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \ + --crate-type=lib -Copt-level=3 ../library/core/src/lib.rs + cp -r /tmp/rustc-perf ./ chown -R $(whoami): ./rustc-perf cd rustc-perf @@ -46,18 +73,13 @@ cd /checkout/obj ./build/$PGO_HOST/llvm/bin/llvm-profdata \ merge -o /tmp/rustc-pgo.profdata /tmp/rustc-pgo -# Merge the profile data we gathered for LLVM -# Note that this uses the profdata from the clang we used to build LLVM, -# which likely has a different version than our in-tree clang. -/rustroot/bin/llvm-profdata \ - merge -o /tmp/llvm-pgo.profdata ./build/$PGO_HOST/llvm/build/profiles - # Rustbuild currently doesn't support rebuilding LLVM when PGO options # change (or any other llvm-related options); so just clear out the relevant # directories ourselves. rm -r ./build/$PGO_HOST/llvm ./build/$PGO_HOST/lld -# This produces the actual final set of artifacts. +# This produces the actual final set of artifacts, using both the LLVM and rustc +# collected profiling data. $@ \ --rust-profile-use=/tmp/rustc-pgo.profdata \ --llvm-profile-use=/tmp/llvm-pgo.profdata From 86608f1796c9335b103b596df53bef03f7fcc303 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Oct 2021 15:20:52 -0400 Subject: [PATCH 095/181] Switch to clang v13 as the C/C++ compiler used for bootstrap --- src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh index ed5edfec4e1a6..562be752f846d 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh @@ -4,7 +4,7 @@ set -ex source shared.sh -LLVM=llvmorg-12.0.1 +LLVM=llvmorg-13.0.0 mkdir llvm-project cd llvm-project From 394f7198cad038594a9a4e4ed652170d3cdf42f6 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 14 Oct 2021 22:24:43 +0200 Subject: [PATCH 096/181] Allow to hash HIR for coverage. --- compiler/rustc_mir_transform/src/coverage/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 1c946bd2d8af2..e980d3d884f56 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -14,7 +14,6 @@ use spans::{CoverageSpan, CoverageSpans}; use crate::MirPass; -use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::graph::WithNumNodes; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; @@ -29,7 +28,6 @@ use rustc_middle::mir::{ TerminatorKind, }; use rustc_middle::ty::TyCtxt; -use rustc_query_system::ich::StableHashingContext; use rustc_span::def_id::DefId; use rustc_span::source_map::SourceMap; use rustc_span::{CharPos, ExpnKind, Pos, SourceFile, Span, Symbol}; @@ -574,15 +572,13 @@ fn get_body_span<'tcx>( } fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx rustc_hir::Body<'tcx>) -> u64 { + // FIXME(cjgillot) Stop hashing HIR manually here. let mut hcx = tcx.create_no_span_stable_hashing_context(); - hash(&mut hcx, &hir_body.value).to_smaller_hash() -} - -fn hash( - hcx: &mut StableHashingContext<'tcx>, - node: &impl HashStable>, -) -> Fingerprint { let mut stable_hasher = StableHasher::new(); - node.hash_stable(hcx, &mut stable_hasher); + let owner = hir_body.id().hir_id.owner; + let bodies = &tcx.hir_owner_nodes(owner).as_ref().unwrap().bodies; + hcx.with_hir_bodies(false, owner, bodies, |hcx| { + hir_body.value.hash_stable(hcx, &mut stable_hasher) + }); stable_hasher.finish() } From 64d18d4c51cf37efeaf25759c7c81bfe43095500 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 7 Oct 2021 13:18:41 -0500 Subject: [PATCH 097/181] Remove unused dependencies from rustc_const_eval --- Cargo.lock | 2 -- compiler/rustc_const_eval/Cargo.toml | 2 -- 2 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2115838185854..102450188aacd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3736,8 +3736,6 @@ dependencies = [ name = "rustc_const_eval" version = "0.0.0" dependencies = [ - "either", - "gsgdt", "rustc_apfloat", "rustc_ast", "rustc_attr", diff --git a/compiler/rustc_const_eval/Cargo.toml b/compiler/rustc_const_eval/Cargo.toml index 5f659dd977a85..4ed908a383332 100644 --- a/compiler/rustc_const_eval/Cargo.toml +++ b/compiler/rustc_const_eval/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" doctest = false [dependencies] -either = "1.5.0" -gsgdt = "0.1.2" tracing = "0.1" rustc_apfloat = { path = "../rustc_apfloat" } rustc_ast = { path = "../rustc_ast" } From 1e2dbb5f4a80077cb4b036b6f4ff96c96ad89805 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 24 Sep 2021 21:15:59 +0200 Subject: [PATCH 098/181] Document structs. --- compiler/rustc_hir/src/hir.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 1ec37566faba8..ddda73b91c98f 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -672,7 +672,7 @@ pub struct ParentedNode<'tcx> { pub node: Node<'tcx>, } -/// Attributes owner by a HIR owner. +/// Attributes owned by a HIR owner. #[derive(Debug)] pub struct AttributeMap<'tcx> { pub map: BTreeMap, @@ -689,6 +689,9 @@ impl<'tcx> AttributeMap<'tcx> { } } +/// Map of all HIR nodes inside the current owner. +/// These nodes are mapped by `ItemLocalId` alongside the index of their parent node. +/// The HIR tree, including bodies, is pre-hashed. #[derive(Debug)] pub struct OwnerNodes<'tcx> { /// Pre-computed hash of the full HIR. @@ -704,6 +707,7 @@ pub struct OwnerNodes<'tcx> { pub bodies: IndexVec>>, } +/// Full information resulting from lowering an AST node. #[derive(Debug, HashStable_Generic)] pub struct OwnerInfo<'hir> { /// Contents of the HIR. From 8007dfa3b2af8f9de8cf3568ac6b3770fd9e5afd Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Fri, 15 Oct 2021 01:41:31 +0200 Subject: [PATCH 099/181] Remove alloc::prelude As per the libs team decision in #58935. Closes #58935 --- .../example/alloc_example.rs | 4 ++-- .../rustc_codegen_gcc/example/alloc_example.rs | 4 ++-- library/alloc/src/lib.rs | 1 - library/alloc/src/prelude/mod.rs | 15 --------------- library/alloc/src/prelude/v1.rs | 14 -------------- 5 files changed, 4 insertions(+), 34 deletions(-) delete mode 100644 library/alloc/src/prelude/mod.rs delete mode 100644 library/alloc/src/prelude/v1.rs diff --git a/compiler/rustc_codegen_cranelift/example/alloc_example.rs b/compiler/rustc_codegen_cranelift/example/alloc_example.rs index d0d492e96742d..bc1594d82ecf9 100644 --- a/compiler/rustc_codegen_cranelift/example/alloc_example.rs +++ b/compiler/rustc_codegen_cranelift/example/alloc_example.rs @@ -1,10 +1,10 @@ -#![feature(start, core_intrinsics, alloc_prelude, alloc_error_handler, box_syntax)] +#![feature(start, core_intrinsics, alloc_error_handler, box_syntax)] #![no_std] extern crate alloc; extern crate alloc_system; -use alloc::prelude::v1::*; +use alloc::boxed::Box; use alloc_system::System; diff --git a/compiler/rustc_codegen_gcc/example/alloc_example.rs b/compiler/rustc_codegen_gcc/example/alloc_example.rs index bc6dd007ba010..74ea7ec4ede69 100644 --- a/compiler/rustc_codegen_gcc/example/alloc_example.rs +++ b/compiler/rustc_codegen_gcc/example/alloc_example.rs @@ -1,10 +1,10 @@ -#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler)] +#![feature(start, box_syntax, core_intrinsics, alloc_error_handler)] #![no_std] extern crate alloc; extern crate alloc_system; -use alloc::prelude::v1::*; +use alloc::boxed::Box; use alloc_system::System; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index e86c41b1ff887..635708fd4cf6e 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -189,7 +189,6 @@ mod boxed { pub mod borrow; pub mod collections; pub mod fmt; -pub mod prelude; pub mod raw_vec; pub mod rc; pub mod slice; diff --git a/library/alloc/src/prelude/mod.rs b/library/alloc/src/prelude/mod.rs deleted file mode 100644 index 0534ad3edc79d..0000000000000 --- a/library/alloc/src/prelude/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! The alloc Prelude -//! -//! The purpose of this module is to alleviate imports of commonly-used -//! items of the `alloc` crate by adding a glob import to the top of modules: -//! -//! ``` -//! # #![allow(unused_imports)] -//! #![feature(alloc_prelude)] -//! extern crate alloc; -//! use alloc::prelude::v1::*; -//! ``` - -#![unstable(feature = "alloc_prelude", issue = "58935")] - -pub mod v1; diff --git a/library/alloc/src/prelude/v1.rs b/library/alloc/src/prelude/v1.rs deleted file mode 100644 index 6a53b4ca1f6ca..0000000000000 --- a/library/alloc/src/prelude/v1.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! The first version of the prelude of `alloc` crate. -//! -//! See the [module-level documentation](../index.html) for more. - -#![unstable(feature = "alloc_prelude", issue = "58935")] - -#[unstable(feature = "alloc_prelude", issue = "58935")] -pub use crate::borrow::ToOwned; -#[unstable(feature = "alloc_prelude", issue = "58935")] -pub use crate::boxed::Box; -#[unstable(feature = "alloc_prelude", issue = "58935")] -pub use crate::string::{String, ToString}; -#[unstable(feature = "alloc_prelude", issue = "58935")] -pub use crate::vec::Vec; From 2a1fbb86ebb04d0a360f4522433b1af9feaddfd0 Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Fri, 15 Oct 2021 06:19:08 +0200 Subject: [PATCH 100/181] test fix: aarch64 atomics are only outlined on Linux. --- src/test/assembly/asm/aarch64-outline-atomics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/assembly/asm/aarch64-outline-atomics.rs b/src/test/assembly/asm/aarch64-outline-atomics.rs index 93dda712e1b9b..42cef9bb67911 100644 --- a/src/test/assembly/asm/aarch64-outline-atomics.rs +++ b/src/test/assembly/asm/aarch64-outline-atomics.rs @@ -4,6 +4,7 @@ // compile-flags: --target aarch64-unknown-linux-gnu // needs-llvm-components: aarch64 // only-aarch64 +// only-linux #![crate_type = "rlib"] From ac298c9181a93a2fa8a041d9902a555a92faab6b Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Thu, 14 Oct 2021 19:37:26 +0200 Subject: [PATCH 101/181] Make `rust.download-ci-llvm="if-available"` work for tier 2 platforms. --- src/bootstrap/bootstrap.py | 25 +++++++++++++++++++++++-- src/bootstrap/config.rs | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 0170be967e1e3..dc1447b4ae4d1 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -492,10 +492,11 @@ def download_toolchain(self, stage0=True, rustc_channel=None): def downloading_llvm(self): opt = self.get_toml('download-ci-llvm', 'llvm') - # This is currently all tier 1 targets (since others may not have CI - # artifacts) + # This is currently all tier 1 targets and tier 2 targets with host tools + # (since others may not have CI artifacts) # https://doc.rust-lang.org/rustc/platform-support.html#tier-1 supported_platforms = [ + # tier 1 "aarch64-unknown-linux-gnu", "i686-pc-windows-gnu", "i686-pc-windows-msvc", @@ -504,6 +505,26 @@ def downloading_llvm(self): "x86_64-apple-darwin", "x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc", + # tier 2 with host tools + "aarch64-apple-darwin", + "aarch64-pc-windows-msvc", + "aarch64-unknown-linux-musl", + "arm-unknown-linux-gnueabi", + "arm-unknown-linux-gnueabihf", + "armv7-unknown-linux-gnueabihf", + "mips-unknown-linux-gnu", + "mips64-unknown-linux-gnuabi64", + "mips64el-unknown-linux-gnuabi64", + "mipsel-unknown-linux-gnu", + "powerpc-unknown-linux-gnu", + "powerpc64-unknown-linux-gnu", + "powerpc64le-unknown-linux-gnu", + "riscv64gc-unknown-linux-gnu", + "s390x-unknown-linux-gnu", + "x86_64-unknown-freebsd", + "x86_64-unknown-illumos", + "x86_64-unknown-linux-musl", + "x86_64-unknown-netbsd", ] return opt == "true" \ or (opt == "if-available" and self.build in supported_platforms) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 7818b8b7d515d..96fc8b5a35bf4 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -765,10 +765,12 @@ impl Config { config.llvm_from_ci = match llvm.download_ci_llvm { Some(StringOrBool::String(s)) => { assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s); - // This is currently all tier 1 targets (since others may not have CI artifacts) + // This is currently all tier 1 targets and tier 2 targets with host tools + // (since others may not have CI artifacts) // https://doc.rust-lang.org/rustc/platform-support.html#tier-1 // FIXME: this is duplicated in bootstrap.py let supported_platforms = [ + // tier 1 "aarch64-unknown-linux-gnu", "i686-pc-windows-gnu", "i686-pc-windows-msvc", @@ -777,6 +779,26 @@ impl Config { "x86_64-apple-darwin", "x86_64-pc-windows-gnu", "x86_64-pc-windows-msvc", + // tier 2 with host tools + "aarch64-apple-darwin", + "aarch64-pc-windows-msvc", + "aarch64-unknown-linux-musl", + "arm-unknown-linux-gnueabi", + "arm-unknown-linux-gnueabihf", + "armv7-unknown-linux-gnueabihf", + "mips-unknown-linux-gnu", + "mips64-unknown-linux-gnuabi64", + "mips64el-unknown-linux-gnuabi64", + "mipsel-unknown-linux-gnu", + "powerpc-unknown-linux-gnu", + "powerpc64-unknown-linux-gnu", + "powerpc64le-unknown-linux-gnu", + "riscv64gc-unknown-linux-gnu", + "s390x-unknown-linux-gnu", + "x86_64-unknown-freebsd", + "x86_64-unknown-illumos", + "x86_64-unknown-linux-musl", + "x86_64-unknown-netbsd", ]; supported_platforms.contains(&&*config.build.triple) } From c75a734a43546911f1365c604c5d2c7383d98a89 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 13 Oct 2021 14:45:35 -0500 Subject: [PATCH 102/181] Remove redundant matching --- compiler/rustc_expand/src/expand.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 1d6703077acff..145733ba985b0 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1087,25 +1087,19 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { let MacCallStmt { mac, style, attrs, .. } = mac.into_inner(); Ok((style == MacStmtStyle::Semicolon, mac, attrs.into())) } - StmtKind::Item(ref item) if matches!(item.kind, ItemKind::MacCall(..)) => { - match stmt.kind { - StmtKind::Item(item) => match item.into_inner() { - ast::Item { kind: ItemKind::MacCall(mac), attrs, .. } => { - Ok((mac.args.need_semicolon(), mac, attrs)) - } - _ => unreachable!(), - }, + StmtKind::Item(item) if matches!(item.kind, ItemKind::MacCall(..)) => { + match item.into_inner() { + ast::Item { kind: ItemKind::MacCall(mac), attrs, .. } => { + Ok((mac.args.need_semicolon(), mac, attrs)) + } _ => unreachable!(), } } - StmtKind::Semi(ref expr) if matches!(expr.kind, ast::ExprKind::MacCall(..)) => { - match stmt.kind { - StmtKind::Semi(expr) => match expr.into_inner() { - ast::Expr { kind: ast::ExprKind::MacCall(mac), attrs, .. } => { - Ok((mac.args.need_semicolon(), mac, attrs.into())) - } - _ => unreachable!(), - }, + StmtKind::Semi(expr) if matches!(expr.kind, ast::ExprKind::MacCall(..)) => { + match expr.into_inner() { + ast::Expr { kind: ast::ExprKind::MacCall(mac), attrs, .. } => { + Ok((mac.args.need_semicolon(), mac, attrs.into())) + } _ => unreachable!(), } } From 1333ae67f4d3c9b04f84e9c893e781282423292a Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 13 Oct 2021 13:58:19 -0500 Subject: [PATCH 103/181] Remove trailing semicolon from macro call span --- compiler/rustc_expand/src/expand.rs | 46 ++++++++++++----------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 145733ba985b0..f548e2848a771 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1024,12 +1024,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id), vis) } - fn collect_bang( - &mut self, - mac: ast::MacCall, - span: Span, - kind: AstFragmentKind, - ) -> AstFragment { + fn collect_bang(&mut self, mac: ast::MacCall, kind: AstFragmentKind) -> AstFragment { + // cache the macro call span so that it can be + // easily adjusted for incremental compilation + let span = mac.span(); self.collect(kind, InvocationKind::Bang { mac, span }) } @@ -1216,7 +1214,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { if let ast::ExprKind::MacCall(mac) = expr.kind { self.check_attributes(&expr.attrs, &mac); - self.collect_bang(mac, expr.span, AstFragmentKind::Expr).make_expr().into_inner() + self.collect_bang(mac, AstFragmentKind::Expr).make_expr().into_inner() } else { assign_id!(self, &mut expr.id, || { ensure_sufficient_stack(|| noop_visit_expr(&mut expr, self)); @@ -1312,7 +1310,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { if let ast::ExprKind::MacCall(mac) = expr.kind { self.check_attributes(&expr.attrs, &mac); - self.collect_bang(mac, expr.span, AstFragmentKind::OptExpr) + self.collect_bang(mac, AstFragmentKind::OptExpr) .make_opt_expr() .map(|expr| expr.into_inner()) } else { @@ -1333,9 +1331,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { } visit_clobber(pat, |mut pat| match mem::replace(&mut pat.kind, PatKind::Wild) { - PatKind::MacCall(mac) => { - self.collect_bang(mac, pat.span, AstFragmentKind::Pat).make_pat() - } + PatKind::MacCall(mac) => self.collect_bang(mac, AstFragmentKind::Pat).make_pat(), _ => unreachable!(), }); } @@ -1354,12 +1350,10 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { .make_stmts(); } - let span = stmt.span; match self.take_stmt_bang(stmt) { Ok((add_semicolon, mac, attrs)) => { self.check_attributes(&attrs, &mac); - let mut stmts = - self.collect_bang(mac, span, AstFragmentKind::Stmts).make_stmts(); + let mut stmts = self.collect_bang(mac, AstFragmentKind::Stmts).make_stmts(); // If this is a macro invocation with a semicolon, then apply that // semicolon to the final statement produced by expansion. @@ -1427,7 +1421,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { item.attrs = attrs; item.and_then(|item| match item.kind { ItemKind::MacCall(mac) => { - self.collect_bang(mac, span, AstFragmentKind::Items).make_items() + self.collect_bang(mac, AstFragmentKind::Items).make_items() } _ => unreachable!(), }) @@ -1536,9 +1530,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ast::AssocItemKind::MacCall(ref mac) => { self.check_attributes(&item.attrs, &mac); item.and_then(|item| match item.kind { - ast::AssocItemKind::MacCall(mac) => self - .collect_bang(mac, item.span, AstFragmentKind::TraitItems) - .make_trait_items(), + ast::AssocItemKind::MacCall(mac) => { + self.collect_bang(mac, AstFragmentKind::TraitItems).make_trait_items() + } _ => unreachable!(), }) } @@ -1561,9 +1555,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ast::AssocItemKind::MacCall(ref mac) => { self.check_attributes(&item.attrs, &mac); item.and_then(|item| match item.kind { - ast::AssocItemKind::MacCall(mac) => self - .collect_bang(mac, item.span, AstFragmentKind::ImplItems) - .make_impl_items(), + ast::AssocItemKind::MacCall(mac) => { + self.collect_bang(mac, AstFragmentKind::ImplItems).make_impl_items() + } _ => unreachable!(), }) } @@ -1580,9 +1574,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { }; visit_clobber(ty, |mut ty| match mem::replace(&mut ty.kind, ast::TyKind::Err) { - ast::TyKind::MacCall(mac) => { - self.collect_bang(mac, ty.span, AstFragmentKind::Ty).make_ty() - } + ast::TyKind::MacCall(mac) => self.collect_bang(mac, AstFragmentKind::Ty).make_ty(), _ => unreachable!(), }); } @@ -1607,9 +1599,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { ast::ForeignItemKind::MacCall(ref mac) => { self.check_attributes(&foreign_item.attrs, &mac); foreign_item.and_then(|item| match item.kind { - ast::ForeignItemKind::MacCall(mac) => self - .collect_bang(mac, item.span, AstFragmentKind::ForeignItems) - .make_foreign_items(), + ast::ForeignItemKind::MacCall(mac) => { + self.collect_bang(mac, AstFragmentKind::ForeignItems).make_foreign_items() + } _ => unreachable!(), }) } From f005e9fe96a938947e8f8e3c85268a2b2ed686c1 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 14 Oct 2021 13:28:25 -0500 Subject: [PATCH 104/181] Guess semicolon span for macro statements --- compiler/rustc_span/src/source_map.rs | 38 +++++++++++++++++++ .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 9 ++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index b79f00a8a3642..74958c4984962 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -653,6 +653,18 @@ impl SourceMap { }) } + /// Extends the given `Span` while the next character matches the predicate + pub fn span_extend_while( + &self, + span: Span, + f: impl Fn(char) -> bool, + ) -> Result { + self.span_to_source(span, |s, _start, end| { + let n = s[end..].char_indices().find(|&(_, c)| !f(c)).map_or(s.len() - end, |(i, _)| i); + Ok(span.with_hi(span.hi() + BytePos(n as u32))) + }) + } + /// Extends the given `Span` to just after the next occurrence of `c`. pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span { if let Ok(next_source) = self.span_to_next_source(sp) { @@ -1013,6 +1025,32 @@ impl SourceMap { let source_file = &self.files()[source_file_index]; source_file.is_imported() } + + /// Gets the span of a statement. If the statement is a macro expansion, the + /// span in the context of the block span is found. The trailing semicolon is included + /// on a best-effort basis. + pub fn stmt_span(&self, stmt_span: Span, block_span: Span) -> Span { + if !stmt_span.from_expansion() { + return stmt_span; + } + let mac_call = original_sp(stmt_span, block_span); + self.mac_call_stmt_semi_span(mac_call).map_or(mac_call, |s| mac_call.with_hi(s.hi())) + } + + /// Tries to find the span of the semicolon of a macro call statement. + /// The input must be the *call site* span of a statement from macro expansion. + /// + /// v output + /// mac!(); + /// ^^^^^^ input + pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option { + let span = self.span_extend_while(mac_call, char::is_whitespace).ok()?; + let span = span.shrink_to_hi().with_hi(BytePos(span.hi().0.checked_add(1)?)); + if self.span_to_snippet(span).as_deref() != Ok(";") { + return None; + } + Some(span) + } } #[derive(Clone)] diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 7b9629e534bf9..ac4bb65224486 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1171,8 +1171,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { return None; } - let original_span = original_sp(last_stmt.span, blk.span); - Some((original_span.with_lo(original_span.hi() - BytePos(1)), needs_box)) + let span = if last_stmt.span.from_expansion() { + let mac_call = original_sp(last_stmt.span, blk.span); + self.tcx.sess.source_map().mac_call_stmt_semi_span(mac_call)? + } else { + last_stmt.span.with_lo(last_stmt.span.hi() - BytePos(1)) + }; + Some((span, needs_box)) } // Instantiates the given path, which must refer to an item with the given From 90f4521cfdfc85fc04759cfba2f86a6acc096cb3 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 14 Oct 2021 13:28:28 -0500 Subject: [PATCH 105/181] Bless tests --- ...hable_asm.main.UnreachablePropagation.diff | 2 +- ...ble_asm_2.main.UnreachablePropagation.diff | 4 +- src/test/rustdoc-ui/intra-doc/warning.stderr | 2 +- .../lint_pass_impl_without_macro.stderr | 2 +- .../issue-76270-panic-in-libproc-macro.stderr | 2 +- src/test/ui/annotate-snippet/multispan.stderr | 14 ++--- .../ui/asm/aarch64/interpolated-idents.stderr | 16 ++--- src/test/ui/asm/aarch64/parse-error.stderr | 4 +- src/test/ui/asm/aarch64/type-check-2.stderr | 2 +- src/test/ui/asm/bad-arch.mirunsafeck.stderr | 4 +- src/test/ui/asm/bad-arch.thirunsafeck.stderr | 4 +- src/test/ui/asm/naked-functions.stderr | 22 +++---- src/test/ui/asm/rustfix-asm.stderr | 4 +- src/test/ui/asm/type-check-4.stderr | 2 +- .../ui/asm/x86_64/interpolated-idents.stderr | 16 ++--- src/test/ui/asm/x86_64/parse-error.stderr | 4 +- src/test/ui/asm/x86_64/type-check-2.stderr | 2 +- .../defaults-not-assumed-fail.stderr | 2 +- src/test/ui/async-await/issue-73541-2.stderr | 2 +- .../ui/attributes/key-value-expansion.stderr | 4 +- .../attributes/nonterminal-expansion.stderr | 4 +- src/test/ui/binop/issue-77910-1.stderr | 4 +- .../consider-removing-last-semi.fixed | 7 +++ .../consider-removing-last-semi.rs | 7 +++ .../consider-removing-last-semi.stderr | 13 +++- src/test/ui/block-result/issue-13428.stderr | 3 - .../ui/borrowck/move-error-snippets.stderr | 2 +- .../closure-body-macro-fragment.stderr | 2 +- .../ui/codemap_tests/bad-format-args.stderr | 2 +- src/test/ui/codemap_tests/issue-28308.stderr | 2 +- src/test/ui/compile_error_macro.stderr | 2 +- .../cfg-attr-syntax-validation.stderr | 4 +- ...r-unknown-attribute-macro-expansion.stderr | 2 +- .../const-external-macro-const-err.stderr | 2 +- src/test/ui/consts/issue-32829.stderr | 2 +- src/test/ui/consts/issue-66693.stderr | 2 +- .../consts/miri_unleashed/inline_asm.stderr | 8 +-- .../cross-crate-macro-backtrace/main.stderr | 2 +- .../ui/cross/cross-file-errors/main.stderr | 4 +- .../ui/deprecation/deprecation-lint-2.stderr | 2 +- .../ui/did_you_mean/bad-assoc-expr.stderr | 2 +- .../did_you_mean/recursion_limit_macro.stderr | 2 +- .../macro-expanded-mod.stderr | 2 +- .../dollar-crate-is-keyword-2.stderr | 6 +- .../dollar-crate-is-keyword.stderr | 8 +-- .../ui/editions/edition-imports-2015.stderr | 2 +- .../ui/editions/edition-imports-2018.stderr | 2 +- .../edition-imports-virtual-2015-gated.stderr | 2 +- src/test/ui/empty/empty-comment.stderr | 2 +- src/test/ui/error-codes/E0660.stderr | 4 +- src/test/ui/expr/if/if-let.stderr | 4 +- src/test/ui/extenv/extenv-no-args.stderr | 2 +- .../extenv/extenv-not-defined-custom.stderr | 2 +- .../extenv/extenv-not-defined-default.stderr | 2 +- .../ui/extenv/extenv-too-many-args.stderr | 2 +- src/test/ui/extoption_env-no-args.stderr | 2 +- .../ui/extoption_env-too-many-args.stderr | 2 +- ...-allow-internal-unsafe-nested-macro.stderr | 2 +- ...llow-internal-unstable-nested-macro.stderr | 2 +- .../feature-gate-concat_idents2.stderr | 2 +- .../thread-local-const-init.stderr | 2 +- .../ui/feature-gates/trace_macros-gate.stderr | 4 +- src/test/ui/fmt/ifmt-bad-format-args.stderr | 2 +- ...pats-inclusive-dotdotdot-bad-syntax.stderr | 2 +- ...lf-open-range-pats-inclusive-no-end.stderr | 4 +- src/test/ui/hygiene/assoc_item_ctxt.stderr | 4 +- .../ui/hygiene/duplicate_lifetimes.stderr | 4 +- .../extern-prelude-from-opaque-fail.stderr | 4 +- src/test/ui/hygiene/fields-definition.stderr | 2 +- src/test/ui/hygiene/generate-mod.stderr | 8 +-- src/test/ui/hygiene/globs.stderr | 4 +- src/test/ui/hygiene/hygienic-label-1.stderr | 2 +- src/test/ui/hygiene/hygienic-label-3.stderr | 2 +- .../ui/hygiene/hygienic-labels-in-let.stderr | 32 +++++----- src/test/ui/hygiene/hygienic-labels.stderr | 32 +++++----- src/test/ui/hygiene/impl_items.stderr | 2 +- src/test/ui/hygiene/missing-self-diag.stderr | 2 +- .../ui/hygiene/no_implicit_prelude.stderr | 4 +- src/test/ui/hygiene/privacy-early.stderr | 4 +- src/test/ui/hygiene/trait_items.stderr | 2 +- .../extern-prelude-extern-crate-fail.stderr | 2 +- ...e-extern-crate-restricted-shadowing.stderr | 4 +- src/test/ui/imports/import-crate-var.stderr | 2 +- .../local-modularized-tricky-fail-1.stderr | 8 +-- .../local-modularized-tricky-fail-2.stderr | 4 +- .../ui/imports/shadow_builtin_macros.stderr | 2 +- .../in-band-lifetimes/elided-lifetimes.stderr | 2 +- src/test/ui/inference/deref-suggestion.stderr | 2 +- .../internal/internal-unstable-noallow.stderr | 4 +- src/test/ui/internal/internal-unstable.stderr | 2 +- src/test/ui/issues/issue-14091-2.stderr | 2 +- src/test/ui/issues/issue-14091.stderr | 2 +- src/test/ui/issues/issue-16966.stderr | 2 +- src/test/ui/issues/issue-19163.stderr | 2 +- src/test/ui/issues/issue-2150.stderr | 2 +- src/test/ui/issues/issue-25385.stderr | 2 +- src/test/ui/issues/issue-26093.stderr | 4 +- src/test/ui/issues/issue-29084.stderr | 2 +- src/test/ui/issues/issue-31011.stderr | 2 +- src/test/ui/issues/issue-32655.stderr | 2 +- src/test/ui/issues/issue-32782.stderr | 2 +- src/test/ui/issues/issue-39848.stderr | 2 +- src/test/ui/issues/issue-42954.stderr | 2 +- src/test/ui/issues/issue-51848.stderr | 2 +- src/test/ui/issues/issue-53251.stderr | 4 +- src/test/ui/issues/issue-59488.stderr | 4 +- src/test/ui/issues/issue-6596-1.stderr | 2 +- src/test/ui/issues/issue-6596-2.stderr | 2 +- .../issue-68091-unicode-ident-after-if.stderr | 2 +- ...70724-add_type_neq_err_label-unwrap.stderr | 6 +- src/test/ui/issues/issue-7970a.stderr | 2 +- src/test/ui/lint/lint-stability2.stderr | 2 +- .../ui/lint/lints-in-foreign-macros.stderr | 2 +- .../ui/lint/unreachable_pub-pub_crate.stderr | 2 +- src/test/ui/lint/unreachable_pub.stderr | 2 +- .../ui/lint/unused/unused-macro-rules.stderr | 2 +- .../liveness-return-last-stmt-semi.stderr | 7 +-- .../llvm-asm/inline-asm-bad-constraint.stderr | 2 +- src/test/ui/llvm-asm/issue-62046.stderr | 2 +- .../ui/llvm-asm/llvm-asm-parse-errors.stderr | 2 +- .../main.-Zmacro-backtrace.stderr | 16 ++--- .../ui/macro_backtrace/main.default.stderr | 6 +- .../ui/macros/assert-trailing-junk.stderr | 2 +- src/test/ui/macros/assert.stderr | 4 +- src/test/ui/macros/cfg.stderr | 2 +- src/test/ui/macros/format-parse-errors.stderr | 2 +- src/test/ui/macros/global-asm.stderr | 2 +- src/test/ui/macros/issue-54441.stderr | 2 +- ...issue-78325-inconsistent-resolution.stderr | 2 +- ...632-eager-expansion-recursion-limit.stderr | 2 +- .../macros/macro-at-most-once-rep-2015.stderr | 4 +- .../macros/macro-at-most-once-rep-2018.stderr | 4 +- .../macro-backtrace-invalid-internals.stderr | 8 +-- .../ui/macros/macro-backtrace-nested.stderr | 2 +- .../ui/macros/macro-backtrace-println.stderr | 2 +- src/test/ui/macros/macro-comma-support.stderr | 4 +- src/test/ui/macros/macro-context.stderr | 2 +- .../macro-lifetime-used-with-labels.stderr | 2 +- .../macros/macro-local-data-key-priv.stderr | 2 +- src/test/ui/macros/macro-shadowing.stderr | 4 +- .../ui/macros/macros-nonfatal-errors.stderr | 10 ++-- .../ui/macros/must-use-in-macro-55516.stderr | 2 +- .../ui/macros/nonterminal-matching.stderr | 2 +- .../ui/macros/out-of-order-shadowing.stderr | 2 +- .../macros/restricted-shadowing-legacy.stderr | 48 +++++++-------- .../macros/restricted-shadowing-modern.stderr | 36 +++++------ src/test/ui/macros/same-sequence-span.stderr | 4 +- .../ui/macros/span-covering-argument-1.stderr | 2 +- src/test/ui/macros/trace-macro.stderr | 2 +- src/test/ui/macros/trace_faulty_macros.stderr | 10 ++-- .../ui/mismatched_types/issue-26480.stderr | 4 +- src/test/ui/modules/issue-56411.stderr | 4 +- src/test/ui/non-fmt-panic.stderr | 2 +- .../ui/parser/bad-interpolated-block.stderr | 6 +- .../ui/parser/float-field-interpolated.stderr | 8 +-- src/test/ui/parser/issue-44406.stderr | 2 +- ...interpolate-impl-items-bad-variants.stderr | 6 +- .../issue-73568-lifetime-after-mut.stderr | 2 +- src/test/ui/parser/issue-87812-path.stderr | 2 +- .../ui/parser/labeled-no-colon-expr.stderr | 2 +- src/test/ui/parser/macro/issue-37113.stderr | 2 +- src/test/ui/parser/macro/issue-37234.stderr | 2 +- .../macro/macro-incomplete-parse.stderr | 4 +- .../ui/parser/macro/pub-item-macro.stderr | 4 +- .../parser/macro/trait-non-item-macros.stderr | 2 +- src/test/ui/parser/missing-semicolon.stderr | 2 +- src/test/ui/parser/mut-patterns.stderr | 2 +- src/test/ui/parser/recover-range-pats.stderr | 8 +-- .../associated-item-privacy-inherent.stderr | 42 ++++++------- .../associated-item-privacy-trait.stderr | 60 +++++++++---------- ...ssociated-item-privacy-type-binding.stderr | 32 +++++----- .../ui/privacy/private-inferred-type-3.stderr | 14 ++--- .../ui/privacy/private-inferred-type.stderr | 12 ++-- .../proc-macro/derive-helper-shadowing.stderr | 2 +- .../proc-macro/gen-macro-rules-hygiene.stderr | 8 +-- src/test/ui/proc-macro/generate-mod.stderr | 4 +- .../group-compat-hack.stderr | 20 +++---- .../proc-macro/invalid-punct-ident-1.stderr | 2 +- .../proc-macro/invalid-punct-ident-2.stderr | 2 +- .../proc-macro/invalid-punct-ident-3.stderr | 2 +- .../proc-macro/invalid-punct-ident-4.stderr | 4 +- src/test/ui/proc-macro/issue-83510.stderr | 8 +-- .../ui/proc-macro/lints_in_proc_macros.stderr | 2 +- .../ui/proc-macro/macro-rules-derive.stderr | 2 +- src/test/ui/proc-macro/mixed-site-span.stderr | 6 +- src/test/ui/proc-macro/multispan.stderr | 14 ++--- .../ui/proc-macro/parent-source-spans.stderr | 44 +++++++------- src/test/ui/proc-macro/raw-ident.stderr | 2 +- src/test/ui/proc-macro/span-api-tests.rs | 2 +- .../ui/proc-macro/span-from-proc-macro.stderr | 4 +- src/test/ui/proc-macro/subspan.stderr | 16 ++--- src/test/ui/proc-macro/three-equals.stderr | 2 +- src/test/ui/proc-macro/weird-hygiene.stderr | 4 +- src/test/ui/reachable/expr_again.stderr | 2 +- src/test/ui/reachable/expr_block.stderr | 2 +- src/test/ui/reachable/expr_if.stderr | 2 +- src/test/ui/reachable/expr_loop.stderr | 6 +- src/test/ui/reachable/expr_match.stderr | 4 +- .../ui/reachable/unreachable-code-ret.stderr | 2 +- src/test/ui/recursion_limit/zero.rs | 2 +- src/test/ui/recursion_limit/zero.stderr | 2 +- .../regions-var-type-out-of-scope.stderr | 2 +- src/test/ui/resolve/issue-82865.stderr | 2 +- .../ambiguity-macros-nested.stderr | 2 +- .../uniform-paths/ambiguity-macros.stderr | 2 +- .../reserved-prefixes-via-macro-2.stderr | 6 +- .../ui/simd/shuffle-not-out-of-bounds.stderr | 12 ++-- .../ui/span/macro-span-replacement.stderr | 2 +- src/test/ui/span/transitive-dep-span.stderr | 2 +- ...gest-deref-inside-macro-issue-58298.stderr | 2 +- .../dont-suggest-try_into-in-macros.stderr | 2 +- .../ui/suggestions/suggest-ref-macro.stderr | 2 +- ...onst-generics-structural-demangling.stderr | 6 +- src/test/ui/trace_macros-format.stderr | 12 ++-- .../ui/try-block/try-block-opt-init.stderr | 2 +- src/test/ui/unsafe/inline_asm.mir.stderr | 4 +- src/test/ui/unsafe/inline_asm.thir.stderr | 4 +- src/test/ui/while-let.stderr | 4 +- 218 files changed, 575 insertions(+), 554 deletions(-) diff --git a/src/test/mir-opt/unreachable_asm.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_asm.main.UnreachablePropagation.diff index 09eb210f36873..c60997be5d3c3 100644 --- a/src/test/mir-opt/unreachable_asm.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_asm.main.UnreachablePropagation.diff @@ -59,7 +59,7 @@ StorageDead(_6); // scope 2 at $DIR/unreachable_asm.rs:18:9: 18:10 StorageDead(_5); // scope 2 at $DIR/unreachable_asm.rs:18:9: 18:10 StorageLive(_7); // scope 2 at $DIR/unreachable_asm.rs:21:9: 21:37 - llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 3 at $DIR/unreachable_asm.rs:21:18: 21:35 + llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 3 at $DIR/unreachable_asm.rs:21:18: 21:34 _7 = const (); // scope 3 at $DIR/unreachable_asm.rs:21:9: 21:37 StorageDead(_7); // scope 2 at $DIR/unreachable_asm.rs:21:36: 21:37 StorageLive(_8); // scope 2 at $DIR/unreachable_asm.rs:22:9: 22:21 diff --git a/src/test/mir-opt/unreachable_asm_2.main.UnreachablePropagation.diff b/src/test/mir-opt/unreachable_asm_2.main.UnreachablePropagation.diff index cdb28ca12cc7f..28c5f031dbbe9 100644 --- a/src/test/mir-opt/unreachable_asm_2.main.UnreachablePropagation.diff +++ b/src/test/mir-opt/unreachable_asm_2.main.UnreachablePropagation.diff @@ -49,7 +49,7 @@ bb3: { StorageLive(_7); // scope 2 at $DIR/unreachable_asm_2.rs:16:13: 16:41 - llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 3 at $DIR/unreachable_asm_2.rs:16:22: 16:39 + llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 3 at $DIR/unreachable_asm_2.rs:16:22: 16:38 _7 = const (); // scope 3 at $DIR/unreachable_asm_2.rs:16:13: 16:41 StorageDead(_7); // scope 2 at $DIR/unreachable_asm_2.rs:16:40: 16:41 _4 = const 21_i32; // scope 2 at $DIR/unreachable_asm_2.rs:17:13: 17:20 @@ -60,7 +60,7 @@ bb4: { StorageLive(_8); // scope 2 at $DIR/unreachable_asm_2.rs:20:13: 20:41 - llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 4 at $DIR/unreachable_asm_2.rs:20:22: 20:39 + llvm_asm!(LlvmInlineAsmInner { asm: "NOP", asm_str_style: Cooked, outputs: [], inputs: [], clobbers: [], volatile: true, alignstack: false, dialect: Att } : [] : []); // scope 4 at $DIR/unreachable_asm_2.rs:20:22: 20:38 _8 = const (); // scope 4 at $DIR/unreachable_asm_2.rs:20:13: 20:41 StorageDead(_8); // scope 2 at $DIR/unreachable_asm_2.rs:20:40: 20:41 _4 = const 42_i32; // scope 2 at $DIR/unreachable_asm_2.rs:21:13: 21:20 diff --git a/src/test/rustdoc-ui/intra-doc/warning.stderr b/src/test/rustdoc-ui/intra-doc/warning.stderr index af83b9b195546..19399a0df5bf9 100644 --- a/src/test/rustdoc-ui/intra-doc/warning.stderr +++ b/src/test/rustdoc-ui/intra-doc/warning.stderr @@ -88,7 +88,7 @@ LL | #[doc = $f] | ^^^^^^^^^^^ ... LL | f!("Foo\nbar [BarF] bar\nbaz"); - | ------------------------------- in this macro invocation + | ------------------------------ in this macro invocation | = note: the link appears in this line: diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr index 66f37f1a3432a..9df6be65eb301 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -18,7 +18,7 @@ LL | impl LintPass for Custom { | ^^^^^^^^ ... LL | custom_lint_pass_macro!(); - | -------------------------- in this macro invocation + | ------------------------- in this macro invocation | = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead = note: this error originates in the macro `custom_lint_pass_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.stderr b/src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.stderr index e472242ce4b07..5cc292dbb40c5 100644 --- a/src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.stderr +++ b/src/test/ui-fulldeps/issue-76270-panic-in-libproc-macro.stderr @@ -2,7 +2,7 @@ error: proc macro panicked --> $DIR/issue-76270-panic-in-libproc-macro.rs:15:1 | LL | proc_macro_panic::panic_in_libproc_macro!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: message: `""` is not a valid identifier diff --git a/src/test/ui/annotate-snippet/multispan.stderr b/src/test/ui/annotate-snippet/multispan.stderr index 4ac31e32ba7cf..baed54c59a4e9 100644 --- a/src/test/ui/annotate-snippet/multispan.stderr +++ b/src/test/ui/annotate-snippet/multispan.stderr @@ -2,41 +2,41 @@ error: hello to you, too! --> $DIR/multispan.rs:15:5 | LL | hello!(hi); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:18:5 | LL | hello!(hi hi); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:21:5 | LL | hello!(hi hi hi); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:24:5 | LL | hello!(hi hey hi yo hi beep beep hi hi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:25:5 | LL | hello!(hi there, hi how are you? hi... hi.); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:26:5 | LL | hello!(whoah. hi di hi di ho); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | error: hello to you, too! --> $DIR/multispan.rs:27:5 | LL | hello!(hi good hi and good bye); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | diff --git a/src/test/ui/asm/aarch64/interpolated-idents.stderr b/src/test/ui/asm/aarch64/interpolated-idents.stderr index d1ab13af84e25..2df17f2e03620 100644 --- a/src/test/ui/asm/aarch64/interpolated-idents.stderr +++ b/src/test/ui/asm/aarch64/interpolated-idents.stderr @@ -7,7 +7,7 @@ LL | $options($pure, $nomem, $readonly, $preserves_flags, $noretur LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack options); - | |_________________________________- in this macro invocation + | |________________________________- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -20,7 +20,7 @@ LL | $options($pure, $nomem, $readonly, $preserves_flags, $noretur LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack options); - | |_________________________________- in this macro invocation + | |________________________________- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,12 +38,12 @@ LL | m!(in out lateout inout inlateout const sym | | LL | | pure nomem readonly preserves_flags LL | | noreturn nostack options); - | | - - | |_________________________________| - | |_________________________________in this macro invocation - | |_________________________________in this macro invocation - | |_________________________________in this macro invocation - | in this macro invocation + | | - + | |________________________________| + | |________________________________in this macro invocation + | |________________________________in this macro invocation + | |________________________________in this macro invocation + | in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/asm/aarch64/parse-error.stderr b/src/test/ui/asm/aarch64/parse-error.stderr index 7b9fa90f70c25..6f318c9b9c2a1 100644 --- a/src/test/ui/asm/aarch64/parse-error.stderr +++ b/src/test/ui/asm/aarch64/parse-error.stderr @@ -2,7 +2,7 @@ error: requires at least a template string argument --> $DIR/parse-error.rs:9:9 | LL | asm!(); - | ^^^^^^^ + | ^^^^^^ error: asm template must be a string literal --> $DIR/parse-error.rs:11:14 @@ -236,7 +236,7 @@ error: requires at least a template string argument --> $DIR/parse-error.rs:90:1 | LL | global_asm!(); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ error: asm template must be a string literal --> $DIR/parse-error.rs:92:13 diff --git a/src/test/ui/asm/aarch64/type-check-2.stderr b/src/test/ui/asm/aarch64/type-check-2.stderr index e8209064d2d54..cea26d73ab164 100644 --- a/src/test/ui/asm/aarch64/type-check-2.stderr +++ b/src/test/ui/asm/aarch64/type-check-2.stderr @@ -77,7 +77,7 @@ error[E0381]: use of possibly-uninitialized variable: `y` --> $DIR/type-check-2.rs:20:9 | LL | asm!("{}", inout(reg) y); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y` + | ^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y` error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/type-check-2.rs:28:29 diff --git a/src/test/ui/asm/bad-arch.mirunsafeck.stderr b/src/test/ui/asm/bad-arch.mirunsafeck.stderr index d86e53c062671..4aa27180758e2 100644 --- a/src/test/ui/asm/bad-arch.mirunsafeck.stderr +++ b/src/test/ui/asm/bad-arch.mirunsafeck.stderr @@ -2,13 +2,13 @@ error[E0472]: inline assembly is unsupported on this target --> $DIR/bad-arch.rs:22:9 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ error[E0472]: inline assembly is unsupported on this target --> $DIR/bad-arch.rs:27:1 | LL | global_asm!(""); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/asm/bad-arch.thirunsafeck.stderr b/src/test/ui/asm/bad-arch.thirunsafeck.stderr index d86e53c062671..4aa27180758e2 100644 --- a/src/test/ui/asm/bad-arch.thirunsafeck.stderr +++ b/src/test/ui/asm/bad-arch.thirunsafeck.stderr @@ -2,13 +2,13 @@ error[E0472]: inline assembly is unsupported on this target --> $DIR/bad-arch.rs:22:9 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ error[E0472]: inline assembly is unsupported on this target --> $DIR/bad-arch.rs:27:1 | LL | global_asm!(""); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/asm/naked-functions.stderr b/src/test/ui/asm/naked-functions.stderr index 46ceef032427c..465db634aa2f0 100644 --- a/src/test/ui/asm/naked-functions.stderr +++ b/src/test/ui/asm/naked-functions.stderr @@ -111,7 +111,7 @@ LL | | in(reg) a, ... | LL | | sym G, LL | | ); - | |______^ + | |_____^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -156,7 +156,7 @@ warning: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:89:5 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -165,7 +165,7 @@ warning: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:92:5 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -174,7 +174,7 @@ warning: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:95:5 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -188,13 +188,13 @@ LL | | LL | | asm!(""); ... | LL | | asm!(""); - | | --------- multiple asm blocks are unsupported in naked functions + | | -------- multiple asm blocks are unsupported in naked functions ... | LL | | asm!(""); - | | --------- multiple asm blocks are unsupported in naked functions + | | -------- multiple asm blocks are unsupported in naked functions ... | LL | | asm!("", options(noreturn)); - | | ---------------------------- multiple asm blocks are unsupported in naked functions + | | --------------------------- multiple asm blocks are unsupported in naked functions LL | | } | |_^ | @@ -228,7 +228,7 @@ warning: the LLVM-style inline assembly is unsupported in naked functions --> $DIR/naked-functions.rs:116:5 | LL | llvm_asm!(""); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -255,7 +255,7 @@ warning: asm options unsupported in naked functions: `nomem`, `preserves_flags` --> $DIR/naked-functions.rs:124:5 | LL | asm!("", options(nomem, preserves_flags, noreturn)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -264,7 +264,7 @@ warning: asm options unsupported in naked functions: `nostack`, `pure`, `readonl --> $DIR/naked-functions.rs:131:5 | LL | asm!("", options(readonly, nostack), options(pure)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 @@ -273,7 +273,7 @@ warning: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:131:5 | LL | asm!("", options(readonly, nostack), options(pure)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #32408 diff --git a/src/test/ui/asm/rustfix-asm.stderr b/src/test/ui/asm/rustfix-asm.stderr index 14927f3eb203e..babb154ccf435 100644 --- a/src/test/ui/asm/rustfix-asm.stderr +++ b/src/test/ui/asm/rustfix-asm.stderr @@ -2,7 +2,7 @@ error: the legacy LLVM-style asm! syntax is no longer supported --> $DIR/rustfix-asm.rs:11:9 | LL | asm!("" :: "r" (x)); - | ----^^^^^^^^^^^^^^^^ + | ----^^^^^^^^^^^^^^^ | | | help: replace with: `llvm_asm!` | @@ -13,7 +13,7 @@ error: the legacy LLVM-style asm! syntax is no longer supported --> $DIR/rustfix-asm.rs:13:9 | LL | asm!("" : "=r" (y)); - | ----^^^^^^^^^^^^^^^^ + | ----^^^^^^^^^^^^^^^ | | | help: replace with: `llvm_asm!` | diff --git a/src/test/ui/asm/type-check-4.stderr b/src/test/ui/asm/type-check-4.stderr index db2bf0a69f7fc..c97cd171b1e38 100644 --- a/src/test/ui/asm/type-check-4.stderr +++ b/src/test/ui/asm/type-check-4.stderr @@ -4,7 +4,7 @@ error[E0506]: cannot assign to `a` because it is borrowed LL | let p = &a; | -- borrow of `a` occurs here LL | asm!("{}", out(reg) a); - | ^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here + | ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here LL | LL | println!("{}", p); | - borrow later used here diff --git a/src/test/ui/asm/x86_64/interpolated-idents.stderr b/src/test/ui/asm/x86_64/interpolated-idents.stderr index 5de8d20547e3e..6ac2ac5a77914 100644 --- a/src/test/ui/asm/x86_64/interpolated-idents.stderr +++ b/src/test/ui/asm/x86_64/interpolated-idents.stderr @@ -7,7 +7,7 @@ LL | $options($pure, $nomem, $readonly, $preserves_flags, $noretur LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack att_syntax options); - | |____________________________________________- in this macro invocation + | |___________________________________________- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -20,7 +20,7 @@ LL | $options($pure, $nomem, $readonly, $preserves_flags, $noretur LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack att_syntax options); - | |____________________________________________- in this macro invocation + | |___________________________________________- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,12 +38,12 @@ LL | m!(in out lateout inout inlateout const sym | | LL | | pure nomem readonly preserves_flags LL | | noreturn nostack att_syntax options); - | | - - | |____________________________________________| - | |____________________________________________in this macro invocation - | |____________________________________________in this macro invocation - | |____________________________________________in this macro invocation - | in this macro invocation + | | - + | |___________________________________________| + | |___________________________________________in this macro invocation + | |___________________________________________in this macro invocation + | |___________________________________________in this macro invocation + | in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/asm/x86_64/parse-error.stderr b/src/test/ui/asm/x86_64/parse-error.stderr index 78d342cc1daf7..91a6baa4afb29 100644 --- a/src/test/ui/asm/x86_64/parse-error.stderr +++ b/src/test/ui/asm/x86_64/parse-error.stderr @@ -2,7 +2,7 @@ error: requires at least a template string argument --> $DIR/parse-error.rs:9:9 | LL | asm!(); - | ^^^^^^^ + | ^^^^^^ error: asm template must be a string literal --> $DIR/parse-error.rs:11:14 @@ -236,7 +236,7 @@ error: requires at least a template string argument --> $DIR/parse-error.rs:90:1 | LL | global_asm!(); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ error: asm template must be a string literal --> $DIR/parse-error.rs:92:13 diff --git a/src/test/ui/asm/x86_64/type-check-2.stderr b/src/test/ui/asm/x86_64/type-check-2.stderr index b82a0b8e2ba26..9e73c9a8d6a38 100644 --- a/src/test/ui/asm/x86_64/type-check-2.stderr +++ b/src/test/ui/asm/x86_64/type-check-2.stderr @@ -77,7 +77,7 @@ error[E0381]: use of possibly-uninitialized variable: `y` --> $DIR/type-check-2.rs:16:9 | LL | asm!("{}", inout(reg) y); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y` + | ^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y` error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/type-check-2.rs:24:29 diff --git a/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr b/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr index 984a8713c991a..7406b2ddee9b2 100644 --- a/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr +++ b/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr @@ -20,7 +20,7 @@ error: erroneous constant used --> $DIR/defaults-not-assumed-fail.rs:34:5 | LL | assert_eq!(<() as Tr>::B, 0); // causes the error above - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #71800 diff --git a/src/test/ui/async-await/issue-73541-2.stderr b/src/test/ui/async-await/issue-73541-2.stderr index 495c5f6bf2cb1..4c9741f6f37a0 100644 --- a/src/test/ui/async-await/issue-73541-2.stderr +++ b/src/test/ui/async-await/issue-73541-2.stderr @@ -8,7 +8,7 @@ LL | continue 'a | ^^ unreachable label `'a` ... LL | b!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: labels are unreachable through functions, closures, async blocks and modules = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/attributes/key-value-expansion.stderr b/src/test/ui/attributes/key-value-expansion.stderr index 31e93ef54f260..ef59381f5f26d 100644 --- a/src/test/ui/attributes/key-value-expansion.stderr +++ b/src/test/ui/attributes/key-value-expansion.stderr @@ -11,7 +11,7 @@ LL | bug!("bug" + stringify!(found)); | ^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | bug!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,7 +31,7 @@ LL | doc_comment! {format!("{coor}", coor = stringify!($t1)).as_str()} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | some_macro!(u8); - | ---------------- in this macro invocation + | --------------- in this macro invocation | = note: this error originates in the macro `some_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/attributes/nonterminal-expansion.stderr b/src/test/ui/attributes/nonterminal-expansion.stderr index 9bf36f3c58e81..52376ac19119b 100644 --- a/src/test/ui/attributes/nonterminal-expansion.stderr +++ b/src/test/ui/attributes/nonterminal-expansion.stderr @@ -5,7 +5,7 @@ LL | #[repr(align($n))] | ^^ ... LL | pass_nonterminal!(n!()); - | ------------------------ in this macro invocation + | ----------------------- in this macro invocation | = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | #[repr(align($n))] | ^^^^^^^^^ ... LL | pass_nonterminal!(n!()); - | ------------------------ in this macro invocation + | ----------------------- in this macro invocation | = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/binop/issue-77910-1.stderr b/src/test/ui/binop/issue-77910-1.stderr index ed71b99da0f52..db854ae80d738 100644 --- a/src/test/ui/binop/issue-77910-1.stderr +++ b/src/test/ui/binop/issue-77910-1.stderr @@ -2,7 +2,7 @@ error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i3 --> $DIR/issue-77910-1.rs:8:5 | LL | assert_eq!(foo, y); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ | | | for<'r> fn(&'r i32) -> &'r i32 {foo} | _ @@ -13,7 +13,7 @@ error[E0277]: `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug` --> $DIR/issue-77910-1.rs:8:5 | LL | assert_eq!(foo, y); - | ^^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/block-result/consider-removing-last-semi.fixed b/src/test/ui/block-result/consider-removing-last-semi.fixed index a2ecb73ac5b28..36a769fe5292a 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.fixed +++ b/src/test/ui/block-result/consider-removing-last-semi.fixed @@ -10,4 +10,11 @@ pub fn g() -> String { //~ ERROR mismatched types "removeme".to_string() } +pub fn macro_tests() -> u32 { //~ ERROR mismatched types + macro_rules! mac { + () => (1); + } + mac!() +} + fn main() {} diff --git a/src/test/ui/block-result/consider-removing-last-semi.rs b/src/test/ui/block-result/consider-removing-last-semi.rs index 4991d24b26cce..b9a7314890290 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.rs +++ b/src/test/ui/block-result/consider-removing-last-semi.rs @@ -10,4 +10,11 @@ pub fn g() -> String { //~ ERROR mismatched types "removeme".to_string(); } +pub fn macro_tests() -> u32 { //~ ERROR mismatched types + macro_rules! mac { + () => (1); + } + mac!(); +} + fn main() {} diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr index 7c3d0165c6d3a..99a367bfccdcd 100644 --- a/src/test/ui/block-result/consider-removing-last-semi.stderr +++ b/src/test/ui/block-result/consider-removing-last-semi.stderr @@ -20,6 +20,17 @@ LL | "this won't work".to_string(); LL | "removeme".to_string(); | - help: consider removing this semicolon -error: aborting due to 2 previous errors +error[E0308]: mismatched types + --> $DIR/consider-removing-last-semi.rs:13:25 + | +LL | pub fn macro_tests() -> u32 { + | ----------- ^^^ expected `u32`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression +... +LL | mac!(); + | - help: consider removing this semicolon + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr index 60aa2c5a6b06f..2f24679cc9591 100644 --- a/src/test/ui/block-result/issue-13428.stderr +++ b/src/test/ui/block-result/issue-13428.stderr @@ -5,9 +5,6 @@ LL | fn foo() -> String { | --- ^^^^^^ expected struct `String`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression -... -LL | ; - | - help: consider removing this semicolon error[E0308]: mismatched types --> $DIR/issue-13428.rs:11:13 diff --git a/src/test/ui/borrowck/move-error-snippets.stderr b/src/test/ui/borrowck/move-error-snippets.stderr index e7ecd0079f08d..78f99e9041522 100644 --- a/src/test/ui/borrowck/move-error-snippets.stderr +++ b/src/test/ui/borrowck/move-error-snippets.stderr @@ -10,7 +10,7 @@ LL | let a = $c; ::: $DIR/move-error-snippets.rs:21:1 | LL | sss!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `aaa` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr index a2a9da5f87ced..675ba0313d73e 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr @@ -17,7 +17,7 @@ LL | | let x = a.0; | | --- in Rust 2018, this closure captures all of `a`, but in Rust 2021, it will only capture `a.0` LL | | println!("{:?}", x); LL | | }); - | |_______- in this macro invocation + | |______- in this macro invocation | note: the lint level is defined here --> $DIR/closure-body-macro-fragment.rs:4:9 diff --git a/src/test/ui/codemap_tests/bad-format-args.stderr b/src/test/ui/codemap_tests/bad-format-args.stderr index 30013a658f13d..ba056cccf997d 100644 --- a/src/test/ui/codemap_tests/bad-format-args.stderr +++ b/src/test/ui/codemap_tests/bad-format-args.stderr @@ -2,7 +2,7 @@ error: requires at least a format string argument --> $DIR/bad-format-args.rs:2:5 | LL | format!(); - | ^^^^^^^^^^ + | ^^^^^^^^^ | = note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/codemap_tests/issue-28308.stderr b/src/test/ui/codemap_tests/issue-28308.stderr index fc902a2b6dbf3..7daa0510cfa1c 100644 --- a/src/test/ui/codemap_tests/issue-28308.stderr +++ b/src/test/ui/codemap_tests/issue-28308.stderr @@ -2,7 +2,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str` --> $DIR/issue-28308.rs:2:5 | LL | assert!("foo"); - | ^^^^^^^^^^^^^^^ cannot apply unary operator `!` + | ^^^^^^^^^^^^^^ cannot apply unary operator `!` | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/compile_error_macro.stderr b/src/test/ui/compile_error_macro.stderr index 8aa1878c5d7cd..91ebcaa6e9de6 100644 --- a/src/test/ui/compile_error_macro.stderr +++ b/src/test/ui/compile_error_macro.stderr @@ -2,7 +2,7 @@ error: a very descriptive error message --> $DIR/compile_error_macro.rs:2:5 | LL | compile_error!("a very descriptive error message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index bbcab9690a9c1..a057fd19b16b9 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -59,7 +59,7 @@ LL | #[cfg(feature = $expr)] | ^^^^^ ... LL | generate_s10!(concat!("nonexistent")); - | -------------------------------------- in this macro invocation + | ------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -70,7 +70,7 @@ LL | #[cfg(feature = $expr)] | ^^^^^ ... LL | generate_s10!(concat!("nonexistent")); - | -------------------------------------- in this macro invocation + | ------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr b/src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr index a662f6803347a..fc8df6552c3e1 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr +++ b/src/test/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr @@ -5,7 +5,7 @@ LL | #[cfg_attr(all(), unknown)] | ^^^^^^^ ... LL | foo!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/consts/const-external-macro-const-err.stderr b/src/test/ui/consts/const-external-macro-const-err.stderr index 108d976ec6dbe..a66d79a16160c 100644 --- a/src/test/ui/consts/const-external-macro-const-err.stderr +++ b/src/test/ui/consts/const-external-macro-const-err.stderr @@ -2,7 +2,7 @@ error: any use of this value will cause an error --> $DIR/const-external-macro-const-err.rs:12:5 | LL | static_assert!(2 + 2 == 5); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1 | = note: `#[deny(const_err)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! diff --git a/src/test/ui/consts/issue-32829.stderr b/src/test/ui/consts/issue-32829.stderr index 4b25bf1c99e18..6155c935a5f6c 100644 --- a/src/test/ui/consts/issue-32829.stderr +++ b/src/test/ui/consts/issue-32829.stderr @@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer --> $DIR/issue-32829.rs:1:22 | LL | static S : u64 = { { panic!("foo"); 0 } }; - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'foo', $DIR/issue-32829.rs:1:22 + | ^^^^^^^^^^^^^ the evaluated program panicked at 'foo', $DIR/issue-32829.rs:1:22 | = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/consts/issue-66693.stderr b/src/test/ui/consts/issue-66693.stderr index 3db6716a72e8b..3530324bda27c 100644 --- a/src/test/ui/consts/issue-66693.stderr +++ b/src/test/ui/consts/issue-66693.stderr @@ -18,7 +18,7 @@ error: argument to `panic!()` in a const context must have type `&str` --> $DIR/issue-66693.rs:11:5 | LL | panic!(&1); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/consts/miri_unleashed/inline_asm.stderr b/src/test/ui/consts/miri_unleashed/inline_asm.stderr index d06afa8048325..ac9191a340c2e 100644 --- a/src/test/ui/consts/miri_unleashed/inline_asm.stderr +++ b/src/test/ui/consts/miri_unleashed/inline_asm.stderr @@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer --> $DIR/inline_asm.rs:11:14 | LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline assembly is not supported + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline assembly is not supported | = note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -10,7 +10,7 @@ error[E0080]: could not evaluate static initializer --> $DIR/inline_asm.rs:20:14 | LL | unsafe { asm!("nop"); } - | ^^^^^^^^^^^^ inline assembly is not supported + | ^^^^^^^^^^^ inline assembly is not supported warning: skipping const checks | @@ -18,12 +18,12 @@ help: skipping check that does not even have a feature gate --> $DIR/inline_asm.rs:11:14 | LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate --> $DIR/inline_asm.rs:20:14 | LL | unsafe { asm!("nop"); } - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ = note: this warning originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors; 1 warning emitted diff --git a/src/test/ui/cross/cross-crate-macro-backtrace/main.stderr b/src/test/ui/cross/cross-crate-macro-backtrace/main.stderr index 9ebffbfb71a53..6e2a1d3bbc4df 100644 --- a/src/test/ui/cross/cross-crate-macro-backtrace/main.stderr +++ b/src/test/ui/cross/cross-crate-macro-backtrace/main.stderr @@ -2,7 +2,7 @@ error: 1 positional argument in format string, but no arguments were given --> $DIR/main.rs:6:5 | LL | myprintln!("{}"); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/cross/cross-file-errors/main.stderr b/src/test/ui/cross/cross-file-errors/main.stderr index ff9e87250c75d..829535f9212eb 100644 --- a/src/test/ui/cross/cross-file-errors/main.stderr +++ b/src/test/ui/cross/cross-file-errors/main.stderr @@ -7,7 +7,7 @@ LL | _ ::: $DIR/main.rs:5:5 | LL | underscore!(); - | -------------- in this macro invocation + | ------------- in this macro invocation | = note: see issue #71126 for more information = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable @@ -22,7 +22,7 @@ LL | _ ::: $DIR/main.rs:5:5 | LL | underscore!(); - | -------------- in this macro invocation + | ------------- in this macro invocation | = note: this error originates in the macro `underscore` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/deprecation/deprecation-lint-2.stderr b/src/test/ui/deprecation/deprecation-lint-2.stderr index 63da838b3c3d3..a73e5605271be 100644 --- a/src/test/ui/deprecation/deprecation-lint-2.stderr +++ b/src/test/ui/deprecation/deprecation-lint-2.stderr @@ -2,7 +2,7 @@ error: use of deprecated function `deprecation_lint::deprecated`: text --> $DIR/deprecation-lint-2.rs:12:5 | LL | macro_test!(); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/deprecation-lint-2.rs:4:9 diff --git a/src/test/ui/did_you_mean/bad-assoc-expr.stderr b/src/test/ui/did_you_mean/bad-assoc-expr.stderr index fd29f8940bb15..c295cac9aa4b2 100644 --- a/src/test/ui/did_you_mean/bad-assoc-expr.stderr +++ b/src/test/ui/did_you_mean/bad-assoc-expr.stderr @@ -53,7 +53,7 @@ LL | ($ty: ty) => ($ty::clone(&0)) | ^^^^^^^^^^ help: try: `<$ty>::clone` ... LL | expr!(u8); - | ---------- in this macro invocation + | --------- in this macro invocation | = note: this error originates in the macro `expr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/did_you_mean/recursion_limit_macro.stderr b/src/test/ui/did_you_mean/recursion_limit_macro.stderr index 609488e4f2f93..71855cf1e20f3 100644 --- a/src/test/ui/did_you_mean/recursion_limit_macro.stderr +++ b/src/test/ui/did_you_mean/recursion_limit_macro.stderr @@ -5,7 +5,7 @@ LL | ($t:tt $($tail:tt)*) => { recurse!($($tail)*) }; | ^^^^^^^^^^^^^^^^^^^ ... LL | recurse!(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9); - | -------------------------------------------------- in this macro invocation + | ------------------------------------------------- in this macro invocation | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`recursion_limit_macro`) = note: this error originates in the macro `recurse` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/directory_ownership/macro-expanded-mod.stderr b/src/test/ui/directory_ownership/macro-expanded-mod.stderr index e1bba8b527e76..8976341b1ad97 100644 --- a/src/test/ui/directory_ownership/macro-expanded-mod.stderr +++ b/src/test/ui/directory_ownership/macro-expanded-mod.stderr @@ -5,7 +5,7 @@ LL | mod $i; | ^^^^^^^ ... LL | mod_decl!(foo); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `mod_decl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/dollar-crate/dollar-crate-is-keyword-2.stderr b/src/test/ui/dollar-crate/dollar-crate-is-keyword-2.stderr index b6df4cacf3981..d46029710d6f7 100644 --- a/src/test/ui/dollar-crate/dollar-crate-is-keyword-2.stderr +++ b/src/test/ui/dollar-crate/dollar-crate-is-keyword-2.stderr @@ -5,7 +5,7 @@ LL | use a::$crate::b; | ^^^^^^ `$crate` in paths can only be used in start position ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | use a::$crate; | ^^^^^^^^^ no `$crate` in `a` ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | type A = a::$crate; | ^^^^^^ `$crate` in paths can only be used in start position ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/dollar-crate/dollar-crate-is-keyword.stderr b/src/test/ui/dollar-crate/dollar-crate-is-keyword.stderr index 8e32be897649e..b027822307417 100644 --- a/src/test/ui/dollar-crate/dollar-crate-is-keyword.stderr +++ b/src/test/ui/dollar-crate/dollar-crate-is-keyword.stderr @@ -5,7 +5,7 @@ LL | struct $crate {} | ^^^^^^ expected identifier, found reserved identifier ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | use $crate as $crate; | ^^^^^^ expected identifier, found reserved identifier ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | use $crate; | ^^^^^^^^^^^ ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | use $crate as $crate; | ^^^^^^^^^^^^^^^^^^^^^ ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/editions/edition-imports-2015.stderr b/src/test/ui/editions/edition-imports-2015.stderr index 2b4eb815b7172..3f38e6f8e8036 100644 --- a/src/test/ui/editions/edition-imports-2015.stderr +++ b/src/test/ui/editions/edition-imports-2015.stderr @@ -2,7 +2,7 @@ error: cannot glob-import all possible crates --> $DIR/edition-imports-2015.rs:23:5 | LL | gen_glob!(); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ | = note: this error originates in the macro `gen_glob` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/editions/edition-imports-2018.stderr b/src/test/ui/editions/edition-imports-2018.stderr index 1a304ebe9ad27..e7f760e49bcc0 100644 --- a/src/test/ui/editions/edition-imports-2018.stderr +++ b/src/test/ui/editions/edition-imports-2018.stderr @@ -2,7 +2,7 @@ error: cannot glob-import all possible crates --> $DIR/edition-imports-2018.rs:24:5 | LL | gen_glob!(); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ | = note: this error originates in the macro `gen_glob` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr index 9ca7514d3aa08..e4bdd28213ea4 100644 --- a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr @@ -2,7 +2,7 @@ error[E0432]: unresolved import `E` --> $DIR/edition-imports-virtual-2015-gated.rs:8:5 | LL | gen_gated!(); - | ^^^^^^^^^^^^^ could not find `E` in the list of imported crates + | ^^^^^^^^^^^^ could not find `E` in the list of imported crates | = note: this error originates in the macro `gen_gated` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/empty/empty-comment.stderr b/src/test/ui/empty/empty-comment.stderr index 116cc83fa9ce5..f583dbbdc64f8 100644 --- a/src/test/ui/empty/empty-comment.stderr +++ b/src/test/ui/empty/empty-comment.stderr @@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro { | -------------------------- when calling this macro ... LL | one_arg_macro!(/**/); - | ^^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0660.stderr b/src/test/ui/error-codes/E0660.stderr index f8d0cb27a37f3..d9d2f35251b9b 100644 --- a/src/test/ui/error-codes/E0660.stderr +++ b/src/test/ui/error-codes/E0660.stderr @@ -2,13 +2,13 @@ error[E0660]: malformed inline assembly --> $DIR/E0660.rs:6:5 | LL | llvm_asm!("nop" "nop"); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error[E0660]: malformed inline assembly --> $DIR/E0660.rs:8:5 | LL | llvm_asm!("nop" "nop" : "=r"(a)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/expr/if/if-let.stderr b/src/test/ui/expr/if/if-let.stderr index 7975a9dca0dc0..3f3a224583424 100644 --- a/src/test/ui/expr/if/if-let.stderr +++ b/src/test/ui/expr/if/if-let.stderr @@ -7,7 +7,7 @@ LL | if let $p = $e $b LL | / foo!(a, 1, { LL | | println!("irrefutable pattern"); LL | | }); - | |_______- in this macro invocation + | |______- in this macro invocation | = note: `#[warn(irrefutable_let_patterns)]` on by default = note: this pattern will always match, so the `if let` is useless @@ -23,7 +23,7 @@ LL | if let $p = $e $b LL | / bar!(a, 1, { LL | | println!("irrefutable pattern"); LL | | }); - | |_______- in this macro invocation + | |______- in this macro invocation | = note: this pattern will always match, so the `if let` is useless = help: consider replacing the `if let` with a `let` diff --git a/src/test/ui/extenv/extenv-no-args.stderr b/src/test/ui/extenv/extenv-no-args.stderr index acdde84afa4d4..318ed635be028 100644 --- a/src/test/ui/extenv/extenv-no-args.stderr +++ b/src/test/ui/extenv/extenv-no-args.stderr @@ -2,7 +2,7 @@ error: env! takes 1 or 2 arguments --> $DIR/extenv-no-args.rs:1:13 | LL | fn main() { env!(); } - | ^^^^^^^ + | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/extenv/extenv-not-defined-custom.stderr b/src/test/ui/extenv/extenv-not-defined-custom.stderr index c81518010bb29..e7da4e046ab85 100644 --- a/src/test/ui/extenv/extenv-not-defined-custom.stderr +++ b/src/test/ui/extenv/extenv-not-defined-custom.stderr @@ -2,7 +2,7 @@ error: my error message --> $DIR/extenv-not-defined-custom.rs:1:13 | LL | fn main() { env!("__HOPEFULLY_NOT_DEFINED__", "my error message"); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/extenv/extenv-not-defined-default.stderr b/src/test/ui/extenv/extenv-not-defined-default.stderr index 8ecba6dbe9af1..884875dca5394 100644 --- a/src/test/ui/extenv/extenv-not-defined-default.stderr +++ b/src/test/ui/extenv/extenv-not-defined-default.stderr @@ -2,7 +2,7 @@ error: environment variable `__HOPEFULLY_NOT_DEFINED__` not defined --> $DIR/extenv-not-defined-default.rs:2:5 | LL | env!("__HOPEFULLY_NOT_DEFINED__"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/extenv/extenv-too-many-args.stderr b/src/test/ui/extenv/extenv-too-many-args.stderr index 3351da0d54762..54150a3328f92 100644 --- a/src/test/ui/extenv/extenv-too-many-args.stderr +++ b/src/test/ui/extenv/extenv-too-many-args.stderr @@ -2,7 +2,7 @@ error: env! takes 1 or 2 arguments --> $DIR/extenv-too-many-args.rs:1:13 | LL | fn main() { env!("one", "two", "three"); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/extoption_env-no-args.stderr b/src/test/ui/extoption_env-no-args.stderr index 386d517a44603..65067942b85c4 100644 --- a/src/test/ui/extoption_env-no-args.stderr +++ b/src/test/ui/extoption_env-no-args.stderr @@ -2,7 +2,7 @@ error: option_env! takes 1 argument --> $DIR/extoption_env-no-args.rs:1:13 | LL | fn main() { option_env!(); } - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/extoption_env-too-many-args.stderr b/src/test/ui/extoption_env-too-many-args.stderr index 2ec5594703260..a34e60b6448f9 100644 --- a/src/test/ui/extoption_env-too-many-args.stderr +++ b/src/test/ui/extoption_env-too-many-args.stderr @@ -2,7 +2,7 @@ error: option_env! takes 1 argument --> $DIR/extoption_env-too-many-args.rs:1:13 | LL | fn main() { option_env!("one", "two"); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/feature-gates/feature-gate-allow-internal-unsafe-nested-macro.stderr b/src/test/ui/feature-gates/feature-gate-allow-internal-unsafe-nested-macro.stderr index f1becfb99a8cb..4621bc0b30e53 100644 --- a/src/test/ui/feature-gates/feature-gate-allow-internal-unsafe-nested-macro.stderr +++ b/src/test/ui/feature-gates/feature-gate-allow-internal-unsafe-nested-macro.stderr @@ -5,7 +5,7 @@ LL | #[allow_internal_unsafe] | ^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | bar!(); - | ------- in this macro invocation + | ------ in this macro invocation | = help: add `#![feature(allow_internal_unsafe)]` to the crate attributes to enable = note: this error originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/feature-gates/feature-gate-allow-internal-unstable-nested-macro.stderr b/src/test/ui/feature-gates/feature-gate-allow-internal-unstable-nested-macro.stderr index 91cf2020a49f0..1232d13a457a7 100644 --- a/src/test/ui/feature-gates/feature-gate-allow-internal-unstable-nested-macro.stderr +++ b/src/test/ui/feature-gates/feature-gate-allow-internal-unstable-nested-macro.stderr @@ -5,7 +5,7 @@ LL | #[allow_internal_unstable()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | bar!(); - | ------- in this macro invocation + | ------ in this macro invocation | = help: add `#![feature(allow_internal_unstable)]` to the crate attributes to enable = note: this error originates in the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/feature-gates/feature-gate-concat_idents2.stderr b/src/test/ui/feature-gates/feature-gate-concat_idents2.stderr index 5e6dcd5447efa..8663bc7ca7e77 100644 --- a/src/test/ui/feature-gates/feature-gate-concat_idents2.stderr +++ b/src/test/ui/feature-gates/feature-gate-concat_idents2.stderr @@ -11,7 +11,7 @@ error[E0425]: cannot find value `ab` in this scope --> $DIR/feature-gate-concat_idents2.rs:2:5 | LL | concat_idents!(a, b); - | ^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: this error originates in the macro `concat_idents` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/feature-gates/thread-local-const-init.stderr b/src/test/ui/feature-gates/thread-local-const-init.stderr index eac2100560a95..f80506831b4e8 100644 --- a/src/test/ui/feature-gates/thread-local-const-init.stderr +++ b/src/test/ui/feature-gates/thread-local-const-init.stderr @@ -2,7 +2,7 @@ error[E0658]: use of unstable library feature 'thread_local_const_init' --> $DIR/thread-local-const-init.rs:1:1 | LL | thread_local!(static X: u32 = const { 0 }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #84223 for more information = help: add `#![feature(thread_local_const_init)]` to the crate attributes to enable diff --git a/src/test/ui/feature-gates/trace_macros-gate.stderr b/src/test/ui/feature-gates/trace_macros-gate.stderr index e934bfcccf540..1ca10aeece566 100644 --- a/src/test/ui/feature-gates/trace_macros-gate.stderr +++ b/src/test/ui/feature-gates/trace_macros-gate.stderr @@ -11,7 +11,7 @@ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-gate.rs:4:5 | LL | trace_macros!(); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change --> $DIR/trace_macros-gate.rs:6:5 @@ -38,7 +38,7 @@ LL | ($x: ident) => { trace_macros!($x) } | ^^^^^^^^^^^^ ... LL | expando!(true); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: see issue #29598 for more information = help: add `#![feature(trace_macros)]` to the crate attributes to enable diff --git a/src/test/ui/fmt/ifmt-bad-format-args.stderr b/src/test/ui/fmt/ifmt-bad-format-args.stderr index 854abb90638c8..2db280c5e2aa4 100644 --- a/src/test/ui/fmt/ifmt-bad-format-args.stderr +++ b/src/test/ui/fmt/ifmt-bad-format-args.stderr @@ -2,7 +2,7 @@ error: requires at least a format string argument --> $DIR/ifmt-bad-format-args.rs:2:5 | LL | format_args!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr index 8584b650ae689..da37ff3016941 100644 --- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr @@ -29,7 +29,7 @@ LL | let ...$e; | ^^^ help: use `..=` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr index 42c55de28e465..5a504a90b5f07 100644 --- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr @@ -37,7 +37,7 @@ LL | let $e...; | ^^^ help: use `..` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -49,7 +49,7 @@ LL | let $e..=; | ^^^ help: use `..` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/assoc_item_ctxt.stderr b/src/test/ui/hygiene/assoc_item_ctxt.stderr index 517b1ff598888..d65716ec2ce61 100644 --- a/src/test/ui/hygiene/assoc_item_ctxt.stderr +++ b/src/test/ui/hygiene/assoc_item_ctxt.stderr @@ -8,7 +8,7 @@ LL | fn method() {} | not a member of trait `Tr` ... LL | mac_trait_impl!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `mac_trait_impl` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,7 +22,7 @@ LL | impl Tr for u8 { | ^^^^^^^^^^^^^^ missing `method` in implementation ... LL | mac_trait_impl!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `mac_trait_impl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/duplicate_lifetimes.stderr b/src/test/ui/hygiene/duplicate_lifetimes.stderr index b699142c6787a..4d41ebaa43733 100644 --- a/src/test/ui/hygiene/duplicate_lifetimes.stderr +++ b/src/test/ui/hygiene/duplicate_lifetimes.stderr @@ -5,7 +5,7 @@ LL | fn g<$a, 'a>() {} | ^^ declared twice ... LL | m!('a); - | ------- + | ------ | | | | | previous declaration here | in this macro invocation @@ -19,7 +19,7 @@ LL | fn h<$a, 'a>() {} | ^^ declared twice ... LL | n!('a); - | ------- + | ------ | | | | | previous declaration here | in this macro invocation diff --git a/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr b/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr index 98e15c9aad050..e89c19b5881e5 100644 --- a/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr +++ b/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr @@ -14,7 +14,7 @@ LL | use my_core; | ^^^^^^^ no `my_core` in the root ... LL | a!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -25,7 +25,7 @@ LL | fn f() { my_core::mem::drop(0); } | ^^^^^^^ use of undeclared crate or module `my_core` ... LL | a!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/fields-definition.stderr b/src/test/ui/hygiene/fields-definition.stderr index 0c62c00aabc18..9d091cedd237d 100644 --- a/src/test/ui/hygiene/fields-definition.stderr +++ b/src/test/ui/hygiene/fields-definition.stderr @@ -7,7 +7,7 @@ LL | $a: u8, | ^^^^^^ field already declared ... LL | legacy!(a); - | ----------- in this macro invocation + | ---------- in this macro invocation | = note: this error originates in the macro `legacy` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/generate-mod.stderr b/src/test/ui/hygiene/generate-mod.stderr index d96f8329fbde4..32a2e145ca942 100644 --- a/src/test/ui/hygiene/generate-mod.stderr +++ b/src/test/ui/hygiene/generate-mod.stderr @@ -17,7 +17,7 @@ LL | type A = FromOutside; | ^^^^^^^^^^^ not found in this scope ... LL | genmod_transparent!(); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this error originates in the macro `genmod_transparent` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -28,7 +28,7 @@ LL | type Inner = Outer; | ^^^^^ not found in this scope ... LL | genmod_transparent!(); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this error originates in the macro `genmod_transparent` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -39,7 +39,7 @@ LL | type A = FromOutside; | ^^^^^^^^^^^ not found in this scope ... LL | genmod_legacy!(); - | ----------------- in this macro invocation + | ---------------- in this macro invocation | = note: this error originates in the macro `genmod_legacy` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -50,7 +50,7 @@ LL | type Inner = Outer; | ^^^^^ not found in this scope ... LL | genmod_legacy!(); - | ----------------- in this macro invocation + | ---------------- in this macro invocation | = note: this error originates in the macro `genmod_legacy` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/globs.stderr b/src/test/ui/hygiene/globs.stderr index 6c8b707b8e2f1..bcfcc28adf776 100644 --- a/src/test/ui/hygiene/globs.stderr +++ b/src/test/ui/hygiene/globs.stderr @@ -32,7 +32,7 @@ error[E0425]: cannot find function `f` in this scope --> $DIR/globs.rs:61:12 | LL | n!(f); - | ------ in this macro invocation + | ----- in this macro invocation ... LL | n!(f); | ^ not found in this scope @@ -45,7 +45,7 @@ error[E0425]: cannot find function `f` in this scope --> $DIR/globs.rs:65:17 | LL | n!(f); - | ------ in this macro invocation + | ----- in this macro invocation ... LL | f | ^ not found in this scope diff --git a/src/test/ui/hygiene/hygienic-label-1.stderr b/src/test/ui/hygiene/hygienic-label-1.stderr index c1ed861836c1c..deb6a205994aa 100644 --- a/src/test/ui/hygiene/hygienic-label-1.stderr +++ b/src/test/ui/hygiene/hygienic-label-1.stderr @@ -5,7 +5,7 @@ LL | () => { break 'x; } | ^^ undeclared label `'x` ... LL | 'x: loop { foo!(); } - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/hygienic-label-3.stderr b/src/test/ui/hygiene/hygienic-label-3.stderr index 29d1b67e09f9b..cf7f78a99e818 100644 --- a/src/test/ui/hygiene/hygienic-label-3.stderr +++ b/src/test/ui/hygiene/hygienic-label-3.stderr @@ -5,7 +5,7 @@ LL | () => { break 'x; } | ^^ undeclared label `'x` ... LL | foo!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/hygienic-labels-in-let.stderr b/src/test/ui/hygiene/hygienic-labels-in-let.stderr index afca48fe84720..519e3c0880ac6 100644 --- a/src/test/ui/hygiene/hygienic-labels-in-let.stderr +++ b/src/test/ui/hygiene/hygienic-labels-in-let.stderr @@ -8,7 +8,7 @@ LL | 'x: loop { | -- first declared here LL | // this 'x should refer to the outer loop, lexically LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -40,7 +40,7 @@ LL | 'x: loop { | -- first declared here ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -54,7 +54,7 @@ LL | 'x: loop { $e } | label `'x` already in scope ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -68,7 +68,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -118,7 +118,7 @@ LL | 'x: loop { | -- first declared here ... LL | while_true!(break 'x); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this warning originates in the macro `while_true` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -132,7 +132,7 @@ LL | 'x: while 1 + 1 == 2 { $e } | ^^ label `'x` already in scope ... LL | while_true!(break 'x); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this warning originates in the macro `while_true` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -146,7 +146,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | while_true!(break 'x); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this warning originates in the macro `while_true` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -160,7 +160,7 @@ LL | 'x: while 1 + 1 == 2 { $e } | ^^ label `'x` already in scope ... LL | while_true!(break 'x); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this warning originates in the macro `while_true` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -174,7 +174,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | while_true!(break 'x); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = note: this warning originates in the macro `while_true` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -242,7 +242,7 @@ LL | 'x: loop { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -256,7 +256,7 @@ LL | 'x: for _ in 0..1 { $e } | ^^ label `'x` already in scope ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -270,7 +270,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -284,7 +284,7 @@ LL | 'x: for _ in 0..1 { $e } | ^^ label `'x` already in scope ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -298,7 +298,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -312,7 +312,7 @@ LL | 'x: for _ in 0..1 { $e } | ^^ label `'x` already in scope ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -326,7 +326,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/hygienic-labels.stderr b/src/test/ui/hygiene/hygienic-labels.stderr index 8c14e4f8a499f..f0b891fe34979 100644 --- a/src/test/ui/hygiene/hygienic-labels.stderr +++ b/src/test/ui/hygiene/hygienic-labels.stderr @@ -8,7 +8,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here LL | // this 'x should refer to the outer loop, lexically LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -40,7 +40,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -54,7 +54,7 @@ LL | 'x: loop { $e } | label `'x` already in scope ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -68,7 +68,7 @@ LL | 'x: loop { | -- first declared here ... LL | loop_x!(break 'x); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this warning originates in the macro `loop_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -118,7 +118,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | while_x!(break 'x); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this warning originates in the macro `while_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -132,7 +132,7 @@ LL | 'x: while 1 + 1 == 2 { $e } | ^^ label `'x` already in scope ... LL | while_x!(break 'x); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this warning originates in the macro `while_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -146,7 +146,7 @@ LL | 'x: loop { | -- first declared here ... LL | while_x!(break 'x); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this warning originates in the macro `while_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -160,7 +160,7 @@ LL | 'x: while 1 + 1 == 2 { $e } | ^^ label `'x` already in scope ... LL | while_x!(break 'x); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this warning originates in the macro `while_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -174,7 +174,7 @@ LL | 'x: while 1 + 1 == 2 { | -- first declared here ... LL | while_x!(break 'x); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this warning originates in the macro `while_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -242,7 +242,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -256,7 +256,7 @@ LL | 'x: for _ in 0..1 { $e } | ^^ label `'x` already in scope ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -270,7 +270,7 @@ LL | 'x: loop { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -284,7 +284,7 @@ LL | 'x: for _ in 0..1 { $e } | ^^ label `'x` already in scope ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -298,7 +298,7 @@ LL | 'x: while 1 + 1 == 2 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -312,7 +312,7 @@ LL | 'x: while 1 + 1 == 2 { $e } | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -326,7 +326,7 @@ LL | 'x: for _ in 0..1 { | -- first declared here ... LL | run_once!(continue 'x); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this warning originates in the macro `run_once` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/impl_items.stderr b/src/test/ui/hygiene/impl_items.stderr index 9fefa29c4d081..523309f432504 100644 --- a/src/test/ui/hygiene/impl_items.stderr +++ b/src/test/ui/hygiene/impl_items.stderr @@ -5,7 +5,7 @@ LL | let _: () = S.f(); | ^ private type ... LL | foo::m!(); - | ---------- in this macro invocation + | --------- in this macro invocation | = note: this error originates in the macro `foo::m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/hygiene/missing-self-diag.stderr b/src/test/ui/hygiene/missing-self-diag.stderr index b5370209f9d0e..690bcd03226fb 100644 --- a/src/test/ui/hygiene/missing-self-diag.stderr +++ b/src/test/ui/hygiene/missing-self-diag.stderr @@ -6,7 +6,7 @@ LL | self.bar(); ... LL | / pub fn foo(&self) { LL | | call_bar!(); - | | ------------ in this macro invocation + | | ----------- in this macro invocation LL | | } | |_____- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters | diff --git a/src/test/ui/hygiene/no_implicit_prelude.stderr b/src/test/ui/hygiene/no_implicit_prelude.stderr index 0e9b63d6370d6..0f2ff96b5edb6 100644 --- a/src/test/ui/hygiene/no_implicit_prelude.stderr +++ b/src/test/ui/hygiene/no_implicit_prelude.stderr @@ -2,7 +2,7 @@ error[E0433]: failed to resolve: use of undeclared type `Vec` --> $DIR/no_implicit_prelude.rs:11:9 | LL | fn f() { ::bar::m!(); } - | ------------ in this macro invocation + | ----------- in this macro invocation ... LL | Vec::new(); | ^^^ not found in this scope @@ -17,7 +17,7 @@ error[E0599]: no method named `clone` found for unit type `()` in the current sc --> $DIR/no_implicit_prelude.rs:12:12 | LL | fn f() { ::bar::m!(); } - | ------------ in this macro invocation + | ----------- in this macro invocation ... LL | ().clone() | ^^^^^ method not found in `()` diff --git a/src/test/ui/hygiene/privacy-early.stderr b/src/test/ui/hygiene/privacy-early.stderr index 42aee62e0970c..0375ed56d9669 100644 --- a/src/test/ui/hygiene/privacy-early.stderr +++ b/src/test/ui/hygiene/privacy-early.stderr @@ -5,7 +5,7 @@ LL | use f as g; | ^^^^^^ ... LL | foo::m!(); - | ---------- in this macro invocation + | --------- in this macro invocation | note: consider marking `f` as `pub` in the imported module --> $DIR/privacy-early.rs:10:13 @@ -14,7 +14,7 @@ LL | use f as g; | ^^^^^^ ... LL | foo::m!(); - | ---------- in this macro invocation + | --------- in this macro invocation = note: this error originates in the macro `foo::m` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/hygiene/trait_items.stderr b/src/test/ui/hygiene/trait_items.stderr index 77ab6e589e07c..80bdbe0e21e04 100644 --- a/src/test/ui/hygiene/trait_items.stderr +++ b/src/test/ui/hygiene/trait_items.stderr @@ -5,7 +5,7 @@ LL | fn f(&self) {} | - the method is available for `()` here ... LL | fn f() { ::baz::m!(); } - | ------------ in this macro invocation + | ----------- in this macro invocation ... LL | pub macro m() { ().f() } | ^ method not found in `()` diff --git a/src/test/ui/imports/extern-prelude-extern-crate-fail.stderr b/src/test/ui/imports/extern-prelude-extern-crate-fail.stderr index ade757127794a..f7e37449eebe5 100644 --- a/src/test/ui/imports/extern-prelude-extern-crate-fail.stderr +++ b/src/test/ui/imports/extern-prelude-extern-crate-fail.stderr @@ -5,7 +5,7 @@ LL | extern crate std as non_existent; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_std_as_non_existent!(); - | ------------------------------ in this macro invocation + | ----------------------------- in this macro invocation | = note: this error originates in the macro `define_std_as_non_existent` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr b/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr index 089a897f1c29a..472824b84f4a1 100644 --- a/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr +++ b/src/test/ui/imports/extern-prelude-extern-crate-restricted-shadowing.stderr @@ -5,7 +5,7 @@ LL | extern crate std as core; | ^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_other_core!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,7 +22,7 @@ LL | extern crate std as Vec; | ^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_vec!(); - | -------------- in this macro invocation + | ------------- in this macro invocation note: `Vec` could also refer to the struct defined here --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL | diff --git a/src/test/ui/imports/import-crate-var.stderr b/src/test/ui/imports/import-crate-var.stderr index fd4c76c1fa4b2..f1f1dfbdbdbfc 100644 --- a/src/test/ui/imports/import-crate-var.stderr +++ b/src/test/ui/imports/import-crate-var.stderr @@ -2,7 +2,7 @@ error: `$crate` may not be imported --> $DIR/import-crate-var.rs:6:5 | LL | m!(); - | ^^^^^ + | ^^^^ | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr index 9983073ece7cd..f809698fe1d4d 100644 --- a/src/test/ui/imports/local-modularized-tricky-fail-1.stderr +++ b/src/test/ui/imports/local-modularized-tricky-fail-1.stderr @@ -13,7 +13,7 @@ LL | | } | |_____^ ... LL | define_exported!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation note: `exported` could also refer to the macro imported here --> $DIR/local-modularized-tricky-fail-1.rs:22:5 | @@ -37,7 +37,7 @@ LL | | } | |_____^ ... LL | define_exported!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation note: `exported` could also refer to the macro imported here --> $DIR/local-modularized-tricky-fail-1.rs:22:5 | @@ -62,7 +62,7 @@ LL | | } | |_____^ ... LL | define_panic!(); - | ---------------- in this macro invocation + | --------------- in this macro invocation = help: use `crate::panic` to refer to this macro unambiguously = note: this error originates in the macro `define_panic` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -82,7 +82,7 @@ LL | | } | |_____^ ... LL | define_include!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation = help: use `crate::include` to refer to this macro unambiguously = note: this error originates in the macro `define_include` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/imports/local-modularized-tricky-fail-2.stderr b/src/test/ui/imports/local-modularized-tricky-fail-2.stderr index ab9f1eca23d92..3c20f552fdf40 100644 --- a/src/test/ui/imports/local-modularized-tricky-fail-2.stderr +++ b/src/test/ui/imports/local-modularized-tricky-fail-2.stderr @@ -16,7 +16,7 @@ LL | | } | |_____^ ... LL | define_exported!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation = note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info) error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths @@ -36,7 +36,7 @@ LL | | } | |_____^ ... LL | define_exported!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation = note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/imports/shadow_builtin_macros.stderr b/src/test/ui/imports/shadow_builtin_macros.stderr index 82d8078856d58..2fcbb2a045cb3 100644 --- a/src/test/ui/imports/shadow_builtin_macros.stderr +++ b/src/test/ui/imports/shadow_builtin_macros.stderr @@ -27,7 +27,7 @@ LL | macro_rules! panic { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | } } LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `n` is ambiguous (glob import vs any other name from outer scope during import/macro resolution) diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr b/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr index 7094f427aa460..037ce401b3cc9 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr @@ -35,7 +35,7 @@ LL | fn $fn_name(gift: &str) -> $type_name { | ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>` ... LL | autowrapper!(Autowrapped, autowrap_gift, 'a); - | --------------------------------------------- in this macro invocation + | -------------------------------------------- in this macro invocation | = note: this error originates in the macro `autowrapper` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/inference/deref-suggestion.stderr b/src/test/ui/inference/deref-suggestion.stderr index c5c8b8842979b..da11ba204cb53 100644 --- a/src/test/ui/inference/deref-suggestion.stderr +++ b/src/test/ui/inference/deref-suggestion.stderr @@ -56,7 +56,7 @@ error[E0308]: mismatched types --> $DIR/deref-suggestion.rs:36:5 | LL | assert_eq!(3i32, &3i32); - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `&i32` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `&i32` | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/internal/internal-unstable-noallow.stderr b/src/test/ui/internal/internal-unstable-noallow.stderr index 29680c0a630ea..b0ceae62aba73 100644 --- a/src/test/ui/internal/internal-unstable-noallow.stderr +++ b/src/test/ui/internal/internal-unstable-noallow.stderr @@ -2,7 +2,7 @@ error[E0658]: use of unstable library feature 'function' --> $DIR/internal-unstable-noallow.rs:16:5 | LL | call_unstable_noallow!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add `#![feature(function)]` to the crate attributes to enable = note: this error originates in the macro `call_unstable_noallow` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -11,7 +11,7 @@ error[E0658]: use of unstable library feature 'struct_field' --> $DIR/internal-unstable-noallow.rs:18:5 | LL | construct_unstable_noallow!(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add `#![feature(struct_field)]` to the crate attributes to enable = note: this error originates in the macro `construct_unstable_noallow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/internal/internal-unstable.stderr b/src/test/ui/internal/internal-unstable.stderr index 5261a79dfa2e1..b973ea67bf7a3 100644 --- a/src/test/ui/internal/internal-unstable.stderr +++ b/src/test/ui/internal/internal-unstable.stderr @@ -37,7 +37,7 @@ LL | internal_unstable::unstable(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | bar!(internal_unstable::unstable()); - | ------------------------------------ in this macro invocation + | ----------------------------------- in this macro invocation | = help: add `#![feature(function)]` to the crate attributes to enable = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-14091-2.stderr b/src/test/ui/issues/issue-14091-2.stderr index 0b1cc9c768407..fbfa6e1abb2da 100644 --- a/src/test/ui/issues/issue-14091-2.stderr +++ b/src/test/ui/issues/issue-14091-2.stderr @@ -2,7 +2,7 @@ error[E0600]: cannot apply unary operator `!` to type `BytePos` --> $DIR/issue-14091-2.rs:15:5 | LL | assert!(x, x); - | ^^^^^^^^^^^^^^ cannot apply unary operator `!` + | ^^^^^^^^^^^^^ cannot apply unary operator `!` | note: an implementation of `Not` might be missing for `BytePos` --> $DIR/issue-14091-2.rs:6:1 diff --git a/src/test/ui/issues/issue-14091.stderr b/src/test/ui/issues/issue-14091.stderr index 7db4734780817..0a9640a9e3178 100644 --- a/src/test/ui/issues/issue-14091.stderr +++ b/src/test/ui/issues/issue-14091.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-14091.rs:2:5 | LL | assert!(1,1); - | ^^^^^^^^^^^^^ expected `bool`, found integer + | ^^^^^^^^^^^^ expected `bool`, found integer error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr index f9467af9e3c4c..09e20c0c77731 100644 --- a/src/test/ui/issues/issue-16966.stderr +++ b/src/test/ui/issues/issue-16966.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-16966.rs:2:5 | LL | panic!(std::default::Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` declared on the function `begin_panic` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` declared on the function `begin_panic` | = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-19163.stderr b/src/test/ui/issues/issue-19163.stderr index def032ba1bb7a..ae1ae14266f70 100644 --- a/src/test/ui/issues/issue-19163.stderr +++ b/src/test/ui/issues/issue-19163.stderr @@ -2,7 +2,7 @@ error[E0596]: cannot borrow data in a `&` reference as mutable --> $DIR/issue-19163.rs:9:5 | LL | mywrite!(&v, "Hello world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable | = note: this error originates in the macro `mywrite` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-2150.stderr b/src/test/ui/issues/issue-2150.stderr index f1cb3890a72ef..26874faa2b938 100644 --- a/src/test/ui/issues/issue-2150.stderr +++ b/src/test/ui/issues/issue-2150.stderr @@ -2,7 +2,7 @@ error: unreachable statement --> $DIR/issue-2150.rs:8:5 | LL | panic!(); - | --------- any code following this expression is unreachable + | -------- any code following this expression is unreachable LL | for x in &v { i += 1; } | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | diff --git a/src/test/ui/issues/issue-25385.stderr b/src/test/ui/issues/issue-25385.stderr index 5b8bd9418629a..39dbdd753a6ff 100644 --- a/src/test/ui/issues/issue-25385.stderr +++ b/src/test/ui/issues/issue-25385.stderr @@ -5,7 +5,7 @@ LL | ($e:expr) => { $e.foo() } | ^^^ method not found in `i32` ... LL | foo!(a); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-26093.stderr b/src/test/ui/issues/issue-26093.stderr index 33526721b1715..1a08d0fef4118 100644 --- a/src/test/ui/issues/issue-26093.stderr +++ b/src/test/ui/issues/issue-26093.stderr @@ -5,7 +5,7 @@ LL | $thing = 42; | ^ ... LL | not_a_place!(99); - | ----------------- + | ---------------- | | | | | cannot assign to this expression | in this macro invocation @@ -19,7 +19,7 @@ LL | $thing += 42; | ^^ ... LL | not_a_place!(99); - | ----------------- + | ---------------- | | | | | cannot assign to this expression | in this macro invocation diff --git a/src/test/ui/issues/issue-29084.stderr b/src/test/ui/issues/issue-29084.stderr index fec1c55f89eb0..a973e23e29e4c 100644 --- a/src/test/ui/issues/issue-29084.stderr +++ b/src/test/ui/issues/issue-29084.stderr @@ -5,7 +5,7 @@ LL | bar(&mut $d); | ^^^^^^^ expected `u8`, found `&mut u8` ... LL | foo!(0u8); - | ---------- in this macro invocation + | --------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-31011.stderr b/src/test/ui/issues/issue-31011.stderr index ab041594863ce..58c170409fd44 100644 --- a/src/test/ui/issues/issue-31011.stderr +++ b/src/test/ui/issues/issue-31011.stderr @@ -8,7 +8,7 @@ LL | fn wrap(context: &T) -> () | - type parameter 'T' declared here LL | { LL | log!(context, "entered wrapper"); - | --------------------------------- in this macro invocation + | -------------------------------- in this macro invocation | = note: this error originates in the macro `log` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-32655.stderr b/src/test/ui/issues/issue-32655.stderr index c0d9899eb841c..2d9ce430a462d 100644 --- a/src/test/ui/issues/issue-32655.stderr +++ b/src/test/ui/issues/issue-32655.stderr @@ -5,7 +5,7 @@ LL | #[derive_Clone] | ^^^^^^^^^^^^ ... LL | foo!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-32782.stderr b/src/test/ui/issues/issue-32782.stderr index ed43fa73a09e3..a6c55ba03fca3 100644 --- a/src/test/ui/issues/issue-32782.stderr +++ b/src/test/ui/issues/issue-32782.stderr @@ -5,7 +5,7 @@ LL | #[allow_internal_unstable] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | foo!(); - | ------- in this macro invocation + | ------ in this macro invocation | = help: add `#![feature(allow_internal_unstable)]` to the crate attributes to enable = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-39848.stderr b/src/test/ui/issues/issue-39848.stderr index 02c6cd0ca44a9..08faed24bc745 100644 --- a/src/test/ui/issues/issue-39848.stderr +++ b/src/test/ui/issues/issue-39848.stderr @@ -9,7 +9,7 @@ LL | if $tgt.has_$field() {} | this `if` expression has a condition, but no block ... LL | get_opt!(bar, foo); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `get_opt` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-42954.stderr b/src/test/ui/issues/issue-42954.stderr index d00fd4aad73a6..396a91994eb59 100644 --- a/src/test/ui/issues/issue-42954.stderr +++ b/src/test/ui/issues/issue-42954.stderr @@ -7,7 +7,7 @@ LL | $i as u32 < 0 | not interpreted as comparison ... LL | is_plainly_printable!(c); - | ------------------------- in this macro invocation + | ------------------------ in this macro invocation | = note: this error originates in the macro `is_plainly_printable` (in Nightly builds, run with -Z macro-backtrace for more info) help: try comparing the cast value diff --git a/src/test/ui/issues/issue-51848.stderr b/src/test/ui/issues/issue-51848.stderr index bb32b7f9a1313..c25bedf37b753 100644 --- a/src/test/ui/issues/issue-51848.stderr +++ b/src/test/ui/issues/issue-51848.stderr @@ -7,7 +7,7 @@ LL | println!("{"); | because of this opening brace ... LL | macro_with_error!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: if you intended to print `{`, you can escape it using `{{` = note: this error originates in the macro `macro_with_error` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-53251.stderr b/src/test/ui/issues/issue-53251.stderr index fd2522dfbeee4..cee9a5deb05e1 100644 --- a/src/test/ui/issues/issue-53251.stderr +++ b/src/test/ui/issues/issue-53251.stderr @@ -7,7 +7,7 @@ LL | S::f::(); | expected 0 generic arguments ... LL | impl_add!(a b); - | --------------- in this macro invocation + | -------------- in this macro invocation | note: associated function defined here, with 0 generic parameters --> $DIR/issue-53251.rs:4:8 @@ -25,7 +25,7 @@ LL | S::f::(); | expected 0 generic arguments ... LL | impl_add!(a b); - | --------------- in this macro invocation + | -------------- in this macro invocation | note: associated function defined here, with 0 generic parameters --> $DIR/issue-53251.rs:4:8 diff --git a/src/test/ui/issues/issue-59488.stderr b/src/test/ui/issues/issue-59488.stderr index 7789ee342ab44..f739557e001f5 100644 --- a/src/test/ui/issues/issue-59488.stderr +++ b/src/test/ui/issues/issue-59488.stderr @@ -72,7 +72,7 @@ error[E0369]: binary operation `==` cannot be applied to type `fn(usize) -> Foo --> $DIR/issue-59488.rs:30:5 | LL | assert_eq!(Foo::Bar, i); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | | | fn(usize) -> Foo {Foo::Bar} | fn(usize) -> Foo {Foo::Bar} @@ -83,7 +83,7 @@ error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `Debug` --> $DIR/issue-59488.rs:30:5 | LL | assert_eq!(Foo::Bar, i); - | ^^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^^^^^^^^^^^^^^^^^^ `fn(usize) -> Foo {Foo::Bar}` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = help: the trait `Debug` is not implemented for `fn(usize) -> Foo {Foo::Bar}` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-6596-1.stderr b/src/test/ui/issues/issue-6596-1.stderr index c01205223d661..7ab3685c5cbf1 100644 --- a/src/test/ui/issues/issue-6596-1.stderr +++ b/src/test/ui/issues/issue-6596-1.stderr @@ -5,7 +5,7 @@ LL | $nonexistent | ^^^^^^^^^^^^ expected expression ... LL | e!(foo); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `e` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-6596-2.stderr b/src/test/ui/issues/issue-6596-2.stderr index 90627d3bbd55e..3fe3d4d9d67c2 100644 --- a/src/test/ui/issues/issue-6596-2.stderr +++ b/src/test/ui/issues/issue-6596-2.stderr @@ -5,7 +5,7 @@ LL | { $inp $nonexistent } | ^^^^^^^^^^^^ expected one of 8 possible tokens ... LL | g!(foo); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `g` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-68091-unicode-ident-after-if.stderr b/src/test/ui/issues/issue-68091-unicode-ident-after-if.stderr index 43fda800cfa1c..cdd4c670500f0 100644 --- a/src/test/ui/issues/issue-68091-unicode-ident-after-if.stderr +++ b/src/test/ui/issues/issue-68091-unicode-ident-after-if.stderr @@ -11,7 +11,7 @@ LL | $($c)ö* {} | ^^ expected `bool`, found `()` ... LL | x!(if); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `x` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr index f074a99e5ecfb..cd4cc969200a6 100644 --- a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr +++ b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr @@ -2,7 +2,7 @@ error[E0369]: binary operation `==` cannot be applied to type `fn() -> i32 {a}` --> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5 | LL | assert_eq!(a, 0); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | | | fn() -> i32 {a} | {integer} @@ -14,7 +14,7 @@ error[E0308]: mismatched types --> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5 | LL | assert_eq!(a, 0); - | ^^^^^^^^^^^^^^^^^ expected fn item, found integer + | ^^^^^^^^^^^^^^^^ expected fn item, found integer | = note: expected fn item `fn() -> i32 {a}` found type `i32` @@ -27,7 +27,7 @@ LL | fn a() -> i32 { | - consider calling this function ... LL | assert_eq!(a, 0); - | ^^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = help: the trait `Debug` is not implemented for `fn() -> i32 {a}` = help: use parentheses to call the function: `a()` diff --git a/src/test/ui/issues/issue-7970a.stderr b/src/test/ui/issues/issue-7970a.stderr index 5cfb62f3d0572..ea400d7e1917e 100644 --- a/src/test/ui/issues/issue-7970a.stderr +++ b/src/test/ui/issues/issue-7970a.stderr @@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro { | -------------------------- when calling this macro ... LL | one_arg_macro!(); - | ^^^^^^^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments error: aborting due to previous error diff --git a/src/test/ui/lint/lint-stability2.stderr b/src/test/ui/lint/lint-stability2.stderr index 52f6c69cfc90c..51bdf84a321bd 100644 --- a/src/test/ui/lint/lint-stability2.stderr +++ b/src/test/ui/lint/lint-stability2.stderr @@ -2,7 +2,7 @@ error: use of deprecated function `lint_stability::deprecated`: text --> $DIR/lint-stability2.rs:12:5 | LL | macro_test!(); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/lint-stability2.rs:4:9 diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr index 55fea4e3636f4..f20e16287af0f 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.stderr +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -5,7 +5,7 @@ LL | () => {use std::string::ToString;} | ^^^^^^^^^^^^^^^^^^^^^ ... LL | mod a { foo!(); } - | ------- in this macro invocation + | ------ in this macro invocation | note: the lint level is defined here --> $DIR/lints-in-foreign-macros.rs:4:9 diff --git a/src/test/ui/lint/unreachable_pub-pub_crate.stderr b/src/test/ui/lint/unreachable_pub-pub_crate.stderr index 27444e05532eb..f284db80ff90f 100644 --- a/src/test/ui/lint/unreachable_pub-pub_crate.stderr +++ b/src/test/ui/lint/unreachable_pub-pub_crate.stderr @@ -126,7 +126,7 @@ LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } | ^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_empty_struct_with_visibility!(pub, Fluorine); - | ---------------------------------------------------- + | --------------------------------------------------- | | | | | help: consider restricting its visibility: `pub(crate)` | in this macro invocation diff --git a/src/test/ui/lint/unreachable_pub.stderr b/src/test/ui/lint/unreachable_pub.stderr index 5d79292e3e382..61c9582287c01 100644 --- a/src/test/ui/lint/unreachable_pub.stderr +++ b/src/test/ui/lint/unreachable_pub.stderr @@ -126,7 +126,7 @@ LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } | ^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_empty_struct_with_visibility!(pub, Fluorine); - | ---------------------------------------------------- + | --------------------------------------------------- | | | | | help: consider restricting its visibility: `crate` | in this macro invocation diff --git a/src/test/ui/lint/unused/unused-macro-rules.stderr b/src/test/ui/lint/unused/unused-macro-rules.stderr index 55072bd81bf8c..6812a1d8f631a 100644 --- a/src/test/ui/lint/unused/unused-macro-rules.stderr +++ b/src/test/ui/lint/unused/unused-macro-rules.stderr @@ -21,7 +21,7 @@ LL | | } | |_________^ ... LL | create_macro!(); - | ---------------- in this macro invocation + | --------------- in this macro invocation | = note: this error originates in the macro `create_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr index d9dac5de6226c..0b33d8d0a2b23 100644 --- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr +++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr @@ -28,13 +28,12 @@ error[E0308]: mismatched types --> $DIR/liveness-return-last-stmt-semi.rs:4:41 | LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } } - | --- ^^^ - help: consider removing this semicolon - | | | - | | expected `i32`, found `()` + | --- ^^^ expected `i32`, found `()` + | | | implicitly returns `()` as its body has no tail or `return` expression ... LL | test!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/llvm-asm/inline-asm-bad-constraint.stderr b/src/test/ui/llvm-asm/inline-asm-bad-constraint.stderr index 5efc38522b73a..a624829f149c8 100644 --- a/src/test/ui/llvm-asm/inline-asm-bad-constraint.stderr +++ b/src/test/ui/llvm-asm/inline-asm-bad-constraint.stderr @@ -18,7 +18,7 @@ error[E0668]: malformed inline assembly --> $DIR/inline-asm-bad-constraint.rs:38:9 | LL | llvm_asm!("addb $1, $0" : "={rax}"((0i32, rax))); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/llvm-asm/issue-62046.stderr b/src/test/ui/llvm-asm/issue-62046.stderr index 73842a4b9e13d..ae271afe2625e 100644 --- a/src/test/ui/llvm-asm/issue-62046.stderr +++ b/src/test/ui/llvm-asm/issue-62046.stderr @@ -2,7 +2,7 @@ error[E0668]: malformed inline assembly --> $DIR/issue-62046.rs:9:9 | LL | llvm_asm!("nop" : "+r"("r15")); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr b/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr index 10cb4fcfe42a3..715d05beaaee9 100644 --- a/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr @@ -2,7 +2,7 @@ error: macro requires a string literal as an argument --> $DIR/llvm-asm-parse-errors.rs:5:5 | LL | llvm_asm!(); - | ^^^^^^^^^^^^ string literal required + | ^^^^^^^^^^^ string literal required error: expected string literal --> $DIR/llvm-asm-parse-errors.rs:6:23 diff --git a/src/test/ui/macro_backtrace/main.-Zmacro-backtrace.stderr b/src/test/ui/macro_backtrace/main.-Zmacro-backtrace.stderr index 438375951493b..1d57b32d47e86 100644 --- a/src/test/ui/macro_backtrace/main.-Zmacro-backtrace.stderr +++ b/src/test/ui/macro_backtrace/main.-Zmacro-backtrace.stderr @@ -8,7 +8,7 @@ LL | | } | |_- in this expansion of `pong!` ... LL | pong!(); - | -------- in this macro invocation + | ------- in this macro invocation error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error` --> $DIR/main.rs:10:20 @@ -20,14 +20,14 @@ LL | | } | |__- in this expansion of `pong!` (#2) ... LL | ping!(); - | -------- in this macro invocation (#1) + | ------- in this macro invocation (#1) | ::: $DIR/auxiliary/ping.rs:5:1 | LL | / macro_rules! ping { LL | | () => { LL | | pong!(); - | | -------- in this macro invocation (#2) + | | ------- in this macro invocation (#2) LL | | } LL | | } | |_- in this expansion of `ping!` (#1) @@ -42,14 +42,14 @@ LL | | } | |__- in this expansion of `pong!` (#5) ... LL | deep!(); - | -------- in this macro invocation (#1) + | ------- in this macro invocation (#1) | ::: $DIR/auxiliary/ping.rs:5:1 | LL | / macro_rules! ping { LL | | () => { LL | | pong!(); - | | -------- in this macro invocation (#5) + | | ------- in this macro invocation (#5) LL | | } LL | | } | |_- in this expansion of `ping!` (#4) @@ -57,7 +57,7 @@ LL | | } LL | / macro_rules! deep { LL | | () => { LL | | foo!(); - | | ------- in this macro invocation (#2) + | | ------ in this macro invocation (#2) LL | | } LL | | } | |__- in this expansion of `deep!` (#1) @@ -65,7 +65,7 @@ LL | | } LL | / macro_rules! foo { LL | | () => { LL | | bar!(); - | | ------- in this macro invocation (#3) + | | ------ in this macro invocation (#3) LL | | } LL | | } | |__- in this expansion of `foo!` (#2) @@ -73,7 +73,7 @@ LL | | } LL | / macro_rules! bar { LL | | () => { LL | | ping!(); - | | -------- in this macro invocation (#4) + | | ------- in this macro invocation (#4) LL | | } LL | | } | |__- in this expansion of `bar!` (#3) diff --git a/src/test/ui/macro_backtrace/main.default.stderr b/src/test/ui/macro_backtrace/main.default.stderr index f03637abb6733..fa9b4090ddfd3 100644 --- a/src/test/ui/macro_backtrace/main.default.stderr +++ b/src/test/ui/macro_backtrace/main.default.stderr @@ -5,7 +5,7 @@ LL | () => { syntax error }; | ^^^^^ expected one of 8 possible tokens ... LL | pong!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `pong` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | () => { syntax error }; | ^^^^^ expected one of 8 possible tokens ... LL | ping!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `pong` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | () => { syntax error }; | ^^^^^ expected one of 8 possible tokens ... LL | deep!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `pong` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/assert-trailing-junk.stderr b/src/test/ui/macros/assert-trailing-junk.stderr index 84a6768b3f453..eb001429c5522 100644 --- a/src/test/ui/macros/assert-trailing-junk.stderr +++ b/src/test/ui/macros/assert-trailing-junk.stderr @@ -38,7 +38,7 @@ error: macro requires an expression as an argument --> $DIR/assert-trailing-junk.rs:19:5 | LL | assert!(true;); - | ^^^^^^^^^^^^-^^ + | ^^^^^^^^^^^^-^ | | | help: try removing semicolon diff --git a/src/test/ui/macros/assert.stderr b/src/test/ui/macros/assert.stderr index c7566d8931882..57e5c77a56692 100644 --- a/src/test/ui/macros/assert.stderr +++ b/src/test/ui/macros/assert.stderr @@ -2,7 +2,7 @@ error: macro requires a boolean expression as an argument --> $DIR/assert.rs:2:5 | LL | assert!(); - | ^^^^^^^^^^ boolean expression required + | ^^^^^^^^^ boolean expression required error: expected expression, found keyword `struct` --> $DIR/assert.rs:3:13 @@ -14,7 +14,7 @@ error: macro requires a boolean expression as an argument --> $DIR/assert.rs:4:5 | LL | debug_assert!(); - | ^^^^^^^^^^^^^^^^ boolean expression required + | ^^^^^^^^^^^^^^^ boolean expression required | = note: this error originates in the macro `debug_assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/cfg.stderr b/src/test/ui/macros/cfg.stderr index a8e96c0137b57..4785ef9aae482 100644 --- a/src/test/ui/macros/cfg.stderr +++ b/src/test/ui/macros/cfg.stderr @@ -2,7 +2,7 @@ error: macro requires a cfg-pattern as an argument --> $DIR/cfg.rs:2:5 | LL | cfg!(); - | ^^^^^^^ cfg-pattern required + | ^^^^^^ cfg-pattern required | = note: this error originates in the macro `cfg` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/format-parse-errors.stderr b/src/test/ui/macros/format-parse-errors.stderr index ef914cc1c6d5c..c0e766681fed6 100644 --- a/src/test/ui/macros/format-parse-errors.stderr +++ b/src/test/ui/macros/format-parse-errors.stderr @@ -2,7 +2,7 @@ error: requires at least a format string argument --> $DIR/format-parse-errors.rs:4:5 | LL | format!(); - | ^^^^^^^^^^ + | ^^^^^^^^^ | = note: this error originates in the macro `$crate::__export::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/global-asm.stderr b/src/test/ui/macros/global-asm.stderr index a8621a0c5185e..3c26ec65aa27b 100644 --- a/src/test/ui/macros/global-asm.stderr +++ b/src/test/ui/macros/global-asm.stderr @@ -2,7 +2,7 @@ error: requires at least a template string argument --> $DIR/global-asm.rs:4:5 | LL | global_asm!(); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ error: expected expression, found keyword `struct` --> $DIR/global-asm.rs:5:17 diff --git a/src/test/ui/macros/issue-54441.stderr b/src/test/ui/macros/issue-54441.stderr index 752916e665560..bbbca211b8d17 100644 --- a/src/test/ui/macros/issue-54441.stderr +++ b/src/test/ui/macros/issue-54441.stderr @@ -5,7 +5,7 @@ LL | let | ^^^ ... LL | m!(); - | ----- caused by the macro expansion here + | ---- caused by the macro expansion here | = note: the usage of `m!` is likely invalid in foreign item context diff --git a/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr b/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr index 2934281cdd6cb..53a0a0793b262 100644 --- a/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr +++ b/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr @@ -5,7 +5,7 @@ LL | extern crate std as core; | ^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_other_core!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr index aa7d33cfd11a0..e266617bd2249 100644 --- a/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr +++ b/src/test/ui/macros/issue-84632-eager-expansion-recursion-limit.stderr @@ -5,7 +5,7 @@ LL | (A, $($A:ident),*) => (concat!("", a!($($A),*))) | ^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | a!(A, A, A, A, A, A, A, A, A, A, A); - | ------------------------------------ in this macro invocation + | ----------------------------------- in this macro invocation | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "30"]` attribute to your crate (`issue_84632_eager_expansion_recursion_limit`) = note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015.stderr index f9871ab8ffe0c..9a3df858e515f 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2015.stderr +++ b/src/test/ui/macros/macro-at-most-once-rep-2015.stderr @@ -38,7 +38,7 @@ LL | macro_rules! barplus { | -------------------- when calling this macro ... LL | barplus!(); - | ^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^ missing tokens in macro arguments error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:30:15 @@ -74,7 +74,7 @@ LL | macro_rules! barstar { | -------------------- when calling this macro ... LL | barstar!(); - | ^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^ missing tokens in macro arguments error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:37:15 diff --git a/src/test/ui/macros/macro-at-most-once-rep-2018.stderr b/src/test/ui/macros/macro-at-most-once-rep-2018.stderr index bfe5883b03fa0..013fabe13e5f6 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2018.stderr +++ b/src/test/ui/macros/macro-at-most-once-rep-2018.stderr @@ -38,7 +38,7 @@ LL | macro_rules! barplus { | -------------------- when calling this macro ... LL | barplus!(); - | ^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^ missing tokens in macro arguments error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:30:15 @@ -74,7 +74,7 @@ LL | macro_rules! barstar { | -------------------- when calling this macro ... LL | barstar!(); - | ^^^^^^^^^^^ missing tokens in macro arguments + | ^^^^^^^^^^ missing tokens in macro arguments error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:37:15 diff --git a/src/test/ui/macros/macro-backtrace-invalid-internals.stderr b/src/test/ui/macros/macro-backtrace-invalid-internals.stderr index 5c8646008258b..aa8f06a0df13b 100644 --- a/src/test/ui/macros/macro-backtrace-invalid-internals.stderr +++ b/src/test/ui/macros/macro-backtrace-invalid-internals.stderr @@ -5,7 +5,7 @@ LL | 1.fake() | ^^^^ method not found in `{integer}` ... LL | fake_method_stmt!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `fake_method_stmt` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | 1.fake | ^^^^ ... LL | fake_field_stmt!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `fake_field_stmt` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | (1).0 | ^ ... LL | fake_anon_field_stmt!(); - | ------------------------ in this macro invocation + | ----------------------- in this macro invocation | = note: this error originates in the macro `fake_anon_field_stmt` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | 2.0.neg() | ^^^ ... LL | real_method_stmt!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `real_method_stmt` (in Nightly builds, run with -Z macro-backtrace for more info) help: you must specify a concrete type for this numeric value, like `f32` diff --git a/src/test/ui/macros/macro-backtrace-nested.stderr b/src/test/ui/macros/macro-backtrace-nested.stderr index d61434e5f2ff2..38b52e1a12909 100644 --- a/src/test/ui/macros/macro-backtrace-nested.stderr +++ b/src/test/ui/macros/macro-backtrace-nested.stderr @@ -16,7 +16,7 @@ LL | () => (fake) | ^^^^ not found in this scope ... LL | call_nested_expr_sum!(); - | ------------------------ in this macro invocation + | ----------------------- in this macro invocation | = note: this error originates in the macro `nested_expr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/macro-backtrace-println.stderr b/src/test/ui/macros/macro-backtrace-println.stderr index 0703868e9b7e5..bc00e0db83ed5 100644 --- a/src/test/ui/macros/macro-backtrace-println.stderr +++ b/src/test/ui/macros/macro-backtrace-println.stderr @@ -5,7 +5,7 @@ LL | ($fmt:expr) => (myprint!(concat!($fmt, "\n"))); | ^^^^^^^^^^^^^^^^^^^ ... LL | myprintln!("{}"); - | ----------------- in this macro invocation + | ---------------- in this macro invocation | = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/macro-comma-support.stderr b/src/test/ui/macros/macro-comma-support.stderr index 28d064f7f5bd2..874efccd323f8 100644 --- a/src/test/ui/macros/macro-comma-support.stderr +++ b/src/test/ui/macros/macro-comma-support.stderr @@ -2,13 +2,13 @@ error: lel --> $DIR/macro-comma-support.rs:6:5 | LL | compile_error!("lel"); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ error: lel --> $DIR/macro-comma-support.rs:7:5 | LL | compile_error!("lel",); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/macros/macro-context.stderr b/src/test/ui/macros/macro-context.stderr index 3b8a6f1749158..5dc178070318f 100644 --- a/src/test/ui/macros/macro-context.stderr +++ b/src/test/ui/macros/macro-context.stderr @@ -38,7 +38,7 @@ LL | () => ( i ; typeof ); | ^^^^^^ expected expression ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/macro-lifetime-used-with-labels.stderr b/src/test/ui/macros/macro-lifetime-used-with-labels.stderr index f6fc8034410ef..69334e2119210 100644 --- a/src/test/ui/macros/macro-lifetime-used-with-labels.stderr +++ b/src/test/ui/macros/macro-lifetime-used-with-labels.stderr @@ -7,7 +7,7 @@ LL | 'b: loop { LL | 'b: loop { | -- first declared here LL | br2!('b); - | --------- in this macro invocation + | -------- in this macro invocation | = note: this warning originates in the macro `br2` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/macro-local-data-key-priv.stderr b/src/test/ui/macros/macro-local-data-key-priv.stderr index 89ff753b378db..b449e34736820 100644 --- a/src/test/ui/macros/macro-local-data-key-priv.stderr +++ b/src/test/ui/macros/macro-local-data-key-priv.stderr @@ -8,7 +8,7 @@ note: the constant `baz` is defined here --> $DIR/macro-local-data-key-priv.rs:4:5 | LL | thread_local!(static baz: f64 = 0.0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/macros/macro-shadowing.stderr b/src/test/ui/macros/macro-shadowing.stderr index 010520845396a..58224b70734da 100644 --- a/src/test/ui/macros/macro-shadowing.stderr +++ b/src/test/ui/macros/macro-shadowing.stderr @@ -5,7 +5,7 @@ LL | #[macro_use] | ^^^^^^^^^^^^ ... LL | m1!(); - | ------ in this macro invocation + | ----- in this macro invocation | = note: macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560) = note: this error originates in the macro `m1` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -23,7 +23,7 @@ LL | macro_rules! foo { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | m1!(); - | ------ in this macro invocation + | ----- in this macro invocation note: `foo` could also refer to the macro defined here --> $DIR/macro-shadowing.rs:5:1 | diff --git a/src/test/ui/macros/macros-nonfatal-errors.stderr b/src/test/ui/macros/macros-nonfatal-errors.stderr index a52f415dcac51..64065cd272af9 100644 --- a/src/test/ui/macros/macros-nonfatal-errors.stderr +++ b/src/test/ui/macros/macros-nonfatal-errors.stderr @@ -142,7 +142,7 @@ error: concat_idents! requires ident args --> $DIR/macros-nonfatal-errors.rs:102:5 | LL | concat_idents!("not", "idents"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: argument must be a string literal --> $DIR/macros-nonfatal-errors.rs:104:17 @@ -166,7 +166,7 @@ error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined --> $DIR/macros-nonfatal-errors.rs:107:5 | LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -197,7 +197,7 @@ error: couldn't read $DIR/i'd be quite surprised if a file with this name existe --> $DIR/macros-nonfatal-errors.rs:114:5 | LL | include_str!("i'd be quite surprised if a file with this name existed"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -211,7 +211,7 @@ error: couldn't read $DIR/i'd be quite surprised if a file with this name existe --> $DIR/macros-nonfatal-errors.rs:116:5 | LL | include_bytes!("i'd be quite surprised if a file with this name existed"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -219,7 +219,7 @@ error: trace_macros! accepts only `true` or `false` --> $DIR/macros-nonfatal-errors.rs:118:5 | LL | trace_macros!(invalid); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 27 previous errors diff --git a/src/test/ui/macros/must-use-in-macro-55516.stderr b/src/test/ui/macros/must-use-in-macro-55516.stderr index 46fa43ac96519..b56b00cc7d93c 100644 --- a/src/test/ui/macros/must-use-in-macro-55516.stderr +++ b/src/test/ui/macros/must-use-in-macro-55516.stderr @@ -2,7 +2,7 @@ warning: unused `Result` that must be used --> $DIR/must-use-in-macro-55516.rs:9:5 | LL | write!(&mut example, "{}", 42); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-W unused-must-use` implied by `-W unused` = note: this `Result` may be an `Err` variant, which should be handled diff --git a/src/test/ui/macros/nonterminal-matching.stderr b/src/test/ui/macros/nonterminal-matching.stderr index 38df53fb698c9..155a94251312c 100644 --- a/src/test/ui/macros/nonterminal-matching.stderr +++ b/src/test/ui/macros/nonterminal-matching.stderr @@ -8,7 +8,7 @@ LL | n!(a $nt_item b); | ^^^^^^^^ no rules expected this token in macro call ... LL | complex_nonterminal!(enum E {}); - | -------------------------------- in this macro invocation + | ------------------------------- in this macro invocation | = note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/out-of-order-shadowing.stderr b/src/test/ui/macros/out-of-order-shadowing.stderr index 1db31e0272c91..6b11916707433 100644 --- a/src/test/ui/macros/out-of-order-shadowing.stderr +++ b/src/test/ui/macros/out-of-order-shadowing.stderr @@ -8,7 +8,7 @@ note: `bar` could refer to the macro defined here --> $DIR/out-of-order-shadowing.rs:4:1 | LL | define_macro!(bar); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ note: `bar` could also refer to the macro defined here --> $DIR/out-of-order-shadowing.rs:3:1 | diff --git a/src/test/ui/macros/restricted-shadowing-legacy.stderr b/src/test/ui/macros/restricted-shadowing-legacy.stderr index cf4203525e6cb..4912166883260 100644 --- a/src/test/ui/macros/restricted-shadowing-legacy.stderr +++ b/src/test/ui/macros/restricted-shadowing-legacy.stderr @@ -5,7 +5,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -14,7 +14,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:97:9 | @@ -22,7 +22,7 @@ LL | macro_rules! m { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_gen_inner_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -32,7 +32,7 @@ LL | macro_rules! gen_invoc { () => { m!() } } | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -41,7 +41,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:135:9 | @@ -49,7 +49,7 @@ LL | macro_rules! m { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -59,7 +59,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -68,7 +68,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:144:9 | @@ -76,7 +76,7 @@ LL | macro_rules! m { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -86,7 +86,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -95,7 +95,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:85:9 | @@ -103,7 +103,7 @@ LL | macro_rules! m { () => { Wrong } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -113,7 +113,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -122,7 +122,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:85:9 | @@ -130,7 +130,7 @@ LL | macro_rules! m { () => { Wrong } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_gen_inner_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -140,7 +140,7 @@ LL | macro_rules! gen_invoc { () => { m!() } } | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -149,7 +149,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:85:9 | @@ -157,7 +157,7 @@ LL | macro_rules! m { () => { Wrong } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -167,7 +167,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -176,7 +176,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:227:13 | @@ -184,7 +184,7 @@ LL | macro_rules! m { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -194,7 +194,7 @@ LL | macro_rules! gen_invoc { () => { m!() } } | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:88:9 @@ -203,7 +203,7 @@ LL | macro_rules! m { () => { Right } } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-legacy.rs:257:13 | @@ -211,7 +211,7 @@ LL | macro_rules! m { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 8 previous errors diff --git a/src/test/ui/macros/restricted-shadowing-modern.stderr b/src/test/ui/macros/restricted-shadowing-modern.stderr index 6161e46e48b58..62639eeb1192a 100644 --- a/src/test/ui/macros/restricted-shadowing-modern.stderr +++ b/src/test/ui/macros/restricted-shadowing-modern.stderr @@ -5,7 +5,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -14,7 +14,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:99:9 | @@ -22,7 +22,7 @@ LL | macro m() {} | ^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_gen_inner_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -32,7 +32,7 @@ LL | macro gen_invoc() { m!() } | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -41,7 +41,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:143:9 | @@ -49,7 +49,7 @@ LL | macro m() {} | ^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -59,7 +59,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -68,7 +68,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:153:9 | @@ -76,7 +76,7 @@ LL | macro m() {} | ^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -86,7 +86,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -95,7 +95,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:87:9 | @@ -103,7 +103,7 @@ LL | macro m() { Wrong } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -113,7 +113,7 @@ LL | m!(); | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -122,7 +122,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:87:9 | @@ -130,7 +130,7 @@ LL | macro m() { Wrong } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_gen_inner_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0659]: `m` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) @@ -140,7 +140,7 @@ LL | macro gen_invoc() { m!() } | ^ ambiguous name ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation | note: `m` could refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:91:9 @@ -149,7 +149,7 @@ LL | macro m() { Right } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation note: `m` could also refer to the macro defined here --> $DIR/restricted-shadowing-modern.rs:87:9 | @@ -157,7 +157,7 @@ LL | macro m() { Wrong } | ^^^^^^^^^^^^^^^^^^^ ... LL | include!(); - | ----------- in this macro invocation + | ---------- in this macro invocation = note: this error originates in the macro `gen_invoc` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/src/test/ui/macros/same-sequence-span.stderr b/src/test/ui/macros/same-sequence-span.stderr index 4581d5831881b..bdd191e8ed6eb 100644 --- a/src/test/ui/macros/same-sequence-span.stderr +++ b/src/test/ui/macros/same-sequence-span.stderr @@ -18,7 +18,7 @@ error: `$x:expr` may be followed by `$y:tt`, which is not allowed for `expr` fra --> $DIR/same-sequence-span.rs:19:1 | LL | proc_macro_sequence::make_foo!(); - | ^-------------------------------- + | ^------------------------------- | | | _in this macro invocation | | @@ -34,7 +34,7 @@ error: `$x:expr` may be followed by `=`, which is not allowed for `expr` fragmen --> $DIR/same-sequence-span.rs:19:1 | LL | proc_macro_sequence::make_foo!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not allowed after `expr` fragments + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not allowed after `expr` fragments | = note: allowed there are: `=>`, `,` or `;` = note: this error originates in the macro `proc_macro_sequence::make_foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/span-covering-argument-1.stderr b/src/test/ui/macros/span-covering-argument-1.stderr index f563b0dc12923..ce3424a8b15f0 100644 --- a/src/test/ui/macros/span-covering-argument-1.stderr +++ b/src/test/ui/macros/span-covering-argument-1.stderr @@ -7,7 +7,7 @@ LL | *&mut $s = 0; | ^^^^^^^ cannot borrow as mutable ... LL | bad!(foo whatever); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `bad` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/macros/trace-macro.stderr b/src/test/ui/macros/trace-macro.stderr index bf48e80eff147..43272248c280e 100644 --- a/src/test/ui/macros/trace-macro.stderr +++ b/src/test/ui/macros/trace-macro.stderr @@ -2,7 +2,7 @@ note: trace_macro --> $DIR/trace-macro.rs:5:5 | LL | println!("Hello, World!"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: expanding `println! { "Hello, World!" }` = note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")) ; }` diff --git a/src/test/ui/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr index dc38972d1d09e..d6fc694021448 100644 --- a/src/test/ui/macros/trace_faulty_macros.stderr +++ b/src/test/ui/macros/trace_faulty_macros.stderr @@ -8,7 +8,7 @@ LL | my_faulty_macro!(bcd); | ^^^ no rules expected this token in macro call ... LL | my_faulty_macro!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `my_faulty_macro` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ note: trace_macro --> $DIR/trace_faulty_macros.rs:31:5 | LL | my_faulty_macro!(); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ | = note: expanding `my_faulty_macro! { }` = note: to `my_faulty_macro! (bcd) ;` @@ -26,10 +26,10 @@ error: recursion limit reached while expanding `my_recursive_macro!` --> $DIR/trace_faulty_macros.rs:22:9 | LL | my_recursive_macro!(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ ... LL | my_recursive_macro!(); - | ---------------------- in this macro invocation + | --------------------- in this macro invocation | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`trace_faulty_macros`) = note: this error originates in the macro `my_recursive_macro` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ note: trace_macro --> $DIR/trace_faulty_macros.rs:32:5 | LL | my_recursive_macro!(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ | = note: expanding `my_recursive_macro! { }` = note: to `my_recursive_macro! () ;` diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr index 3e2ebf43b8c3a..da8a976daaf1a 100644 --- a/src/test/ui/mismatched_types/issue-26480.stderr +++ b/src/test/ui/mismatched_types/issue-26480.stderr @@ -5,7 +5,7 @@ LL | $arr.len() * size_of($arr[0])); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `usize` ... LL | write!(hello); - | -------------- in this macro invocation + | ------------- in this macro invocation | = note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info) help: you can convert a `usize` to a `u64` and panic if the converted value doesn't fit @@ -20,7 +20,7 @@ LL | ($x:expr) => ($x as ()) | ^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object ... LL | cast!(2); - | --------- in this macro invocation + | -------- in this macro invocation | = note: this error originates in the macro `cast` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/modules/issue-56411.stderr b/src/test/ui/modules/issue-56411.stderr index cbeaafd9268aa..5ab4542b0402b 100644 --- a/src/test/ui/modules/issue-56411.stderr +++ b/src/test/ui/modules/issue-56411.stderr @@ -10,7 +10,7 @@ LL | pub use self::$name; | you can use `as` to change the binding name of the import ... LL | import!(("issue-56411-aux.rs", issue_56411_aux)); - | ------------------------------------------------- in this macro invocation + | ------------------------------------------------ in this macro invocation | = note: `issue_56411_aux` must be defined only once in the type namespace of this module = note: this error originates in the macro `import` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,7 +22,7 @@ LL | pub use self::$name; | ^^^^^^^^^^^ re-export of private `issue_56411_aux` ... LL | import!(("issue-56411-aux.rs", issue_56411_aux)); - | ------------------------------------------------- in this macro invocation + | ------------------------------------------------ in this macro invocation | = note: consider declaring type or module `issue_56411_aux` with `pub` = note: this error originates in the macro `import` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr index b62cc378aa5e4..f9e6d89513630 100644 --- a/src/test/ui/non-fmt-panic.stderr +++ b/src/test/ui/non-fmt-panic.stderr @@ -199,7 +199,7 @@ warning: panic message contains braces --> $DIR/non-fmt-panic.rs:31:5 | LL | panic!(concat!("{", "{")); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this message is not used as a format string, but will be in Rust 2021 help: add a "{}" format string to use the message literally diff --git a/src/test/ui/parser/bad-interpolated-block.stderr b/src/test/ui/parser/bad-interpolated-block.stderr index 9a6957a040849..77933b1bcec68 100644 --- a/src/test/ui/parser/bad-interpolated-block.stderr +++ b/src/test/ui/parser/bad-interpolated-block.stderr @@ -7,7 +7,7 @@ LL | 'lab: $b; | the `block` fragment is within this context ... LL | m!({}); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -20,7 +20,7 @@ LL | unsafe $b; | the `block` fragment is within this context ... LL | m!({}); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,7 +31,7 @@ LL | |x: u8| -> () $b; | ^^ the `block` fragment is within this context ... LL | m!({}); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/float-field-interpolated.stderr b/src/test/ui/parser/float-field-interpolated.stderr index 4b03427cd5871..664adb35818aa 100644 --- a/src/test/ui/parser/float-field-interpolated.stderr +++ b/src/test/ui/parser/float-field-interpolated.stderr @@ -5,7 +5,7 @@ LL | { s.$b; } | ^^ ... LL | generate_field_accesses!(1.1, 1.1, 1.1); - | ---------------------------------------- in this macro invocation + | --------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | { s.$b; } | ^^ expected one of `.`, `;`, `?`, `}`, or an operator ... LL | generate_field_accesses!(1.1, 1.1, 1.1); - | ---------------------------------------- in this macro invocation + | --------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | { s.$c; } | ^^ ... LL | generate_field_accesses!(1.1, 1.1, 1.1); - | ---------------------------------------- in this macro invocation + | --------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | { s.$c; } | ^^ expected one of `.`, `;`, `?`, `}`, or an operator ... LL | generate_field_accesses!(1.1, 1.1, 1.1); - | ---------------------------------------- in this macro invocation + | --------------------------------------- in this macro invocation | = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/issue-44406.stderr b/src/test/ui/parser/issue-44406.stderr index a37a806a15749..61419040b3381 100644 --- a/src/test/ui/parser/issue-44406.stderr +++ b/src/test/ui/parser/issue-44406.stderr @@ -16,7 +16,7 @@ LL | bar(baz: $rest) | ^^^^^^^^^^^^^^^ ... LL | foo!(true); - | ----------- in this macro invocation + | ---------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: if `bar` is a struct, use braces as delimiters diff --git a/src/test/ui/parser/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.stderr b/src/test/ui/parser/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.stderr index 0ab718d8bd4f5..fdef8ff6df923 100644 --- a/src/test/ui/parser/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.stderr +++ b/src/test/ui/parser/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.stderr @@ -13,7 +13,7 @@ LL | enum BadE {} | ^^^^^^^^^ ... LL | expand_to_enum!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = help: consider moving the enum out to a nearby module scope = note: this error originates in the macro `expand_to_enum` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -33,7 +33,7 @@ LL | enum BadE {} | ^^^^^^^^^ ... LL | expand_to_enum!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = help: consider moving the enum out to a nearby module scope = note: this error originates in the macro `expand_to_enum` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -53,7 +53,7 @@ LL | enum BadE {} | ^^^^^^^^^ ... LL | expand_to_enum!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = help: consider moving the enum out to a nearby module scope = note: this error originates in the macro `expand_to_enum` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/issue-73568-lifetime-after-mut.stderr b/src/test/ui/parser/issue-73568-lifetime-after-mut.stderr index 6f26f36e76315..48c2b2a19d414 100644 --- a/src/test/ui/parser/issue-73568-lifetime-after-mut.stderr +++ b/src/test/ui/parser/issue-73568-lifetime-after-mut.stderr @@ -17,7 +17,7 @@ LL | fn w<$lt>(w: &mut $lt i32) {} | ^^^^^^^^ help: place the lifetime before `mut`: `&$lt mut` ... LL | mac!('a); - | --------- in this macro invocation + | -------- in this macro invocation | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/issue-87812-path.stderr b/src/test/ui/parser/issue-87812-path.stderr index 0c8e6fdd3076a..f8ee0517533c6 100644 --- a/src/test/ui/parser/issue-87812-path.stderr +++ b/src/test/ui/parser/issue-87812-path.stderr @@ -7,7 +7,7 @@ LL | let _: usize = $f; | expected due to this ... LL | foo!(Baz); - | ---------- in this macro invocation + | --------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/labeled-no-colon-expr.stderr b/src/test/ui/parser/labeled-no-colon-expr.stderr index 50995895bc8fe..26884dc5d7452 100644 --- a/src/test/ui/parser/labeled-no-colon-expr.stderr +++ b/src/test/ui/parser/labeled-no-colon-expr.stderr @@ -68,7 +68,7 @@ LL | 'l5 $b; | the `block` fragment is within this context ... LL | m!({}); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/macro/issue-37113.stderr b/src/test/ui/parser/macro/issue-37113.stderr index f9f53e65d7bf0..0912858ddc4a6 100644 --- a/src/test/ui/parser/macro/issue-37113.stderr +++ b/src/test/ui/parser/macro/issue-37113.stderr @@ -5,7 +5,7 @@ LL | $( $t, )* | ^^ expected identifier ... LL | test_macro!(String,); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `test_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/macro/issue-37234.stderr b/src/test/ui/parser/macro/issue-37234.stderr index 8d9636d401c1e..d7919620449f4 100644 --- a/src/test/ui/parser/macro/issue-37234.stderr +++ b/src/test/ui/parser/macro/issue-37234.stderr @@ -5,7 +5,7 @@ LL | let x = 5 ""; | ^^ expected one of `.`, `;`, `?`, `else`, or an operator ... LL | failed!(); - | ---------- in this macro invocation + | --------- in this macro invocation | = note: this error originates in the macro `failed` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/macro/macro-incomplete-parse.stderr b/src/test/ui/parser/macro/macro-incomplete-parse.stderr index 186b22dce9a58..707417b725e9f 100644 --- a/src/test/ui/parser/macro/macro-incomplete-parse.stderr +++ b/src/test/ui/parser/macro/macro-incomplete-parse.stderr @@ -5,7 +5,7 @@ LL | , | ^ ... LL | ignored_item!(); - | ---------------- caused by the macro expansion here + | --------------- caused by the macro expansion here | = note: the usage of `ignored_item!` is likely invalid in item context @@ -16,7 +16,7 @@ LL | () => ( 1, | ^ expected one of `.`, `;`, `?`, `}`, or an operator ... LL | ignored_expr!(); - | ---------------- in this macro invocation + | --------------- in this macro invocation | = note: this error originates in the macro `ignored_expr` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/macro/pub-item-macro.stderr b/src/test/ui/parser/macro/pub-item-macro.stderr index 0b81d2074b6f1..4f82acf38e109 100644 --- a/src/test/ui/parser/macro/pub-item-macro.stderr +++ b/src/test/ui/parser/macro/pub-item-macro.stderr @@ -5,7 +5,7 @@ LL | pub priv_x!(); | ^^^ help: remove the visibility ... LL | pub_x!(); - | --------- in this macro invocation + | -------- in this macro invocation | = help: try adjusting the macro to put `pub` inside the invocation = note: this error originates in the macro `pub_x` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -23,7 +23,7 @@ LL | static x: u32 = 0; | ^^^^^^^^^^^^^^^^^^ ... LL | pub_x!(); - | --------- in this macro invocation + | -------- in this macro invocation = note: this error originates in the macro `priv_x` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/macro/trait-non-item-macros.stderr b/src/test/ui/parser/macro/trait-non-item-macros.stderr index 35e5bfe62f5b4..db20e6b24aa03 100644 --- a/src/test/ui/parser/macro/trait-non-item-macros.stderr +++ b/src/test/ui/parser/macro/trait-non-item-macros.stderr @@ -5,7 +5,7 @@ LL | $a | ^^ ... LL | bah!(2); - | -------- caused by the macro expansion here + | ------- caused by the macro expansion here | = note: the usage of `bah!` is likely invalid in trait item context diff --git a/src/test/ui/parser/missing-semicolon.stderr b/src/test/ui/parser/missing-semicolon.stderr index 72f76b6fe3f54..e0d5e84ec3177 100644 --- a/src/test/ui/parser/missing-semicolon.stderr +++ b/src/test/ui/parser/missing-semicolon.stderr @@ -5,7 +5,7 @@ LL | $( let x = $e1 )*; | ^^^ expected one of `.`, `;`, `?`, `else`, or an operator ... LL | fn main() { m!(0, 0; 0, 0); } - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/mut-patterns.stderr b/src/test/ui/parser/mut-patterns.stderr index bfa443a7f0113..59dba4ae21646 100644 --- a/src/test/ui/parser/mut-patterns.stderr +++ b/src/test/ui/parser/mut-patterns.stderr @@ -106,7 +106,7 @@ LL | let mut $p = 0; | ^^ expected identifier ... LL | foo!(x); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/parser/recover-range-pats.stderr b/src/test/ui/parser/recover-range-pats.stderr index 762066825db29..9296ad2e335f1 100644 --- a/src/test/ui/parser/recover-range-pats.stderr +++ b/src/test/ui/parser/recover-range-pats.stderr @@ -165,7 +165,7 @@ LL | let ...$e; | ^^^ help: use `..=` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -176,7 +176,7 @@ LL | let $e...; | ^^^ help: use `..` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -188,7 +188,7 @@ LL | let $e..=; | ^^^ help: use `..` instead ... LL | mac!(0); - | -------- in this macro invocation + | ------- in this macro invocation | = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -277,7 +277,7 @@ LL | let $e1...$e2; | ^^^ help: use `..=` for an inclusive range ... LL | mac2!(0, 1); - | ------------ in this macro invocation + | ----------- in this macro invocation | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see diff --git a/src/test/ui/privacy/associated-item-privacy-inherent.stderr b/src/test/ui/privacy/associated-item-privacy-inherent.stderr index 08b282e1870de..4478e5c2aba57 100644 --- a/src/test/ui/privacy/associated-item-privacy-inherent.stderr +++ b/src/test/ui/privacy/associated-item-privacy-inherent.stderr @@ -5,7 +5,7 @@ LL | let value = Pub::method; | ^^^^^^^^^^^ private type ... LL | priv_nominal::mac!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | value; | ^^^^^ private type ... LL | priv_nominal::mac!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | Pub.method(); | ^^^^^^ private type ... LL | priv_nominal::mac!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | Pub::CONST; | ^^^^^^^^^^ private associated constant ... LL | priv_nominal::mac!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -49,7 +49,7 @@ LL | let value = Pub::method; | ^^^^^^^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | value; | ^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -71,7 +71,7 @@ LL | Pub.method(loop {}); | ^^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -82,7 +82,7 @@ LL | let value = Pub::method::; | ^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -93,7 +93,7 @@ LL | value; | ^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -104,7 +104,7 @@ LL | Pub.method::(); | ^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -115,7 +115,7 @@ LL | let value = ::method; | ^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -126,7 +126,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -137,7 +137,7 @@ LL | let value = Pub::method; | ^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -148,7 +148,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -159,7 +159,7 @@ LL | let value = ::static_method; | ^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -170,7 +170,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -181,7 +181,7 @@ LL | let value = Pub::static_method; | ^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -192,7 +192,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -203,7 +203,7 @@ LL | Pub(Priv).method(); | ^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -214,7 +214,7 @@ LL | ::CONST; | ^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -225,7 +225,7 @@ LL | Pub::CONST; | ^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/privacy/associated-item-privacy-trait.stderr b/src/test/ui/privacy/associated-item-privacy-trait.stderr index 3a42415e4746c..6095f5f42b86d 100644 --- a/src/test/ui/privacy/associated-item-privacy-trait.stderr +++ b/src/test/ui/privacy/associated-item-privacy-trait.stderr @@ -5,7 +5,7 @@ LL | let value = ::method; | ^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | value; | ^^^^^ private type ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | Pub.method(); | ^^^^^^ private type ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | ::CONST; | ^^^^^^^^^^^^^^^^^^^^^^ private associated constant ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -49,7 +49,7 @@ LL | let _: ::AssocTy; | ^^^^^^^^^^^^^^^^^^^^^^^^ private associated type ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | pub type InSignatureTy = ::AssocTy; | ^^^^^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -71,7 +71,7 @@ LL | pub trait InSignatureTr: PrivTr {} | ^^^^^^ private trait ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -82,7 +82,7 @@ LL | impl PrivTr for u8 {} | ^^^^^^ private trait ... LL | priv_trait::mac!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation | = note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -93,7 +93,7 @@ LL | let value = ::method; | ^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -104,7 +104,7 @@ LL | value; | ^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -115,7 +115,7 @@ LL | Pub.method(loop {}); | ^^^^^^ private type ... LL | priv_signature::mac!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `priv_signature::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -126,7 +126,7 @@ LL | let value = ::method::; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -137,7 +137,7 @@ LL | value; | ^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -148,7 +148,7 @@ LL | Pub.method::(); | ^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_substs::mac!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -159,7 +159,7 @@ LL | let value = ::method; | ^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -170,7 +170,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -181,7 +181,7 @@ LL | let value = >::method; | ^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -192,7 +192,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -203,7 +203,7 @@ LL | Pub.method(); | ^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -214,7 +214,7 @@ LL | let value = >::method; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -225,7 +225,7 @@ LL | value; | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -236,7 +236,7 @@ LL | Priv.method(); | ^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -247,7 +247,7 @@ LL | ::CONST; | ^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -258,7 +258,7 @@ LL | >::CONST; | ^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -269,7 +269,7 @@ LL | >::CONST; | ^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -280,7 +280,7 @@ LL | let _: >::AssocTy; | ^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -291,7 +291,7 @@ LL | let _: >::AssocTy; | ^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -302,7 +302,7 @@ LL | pub type InSignatureTy1 = ::AssocTy; | ^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -313,7 +313,7 @@ LL | pub type InSignatureTy2 = >::AssocTy; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -324,7 +324,7 @@ LL | impl PubTr for u8 {} | ^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/privacy/associated-item-privacy-type-binding.stderr b/src/test/ui/privacy/associated-item-privacy-type-binding.stderr index c275413b4501a..de9893816fade 100644 --- a/src/test/ui/privacy/associated-item-privacy-type-binding.stderr +++ b/src/test/ui/privacy/associated-item-privacy-type-binding.stderr @@ -5,7 +5,7 @@ LL | let _: Box>; | ^ private trait ... LL | priv_trait::mac1!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac1` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | let _: Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac1!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac1` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | type InSignatureTy2 = Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac1!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac1` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | trait InSignatureTr2: PubTr {} | ^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac1!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac1` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -49,7 +49,7 @@ LL | let _: Box>; | ^ private trait ... LL | priv_trait::mac2!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac2` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | let _: Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac2!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac2` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -71,7 +71,7 @@ LL | type InSignatureTy1 = Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac2!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac2` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -82,7 +82,7 @@ LL | trait InSignatureTr1: PrivTr {} | ^^^^^^^^^^^^^^^^^^^^ private trait ... LL | priv_trait::mac2!(); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `priv_trait::mac2` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -93,7 +93,7 @@ LL | let _: Box>; | ^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -104,7 +104,7 @@ LL | let _: Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -115,7 +115,7 @@ LL | let _: Box>; | ^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -126,7 +126,7 @@ LL | let _: Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -137,7 +137,7 @@ LL | pub type InSignatureTy1 = Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -148,7 +148,7 @@ LL | pub type InSignatureTy2 = Box>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -159,7 +159,7 @@ LL | trait InSignatureTr1: PubTrWithParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -170,7 +170,7 @@ LL | trait InSignatureTr2: PubTr {} | ^^^^^^^^^^^^^^^^^^^ private type ... LL | priv_parent_substs::mac!(); - | --------------------------- in this macro invocation + | -------------------------- in this macro invocation | = note: this error originates in the macro `priv_parent_substs::mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/privacy/private-inferred-type-3.stderr b/src/test/ui/privacy/private-inferred-type-3.stderr index 3cd4b4d26c809..f9dd1c3d03509 100644 --- a/src/test/ui/privacy/private-inferred-type-3.stderr +++ b/src/test/ui/privacy/private-inferred-type-3.stderr @@ -2,7 +2,7 @@ error: type `fn() {ext::priv_fn}` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -10,7 +10,7 @@ error: static `PRIV_STATIC` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private static + | ^^^^^^^^^ private static | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -18,7 +18,7 @@ error: type `ext::PrivEnum` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -26,7 +26,7 @@ error: type `fn() {::method}` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -34,7 +34,7 @@ error: type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct}` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -42,7 +42,7 @@ error: type `fn(u8) -> PubTupleStruct {PubTupleStruct}` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -50,7 +50,7 @@ error: type `for<'r> fn(&'r Pub) {Pub::::priv_method}` is private --> $DIR/private-inferred-type-3.rs:16:5 | LL | ext::m!(); - | ^^^^^^^^^^ private type + | ^^^^^^^^^ private type | = note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/privacy/private-inferred-type.stderr b/src/test/ui/privacy/private-inferred-type.stderr index c6bdb898f966d..e7e968839b6fa 100644 --- a/src/test/ui/privacy/private-inferred-type.stderr +++ b/src/test/ui/privacy/private-inferred-type.stderr @@ -113,7 +113,7 @@ LL | priv_fn; | ^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -124,7 +124,7 @@ LL | PrivEnum::Variant; | ^^^^^^^^^^^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -135,7 +135,7 @@ LL | ::method; | ^^^^^^^^^^^^^^^^^^^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -146,7 +146,7 @@ LL | PrivTupleStruct; | ^^^^^^^^^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -157,7 +157,7 @@ LL | PubTupleStruct; | ^^^^^^^^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -168,7 +168,7 @@ LL | Pub(0u8).priv_method(); | ^^^^^^^^^^^ private type ... LL | m::m!(); - | -------- in this macro invocation + | ------- in this macro invocation | = note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.stderr b/src/test/ui/proc-macro/derive-helper-shadowing.stderr index 3b160935a2f8d..df462903fc077 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowing.stderr +++ b/src/test/ui/proc-macro/derive-helper-shadowing.stderr @@ -27,7 +27,7 @@ LL | #[empty_helper] | ^^^^^^^^^^^^ ... LL | gen_helper_use!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: consider importing this attribute macro: crate::empty_helper diff --git a/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr b/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr index b16b24b9dc673..6060f872f227a 100644 --- a/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr +++ b/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr @@ -2,10 +2,10 @@ error[E0426]: use of undeclared label `'label_use` --> $DIR/gen-macro-rules-hygiene.rs:12:1 | LL | gen_macro_rules!(); - | ^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use` + | ^^^^^^^^^^^^^^^^^^ undeclared label `'label_use` ... LL | generated!(); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `generated` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -13,10 +13,10 @@ error[E0425]: cannot find value `local_use` in this scope --> $DIR/gen-macro-rules-hygiene.rs:12:1 | LL | gen_macro_rules!(); - | ^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^ not found in this scope ... LL | generated!(); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `generated` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/generate-mod.stderr b/src/test/ui/proc-macro/generate-mod.stderr index d6fd4baeb5ece..be58cc40ed299 100644 --- a/src/test/ui/proc-macro/generate-mod.stderr +++ b/src/test/ui/proc-macro/generate-mod.stderr @@ -2,7 +2,7 @@ error[E0412]: cannot find type `FromOutside` in this scope --> $DIR/generate-mod.rs:9:1 | LL | generate_mod::check!(); - | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: consider importing this struct: FromOutside @@ -12,7 +12,7 @@ error[E0412]: cannot find type `Outer` in this scope --> $DIR/generate-mod.rs:9:1 | LL | generate_mod::check!(); - | ^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: consider importing this struct: Outer diff --git a/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr b/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr index 001b345204d34..1a56291896c76 100644 --- a/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr +++ b/src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr @@ -7,7 +7,7 @@ LL | #[my_macro] struct One($name); ::: $DIR/group-compat-hack.rs:27:5 | LL | impl_macros!(Foo); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: `#[warn(proc_macro_back_compat)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -24,7 +24,7 @@ LL | #[my_macro] struct One($name); ::: $DIR/group-compat-hack.rs:44:5 | LL | impl_macros!(Foo); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -40,7 +40,7 @@ LL | #[my_macro] struct Two($name); ::: $DIR/group-compat-hack.rs:46:5 | LL | arrays!(Foo); - | ------------- in this macro invocation + | ------------ in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -56,7 +56,7 @@ LL | #[my_macro] struct Three($T); ::: $DIR/group-compat-hack.rs:55:5 | LL | tuple_from_req!(Foo); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -72,7 +72,7 @@ LL | #[my_macro] struct Three($T); ::: $DIR/group-compat-hack.rs:63:5 | LL | tuple_from_req!(Foo); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -91,7 +91,7 @@ LL | #[my_macro] struct One($name); ::: $DIR/group-compat-hack.rs:27:5 | LL | impl_macros!(Foo); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: `#[warn(proc_macro_back_compat)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -109,7 +109,7 @@ LL | #[my_macro] struct One($name); ::: $DIR/group-compat-hack.rs:44:5 | LL | impl_macros!(Foo); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -126,7 +126,7 @@ LL | #[my_macro] struct Two($name); ::: $DIR/group-compat-hack.rs:46:5 | LL | arrays!(Foo); - | ------------- in this macro invocation + | ------------ in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -143,7 +143,7 @@ LL | #[my_macro] struct Three($T); ::: $DIR/group-compat-hack.rs:55:5 | LL | tuple_from_req!(Foo); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 @@ -160,7 +160,7 @@ LL | #[my_macro] struct Three($T); ::: $DIR/group-compat-hack.rs:63:5 | LL | tuple_from_req!(Foo); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 diff --git a/src/test/ui/proc-macro/invalid-punct-ident-1.stderr b/src/test/ui/proc-macro/invalid-punct-ident-1.stderr index 5ef22709cb371..eaf41c080faf4 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-1.stderr +++ b/src/test/ui/proc-macro/invalid-punct-ident-1.stderr @@ -2,7 +2,7 @@ error: proc macro panicked --> $DIR/invalid-punct-ident-1.rs:19:1 | LL | invalid_punct!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = help: message: unsupported character `'`'` diff --git a/src/test/ui/proc-macro/invalid-punct-ident-2.stderr b/src/test/ui/proc-macro/invalid-punct-ident-2.stderr index 4bd7a5351d3a0..f7e1f4bc7d361 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-2.stderr +++ b/src/test/ui/proc-macro/invalid-punct-ident-2.stderr @@ -2,7 +2,7 @@ error: proc macro panicked --> $DIR/invalid-punct-ident-2.rs:19:1 | LL | invalid_ident!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = help: message: `"*"` is not a valid identifier diff --git a/src/test/ui/proc-macro/invalid-punct-ident-3.stderr b/src/test/ui/proc-macro/invalid-punct-ident-3.stderr index 072d13956ac6c..541c71d74db53 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-3.stderr +++ b/src/test/ui/proc-macro/invalid-punct-ident-3.stderr @@ -2,7 +2,7 @@ error: proc macro panicked --> $DIR/invalid-punct-ident-3.rs:19:1 | LL | invalid_raw_ident!(); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ | = help: message: `self` cannot be a raw identifier diff --git a/src/test/ui/proc-macro/invalid-punct-ident-4.stderr b/src/test/ui/proc-macro/invalid-punct-ident-4.stderr index 59cf767c55959..deb93b893685b 100644 --- a/src/test/ui/proc-macro/invalid-punct-ident-4.stderr +++ b/src/test/ui/proc-macro/invalid-punct-ident-4.stderr @@ -2,7 +2,7 @@ error: unexpected closing delimiter: `)` --> $DIR/invalid-punct-ident-4.rs:6:1 | LL | lexer_failure!(); - | ^^^^^^^^^^^^^^^^^ unexpected closing delimiter + | ^^^^^^^^^^^^^^^^ unexpected closing delimiter | = note: this error originates in the macro `lexer_failure` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -10,7 +10,7 @@ error: proc macro panicked --> $DIR/invalid-punct-ident-4.rs:6:1 | LL | lexer_failure!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/invalid-punct-ident-4.rs:11:33 diff --git a/src/test/ui/proc-macro/issue-83510.stderr b/src/test/ui/proc-macro/issue-83510.stderr index 040ace9160f62..e0628a317918b 100644 --- a/src/test/ui/proc-macro/issue-83510.stderr +++ b/src/test/ui/proc-macro/issue-83510.stderr @@ -2,7 +2,7 @@ error[E0412]: cannot find type `Foo` in this scope --> $DIR/issue-83510.rs:5:1 | LL | issue_83510::dance_like_you_want_to_ice!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: this error originates in the macro `issue_83510::dance_like_you_want_to_ice` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -10,7 +10,7 @@ error[E0404]: expected trait, found struct `Box` --> $DIR/issue-83510.rs:5:1 | LL | issue_83510::dance_like_you_want_to_ice!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait | = note: this error originates in the macro `issue_83510::dance_like_you_want_to_ice` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -18,7 +18,7 @@ error[E0405]: cannot find trait `Baz` in this scope --> $DIR/issue-83510.rs:5:1 | LL | issue_83510::dance_like_you_want_to_ice!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: this error originates in the macro `issue_83510::dance_like_you_want_to_ice` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -26,7 +26,7 @@ error[E0658]: inherent associated types are unstable --> $DIR/issue-83510.rs:5:1 | LL | issue_83510::dance_like_you_want_to_ice!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #8995 for more information = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable diff --git a/src/test/ui/proc-macro/lints_in_proc_macros.stderr b/src/test/ui/proc-macro/lints_in_proc_macros.stderr index f36f937fc06b8..4dd8be7d9b6ef 100644 --- a/src/test/ui/proc-macro/lints_in_proc_macros.stderr +++ b/src/test/ui/proc-macro/lints_in_proc_macros.stderr @@ -2,7 +2,7 @@ error[E0425]: cannot find value `foobar2` in this scope --> $DIR/lints_in_proc_macros.rs:9:5 | LL | bang_proc_macro2!(); - | ^^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `foobar` + | ^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `foobar` | = note: this error originates in the macro `bang_proc_macro2` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/macro-rules-derive.stderr b/src/test/ui/proc-macro/macro-rules-derive.stderr index 85766548bff2a..517cbabd5c65a 100644 --- a/src/test/ui/proc-macro/macro-rules-derive.stderr +++ b/src/test/ui/proc-macro/macro-rules-derive.stderr @@ -5,7 +5,7 @@ LL | field: MissingType | ^^^^^^^^^^^ not found in this scope ... LL | produce_it!(MyName); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `produce_it` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/mixed-site-span.stderr b/src/test/ui/proc-macro/mixed-site-span.stderr index c8ed20d30c911..60f082d177a9e 100644 --- a/src/test/ui/proc-macro/mixed-site-span.stderr +++ b/src/test/ui/proc-macro/mixed-site-span.stderr @@ -2,7 +2,7 @@ error[E0426]: use of undeclared label `'label_use` --> $DIR/mixed-site-span.rs:13:9 | LL | proc_macro_rules!(); - | ^^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use` + | ^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use` | = note: this error originates in the macro `proc_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -10,7 +10,7 @@ error[E0425]: cannot find value `local_use` in this scope --> $DIR/mixed-site-span.rs:13:9 | LL | proc_macro_rules!(); - | ^^^^^^^^^^^^^^^^^^^^ not found in this scope + | ^^^^^^^^^^^^^^^^^^^ not found in this scope | = note: this error originates in the macro `proc_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -24,7 +24,7 @@ error[E0412]: cannot find type `ItemUse` in crate `$crate` --> $DIR/mixed-site-span.rs:24:1 | LL | pass_dollar_crate!(); - | ^^^^^^^^^^^^^^^^^^^^^ not found in `$crate` + | ^^^^^^^^^^^^^^^^^^^^ not found in `$crate` | = note: this error originates in the macro `proc_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/multispan.stderr b/src/test/ui/proc-macro/multispan.stderr index d37df81496c38..0aea02bbda956 100644 --- a/src/test/ui/proc-macro/multispan.stderr +++ b/src/test/ui/proc-macro/multispan.stderr @@ -2,7 +2,7 @@ error: hello to you, too! --> $DIR/multispan.rs:12:5 | LL | hello!(hi); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:12:12 @@ -15,7 +15,7 @@ error: hello to you, too! --> $DIR/multispan.rs:15:5 | LL | hello!(hi hi); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:15:12 @@ -28,7 +28,7 @@ error: hello to you, too! --> $DIR/multispan.rs:18:5 | LL | hello!(hi hi hi); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:18:12 @@ -41,7 +41,7 @@ error: hello to you, too! --> $DIR/multispan.rs:21:5 | LL | hello!(hi hey hi yo hi beep beep hi hi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:21:12 @@ -54,7 +54,7 @@ error: hello to you, too! --> $DIR/multispan.rs:22:5 | LL | hello!(hi there, hi how are you? hi... hi.); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:22:12 @@ -67,7 +67,7 @@ error: hello to you, too! --> $DIR/multispan.rs:23:5 | LL | hello!(whoah. hi di hi di ho); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:23:19 @@ -80,7 +80,7 @@ error: hello to you, too! --> $DIR/multispan.rs:24:5 | LL | hello!(hi good hi and good bye); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: found these 'hi's --> $DIR/multispan.rs:24:12 diff --git a/src/test/ui/proc-macro/parent-source-spans.stderr b/src/test/ui/proc-macro/parent-source-spans.stderr index 071e103742e66..4548269b50793 100644 --- a/src/test/ui/proc-macro/parent-source-spans.stderr +++ b/src/test/ui/proc-macro/parent-source-spans.stderr @@ -5,7 +5,7 @@ LL | three!($a, $b); | ^^ ... LL | one!("hello", "world"); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `two` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | three!($a, $b); | ^^ ... LL | one!("hello", "world"); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `two` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -24,10 +24,10 @@ error: first parent: "hello" --> $DIR/parent-source-spans.rs:10:5 | LL | two!($a, $b); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ ... LL | one!("hello", "world"); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `one` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -35,10 +35,10 @@ error: second parent: "world" --> $DIR/parent-source-spans.rs:10:5 | LL | two!($a, $b); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ ... LL | one!("hello", "world"); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `one` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -46,25 +46,25 @@ error: first grandparent: "hello" --> $DIR/parent-source-spans.rs:36:5 | LL | one!("hello", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: second grandparent: "world" --> $DIR/parent-source-spans.rs:36:5 | LL | one!("hello", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: first source: "hello" --> $DIR/parent-source-spans.rs:36:5 | LL | one!("hello", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: second source: "world" --> $DIR/parent-source-spans.rs:36:5 | LL | one!("hello", "world"); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: first final: "yay" --> $DIR/parent-source-spans.rs:16:12 @@ -73,7 +73,7 @@ LL | three!($a, $b); | ^^ ... LL | two!("yay", "rust"); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `two` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -84,7 +84,7 @@ LL | three!($a, $b); | ^^ ... LL | two!("yay", "rust"); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | = note: this error originates in the macro `two` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -92,25 +92,25 @@ error: first parent: "yay" --> $DIR/parent-source-spans.rs:42:5 | LL | two!("yay", "rust"); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: second parent: "rust" --> $DIR/parent-source-spans.rs:42:5 | LL | two!("yay", "rust"); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: first source: "yay" --> $DIR/parent-source-spans.rs:42:5 | LL | two!("yay", "rust"); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: second source: "rust" --> $DIR/parent-source-spans.rs:42:5 | LL | two!("yay", "rust"); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ error: first final: "hip" --> $DIR/parent-source-spans.rs:48:12 @@ -140,10 +140,10 @@ error[E0425]: cannot find value `ok` in this scope --> $DIR/parent-source-spans.rs:29:5 | LL | parent_source_spans!($($tokens)*); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` ... LL | one!("hello", "world"); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | ::: $SRC_DIR/core/src/result.rs:LL:COL | @@ -156,10 +156,10 @@ error[E0425]: cannot find value `ok` in this scope --> $DIR/parent-source-spans.rs:29:5 | LL | parent_source_spans!($($tokens)*); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` ... LL | two!("yay", "rust"); - | -------------------- in this macro invocation + | ------------------- in this macro invocation | ::: $SRC_DIR/core/src/result.rs:LL:COL | @@ -172,10 +172,10 @@ error[E0425]: cannot find value `ok` in this scope --> $DIR/parent-source-spans.rs:29:5 | LL | parent_source_spans!($($tokens)*); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a tuple variant with a similar name exists: `Ok` ... LL | three!("hip", "hop"); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | ::: $SRC_DIR/core/src/result.rs:LL:COL | diff --git a/src/test/ui/proc-macro/raw-ident.stderr b/src/test/ui/proc-macro/raw-ident.stderr index ee6dffe93edce..905a5f9463af8 100644 --- a/src/test/ui/proc-macro/raw-ident.stderr +++ b/src/test/ui/proc-macro/raw-ident.stderr @@ -2,7 +2,7 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found --> $DIR/raw-ident.rs:15:5 | LL | make_bad_struct!(S); - | ^^^^^^^^^^^^^^^^^^^^ expected one of 8 possible tokens + | ^^^^^^^^^^^^^^^^^^^ expected one of 8 possible tokens | = note: this error originates in the macro `make_bad_struct` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/span-api-tests.rs b/src/test/ui/proc-macro/span-api-tests.rs index 5c149e4a1e526..914ad54ed0370 100644 --- a/src/test/ui/proc-macro/span-api-tests.rs +++ b/src/test/ui/proc-macro/span-api-tests.rs @@ -41,7 +41,7 @@ fn main() { reemit!(macro_stringify!(Hello, world!)), "reemit!(macro_stringify!(Hello, world!))" ); - let r = "reemit!(assert_eq!(macro_stringify!(Hello, world!), r));"; + let r = "reemit!(assert_eq!(macro_stringify!(Hello, world!), r))"; reemit!(assert_eq!(macro_stringify!(Hello, world!), r)); assert_eq!(macro_stringify!( diff --git a/src/test/ui/proc-macro/span-from-proc-macro.stderr b/src/test/ui/proc-macro/span-from-proc-macro.stderr index 11ee20e846d32..7beed505a7efa 100644 --- a/src/test/ui/proc-macro/span-from-proc-macro.stderr +++ b/src/test/ui/proc-macro/span-from-proc-macro.stderr @@ -38,7 +38,7 @@ LL | my_ident ::: $DIR/span-from-proc-macro.rs:16:5 | LL | other_error_from_bang!(); - | ------------------------- in this macro invocation + | ------------------------ in this macro invocation error[E0308]: mismatched types --> $DIR/auxiliary/span-from-proc-macro.rs:16:36 @@ -54,7 +54,7 @@ LL | pub fn error_from_bang(_input: TokenStream) -> TokenStream { ::: $DIR/span-from-proc-macro.rs:15:5 | LL | error_from_bang!(); - | ------------------- in this macro invocation + | ------------------ in this macro invocation error: aborting due to 4 previous errors diff --git a/src/test/ui/proc-macro/subspan.stderr b/src/test/ui/proc-macro/subspan.stderr index d65b1d0cfaf56..b5dacba0e37e0 100644 --- a/src/test/ui/proc-macro/subspan.stderr +++ b/src/test/ui/proc-macro/subspan.stderr @@ -2,7 +2,7 @@ error: found 'hi's --> $DIR/subspan.rs:11:1 | LL | subspan!("hi"); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:11:11 @@ -15,7 +15,7 @@ error: found 'hi's --> $DIR/subspan.rs:14:1 | LL | subspan!("hihi"); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:14:11 @@ -28,7 +28,7 @@ error: found 'hi's --> $DIR/subspan.rs:17:1 | LL | subspan!("hihihi"); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:17:11 @@ -41,7 +41,7 @@ error: found 'hi's --> $DIR/subspan.rs:20:1 | LL | subspan!("why I hide? hi!"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:20:17 @@ -54,7 +54,7 @@ error: found 'hi's --> $DIR/subspan.rs:21:1 | LL | subspan!("hey, hi, hidy, hidy, hi hi"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:21:16 @@ -67,7 +67,7 @@ error: found 'hi's --> $DIR/subspan.rs:22:1 | LL | subspan!("this is a hi, and this is another hi"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:22:12 @@ -80,7 +80,7 @@ error: found 'hi's --> $DIR/subspan.rs:23:1 | LL | subspan!("how are you this evening"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:23:24 @@ -93,7 +93,7 @@ error: found 'hi's --> $DIR/subspan.rs:24:1 | LL | subspan!("this is highly eradic"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: here --> $DIR/subspan.rs:24:12 diff --git a/src/test/ui/proc-macro/three-equals.stderr b/src/test/ui/proc-macro/three-equals.stderr index 485aefe62fd58..1ce5e02bd82f7 100644 --- a/src/test/ui/proc-macro/three-equals.stderr +++ b/src/test/ui/proc-macro/three-equals.stderr @@ -2,7 +2,7 @@ error: found 2 equal signs, need exactly 3 --> $DIR/three-equals.rs:12:5 | LL | three_equals!(==); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ | = help: input must be: `===` = note: this error originates in the macro `three_equals` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/proc-macro/weird-hygiene.stderr b/src/test/ui/proc-macro/weird-hygiene.stderr index 03a984c58ceb8..b4e7fe444acce 100644 --- a/src/test/ui/proc-macro/weird-hygiene.stderr +++ b/src/test/ui/proc-macro/weird-hygiene.stderr @@ -5,7 +5,7 @@ LL | Value = (stringify!($tokens + hidden_ident), 1).1 | ^^^^^^^^^^^^ not found in this scope ... LL | other!(50); - | ----------- in this macro invocation + | ---------- in this macro invocation | = note: this error originates in the macro `inner` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | hidden_ident | ^^^^^^^^^^^^ not found in this scope ... LL | invoke_it!(25); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `invoke_it` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/reachable/expr_again.stderr b/src/test/ui/reachable/expr_again.stderr index 0192f4359e590..a3c54e135604c 100644 --- a/src/test/ui/reachable/expr_again.stderr +++ b/src/test/ui/reachable/expr_again.stderr @@ -4,7 +4,7 @@ error: unreachable statement LL | continue; | -------- any code following this expression is unreachable LL | println!("hi"); - | ^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^ unreachable statement | note: the lint level is defined here --> $DIR/expr_again.rs:3:9 diff --git a/src/test/ui/reachable/expr_block.stderr b/src/test/ui/reachable/expr_block.stderr index 4ed84c566a772..d5f248a24910e 100644 --- a/src/test/ui/reachable/expr_block.stderr +++ b/src/test/ui/reachable/expr_block.stderr @@ -18,7 +18,7 @@ error: unreachable statement LL | return; | ------ any code following this expression is unreachable LL | println!("foo"); - | ^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^ unreachable statement | = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/reachable/expr_if.stderr b/src/test/ui/reachable/expr_if.stderr index 1112273f441c6..ebd0b5a3ebefc 100644 --- a/src/test/ui/reachable/expr_if.stderr +++ b/src/test/ui/reachable/expr_if.stderr @@ -22,7 +22,7 @@ LL | return; | ------ any code following this expression is unreachable ... LL | println!("But I am."); - | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/reachable/expr_loop.stderr b/src/test/ui/reachable/expr_loop.stderr index d6c140375e3c7..9185846860507 100644 --- a/src/test/ui/reachable/expr_loop.stderr +++ b/src/test/ui/reachable/expr_loop.stderr @@ -4,7 +4,7 @@ error: unreachable statement LL | loop { return; } | ------ any code following this expression is unreachable LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: the lint level is defined here --> $DIR/expr_loop.rs:4:9 @@ -19,7 +19,7 @@ error: unreachable statement LL | loop { return; } | ------ any code following this expression is unreachable LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -29,7 +29,7 @@ error: unreachable statement LL | loop { 'middle: loop { loop { break 'middle; } } } | -------------------------------------------------- any code following this expression is unreachable LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/reachable/expr_match.stderr b/src/test/ui/reachable/expr_match.stderr index 9d660a43866de..d15208609cff8 100644 --- a/src/test/ui/reachable/expr_match.stderr +++ b/src/test/ui/reachable/expr_match.stderr @@ -4,7 +4,7 @@ error: unreachable statement LL | match () { () => return } | ------------------------- any code following this `match` expression is unreachable, as all arms diverge LL | println!("I am dead"); - | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: the lint level is defined here --> $DIR/expr_match.rs:4:9 @@ -19,7 +19,7 @@ error: unreachable statement LL | match () { () if false => return, () => return } | ------------------------------------------------ any code following this `match` expression is unreachable, as all arms diverge LL | println!("I am dead"); - | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/reachable/unreachable-code-ret.stderr b/src/test/ui/reachable/unreachable-code-ret.stderr index 839b585c63f26..263a1b5a960fc 100644 --- a/src/test/ui/reachable/unreachable-code-ret.stderr +++ b/src/test/ui/reachable/unreachable-code-ret.stderr @@ -4,7 +4,7 @@ error: unreachable statement LL | return; | ------ any code following this expression is unreachable LL | println!("Paul is dead"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | ^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: the lint level is defined here --> $DIR/unreachable-code-ret.rs:3:9 diff --git a/src/test/ui/recursion_limit/zero.rs b/src/test/ui/recursion_limit/zero.rs index eb95d7babc6b2..3a2d904cb1c21 100644 --- a/src/test/ui/recursion_limit/zero.rs +++ b/src/test/ui/recursion_limit/zero.rs @@ -7,6 +7,6 @@ macro_rules! test { ($tt:tt) => { test!(); }; } -test!(test); //~ ERROR 10:1: 10:13: recursion limit reached while expanding `test!` +test!(test); //~ ERROR recursion limit reached while expanding `test!` fn main() {} diff --git a/src/test/ui/recursion_limit/zero.stderr b/src/test/ui/recursion_limit/zero.stderr index c85cbadea7101..b43565909a3f4 100644 --- a/src/test/ui/recursion_limit/zero.stderr +++ b/src/test/ui/recursion_limit/zero.stderr @@ -2,7 +2,7 @@ error: recursion limit reached while expanding `test!` --> $DIR/zero.rs:10:1 | LL | test!(test); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero`) diff --git a/src/test/ui/regions/regions-var-type-out-of-scope.stderr b/src/test/ui/regions/regions-var-type-out-of-scope.stderr index d95717676855e..476e82f046f01 100644 --- a/src/test/ui/regions/regions-var-type-out-of-scope.stderr +++ b/src/test/ui/regions/regions-var-type-out-of-scope.stderr @@ -6,7 +6,7 @@ LL | x = &id(3); | | | creates a temporary which is freed while still in use LL | assert_eq!(*x, 3); - | ------------------ borrow later used here + | ----------------- borrow later used here | = note: consider using a `let` binding to create a longer lived value diff --git a/src/test/ui/resolve/issue-82865.stderr b/src/test/ui/resolve/issue-82865.stderr index 0aa0610de74d9..7898c2a360f12 100644 --- a/src/test/ui/resolve/issue-82865.stderr +++ b/src/test/ui/resolve/issue-82865.stderr @@ -11,7 +11,7 @@ LL | Box::z | ^ function or associated item not found in `Box<_, _>` ... LL | mac!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr index 7819a2588e8a6..2545231a1712c 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr @@ -15,7 +15,7 @@ LL | | } | |_____________^ ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation = help: use `self::std` to refer to this module unambiguously = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr index 54f28113cba52..af45cd81a3b10 100644 --- a/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr +++ b/src/test/ui/rust-2018/uniform-paths/ambiguity-macros.stderr @@ -15,7 +15,7 @@ LL | | } | |_________^ ... LL | m!(); - | ----- in this macro invocation + | ---- in this macro invocation = help: use `crate::std` to refer to this module unambiguously = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr index 9d7ca570c4cc3..ae7c5d60cbacc 100644 --- a/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr +++ b/src/test/ui/rust-2021/reserved-prefixes-via-macro-2.stderr @@ -2,7 +2,7 @@ error: prefix `hey` is unknown --> $DIR/reserved-prefixes-via-macro-2.rs:15:5 | LL | m2021::number_of_tokens_in_a_prefixed_integer_literal!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix | = note: prefixed identifiers and literals are reserved since Rust 2021 = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_integer_literal` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -11,7 +11,7 @@ error: prefix `hey` is unknown --> $DIR/reserved-prefixes-via-macro-2.rs:17:5 | LL | m2021::number_of_tokens_in_a_prefixed_char_literal!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix | = note: prefixed identifiers and literals are reserved since Rust 2021 = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_char_literal` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -20,7 +20,7 @@ error: prefix `hey` is unknown --> $DIR/reserved-prefixes-via-macro-2.rs:19:5 | LL | m2021::number_of_tokens_in_a_prefixed_string_literal!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown prefix | = note: prefixed identifiers and literals are reserved since Rust 2021 = note: this error originates in the macro `m2021::number_of_tokens_in_a_prefixed_string_literal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/simd/shuffle-not-out-of-bounds.stderr b/src/test/ui/simd/shuffle-not-out-of-bounds.stderr index 5492d14f7c924..415f04d933f25 100644 --- a/src/test/ui/simd/shuffle-not-out-of-bounds.stderr +++ b/src/test/ui/simd/shuffle-not-out-of-bounds.stderr @@ -5,7 +5,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(2, u8x2, simd_shuffle2); - | -------------------------------------------- in this macro invocation + | ------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -16,7 +16,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(4, u8x4, simd_shuffle4); - | -------------------------------------------- in this macro invocation + | ------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -27,7 +27,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(8, u8x8, simd_shuffle8); - | -------------------------------------------- in this macro invocation + | ------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -38,7 +38,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(16, u8x16, simd_shuffle16); - | ----------------------------------------------- in this macro invocation + | ---------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -49,7 +49,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(32, u8x32, simd_shuffle32); - | ----------------------------------------------- in this macro invocation + | ---------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | $y(vec1, vec2, ARR) | ^^^^^^^^^^^^^^^^^^^ ... LL | test_shuffle_lanes!(64, u8x64, simd_shuffle64); - | ----------------------------------------------- in this macro invocation + | ---------------------------------------------- in this macro invocation | = note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/span/macro-span-replacement.stderr b/src/test/ui/span/macro-span-replacement.stderr index afdf036f833b1..d08b24e9562b9 100644 --- a/src/test/ui/span/macro-span-replacement.stderr +++ b/src/test/ui/span/macro-span-replacement.stderr @@ -5,7 +5,7 @@ LL | $b $a; | ^ ... LL | m!(S struct); - | ------------- in this macro invocation + | ------------ in this macro invocation | note: the lint level is defined here --> $DIR/macro-span-replacement.rs:3:9 diff --git a/src/test/ui/span/transitive-dep-span.stderr b/src/test/ui/span/transitive-dep-span.stderr index 1787b0ee19ad6..2b3dfc5c13533 100644 --- a/src/test/ui/span/transitive-dep-span.stderr +++ b/src/test/ui/span/transitive-dep-span.stderr @@ -10,7 +10,7 @@ LL | | } ::: $DIR/transitive-dep-span.rs:13:1 | LL | transitive_dep_two::parse_error!(); - | ----------------------------------- + | ---------------------------------- | | | in this macro invocation | in this macro invocation diff --git a/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr b/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr index 59e7cfc6f085f..3599d53d2a11f 100644 --- a/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr +++ b/src/test/ui/suggestions/dont-suggest-deref-inside-macro-issue-58298.stderr @@ -4,7 +4,7 @@ error[E0308]: mismatched types LL | / intrinsic_match! { LL | | "abc" LL | | }; - | |______^ expected `&str`, found struct `String` + | |_____^ expected `&str`, found struct `String` | = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/suggestions/dont-suggest-try_into-in-macros.stderr b/src/test/ui/suggestions/dont-suggest-try_into-in-macros.stderr index e15e7e905cf67..4e21d36014c90 100644 --- a/src/test/ui/suggestions/dont-suggest-try_into-in-macros.stderr +++ b/src/test/ui/suggestions/dont-suggest-try_into-in-macros.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/dont-suggest-try_into-in-macros.rs:2:5 | LL | assert_eq!(10u64, 10usize); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `usize` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `usize` | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/suggestions/suggest-ref-macro.stderr b/src/test/ui/suggestions/suggest-ref-macro.stderr index 1f41d2329ee9e..5c05810e5868d 100644 --- a/src/test/ui/suggestions/suggest-ref-macro.stderr +++ b/src/test/ui/suggestions/suggest-ref-macro.stderr @@ -8,7 +8,7 @@ LL | x(123); | help: consider mutably borrowing here: `&mut 123` ... LL | bla!(); - | ------- in this macro invocation + | ------ in this macro invocation | = note: this error originates in the macro `bla` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.stderr b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr index b3c5bd2b89d30..45cbcecacab2d 100644 --- a/src/test/ui/symbol-names/const-generics-structural-demangling.stderr +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr @@ -131,7 +131,7 @@ LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ ... LL | duplicate_field_name_test!(x); - | ------------------------------ in this macro invocation + | ----------------------------- in this macro invocation | = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -142,7 +142,7 @@ LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ ... LL | duplicate_field_name_test!(x); - | ------------------------------ in this macro invocation + | ----------------------------- in this macro invocation | = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -153,7 +153,7 @@ LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ ... LL | duplicate_field_name_test!(x); - | ------------------------------ in this macro invocation + | ----------------------------- in this macro invocation | = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/trace_macros-format.stderr b/src/test/ui/trace_macros-format.stderr index 650b87076981f..c32027086aa19 100644 --- a/src/test/ui/trace_macros-format.stderr +++ b/src/test/ui/trace_macros-format.stderr @@ -2,37 +2,37 @@ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:4:5 | LL | trace_macros!(); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:5:5 | LL | trace_macros!(1); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:6:5 | LL | trace_macros!(ident); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:7:5 | LL | trace_macros!(for); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:8:5 | LL | trace_macros!(true,); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ error: trace_macros! accepts only `true` or `false` --> $DIR/trace_macros-format.rs:9:5 | LL | trace_macros!(false 1); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/try-block/try-block-opt-init.stderr b/src/test/ui/try-block/try-block-opt-init.stderr index 58eb076bba3f1..bd145fd64e765 100644 --- a/src/test/ui/try-block/try-block-opt-init.stderr +++ b/src/test/ui/try-block/try-block-opt-init.stderr @@ -2,7 +2,7 @@ error[E0381]: borrow of possibly-uninitialized variable: `cfg_res` --> $DIR/try-block-opt-init.rs:15:5 | LL | assert_eq!(cfg_res, 5); - | ^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `cfg_res` + | ^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `cfg_res` | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/unsafe/inline_asm.mir.stderr b/src/test/ui/unsafe/inline_asm.mir.stderr index 5d9828b5594e3..865d5cc61cadf 100644 --- a/src/test/ui/unsafe/inline_asm.mir.stderr +++ b/src/test/ui/unsafe/inline_asm.mir.stderr @@ -2,7 +2,7 @@ error[E0133]: use of inline assembly is unsafe and requires unsafe function or b --> $DIR/inline_asm.rs:10:5 | LL | asm!("nop"); - | ^^^^^^^^^^^^ use of inline assembly + | ^^^^^^^^^^^ use of inline assembly | = note: inline assembly is entirely unchecked and can cause undefined behavior @@ -10,7 +10,7 @@ error[E0133]: use of inline assembly is unsafe and requires unsafe function or b --> $DIR/inline_asm.rs:11:5 | LL | llvm_asm!("nop"); - | ^^^^^^^^^^^^^^^^^ use of inline assembly + | ^^^^^^^^^^^^^^^^ use of inline assembly | = note: inline assembly is entirely unchecked and can cause undefined behavior = note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/unsafe/inline_asm.thir.stderr b/src/test/ui/unsafe/inline_asm.thir.stderr index 5d9828b5594e3..865d5cc61cadf 100644 --- a/src/test/ui/unsafe/inline_asm.thir.stderr +++ b/src/test/ui/unsafe/inline_asm.thir.stderr @@ -2,7 +2,7 @@ error[E0133]: use of inline assembly is unsafe and requires unsafe function or b --> $DIR/inline_asm.rs:10:5 | LL | asm!("nop"); - | ^^^^^^^^^^^^ use of inline assembly + | ^^^^^^^^^^^ use of inline assembly | = note: inline assembly is entirely unchecked and can cause undefined behavior @@ -10,7 +10,7 @@ error[E0133]: use of inline assembly is unsafe and requires unsafe function or b --> $DIR/inline_asm.rs:11:5 | LL | llvm_asm!("nop"); - | ^^^^^^^^^^^^^^^^^ use of inline assembly + | ^^^^^^^^^^^^^^^^ use of inline assembly | = note: inline assembly is entirely unchecked and can cause undefined behavior = note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/while-let.stderr b/src/test/ui/while-let.stderr index 17e8830f63092..c5e2fd92f0441 100644 --- a/src/test/ui/while-let.stderr +++ b/src/test/ui/while-let.stderr @@ -7,7 +7,7 @@ LL | while let $p = $e $b LL | / foo!(_a, 1, { LL | | println!("irrefutable pattern"); LL | | }); - | |_______- in this macro invocation + | |______- in this macro invocation | = note: `#[warn(irrefutable_let_patterns)]` on by default = note: this pattern will always match, so the loop will never exit @@ -23,7 +23,7 @@ LL | while let $p = $e $b LL | / bar!(_a, 1, { LL | | println!("irrefutable pattern"); LL | | }); - | |_______- in this macro invocation + | |______- in this macro invocation | = note: this pattern will always match, so the loop will never exit = help: consider instead using a `loop { ... }` with a `let` inside it From cc4bc571f4e3da483184a843259639454eb414b2 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 14 Oct 2021 13:28:30 -0500 Subject: [PATCH 106/181] Fix clippy with changed macro statement spans --- src/tools/clippy/clippy_lints/src/copies.rs | 18 ++++---- src/tools/clippy/clippy_lints/src/format.rs | 7 +-- .../clippy_lints/src/needless_continue.rs | 13 +++--- .../conf_nonstandard_macro_braces.stderr | 6 +-- src/tools/clippy/tests/ui/asm_syntax.stderr | 10 ++--- .../tests/ui/assertions_on_constants.stderr | 18 ++++---- .../tests/ui/bool_assert_comparison.stderr | 44 +++++++++---------- .../checked_unwrap/simple_conditionals.stderr | 2 +- .../clippy/tests/ui/collapsible_match2.stderr | 2 +- .../clippy/tests/ui/crashes/ice-6255.stderr | 2 +- .../others.stderr | 2 +- .../traits.stderr | 2 +- .../ui/default_numeric_fallback_f64.stderr | 2 +- .../ui/default_numeric_fallback_i32.stderr | 2 +- src/tools/clippy/tests/ui/doc_unsafe.stderr | 2 +- src/tools/clippy/tests/ui/eq_op_macros.stderr | 8 ++-- .../clippy/tests/ui/fallible_impl_from.stderr | 8 ++-- src/tools/clippy/tests/ui/format.stderr | 26 +++++------ .../clippy/tests/ui/implicit_hasher.stderr | 6 +-- .../tests/ui/item_after_statement.stderr | 2 +- .../clippy/tests/ui/mem_replace_macro.stderr | 2 +- .../clippy/tests/ui/missing_panics_doc.stderr | 4 +- .../clippy/tests/ui/panic_in_result_fn.stderr | 12 ++--- .../ui/panic_in_result_fn_assertions.stderr | 6 +-- .../clippy/tests/ui/panicking_macros.stderr | 32 +++++++------- .../ui/pattern_type_mismatch/syntax.stderr | 2 +- .../clippy/tests/ui/toplevel_ref_arg.stderr | 2 +- .../ui/toplevel_ref_arg_non_rustfix.stderr | 2 +- src/tools/clippy/tests/ui/try_err.stderr | 4 +- src/tools/clippy/tests/ui/unit_cmp.stderr | 8 ++-- 30 files changed, 126 insertions(+), 130 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/copies.rs b/src/tools/clippy/clippy_lints/src/copies.rs index 6ded2f233efea..b7385dcfbca19 100644 --- a/src/tools/clippy/clippy_lints/src/copies.rs +++ b/src/tools/clippy/clippy_lints/src/copies.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Block, Expr, ExprKind, HirId}; -use rustc_lint::{LateContext, LateLintPass}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{source_map::Span, symbol::Symbol, BytePos}; @@ -432,10 +432,11 @@ fn emit_branches_sharing_code_lint( let mut add_expr_note = false; // Construct suggestions + let sm = cx.sess().source_map(); if start_stmts > 0 { let block = blocks[0]; let span_start = first_line_of_span(cx, if_expr.span).shrink_to_lo(); - let span_end = block.stmts[start_stmts - 1].span.source_callsite(); + let span_end = sm.stmt_span(block.stmts[start_stmts - 1].span, block.span); let cond_span = first_line_of_span(cx, if_expr.span).until(block.span); let cond_snippet = reindent_multiline(snippet(cx, cond_span, "_"), false, None); @@ -454,15 +455,16 @@ fn emit_branches_sharing_code_lint( let span_end = block.span.shrink_to_hi(); let moved_start = if end_stmts == 0 && block.expr.is_some() { - block.expr.unwrap().span + block.expr.unwrap().span.source_callsite() } else { - block.stmts[block.stmts.len() - end_stmts].span - } - .source_callsite(); + sm.stmt_span(block.stmts[block.stmts.len() - end_stmts].span, block.span) + }; let moved_end = block .expr - .map_or_else(|| block.stmts[block.stmts.len() - 1].span, |expr| expr.span) - .source_callsite(); + .map_or_else( + || sm.stmt_span(block.stmts[block.stmts.len() - 1].span, block.span), + |expr| expr.span.source_callsite(), + ); let moved_span = moved_start.to(moved_end); let moved_snipped = reindent_multiline(snippet(cx, moved_span, "_"), true, None); diff --git a/src/tools/clippy/clippy_lints/src/format.rs b/src/tools/clippy/clippy_lints/src/format.rs index 8df7f91ce59f5..37d9ea3bdc117 100644 --- a/src/tools/clippy/clippy_lints/src/format.rs +++ b/src/tools/clippy/clippy_lints/src/format.rs @@ -90,12 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat { } } -fn span_useless_format(cx: &LateContext<'_>, span: Span, mut sugg: String, mut applicability: Applicability) { - // The callsite span contains the statement semicolon for some reason. - if snippet_with_applicability(cx, span, "..", &mut applicability).ends_with(';') { - sugg.push(';'); - } - +fn span_useless_format(cx: &LateContext<'_>, span: Span, sugg: String, applicability: Applicability) { span_lint_and_sugg( cx, USELESS_FORMAT, diff --git a/src/tools/clippy/clippy_lints/src/needless_continue.rs b/src/tools/clippy/clippy_lints/src/needless_continue.rs index 5a50cc48d61bf..7aa93ed783920 100644 --- a/src/tools/clippy/clippy_lints/src/needless_continue.rs +++ b/src/tools/clippy/clippy_lints/src/needless_continue.rs @@ -36,9 +36,8 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::{indent_of, snippet, snippet_block}; use rustc_ast::ast; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::{original_sp, DUMMY_SP}; use rustc_span::Span; declare_clippy_lint! { @@ -270,7 +269,7 @@ struct LintData<'a> { /// The 0-based index of the `if` statement in the containing loop block. stmt_idx: usize, /// The statements of the loop block. - block_stmts: &'a [ast::Stmt], + loop_block: &'a ast::Block, } const MSG_REDUNDANT_CONTINUE_EXPRESSION: &str = "this `continue` expression is redundant"; @@ -343,10 +342,10 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data: let indent = span_of_first_expr_in_block(data.if_block) .and_then(|span| indent_of(cx, span)) .unwrap_or(0); - let to_annex = data.block_stmts[data.stmt_idx + 1..] + let to_annex = data.loop_block.stmts[data.stmt_idx + 1..] .iter() - .map(|stmt| original_sp(stmt.span, DUMMY_SP)) - .map(|span| { + .map(|stmt| { + let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span); let snip = snippet_block(cx, span, "..", None).into_owned(); snip.lines() .map(|line| format!("{}{}", " ".repeat(indent), line)) @@ -393,7 +392,7 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) { if_cond: cond, if_block: then_block, else_expr, - block_stmts: &loop_block.stmts, + loop_block, }; if needless_continue_in_else(else_expr, label) { emit_warning( diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr index 87e962b9228c4..039b23b1bdb2f 100644 --- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr +++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr @@ -82,13 +82,13 @@ error: use of irregular braces for `eprint!` macro --> $DIR/conf_nonstandard_macro_braces.rs:57:5 | LL | eprint!("test if user config overrides defaults"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: consider writing `eprint!["test if user config overrides defaults"];` +help: consider writing `eprint!["test if user config overrides defaults"]` --> $DIR/conf_nonstandard_macro_braces.rs:57:5 | LL | eprint!("test if user config overrides defaults"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/asm_syntax.stderr b/src/tools/clippy/tests/ui/asm_syntax.stderr index e3abbe086586e..409f4db76bc25 100644 --- a/src/tools/clippy/tests/ui/asm_syntax.stderr +++ b/src/tools/clippy/tests/ui/asm_syntax.stderr @@ -2,7 +2,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:9:9 | LL | asm!(""); - | ^^^^^^^^^ + | ^^^^^^^^ | = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings` = help: use AT&T x86 assembly syntax @@ -11,7 +11,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:10:9 | LL | asm!("", options()); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | = help: use AT&T x86 assembly syntax @@ -19,7 +19,7 @@ error: Intel x86 assembly syntax used --> $DIR/asm_syntax.rs:11:9 | LL | asm!("", options(nostack)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use AT&T x86 assembly syntax @@ -27,7 +27,7 @@ error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:23:9 | LL | asm!("", options(att_syntax)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings` = help: use Intel x86 assembly syntax @@ -36,7 +36,7 @@ error: AT&T x86 assembly syntax used --> $DIR/asm_syntax.rs:24:9 | LL | asm!("", options(nostack, att_syntax)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use Intel x86 assembly syntax diff --git a/src/tools/clippy/tests/ui/assertions_on_constants.stderr b/src/tools/clippy/tests/ui/assertions_on_constants.stderr index 1eb87d89fad02..4ca1e6f6e88cc 100644 --- a/src/tools/clippy/tests/ui/assertions_on_constants.stderr +++ b/src/tools/clippy/tests/ui/assertions_on_constants.stderr @@ -2,7 +2,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:11:5 | LL | assert!(true); - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ | = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: remove it @@ -12,7 +12,7 @@ error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:12:5 | LL | assert!(false); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -21,7 +21,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:13:5 | LL | assert!(true, "true message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -30,7 +30,7 @@ error: `assert!(false, "false message")` should probably be replaced --> $DIR/assertions_on_constants.rs:14:5 | LL | assert!(false, "false message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("false message")` or `unreachable!("false message")` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -39,7 +39,7 @@ error: `assert!(false, msg.to_uppercase())` should probably be replaced --> $DIR/assertions_on_constants.rs:17:5 | LL | assert!(false, msg.to_uppercase()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!(msg.to_uppercase())` or `unreachable!(msg.to_uppercase())` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -48,7 +48,7 @@ error: `assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:20:5 | LL | assert!(B); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -57,7 +57,7 @@ error: `assert!(false)` should probably be replaced --> $DIR/assertions_on_constants.rs:23:5 | LL | assert!(C); - | ^^^^^^^^^^^ + | ^^^^^^^^^^ | = help: use `panic!()` or `unreachable!()` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -66,7 +66,7 @@ error: `assert!(false, "C message")` should probably be replaced --> $DIR/assertions_on_constants.rs:24:5 | LL | assert!(C, "C message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `panic!("C message")` or `unreachable!("C message")` = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -75,7 +75,7 @@ error: `debug_assert!(true)` will be optimized out by the compiler --> $DIR/assertions_on_constants.rs:26:5 | LL | debug_assert!(true); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ | = help: remove it = note: this error originates in the macro `$crate::assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr index da9b56aa7795d..377d51be4cde7 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr @@ -2,7 +2,7 @@ error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:69:5 | LL | assert_eq!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` | = note: `-D clippy::bool-assert-comparison` implied by `-D warnings` @@ -10,127 +10,127 @@ error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:70:5 | LL | assert_eq!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:71:5 | LL | assert_eq!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:76:5 | LL | assert_eq!(b, true); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:79:5 | LL | assert_ne!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:80:5 | LL | assert_ne!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:81:5 | LL | assert_ne!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:86:5 | LL | assert_ne!(b, true); - | ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:89:5 | LL | debug_assert_eq!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:90:5 | LL | debug_assert_eq!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:91:5 | LL | debug_assert_eq!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:96:5 | LL | debug_assert_eq!(b, true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:99:5 | LL | debug_assert_ne!("a".is_empty(), false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:100:5 | LL | debug_assert_ne!("".is_empty(), true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:101:5 | LL | debug_assert_ne!(true, "".is_empty()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_ne!` with a literal bool --> $DIR/bool_assert_comparison.rs:106:5 | LL | debug_assert_ne!(b, true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:111:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:112:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:113:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:118:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:119:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: used `debug_assert_eq!` with a literal bool --> $DIR/bool_assert_comparison.rs:120:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)` error: aborting due to 22 previous errors diff --git a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr index 82f269543800f..3413159280217 100644 --- a/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr +++ b/src/tools/clippy/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -71,7 +71,7 @@ LL | $a.unwrap(); // unnecessary | ^^^^^^^^^^^ ... LL | m!(x); - | ------ in this macro invocation + | ----- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/collapsible_match2.stderr b/src/tools/clippy/tests/ui/collapsible_match2.stderr index 55e70dce208a0..46b645aea135c 100644 --- a/src/tools/clippy/tests/ui/collapsible_match2.stderr +++ b/src/tools/clippy/tests/ui/collapsible_match2.stderr @@ -46,7 +46,7 @@ LL | | }, | |_____________________^ ... LL | mac!(res_opt => Ok(val), val => Some(n), foo(n)); - | ------------------------------------------------- in this macro invocation + | ------------------------------------------------ in this macro invocation | help: the outer pattern can be modified to include the inner pattern --> $DIR/collapsible_match2.rs:46:28 diff --git a/src/tools/clippy/tests/ui/crashes/ice-6255.stderr b/src/tools/clippy/tests/ui/crashes/ice-6255.stderr index 5dbf9d440dd75..db0cb25e34a0f 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6255.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6255.stderr @@ -5,7 +5,7 @@ LL | extern crate std as core; | ^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | define_other_core!(); - | --------------------- in this macro invocation + | -------------------- in this macro invocation | = note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr index 7c9d705fa9895..fd0689dfc4c99 100644 --- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr +++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/others.stderr @@ -31,7 +31,7 @@ LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable - | ------------------------------------------ in this macro invocation + | ----------------------------------------- in this macro invocation | = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr index bed385b5273a9..7debe059ff4ee 100644 --- a/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr +++ b/src/tools/clippy/tests/ui/declare_interior_mutable_const/traits.stderr @@ -13,7 +13,7 @@ LL | const $name: $ty = $e; | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable - | ----------------------------------------------------------- in this macro invocation + | ---------------------------------------------------------- in this macro invocation | = note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr index 961c7cb57c523..f8a2407b6933d 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr @@ -139,7 +139,7 @@ LL | let x = 22.; | ^^^ help: consider adding suffix: `22.0_f64` ... LL | internal_macro!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr index 5edf48b202087..6f9e124704b2c 100644 --- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr +++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr @@ -151,7 +151,7 @@ LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` ... LL | internal_macro!(); - | ------------------ in this macro invocation + | ----------------- in this macro invocation | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/doc_unsafe.stderr b/src/tools/clippy/tests/ui/doc_unsafe.stderr index 34ca37a6efdc0..d68b8a0c67be6 100644 --- a/src/tools/clippy/tests/ui/doc_unsafe.stderr +++ b/src/tools/clippy/tests/ui/doc_unsafe.stderr @@ -47,7 +47,7 @@ LL | | } | |_________^ ... LL | very_unsafe!(); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/eq_op_macros.stderr b/src/tools/clippy/tests/ui/eq_op_macros.stderr index a28961e7568ed..885415b42c787 100644 --- a/src/tools/clippy/tests/ui/eq_op_macros.stderr +++ b/src/tools/clippy/tests/ui/eq_op_macros.stderr @@ -5,7 +5,7 @@ LL | assert_eq!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: `-D clippy::eq-op` implied by `-D warnings` = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -17,7 +17,7 @@ LL | assert_ne!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -52,7 +52,7 @@ LL | debug_assert_eq!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -63,7 +63,7 @@ LL | debug_assert_ne!(a, a); | ^^^^ ... LL | assert_in_macro_def!(); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = note: this error originates in the macro `assert_in_macro_def` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/fallible_impl_from.stderr b/src/tools/clippy/tests/ui/fallible_impl_from.stderr index 8b8054586e690..f5d0b98c10862 100644 --- a/src/tools/clippy/tests/ui/fallible_impl_from.stderr +++ b/src/tools/clippy/tests/ui/fallible_impl_from.stderr @@ -37,7 +37,7 @@ note: potential failure(s) --> $DIR/fallible_impl_from.rs:30:13 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead @@ -60,11 +60,11 @@ LL | let s = s.unwrap(); | ^^^^^^^^^^ LL | if !s.is_empty() { LL | panic!("42"); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ LL | } else if s.parse::().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: consider implementing `TryFrom` instead @@ -86,7 +86,7 @@ note: potential failure(s) LL | if s.parse::().ok().unwrap() != 42 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | panic!("{:?}", s); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 4 previous errors diff --git a/src/tools/clippy/tests/ui/format.stderr b/src/tools/clippy/tests/ui/format.stderr index 496a083497dfa..701399b32d628 100644 --- a/src/tools/clippy/tests/ui/format.stderr +++ b/src/tools/clippy/tests/ui/format.stderr @@ -2,7 +2,7 @@ error: useless use of `format!` --> $DIR/format.rs:13:5 | LL | format!("foo"); - | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` | = note: `-D clippy::useless-format` implied by `-D warnings` @@ -10,13 +10,13 @@ error: useless use of `format!` --> $DIR/format.rs:14:5 | LL | format!("{{}}"); - | ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string();` + | ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()` error: useless use of `format!` --> $DIR/format.rs:15:5 | LL | format!("{{}} abc {{}}"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()` error: useless use of `format!` --> $DIR/format.rs:16:5 @@ -25,61 +25,61 @@ LL | / format!( LL | | r##"foo {{}} LL | | " bar"## LL | | ); - | |______^ + | |_____^ | help: consider using `.to_string()` | LL ~ r##"foo {} -LL + " bar"##.to_string(); +LL ~ " bar"##.to_string(); | error: useless use of `format!` --> $DIR/format.rs:21:5 | LL | format!("{}", "foo"); - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:25:5 | LL | format!("{:+}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:26:5 | LL | format!("{:<}", "foo"); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()` error: useless use of `format!` --> $DIR/format.rs:31:5 | LL | format!("{}", arg); - | ^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:35:5 | LL | format!("{:+}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:36:5 | LL | format!("{:<}", arg); // Warn when the format makes no difference. - | ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string();` + | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()` error: useless use of `format!` --> $DIR/format.rs:63:5 | LL | format!("{}", 42.to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()` error: useless use of `format!` --> $DIR/format.rs:65:5 | LL | format!("{}", x.display().to_string()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string();` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()` error: useless use of `format!` --> $DIR/format.rs:69:18 diff --git a/src/tools/clippy/tests/ui/implicit_hasher.stderr b/src/tools/clippy/tests/ui/implicit_hasher.stderr index dad5ab71f157f..3f5f56b923fe2 100644 --- a/src/tools/clippy/tests/ui/implicit_hasher.stderr +++ b/src/tools/clippy/tests/ui/implicit_hasher.stderr @@ -107,7 +107,7 @@ LL | impl Foo for HashMap { | ^^^^^^^^^^^^^ ... LL | gen!(impl); - | ----------- in this macro invocation + | ---------- in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter @@ -126,7 +126,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) | ^^^^^^^^^^^^^^^^^ ... LL | gen!(fn bar); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter @@ -141,7 +141,7 @@ LL | pub fn $name(_map: &mut HashMap, _set: &mut HashSet) | ^^^^^^^^^^^^ ... LL | gen!(fn bar); - | ------------- in this macro invocation + | ------------ in this macro invocation | = note: this error originates in the macro `gen` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding a type parameter diff --git a/src/tools/clippy/tests/ui/item_after_statement.stderr b/src/tools/clippy/tests/ui/item_after_statement.stderr index bcb163d4bc124..ab4a6374c73ca 100644 --- a/src/tools/clippy/tests/ui/item_after_statement.stderr +++ b/src/tools/clippy/tests/ui/item_after_statement.stderr @@ -25,7 +25,7 @@ LL | | } | |_____________^ ... LL | b!(); - | ----- in this macro invocation + | ---- in this macro invocation | = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/mem_replace_macro.stderr b/src/tools/clippy/tests/ui/mem_replace_macro.stderr index b4963acc4553c..dd69ab8b5efb8 100644 --- a/src/tools/clippy/tests/ui/mem_replace_macro.stderr +++ b/src/tools/clippy/tests/ui/mem_replace_macro.stderr @@ -5,7 +5,7 @@ LL | std::mem::replace($s, Default::default()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... LL | take!(s); - | --------- in this macro invocation + | -------- in this macro invocation | = note: `-D clippy::mem-replace-with-default` implied by `-D warnings` = note: this error originates in the macro `take` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.stderr b/src/tools/clippy/tests/ui/missing_panics_doc.stderr index 8d882cc6e0d07..b863063b626db 100644 --- a/src/tools/clippy/tests/ui/missing_panics_doc.stderr +++ b/src/tools/clippy/tests/ui/missing_panics_doc.stderr @@ -91,7 +91,7 @@ note: first possible panic found here --> $DIR/missing_panics_doc.rs:39:5 | LL | assert_eq!(x, 0); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: docs for function which may panic missing `# Panics` section @@ -107,7 +107,7 @@ note: first possible panic found here --> $DIR/missing_panics_doc.rs:45:5 | LL | assert_ne!(x, 0); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 7 previous errors diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr index 8d6e40c30a109..f56c2d03c664f 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr +++ b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr @@ -13,7 +13,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:9:9 | LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -30,7 +30,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:14:9 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -47,7 +47,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:19:9 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -64,7 +64,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:24:9 | LL | todo!("Finish this"); - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -81,7 +81,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:55:5 | LL | panic!("error"); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -98,7 +98,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn.rs:69:5 | LL | todo!("finish main method"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 6 previous errors diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr index 4c39b37d8798f..7501d6d85edd7 100644 --- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr +++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr @@ -14,7 +14,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:9:9 | LL | assert!(x == 5, "wrong argument"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -32,7 +32,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:15:9 | LL | assert_eq!(x, 5); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result` @@ -50,7 +50,7 @@ note: return Err() instead of panicking --> $DIR/panic_in_result_fn_assertions.rs:21:9 | LL | assert_ne!(x, 1); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/src/tools/clippy/tests/ui/panicking_macros.stderr b/src/tools/clippy/tests/ui/panicking_macros.stderr index 2e83c305a67e0..2b607ff588895 100644 --- a/src/tools/clippy/tests/ui/panicking_macros.stderr +++ b/src/tools/clippy/tests/ui/panicking_macros.stderr @@ -2,7 +2,7 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:8:5 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ | = note: `-D clippy::panic` implied by `-D warnings` @@ -10,19 +10,19 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:9:5 | LL | panic!("message"); - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:10:5 | LL | panic!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:16:5 | LL | todo!(); - | ^^^^^^^^ + | ^^^^^^^ | = note: `-D clippy::todo` implied by `-D warnings` = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,7 +31,7 @@ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:17:5 | LL | todo!("message"); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -39,7 +39,7 @@ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:18:5 | LL | todo!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -47,7 +47,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:24:5 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: `-D clippy::unimplemented` implied by `-D warnings` = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -56,7 +56,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:25:5 | LL | unimplemented!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -64,7 +64,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:26:5 | LL | unimplemented!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -72,7 +72,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:32:5 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = note: `-D clippy::unreachable` implied by `-D warnings` = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -81,7 +81,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:33:5 | LL | unreachable!("message"); - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `$crate::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -89,7 +89,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:34:5 | LL | unreachable!("{} {}", "panic with", "multiple arguments"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -97,13 +97,13 @@ error: `panic` should not be present in production code --> $DIR/panicking_macros.rs:40:5 | LL | panic!(); - | ^^^^^^^^^ + | ^^^^^^^^ error: `todo` should not be present in production code --> $DIR/panicking_macros.rs:41:5 | LL | todo!(); - | ^^^^^^^^ + | ^^^^^^^ | = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -111,7 +111,7 @@ error: `unimplemented` should not be present in production code --> $DIR/panicking_macros.rs:42:5 | LL | unimplemented!(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `unimplemented` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -119,7 +119,7 @@ error: usage of the `unreachable!` macro --> $DIR/panicking_macros.rs:43:5 | LL | unreachable!(); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ | = note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr index f309b2739829f..12b3d3a8bd075 100644 --- a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr +++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr @@ -70,7 +70,7 @@ LL | Some(_) => (), | ^^^^^^^ ... LL | matching_macro!(value); - | ----------------------- in this macro invocation + | ---------------------- in this macro invocation | = help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings = note: this error originates in the macro `matching_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr b/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr index 48e7d9ddd5aee..9c853020ab019 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.stderr @@ -37,7 +37,7 @@ LL | let ref _y = 42; | ----^^^^^^------ help: try: `let _y = &42;` ... LL | gen_binding!(); - | --------------- in this macro invocation + | -------------- in this macro invocation | = note: this error originates in the macro `gen_binding` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr index 31f8c103ede57..e97011c7fd51f 100644 --- a/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr +++ b/src/tools/clippy/tests/ui/toplevel_ref_arg_non_rustfix.stderr @@ -13,7 +13,7 @@ LL | fn fun_example(ref _x: usize) {} | ^^^^^^ ... LL | gen_function!(); - | ---------------- in this macro invocation + | --------------- in this macro invocation | = note: this error originates in the macro `gen_function` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/try_err.stderr b/src/tools/clippy/tests/ui/try_err.stderr index 09efc16c154ef..0cb1328fbfcf0 100644 --- a/src/tools/clippy/tests/ui/try_err.stderr +++ b/src/tools/clippy/tests/ui/try_err.stderr @@ -35,7 +35,7 @@ LL | Err(_) => Err(1)?, | ^^^^^^^ help: try this: `return Err(1)` ... LL | try_validation!(Ok::<_, i32>(5)); - | --------------------------------- in this macro invocation + | -------------------------------- in this macro invocation | = note: this error originates in the macro `try_validation` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -46,7 +46,7 @@ LL | Err(_) => Err(ret_one!())?, | ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())` ... LL | try_validation_in_macro!(Ok::<_, i32>(5)); - | ------------------------------------------ in this macro invocation + | ----------------------------------------- in this macro invocation | = note: this error originates in the macro `try_validation_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/tools/clippy/tests/ui/unit_cmp.stderr b/src/tools/clippy/tests/ui/unit_cmp.stderr index 75017cab05776..2b5a7b348b982 100644 --- a/src/tools/clippy/tests/ui/unit_cmp.stderr +++ b/src/tools/clippy/tests/ui/unit_cmp.stderr @@ -32,7 +32,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -46,7 +46,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -60,7 +60,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -74,7 +74,7 @@ LL | | }, ... | LL | | } LL | | ); - | |______^ + | |_____^ | = note: this error originates in the macro `$crate::assert_ne` (in Nightly builds, run with -Z macro-backtrace for more info) From 43f4ef5c6a059c32e19483ff3d295feb2f37c5b8 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Fri, 15 Oct 2021 12:27:42 +0300 Subject: [PATCH 107/181] Moved format-version constant to rustdoc-json-types --- src/librustdoc/json/mod.rs | 2 +- src/rustdoc-json-types/lib.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 637e5f2288d62..0031e3915fa40 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -255,7 +255,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .collect(), - format_version: 9, + format_version: types::FORMAT_VERSION, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 7c418697c1c1c..9466f84ffcd59 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -510,5 +510,8 @@ pub struct Static { pub expr: String, } +/// rustdoc format-version. +pub const FORMAT_VERSION: u32 = 9; + #[cfg(test)] mod tests; From 44570143989cdd529aff488b8fa5534c4802fbce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 15 Oct 2021 11:24:20 +0200 Subject: [PATCH 108/181] Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" The PR had some unforseen perf regressions that are not as easy to find. Revert the PR for now. This reverts commit 6ae8912a3e7d2c4c775024f58a7ba4b1aedc4073, reversing changes made to 86d6d2b7389fe1b339402c1798edae8b695fc9ef. --- compiler/rustc_apfloat/src/ieee.rs | 2 -- compiler/rustc_data_structures/src/base_n.rs | 2 +- .../src/graph/implementation/mod.rs | 10 ++++++++-- .../src/graph/iterate/mod.rs | 4 ++-- .../src/obligation_forest/mod.rs | 12 ++++++------ compiler/rustc_data_structures/src/sorted_map.rs | 8 ++++---- .../src/sorted_map/index_map.rs | 4 ++-- compiler/rustc_data_structures/src/sso/map.rs | 16 ++++++++++++---- compiler/rustc_data_structures/src/sso/set.rs | 2 +- .../rustc_data_structures/src/stable_hasher.rs | 4 ++-- compiler/rustc_data_structures/src/stack.rs | 1 - compiler/rustc_data_structures/src/steal.rs | 2 +- compiler/rustc_data_structures/src/tiny_list.rs | 2 +- .../rustc_data_structures/src/vec_linked_list.rs | 4 ++-- compiler/rustc_graphviz/src/lib.rs | 2 +- compiler/rustc_index/src/bit_set.rs | 7 ++++--- compiler/rustc_index/src/vec.rs | 11 +++++++---- compiler/rustc_lexer/src/unescape.rs | 11 ++++++----- compiler/rustc_macros/src/hash_stable.rs | 8 +++++--- compiler/rustc_macros/src/session_diagnostic.rs | 8 ++++---- compiler/rustc_serialize/src/serialize.rs | 4 ++-- library/core/src/num/fmt.rs | 4 +--- 22 files changed, 72 insertions(+), 56 deletions(-) diff --git a/compiler/rustc_apfloat/src/ieee.rs b/compiler/rustc_apfloat/src/ieee.rs index 739c6fd0a435f..96277950cfe1a 100644 --- a/compiler/rustc_apfloat/src/ieee.rs +++ b/compiler/rustc_apfloat/src/ieee.rs @@ -389,7 +389,6 @@ impl fmt::Display for IeeeFloat { let _: Loss = sig::shift_right(&mut sig, &mut exp, trailing_zeros as usize); // Change the exponent from 2^e to 10^e. - #[allow(clippy::comparison_chain)] if exp == 0 { // Nothing to do. } else if exp > 0 { @@ -2527,7 +2526,6 @@ mod sig { if *a_sign ^ b_sign { let (reverse, loss); - #[allow(clippy::comparison_chain)] if bits == 0 { reverse = cmp(a_sig, b_sig) == Ordering::Less; loss = Loss::ExactlyZero; diff --git a/compiler/rustc_data_structures/src/base_n.rs b/compiler/rustc_data_structures/src/base_n.rs index 81e2501ecbead..3c7bea2712409 100644 --- a/compiler/rustc_data_structures/src/base_n.rs +++ b/compiler/rustc_data_structures/src/base_n.rs @@ -14,7 +14,7 @@ const BASE_64: &[u8; MAX_BASE as usize] = #[inline] pub fn push_str(mut n: u128, base: usize, output: &mut String) { - debug_assert!((2..=MAX_BASE).contains(&base)); + debug_assert!(base >= 2 && base <= MAX_BASE); let mut s = [0u8; 128]; let mut index = 0; diff --git a/compiler/rustc_data_structures/src/graph/implementation/mod.rs b/compiler/rustc_data_structures/src/graph/implementation/mod.rs index 9ff401c3c7aad..1aa7ac024d94e 100644 --- a/compiler/rustc_data_structures/src/graph/implementation/mod.rs +++ b/compiler/rustc_data_structures/src/graph/implementation/mod.rs @@ -206,11 +206,17 @@ impl Graph { AdjacentEdges { graph: self, direction, next: first_edge } } - pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator + '_ { + pub fn successor_nodes<'a>( + &'a self, + source: NodeIndex, + ) -> impl Iterator + 'a { self.outgoing_edges(source).targets() } - pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator + '_ { + pub fn predecessor_nodes<'a>( + &'a self, + target: NodeIndex, + ) -> impl Iterator + 'a { self.incoming_edges(target).sources() } diff --git a/compiler/rustc_data_structures/src/graph/iterate/mod.rs b/compiler/rustc_data_structures/src/graph/iterate/mod.rs index 1c6979dc489a6..a9db3497b2390 100644 --- a/compiler/rustc_data_structures/src/graph/iterate/mod.rs +++ b/compiler/rustc_data_structures/src/graph/iterate/mod.rs @@ -48,7 +48,7 @@ fn post_order_walk( let node = frame.node; visited[node] = true; - for successor in frame.iter.by_ref() { + while let Some(successor) = frame.iter.next() { if !visited[successor] { stack.push(PostOrderFrame { node: successor, iter: graph.successors(successor) }); continue 'recurse; @@ -112,7 +112,7 @@ where /// This is equivalent to just invoke `next` repeatedly until /// you get a `None` result. pub fn complete_search(&mut self) { - for _ in self {} + while let Some(_) = self.next() {} } /// Returns true if node has been visited thus far. diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index caf515b0d192a..25b7a84b3a069 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -390,7 +390,7 @@ impl ObligationForest { .map(|(index, _node)| Error { error: error.clone(), backtrace: self.error_at(index) }) .collect(); - self.compress(|_| unreachable!()); + self.compress(|_| assert!(false)); errors } @@ -612,7 +612,7 @@ impl ObligationForest { fn compress(&mut self, mut outcome_cb: impl FnMut(&O)) { let orig_nodes_len = self.nodes.len(); let mut node_rewrites: Vec<_> = std::mem::take(&mut self.reused_node_vec); - assert!(node_rewrites.is_empty()); + debug_assert!(node_rewrites.is_empty()); node_rewrites.extend(0..orig_nodes_len); let mut dead_nodes = 0; @@ -623,13 +623,13 @@ impl ObligationForest { // self.nodes[0..index - dead_nodes] are the first remaining nodes // self.nodes[index - dead_nodes..index] are all dead // self.nodes[index..] are unchanged - for (index, node_rewrite) in node_rewrites.iter_mut().enumerate() { + for index in 0..orig_nodes_len { let node = &self.nodes[index]; match node.state.get() { NodeState::Pending | NodeState::Waiting => { if dead_nodes > 0 { self.nodes.swap(index, index - dead_nodes); - *node_rewrite -= dead_nodes; + node_rewrites[index] -= dead_nodes; } } NodeState::Done => { @@ -646,7 +646,7 @@ impl ObligationForest { } // Extract the success stories. outcome_cb(&node.obligation); - *node_rewrite = orig_nodes_len; + node_rewrites[index] = orig_nodes_len; dead_nodes += 1; } NodeState::Error => { @@ -655,7 +655,7 @@ impl ObligationForest { // check against. self.active_cache.remove(&node.obligation.as_cache_key()); self.insert_into_error_cache(index); - *node_rewrite = orig_nodes_len; + node_rewrites[index] = orig_nodes_len; dead_nodes += 1; } NodeState::Success => unreachable!(), diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index e80db0845a7be..20e2a3b9696e8 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -205,10 +205,10 @@ impl SortedMap { R: RangeBounds, { let start = match range.start_bound() { - Bound::Included(k) => match self.lookup_index_for(k) { + Bound::Included(ref k) => match self.lookup_index_for(k) { Ok(index) | Err(index) => index, }, - Bound::Excluded(k) => match self.lookup_index_for(k) { + Bound::Excluded(ref k) => match self.lookup_index_for(k) { Ok(index) => index + 1, Err(index) => index, }, @@ -216,11 +216,11 @@ impl SortedMap { }; let end = match range.end_bound() { - Bound::Included(k) => match self.lookup_index_for(k) { + Bound::Included(ref k) => match self.lookup_index_for(k) { Ok(index) => index + 1, Err(index) => index, }, - Bound::Excluded(k) => match self.lookup_index_for(k) { + Bound::Excluded(ref k) => match self.lookup_index_for(k) { Ok(index) | Err(index) => index, }, Bound::Unbounded => self.data.len(), diff --git a/compiler/rustc_data_structures/src/sorted_map/index_map.rs b/compiler/rustc_data_structures/src/sorted_map/index_map.rs index 1395bb16e875c..e92db9ea12805 100644 --- a/compiler/rustc_data_structures/src/sorted_map/index_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map/index_map.rs @@ -75,7 +75,7 @@ impl SortedIndexMultiMap { /// /// If there are multiple items that are equivalent to `key`, they will be yielded in /// insertion order. - pub fn get_by_key(&self, key: K) -> impl Iterator { + pub fn get_by_key(&'a self, key: K) -> impl 'a + Iterator { self.get_by_key_enumerated(key).map(|(_, v)| v) } @@ -84,7 +84,7 @@ impl SortedIndexMultiMap { /// /// If there are multiple items that are equivalent to `key`, they will be yielded in /// insertion order. - pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator { + pub fn get_by_key_enumerated(&'a self, key: K) -> impl '_ + Iterator { let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key); self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| { let (k, v) = &self.items[i]; diff --git a/compiler/rustc_data_structures/src/sso/map.rs b/compiler/rustc_data_structures/src/sso/map.rs index d4274e99f1cff..2de05cd4e5679 100644 --- a/compiler/rustc_data_structures/src/sso/map.rs +++ b/compiler/rustc_data_structures/src/sso/map.rs @@ -257,7 +257,11 @@ impl SsoHashMap { pub fn remove(&mut self, key: &K) -> Option { match self { SsoHashMap::Array(array) => { - array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index).1) + if let Some(index) = array.iter().position(|(k, _v)| k == key) { + Some(array.swap_remove(index).1) + } else { + None + } } SsoHashMap::Map(map) => map.remove(key), } @@ -268,7 +272,11 @@ impl SsoHashMap { pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)> { match self { SsoHashMap::Array(array) => { - array.iter().position(|(k, _v)| k == key).map(|index| array.swap_remove(index)) + if let Some(index) = array.iter().position(|(k, _v)| k == key) { + Some(array.swap_remove(index)) + } else { + None + } } SsoHashMap::Map(map) => map.remove_entry(key), } @@ -415,14 +423,14 @@ impl IntoIterator for SsoHashMap { /// adapts Item of array reference iterator to Item of hashmap reference iterator. #[inline(always)] -fn adapt_array_ref_it(pair: &(K, V)) -> (&K, &V) { +fn adapt_array_ref_it(pair: &'a (K, V)) -> (&'a K, &'a V) { let (a, b) = pair; (a, b) } /// adapts Item of array mut reference iterator to Item of hashmap mut reference iterator. #[inline(always)] -fn adapt_array_mut_it(pair: &mut (K, V)) -> (&K, &mut V) { +fn adapt_array_mut_it(pair: &'a mut (K, V)) -> (&'a K, &'a mut V) { let (a, b) = pair; (a, b) } diff --git a/compiler/rustc_data_structures/src/sso/set.rs b/compiler/rustc_data_structures/src/sso/set.rs index f71522d37148a..29baf4e1ddb66 100644 --- a/compiler/rustc_data_structures/src/sso/set.rs +++ b/compiler/rustc_data_structures/src/sso/set.rs @@ -75,7 +75,7 @@ impl SsoHashSet { /// An iterator visiting all elements in arbitrary order. /// The iterator element type is `&'a T`. #[inline] - pub fn iter(&self) -> impl Iterator { + pub fn iter(&'a self) -> impl Iterator { self.into_iter() } diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 2e992e762273c..354f9dd93cc4d 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -229,14 +229,14 @@ impl HashStable for ::std::num::NonZeroUsize { impl HashStable for f32 { fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - let val: u32 = self.to_bits(); + let val: u32 = unsafe { ::std::mem::transmute(*self) }; val.hash_stable(ctx, hasher); } } impl HashStable for f64 { fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { - let val: u64 = self.to_bits(); + let val: u64 = unsafe { ::std::mem::transmute(*self) }; val.hash_stable(ctx, hasher); } } diff --git a/compiler/rustc_data_structures/src/stack.rs b/compiler/rustc_data_structures/src/stack.rs index ba22c7f9b9799..a4964b7aa0cc8 100644 --- a/compiler/rustc_data_structures/src/stack.rs +++ b/compiler/rustc_data_structures/src/stack.rs @@ -5,7 +5,6 @@ const RED_ZONE: usize = 100 * 1024; // 100k // Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then // on. This flag has performance relevant characteristics. Don't set it too high. -#[allow(clippy::identity_op)] const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB /// Grows the stack on demand to prevent stack overflow. Call this in strategic locations diff --git a/compiler/rustc_data_structures/src/steal.rs b/compiler/rustc_data_structures/src/steal.rs index a3ece6550473c..a1ffbae8b15f6 100644 --- a/compiler/rustc_data_structures/src/steal.rs +++ b/compiler/rustc_data_structures/src/steal.rs @@ -34,7 +34,7 @@ impl Steal { #[track_caller] pub fn borrow(&self) -> MappedReadGuard<'_, T> { let borrow = self.value.borrow(); - if borrow.is_none() { + if let None = &*borrow { panic!("attempted to read from stolen value: {}", std::any::type_name::()); } ReadGuard::map(borrow, |opt| opt.as_ref().unwrap()) diff --git a/compiler/rustc_data_structures/src/tiny_list.rs b/compiler/rustc_data_structures/src/tiny_list.rs index 9e605ea2d982c..9b07f86846eb3 100644 --- a/compiler/rustc_data_structures/src/tiny_list.rs +++ b/compiler/rustc_data_structures/src/tiny_list.rs @@ -48,7 +48,7 @@ impl TinyList { #[inline] pub fn contains(&self, data: &T) -> bool { let mut elem = self.head.as_ref(); - while let Some(e) = elem { + while let Some(ref e) = elem { if &e.data == data { return true; } diff --git a/compiler/rustc_data_structures/src/vec_linked_list.rs b/compiler/rustc_data_structures/src/vec_linked_list.rs index ce60d40b24b44..1cf030d852e9f 100644 --- a/compiler/rustc_data_structures/src/vec_linked_list.rs +++ b/compiler/rustc_data_structures/src/vec_linked_list.rs @@ -2,8 +2,8 @@ use rustc_index::vec::{Idx, IndexVec}; pub fn iter( first: Option, - links: &Ls, -) -> impl Iterator + '_ + links: &'a Ls, +) -> impl Iterator + 'a where Ls: Links, { diff --git a/compiler/rustc_graphviz/src/lib.rs b/compiler/rustc_graphviz/src/lib.rs index e69289b71f97f..27390fd2e4d91 100644 --- a/compiler/rustc_graphviz/src/lib.rs +++ b/compiler/rustc_graphviz/src/lib.rs @@ -512,7 +512,7 @@ impl<'a> LabelText<'a> { pub fn to_dot_string(&self) -> String { match *self { LabelStr(ref s) => format!("\"{}\"", s.escape_default()), - EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(s)), + EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)), HtmlStr(ref s) => format!("<{}>", s), } } diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 573124c8ec9a8..67b3cec0a3e59 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -990,8 +990,9 @@ impl BitMatrix { pub fn insert_all_into_row(&mut self, row: R) { assert!(row.index() < self.num_rows); let (start, end) = self.range(row); - for word in self.words[start..end].iter_mut() { - *word = !0; + let words = &mut self.words[..]; + for index in start..end { + words[index] = !0; } self.clear_excess_bits(row); } @@ -1143,7 +1144,7 @@ impl SparseBitMatrix { /// Iterates through all the columns set to true in a given row of /// the matrix. - pub fn iter(&self, row: R) -> impl Iterator + '_ { + pub fn iter<'a>(&'a self, row: R) -> impl Iterator + 'a { self.row(row).into_iter().flat_map(|r| r.iter()) } diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index 69578e85f2781..66399d2999848 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -634,15 +634,18 @@ impl IndexVec { } #[inline] - pub fn drain>(&mut self, range: R) -> impl Iterator + '_ { + pub fn drain<'a, R: RangeBounds>( + &'a mut self, + range: R, + ) -> impl Iterator + 'a { self.raw.drain(range) } #[inline] - pub fn drain_enumerated>( - &mut self, + pub fn drain_enumerated<'a, R: RangeBounds>( + &'a mut self, range: R, - ) -> impl Iterator + '_ { + ) -> impl Iterator + 'a { self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t)) } diff --git a/compiler/rustc_lexer/src/unescape.rs b/compiler/rustc_lexer/src/unescape.rs index 804dc657f2d47..b970c9e4911fa 100644 --- a/compiler/rustc_lexer/src/unescape.rs +++ b/compiler/rustc_lexer/src/unescape.rs @@ -68,10 +68,11 @@ pub enum EscapeError { impl EscapeError { /// Returns true for actual errors, as opposed to warnings. pub fn is_fatal(&self) -> bool { - !matches!( - self, - EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning - ) + match self { + EscapeError::UnskippedWhitespaceWarning => false, + EscapeError::MultipleSkippedLinesWarning => false, + _ => true, + } } } @@ -329,7 +330,7 @@ where callback(start..end, Err(EscapeError::MultipleSkippedLinesWarning)); } let tail = &tail[first_non_space..]; - if let Some(c) = tail.chars().next() { + if let Some(c) = tail.chars().nth(0) { // For error reporting, we would like the span to contain the character that was not // skipped. The +1 is necessary to account for the leading \ that started the escape. let end = start + first_non_space + c.len_utf8() + 1; diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index 63bdcea87f817..dba885a27fe22 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -24,9 +24,11 @@ fn parse_attributes(field: &syn::Field) -> Attributes { } if meta.path().is_ident("project") { if let Meta::List(list) = meta { - if let Some(NestedMeta::Meta(meta)) = list.nested.iter().next() { - attrs.project = meta.path().get_ident().cloned(); - any_attr = true; + if let Some(nested) = list.nested.iter().next() { + if let NestedMeta::Meta(meta) = nested { + attrs.project = meta.path().get_ident().cloned(); + any_attr = true; + } } } } diff --git a/compiler/rustc_macros/src/session_diagnostic.rs b/compiler/rustc_macros/src/session_diagnostic.rs index c8959dc86ad2d..80dcf99da6224 100644 --- a/compiler/rustc_macros/src/session_diagnostic.rs +++ b/compiler/rustc_macros/src/session_diagnostic.rs @@ -349,14 +349,14 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> { ) -> Result { let field_binding = &info.binding.binding; - let option_ty = option_inner_ty(info.ty); + let option_ty = option_inner_ty(&info.ty); let generated_code = self.generate_non_option_field_code( attr, FieldInfo { vis: info.vis, binding: info.binding, - ty: option_ty.unwrap_or(info.ty), + ty: option_ty.unwrap_or(&info.ty), span: info.span, }, )?; @@ -388,7 +388,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> { let formatted_str = self.build_format(&s.value(), attr.span()); match name { "message" => { - if type_matches_path(info.ty, &["rustc_span", "Span"]) { + if type_matches_path(&info.ty, &["rustc_span", "Span"]) { quote! { #diag.set_span(*#field_binding); #diag.set_primary_message(#formatted_str); @@ -401,7 +401,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> { } } "label" => { - if type_matches_path(info.ty, &["rustc_span", "Span"]) { + if type_matches_path(&info.ty, &["rustc_span", "Span"]) { quote! { #diag.span_label(*#field_binding, #formatted_str); } diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 6671c7c0fa60c..e32e4493726db 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -500,8 +500,8 @@ impl Decodable for [u8; N] { d.read_seq(|d, len| { assert!(len == N); let mut v = [0u8; N]; - for x in &mut v { - *x = d.read_seq_elt(|d| Decodable::decode(d))?; + for i in 0..len { + v[i] = d.read_seq_elt(|d| Decodable::decode(d))?; } Ok(v) }) diff --git a/library/core/src/num/fmt.rs b/library/core/src/num/fmt.rs index 8cff266642fef..578288bda2595 100644 --- a/library/core/src/num/fmt.rs +++ b/library/core/src/num/fmt.rs @@ -31,10 +31,8 @@ impl<'a> Part<'a> { } else { 3 } - } else if v < 10_000 { - 4 } else { - 5 + if v < 10_000 { 4 } else { 5 } } } Part::Copy(buf) => buf.len(), From 55fad2990317ce6655cb32beefbcff8f2300848d Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 15 Oct 2021 12:21:25 +0200 Subject: [PATCH 109/181] Apply documentation suggestions from code review Co-authored-by: Guillaume Gomez --- src/librustdoc/visit_ast.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index f60d4e1f29537..ce967038c50a6 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -88,9 +88,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { // we add the rexport as an item here, and then skip over the original // definition in `visit_item()` below. // - // We also skip `#[macro_export] macro_rules!` that have alredy been inserted, - // this can append if within the same module a `#[macro_export] macro_rules!` - // is declared but also a reexport of itself producing two export of the same + // We also skip `#[macro_export] macro_rules!` that have already been inserted, + // it can happen if within the same module a `#[macro_export] macro_rules!` + // is declared but also a reexport of itself producing two exports of the same // macro in the same module. let mut inserted = FxHashSet::default(); for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) { From e259cc46a643101775709ae6b9bbd5abb834906d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Fri, 15 Oct 2021 12:56:47 +0200 Subject: [PATCH 110/181] Add equivalent test in src/test/rustdoc --- src/test/rustdoc/issue-89852.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/test/rustdoc/issue-89852.rs diff --git a/src/test/rustdoc/issue-89852.rs b/src/test/rustdoc/issue-89852.rs new file mode 100644 index 0000000000000..dff2d07ac2537 --- /dev/null +++ b/src/test/rustdoc/issue-89852.rs @@ -0,0 +1,14 @@ +// edition:2018 + +#![no_core] +#![feature(no_core)] + +// @count issue_89852/index.html '//*[@class="macro"]' 2 +// @has - '//*[@class="macro"]/@href' 'macro.repro.html' +#[macro_export] +macro_rules! repro { + () => {}; +} + +// @!has issue_89852/macro.repro.html '//*[@class="macro"]/@content' 'repro2' +pub use crate::repro as repro2; From 1ed123828c97d9f7e031a9caee02e340295ef21e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sun, 11 Apr 2021 14:55:47 +0200 Subject: [PATCH 111/181] Use BCryptGenRandom instead of RtlGenRandom on Windows. BCryptGenRandom isn't available on XP, but we dropped XP support a while ago. --- library/std/src/sys/windows/c.rs | 29 ++++++++++++++--------------- library/std/src/sys/windows/rand.rs | 12 ------------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 6fb850d182889..e5c550802a7ab 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -262,6 +262,8 @@ pub const STACK_SIZE_PARAM_IS_A_RESERVATION: DWORD = 0x00010000; pub const STATUS_SUCCESS: NTSTATUS = 0x00000000; +pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002; + #[repr(C)] #[cfg(not(target_pointer_width = "64"))] pub struct WSADATA { @@ -678,10 +680,6 @@ if #[cfg(not(target_vendor = "uwp"))] { #[link(name = "advapi32")] extern "system" { - // Forbidden when targeting UWP - #[link_name = "SystemFunction036"] - pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: ULONG) -> BOOLEAN; - // Allowed but unused by UWP pub fn OpenProcessToken( ProcessHandle: HANDLE, @@ -743,8 +741,6 @@ if #[cfg(not(target_vendor = "uwp"))] { // UWP specific functions & types cfg_if::cfg_if! { if #[cfg(target_vendor = "uwp")] { - pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD = 0x00000002; - #[repr(C)] pub struct FILE_STANDARD_INFO { pub AllocationSize: LARGE_INTEGER, @@ -754,15 +750,6 @@ if #[cfg(target_vendor = "uwp")] { pub Directory: BOOLEAN, } - #[link(name = "bcrypt")] - extern "system" { - pub fn BCryptGenRandom( - hAlgorithm: LPVOID, - pBuffer: *mut u8, - cbBuffer: ULONG, - dwFlags: ULONG, - ) -> LONG; - } #[link(name = "kernel32")] extern "system" { pub fn GetFileInformationByHandleEx( @@ -1085,6 +1072,18 @@ extern "system" { ) -> c_int; } +#[link(name = "bcrypt")] +extern "system" { + // >= Vista / Server 2008 + // https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom + pub fn BCryptGenRandom( + hAlgorithm: LPVOID, + pBuffer: *mut u8, + cbBuffer: ULONG, + dwFlags: ULONG, + ) -> NTSTATUS; +} + // Functions that aren't available on every version of Windows that we support, // but we still use them and just provide some form of a fallback implementation. compat_fn! { diff --git a/library/std/src/sys/windows/rand.rs b/library/std/src/sys/windows/rand.rs index 87ea416bf675a..de73e9154b45e 100644 --- a/library/std/src/sys/windows/rand.rs +++ b/library/std/src/sys/windows/rand.rs @@ -2,18 +2,6 @@ use crate::io; use crate::mem; use crate::sys::c; -#[cfg(not(target_vendor = "uwp"))] -pub fn hashmap_random_keys() -> (u64, u64) { - let mut v = (0, 0); - let ret = - unsafe { c::RtlGenRandom(&mut v as *mut _ as *mut u8, mem::size_of_val(&v) as c::ULONG) }; - if ret == 0 { - panic!("couldn't generate random bytes: {}", io::Error::last_os_error()); - } - v -} - -#[cfg(target_vendor = "uwp")] pub fn hashmap_random_keys() -> (u64, u64) { use crate::ptr; From acee39e5c5be203e6ebd9efb259a66d9a89e9267 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 15 Oct 2021 13:25:39 +0200 Subject: [PATCH 112/181] Add missing bcrypt.lib to make-fulldeps Makefile. --- src/test/run-make-fulldeps/tools.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk index a1a076dd7473d..3934c4725f413 100644 --- a/src/test/run-make-fulldeps/tools.mk +++ b/src/test/run-make-fulldeps/tools.mk @@ -101,9 +101,9 @@ endif # Extra flags needed to compile a working executable with the standard library ifdef IS_WINDOWS ifdef IS_MSVC - EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib + EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib else - EXTRACFLAGS := -lws2_32 -luserenv + EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt EXTRACXXFLAGS := -lstdc++ # So this is a bit hacky: we can't use the DLL version of libstdc++ because # it pulls in the DLL version of libgcc, which means that we end up with 2 From db5b64a484dbea09f1f39e0640662b50c6e934cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Fri, 15 Oct 2021 16:54:31 +0200 Subject: [PATCH 113/181] Rework the equivalent test to work with sidebar-items.js --- src/test/rustdoc/issue-89852.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/rustdoc/issue-89852.rs b/src/test/rustdoc/issue-89852.rs index dff2d07ac2537..45544dbeea6a0 100644 --- a/src/test/rustdoc/issue-89852.rs +++ b/src/test/rustdoc/issue-89852.rs @@ -3,12 +3,12 @@ #![no_core] #![feature(no_core)] -// @count issue_89852/index.html '//*[@class="macro"]' 2 -// @has - '//*[@class="macro"]/@href' 'macro.repro.html' +// @matches 'issue_89852/sidebar-items.js' '"repro"' +// @!matches 'issue_89852/sidebar-items.js' '"repro".*"repro"' + #[macro_export] macro_rules! repro { () => {}; } -// @!has issue_89852/macro.repro.html '//*[@class="macro"]/@content' 'repro2' pub use crate::repro as repro2; From d2dc0f3b0f0267941b47bde7bd48d26b2c22ca6a Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 15 Oct 2021 14:48:57 +0000 Subject: [PATCH 114/181] emitter: current substitution can be multi-line In `splice_lines`, there is some arithmetic to compute the required alignment such that future substitutions in a suggestion are aligned correctly. However, this assumed that the current substitution's span was only on a single line. In circumstances where this was not true, it could result in a arithmetic overflow when the substitution's end column was less than the substitution's start column. Signed-off-by: David Wood --- compiler/rustc_errors/src/lib.rs | 2 +- ...sue-89280-emitter-overflow-splice-lines.rs | 10 ++++++++ ...89280-emitter-overflow-splice-lines.stderr | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs create mode 100644 src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 60a48b5a2d9c1..9b2094adb150c 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -341,7 +341,7 @@ impl CodeSuggestion { }); buf.push_str(&part.snippet); let cur_hi = sm.lookup_char_pos(part.span.hi()); - if prev_hi.line == cur_lo.line { + if prev_hi.line == cur_lo.line && cur_hi.line == cur_lo.line { // Account for the difference between the width of the current code and the // snippet being suggested, so that the *later* suggestions are correctly // aligned on the screen. diff --git a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs new file mode 100644 index 0000000000000..a1c7af128d2ee --- /dev/null +++ b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.rs @@ -0,0 +1,10 @@ +// check-pass + +trait X { + fn test(x: u32, ( +//~^ WARN anonymous parameters are deprecated and will be removed in the next edition +//~^^ WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + )) {} +} + +fn main() {} diff --git a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr new file mode 100644 index 0000000000000..4ec78a298fe62 --- /dev/null +++ b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr @@ -0,0 +1,23 @@ +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/issue-89280-emitter-overflow-splice-lines.rs:4:21 + | +LL | fn test(x: u32, ( + | _____________________^ +LL | | +LL | | +LL | | )) {} + | |_____^ + | + = note: `#[warn(anonymous_parameters)]` on by default + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 +help: try naming the parameter or explicitly ignoring it + | +LL ~ fn test(x: u32, _: ( +LL + +LL + +LL ~ )) {} + | + +warning: 1 warning emitted + From c4f9eb1e5a6ab0f1eaf36170b083e28946c69e15 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Tue, 5 Oct 2021 17:43:45 -0400 Subject: [PATCH 115/181] Emit impl difference error for GenericBoundFailure too --- .../nice_region_error/trait_impl_difference.rs | 4 +++- .../ui/generic-associated-types/impl_bounds.rs | 2 +- .../generic-associated-types/impl_bounds.stderr | 12 ++++++------ .../ui/generic-associated-types/issue-86787.rs | 4 ++-- .../generic-associated-types/issue-86787.stderr | 17 ++++++++++------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index 0efe5a56436b5..ea9d0eae17e2c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -46,7 +46,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { } } } - if let RegionResolutionError::ConcreteFailure(origin, _, _) = error.clone() { + if let RegionResolutionError::ConcreteFailure(origin, _, _) + | RegionResolutionError::GenericBoundFailure(origin, _, _) = error.clone() + { if let SubregionOrigin::CompareImplTypeObligation { span, item_name, diff --git a/src/test/ui/generic-associated-types/impl_bounds.rs b/src/test/ui/generic-associated-types/impl_bounds.rs index 27c135cb7cf82..ff2ffec22c456 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.rs +++ b/src/test/ui/generic-associated-types/impl_bounds.rs @@ -13,7 +13,7 @@ struct Fooy(T); impl Foo for Fooy { type A<'a> where Self: 'static = (&'a ()); - //~^ ERROR the parameter type `T` may not live long enough + //~^ ERROR `impl` associated type type B<'a, 'b> where 'b: 'a = (&'a(), &'b ()); //~^ ERROR `impl` associated type //~| ERROR lifetime bound not satisfied diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 649eadec515d0..f47b5f81e25b2 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -1,11 +1,11 @@ -error[E0310]: the parameter type `T` may not live long enough +error: `impl` associated type signature for `A` doesn't match `trait` associated type signature --> $DIR/impl_bounds.rs:15:5 | +LL | type A<'a> where Self: 'a; + | -------------------------- expected +... LL | type A<'a> where Self: 'static = (&'a ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: consider adding an explicit lifetime bound `T: 'static`... - = note: ...so that the definition in impl matches the definition from the trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found error: `impl` associated type signature for `B` doesn't match `trait` associated type signature --> $DIR/impl_bounds.rs:17:5 @@ -85,5 +85,5 @@ LL | impl Foo for Fooy { error: aborting due to 5 previous errors -Some errors have detailed explanations: E0277, E0310, E0478. +Some errors have detailed explanations: E0277, E0478. For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/generic-associated-types/issue-86787.rs b/src/test/ui/generic-associated-types/issue-86787.rs index 57d478a9ef1e3..f1f05ea6627e8 100644 --- a/src/test/ui/generic-associated-types/issue-86787.rs +++ b/src/test/ui/generic-associated-types/issue-86787.rs @@ -21,8 +21,8 @@ where { type T = Either; type TRef<'a> - //~^ the associated type - //~^^ the associated type + //~^ `impl` associated type signature + //~^^ `impl` associated type signature where ::T: 'a, ::T: 'a diff --git a/src/test/ui/generic-associated-types/issue-86787.stderr b/src/test/ui/generic-associated-types/issue-86787.stderr index e1ff772921104..648eff77d73bb 100644 --- a/src/test/ui/generic-associated-types/issue-86787.stderr +++ b/src/test/ui/generic-associated-types/issue-86787.stderr @@ -1,29 +1,32 @@ -error[E0309]: the associated type `::T` may not live long enough +error: `impl` associated type signature for `TRef` doesn't match `trait` associated type signature --> $DIR/issue-86787.rs:23:5 | +LL | type TRef<'a>; + | -------------- expected +... LL | / type TRef<'a> LL | | LL | | LL | | where LL | | ::T: 'a, LL | | ::T: 'a - | | - help: consider adding a where clause: `, ::T: 'a` LL | | = Either<&'a Left::T, &'a Right::T>; - | |________________________________________^ ...so that the definition in impl matches the definition from the trait + | |________________________________________^ found -error[E0309]: the associated type `::T` may not live long enough +error: `impl` associated type signature for `TRef` doesn't match `trait` associated type signature --> $DIR/issue-86787.rs:23:5 | +LL | type TRef<'a>; + | -------------- expected +... LL | / type TRef<'a> LL | | LL | | LL | | where LL | | ::T: 'a, LL | | ::T: 'a - | | - help: consider adding a where clause: `, ::T: 'a` LL | | = Either<&'a Left::T, &'a Right::T>; - | |________________________________________^ ...so that the definition in impl matches the definition from the trait + | |________________________________________^ found error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0309`. From a7c132de559ee904ec59d8305d0e9c4ef6d822b1 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Fri, 8 Oct 2021 22:55:06 -0400 Subject: [PATCH 116/181] Move push_outlives_components to rustc_infer --- .../src/infer/outlives/components.rs} | 24 ++++++++++--------- .../rustc_infer/src/infer/outlives/mod.rs | 1 + .../src/infer/outlives/obligations.rs | 6 ++--- compiler/rustc_infer/src/traits/util.rs | 4 ++-- compiler/rustc_middle/src/ty/mod.rs | 1 - .../src/implied_outlives_bounds.rs | 4 ++-- compiler/rustc_typeck/src/outlives/utils.rs | 4 ++-- 7 files changed, 23 insertions(+), 21 deletions(-) rename compiler/{rustc_middle/src/ty/outlives.rs => rustc_infer/src/infer/outlives/components.rs} (94%) diff --git a/compiler/rustc_middle/src/ty/outlives.rs b/compiler/rustc_infer/src/infer/outlives/components.rs similarity index 94% rename from compiler/rustc_middle/src/ty/outlives.rs rename to compiler/rustc_infer/src/infer/outlives/components.rs index ef4ad998f10c8..98f926e9d76d5 100644 --- a/compiler/rustc_middle/src/ty/outlives.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -2,10 +2,10 @@ // refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that // RFC for reference. -use crate::ty::subst::{GenericArg, GenericArgKind}; -use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::sso::SsoHashSet; -use smallvec::SmallVec; +use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; +use smallvec::{smallvec, SmallVec}; #[derive(Debug)] pub enum Component<'tcx> { @@ -47,14 +47,16 @@ pub enum Component<'tcx> { EscapingProjection(Vec>), } -impl<'tcx> TyCtxt<'tcx> { - /// Push onto `out` all the things that must outlive `'a` for the condition - /// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**. - pub fn push_outlives_components(self, ty0: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>) { - let mut visited = SsoHashSet::new(); - compute_components(self, ty0, out, &mut visited); - debug!("components({:?}) = {:?}", ty0, out); - } +/// Push onto `out` all the things that must outlive `'a` for the condition +/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**. +pub fn push_outlives_components( + tcx: TyCtxt<'tcx>, + ty0: Ty<'tcx>, + out: &mut SmallVec<[Component<'tcx>; 4]>, +) { + let mut visited = SsoHashSet::new(); + compute_components(tcx, ty0, out, &mut visited); + debug!("components({:?}) = {:?}", ty0, out); } fn compute_components( diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index 4dd5e8ba54500..03d6c45a65345 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -1,5 +1,6 @@ //! Various code related to computing outlives relations. +pub mod components; pub mod env; pub mod obligations; pub mod verify; diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 437083c68dcec..91a22ecc5a994 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -1,5 +1,5 @@ //! Code that handles "type-outlives" constraints like `T: 'a`. This -//! is based on the `push_outlives_components` function defined on the tcx, +//! is based on the `push_outlives_components` function defined in rustc_infer, //! but it adds a bit of heuristics on top, in particular to deal with //! associated types and projections. //! @@ -59,13 +59,13 @@ //! might later infer `?U` to something like `&'b u32`, which would //! imply that `'b: 'a`. +use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::outlives::verify::VerifyBoundCx; use crate::infer::{ self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound, }; use crate::traits::{ObligationCause, ObligationCauseCode}; -use rustc_middle::ty::outlives::Component; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeFoldable}; @@ -271,7 +271,7 @@ where assert!(!ty.has_escaping_bound_vars()); let mut components = smallvec![]; - self.tcx.push_outlives_components(ty, &mut components); + push_outlives_components(self.tcx, ty, &mut components); self.components_must_outlive(origin, &components, region); } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 30d5613d5820d..c839f824d1c9c 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -1,8 +1,8 @@ use smallvec::smallvec; +use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::traits::{Obligation, ObligationCause, PredicateObligation}; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; -use rustc_middle::ty::outlives::Component; use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness}; use rustc_span::symbol::Ident; @@ -200,7 +200,7 @@ impl Elaborator<'tcx> { let visited = &mut self.visited; let mut components = smallvec![]; - tcx.push_outlives_components(ty_max, &mut components); + push_outlives_components(tcx, ty_max, &mut components); self.stack.extend( components .into_iter() diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 0eacedc09ee6d..20d07bdc48a62 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -92,7 +92,6 @@ pub mod fold; pub mod inhabitedness; pub mod layout; pub mod normalize_erasing_regions; -pub mod outlives; pub mod print; pub mod query; pub mod relate; diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index 1d10d06849062..f2fc4e59d4649 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -4,9 +4,9 @@ use rustc_hir as hir; use rustc_infer::infer::canonical::{self, Canonical}; +use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; -use rustc_middle::ty::outlives::Component; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map::DUMMY_SP; @@ -118,7 +118,7 @@ fn compute_implied_outlives_bounds<'tcx>( ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => { let ty_a = infcx.resolve_vars_if_possible(ty_a); let mut components = smallvec![]; - tcx.push_outlives_components(ty_a, &mut components); + push_outlives_components(tcx, ty_a, &mut components); implied_bounds_from_components(r_b, components) } }, diff --git a/compiler/rustc_typeck/src/outlives/utils.rs b/compiler/rustc_typeck/src/outlives/utils.rs index 8b06967879638..76ae2ee43566e 100644 --- a/compiler/rustc_typeck/src/outlives/utils.rs +++ b/compiler/rustc_typeck/src/outlives/utils.rs @@ -1,4 +1,4 @@ -use rustc_middle::ty::outlives::Component; +use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt}; use rustc_span::Span; @@ -35,7 +35,7 @@ pub fn insert_outlives_predicate<'tcx>( // Or if within `struct Foo` you had `T = Vec`, then // we would want to add `U: 'outlived_region` let mut components = smallvec![]; - tcx.push_outlives_components(ty, &mut components); + push_outlives_components(tcx, ty, &mut components); for component in components { match component { Component::Region(r) => { From d3fa07c72e079e8a72fcb55a792d2f855e80722b Mon Sep 17 00:00:00 2001 From: jackh726 Date: Wed, 13 Oct 2021 22:22:09 -0400 Subject: [PATCH 117/181] Use LocalDefId directly in more places in wfcheck --- compiler/rustc_typeck/src/check/wfcheck.rs | 57 +++++++++------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 20cf9a75e1267..30aab38b1eb85 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -142,23 +142,23 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { } } hir::ItemKind::Fn(ref sig, ..) => { - check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl); + check_item_fn(tcx, item.def_id, item.ident, item.span, sig.decl); } hir::ItemKind::Static(ty, ..) => { - check_item_type(tcx, item.hir_id(), ty.span, false); + check_item_type(tcx, item.def_id, ty.span, false); } hir::ItemKind::Const(ty, ..) => { - check_item_type(tcx, item.hir_id(), ty.span, false); + check_item_type(tcx, item.def_id, ty.span, false); } hir::ItemKind::ForeignMod { items, .. } => { for it in items.iter() { let it = tcx.hir().foreign_item(it.id); match it.kind { hir::ForeignItemKind::Fn(decl, ..) => { - check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl) + check_item_fn(tcx, it.def_id, it.ident, it.span, decl) } hir::ForeignItemKind::Static(ty, ..) => { - check_item_type(tcx, it.hir_id(), ty.span, true) + check_item_type(tcx, it.def_id, ty.span, true) } hir::ForeignItemKind::Type => (), } @@ -199,7 +199,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { _ => (None, trait_item.span), }; check_object_unsafe_self_trait_by_name(tcx, trait_item); - check_associated_item(tcx, trait_item.hir_id(), span, method_sig); + check_associated_item(tcx, trait_item.def_id, span, method_sig); let encl_trait_hir_id = tcx.hir().get_parent_item(hir_id); let encl_trait = tcx.hir().expect_item(encl_trait_hir_id); @@ -327,7 +327,7 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { _ => (None, impl_item.span), }; - check_associated_item(tcx, impl_item.hir_id(), span, method_sig); + check_associated_item(tcx, impl_item.def_id, span, method_sig); } fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { @@ -437,13 +437,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) { #[tracing::instrument(level = "debug", skip(tcx, span, sig_if_method))] fn check_associated_item( tcx: TyCtxt<'_>, - item_id: hir::HirId, + item_id: LocalDefId, span: Span, sig_if_method: Option<&hir::FnSig<'_>>, ) { - let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner()))); + let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id))); for_id(tcx, item_id, span).with_fcx(|fcx| { - let item = fcx.tcx.associated_item(fcx.tcx.hir().local_def_id(item_id)); + let item = fcx.tcx.associated_item(item_id); let (mut implied_bounds, self_ty) = match item.container { ty::TraitContainer(_) => (FxHashSet::default(), fcx.tcx.types.self_param), @@ -455,11 +455,7 @@ fn check_associated_item( match item.kind { ty::AssocKind::Const => { let ty = fcx.tcx.type_of(item.def_id); - let ty = fcx.normalize_associated_types_in_wf( - span, - ty, - WellFormedLoc::Ty(item_id.expect_owner()), - ); + let ty = fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id)); fcx.register_wf_obligation(ty.into(), span, code.clone()); } ty::AssocKind::Fn => { @@ -481,11 +477,8 @@ fn check_associated_item( } if item.defaultness.has_value() { let ty = fcx.tcx.type_of(item.def_id); - let ty = fcx.normalize_associated_types_in_wf( - span, - ty, - WellFormedLoc::Ty(item_id.expect_owner()), - ); + let ty = + fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id)); fcx.register_wf_obligation(ty.into(), span, code.clone()); } } @@ -496,14 +489,13 @@ fn check_associated_item( } fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> { - for_id(tcx, item.hir_id(), item.span) + for_id(tcx, item.def_id, item.span) } -fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> { - let def_id = tcx.hir().local_def_id(id); +fn for_id(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> CheckWfFcxBuilder<'_> { CheckWfFcxBuilder { inherited: Inherited::build(tcx, def_id), - id, + id: hir::HirId::make_owner(def_id), span, param_env: tcx.param_env(def_id), } @@ -665,13 +657,12 @@ fn check_associated_type_bounds(fcx: &FnCtxt<'_, '_>, item: &ty::AssocItem, span fn check_item_fn( tcx: TyCtxt<'_>, - item_id: hir::HirId, + def_id: LocalDefId, ident: Ident, span: Span, decl: &hir::FnDecl<'_>, ) { - for_id(tcx, item_id, span).with_fcx(|fcx| { - let def_id = tcx.hir().local_def_id(item_id); + for_id(tcx, def_id, span).with_fcx(|fcx| { let sig = tcx.fn_sig(def_id); let mut implied_bounds = FxHashSet::default(); check_fn_or_method(fcx, ident.span, sig, decl, def_id.to_def_id(), &mut implied_bounds); @@ -679,16 +670,12 @@ fn check_item_fn( }) } -fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_foreign_ty: bool) { +fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_foreign_ty: bool) { debug!("check_item_type: {:?}", item_id); for_id(tcx, item_id, ty_span).with_fcx(|fcx| { - let ty = tcx.type_of(tcx.hir().local_def_id(item_id)); - let item_ty = fcx.normalize_associated_types_in_wf( - ty_span, - ty, - WellFormedLoc::Ty(item_id.expect_owner()), - ); + let ty = tcx.type_of(item_id); + let item_ty = fcx.normalize_associated_types_in_wf(ty_span, ty, WellFormedLoc::Ty(item_id)); let mut forbid_unsized = true; if allow_foreign_ty { @@ -701,7 +688,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo fcx.register_wf_obligation( item_ty.into(), ty_span, - ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner()))), + ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id))), ); if forbid_unsized { fcx.register_bound( From 2b5b456e23b61ccd36732046134d17ebe2152e7d Mon Sep 17 00:00:00 2001 From: jackh726 Date: Fri, 15 Oct 2021 11:31:22 -0400 Subject: [PATCH 118/181] Move some outlives bounds things from rustc_trait_selection to rustc_typeck --- compiler/rustc_trait_selection/src/infer.rs | 49 ------------------ .../src/traits/query/mod.rs | 1 - .../query/type_op/implied_outlives_bounds.rs | 2 +- .../src/implied_outlives_bounds.rs | 2 +- compiler/rustc_typeck/src/check/regionck.rs | 51 +++++++++++++++++-- compiler/rustc_typeck/src/outlives/mod.rs | 1 + .../src/outlives}/outlives_bounds.rs | 8 +-- 7 files changed, 55 insertions(+), 59 deletions(-) rename compiler/{rustc_trait_selection/src/traits/query => rustc_typeck/src/outlives}/outlives_bounds.rs (93%) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 8fb4eb641c26a..70816b5722b2d 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -1,12 +1,8 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _; -use crate::traits::query::outlives_bounds::InferCtxtExt as _; use crate::traits::{self, TraitEngine, TraitEngineExt}; -use rustc_data_structures::stable_set::FxHashSet; -use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; -use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::traits::ObligationCause; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse}; @@ -180,48 +176,3 @@ impl<'tcx> InferCtxtBuilderExt<'tcx> for InferCtxtBuilder<'tcx> { ) } } - -pub trait OutlivesEnvironmentExt<'tcx> { - fn add_implied_bounds( - &mut self, - infcx: &InferCtxt<'a, 'tcx>, - fn_sig_tys: FxHashSet>, - body_id: hir::HirId, - span: Span, - ); -} - -impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> { - /// This method adds "implied bounds" into the outlives environment. - /// Implied bounds are outlives relationships that we can deduce - /// on the basis that certain types must be well-formed -- these are - /// either the types that appear in the function signature or else - /// the input types to an impl. For example, if you have a function - /// like - /// - /// ``` - /// fn foo<'a, 'b, T>(x: &'a &'b [T]) { } - /// ``` - /// - /// we can assume in the caller's body that `'b: 'a` and that `T: - /// 'b` (and hence, transitively, that `T: 'a`). This method would - /// add those assumptions into the outlives-environment. - /// - /// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs` - fn add_implied_bounds( - &mut self, - infcx: &InferCtxt<'a, 'tcx>, - fn_sig_tys: FxHashSet>, - body_id: hir::HirId, - span: Span, - ) { - debug!("add_implied_bounds()"); - - for ty in fn_sig_tys { - let ty = infcx.resolve_vars_if_possible(ty); - debug!("add_implied_bounds: ty = {}", ty); - let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span); - self.add_outlives_bounds(Some(infcx), implied_bounds) - } - } -} diff --git a/compiler/rustc_trait_selection/src/traits/query/mod.rs b/compiler/rustc_trait_selection/src/traits/query/mod.rs index f6f42814d3f07..ef3493678131f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/query/mod.rs @@ -9,7 +9,6 @@ pub mod dropck_outlives; pub mod evaluate_obligation; pub mod method_autoderef; pub mod normalize; -pub mod outlives_bounds; pub mod type_op; pub use rustc_middle::traits::query::*; diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs index 03087e3353a6e..04c382d439d4c 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs @@ -1,6 +1,6 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse}; -use crate::traits::query::outlives_bounds::OutlivesBound; use crate::traits::query::Fallible; +use rustc_infer::traits::query::OutlivesBound; use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt}; #[derive(Copy, Clone, Debug, HashStable, TypeFoldable, Lift)] diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index f2fc4e59d4649..37e007337374f 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -6,12 +6,12 @@ use rustc_hir as hir; use rustc_infer::infer::canonical::{self, Canonical}; use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; +use rustc_infer::traits::query::OutlivesBound; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map::DUMMY_SP; use rustc_trait_selection::infer::InferCtxtBuilderExt; -use rustc_trait_selection::traits::query::outlives_bounds::OutlivesBound; use rustc_trait_selection::traits::query::{CanonicalTyGoal, Fallible, NoSolution}; use rustc_trait_selection::traits::wf; use rustc_trait_selection::traits::FulfillmentContext; diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index 79443010fbb3d..7c8b75271871a 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -76,19 +76,19 @@ use crate::check::dropck; use crate::check::FnCtxt; use crate::mem_categorization as mc; use crate::middle::region; +use crate::outlives::outlives_bounds::InferCtxtExt as _; use rustc_data_structures::stable_set::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::PatKind; use rustc_infer::infer::outlives::env::OutlivesEnvironment; -use rustc_infer::infer::{self, RegionObligation, RegionckMode}; +use rustc_infer::infer::{self, InferCtxt, RegionObligation, RegionckMode}; use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId}; use rustc_middle::ty::adjustment; use rustc_middle::ty::{self, Ty}; use rustc_span::Span; -use rustc_trait_selection::infer::OutlivesEnvironmentExt; -use rustc_trait_selection::opaque_types::InferCtxtExt; +use rustc_trait_selection::opaque_types::InferCtxtExt as _; use std::ops::Deref; // a variation on try that just returns unit @@ -104,6 +104,51 @@ macro_rules! ignore_err { }; } +trait OutlivesEnvironmentExt<'tcx> { + fn add_implied_bounds( + &mut self, + infcx: &InferCtxt<'a, 'tcx>, + fn_sig_tys: FxHashSet>, + body_id: hir::HirId, + span: Span, + ); +} + +impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> { + /// This method adds "implied bounds" into the outlives environment. + /// Implied bounds are outlives relationships that we can deduce + /// on the basis that certain types must be well-formed -- these are + /// either the types that appear in the function signature or else + /// the input types to an impl. For example, if you have a function + /// like + /// + /// ``` + /// fn foo<'a, 'b, T>(x: &'a &'b [T]) { } + /// ``` + /// + /// we can assume in the caller's body that `'b: 'a` and that `T: + /// 'b` (and hence, transitively, that `T: 'a`). This method would + /// add those assumptions into the outlives-environment. + /// + /// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs` + fn add_implied_bounds( + &mut self, + infcx: &InferCtxt<'a, 'tcx>, + fn_sig_tys: FxHashSet>, + body_id: hir::HirId, + span: Span, + ) { + debug!("add_implied_bounds()"); + + for ty in fn_sig_tys { + let ty = infcx.resolve_vars_if_possible(ty); + debug!("add_implied_bounds: ty = {}", ty); + let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span); + self.add_outlives_bounds(Some(infcx), implied_bounds) + } + } +} + /////////////////////////////////////////////////////////////////////////// // PUBLIC ENTRY POINTS diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index 957ff2525190d..eb3853b6b3dee 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -9,6 +9,7 @@ use rustc_span::Span; mod explicit; mod implicit_infer; +crate mod outlives_bounds; /// Code to write unit test for outlives. pub mod test; mod utils; diff --git a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs b/compiler/rustc_typeck/src/outlives/outlives_bounds.rs similarity index 93% rename from compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs rename to compiler/rustc_typeck/src/outlives/outlives_bounds.rs index f5fa52c915d90..4ab5fe26abe56 100644 --- a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs +++ b/compiler/rustc_typeck/src/outlives/outlives_bounds.rs @@ -1,11 +1,11 @@ -use crate::infer::canonical::OriginalQueryValues; -use crate::infer::InferCtxt; -use crate::traits::query::NoSolution; -use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine}; use rustc_hir as hir; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::{self, Ty}; use rustc_span::source_map::Span; +use rustc_trait_selection::infer::canonical::OriginalQueryValues; +use rustc_trait_selection::infer::InferCtxt; +use rustc_trait_selection::traits::query::NoSolution; +use rustc_trait_selection::traits::{FulfillmentContext, ObligationCause, TraitEngine}; pub use rustc_middle::traits::query::OutlivesBound; From a51798a27ba215307dddd3ecc2bfc73f9f08efa9 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Oct 2021 01:38:49 +0900 Subject: [PATCH 119/181] Add some GATs related regression tests --- .../generic-associated-types/issue-88287.rs | 39 +++++++++++++++++++ .../generic-associated-types/issue-88405.rs | 16 ++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-88287.rs create mode 100644 src/test/ui/generic-associated-types/issue-88405.rs diff --git a/src/test/ui/generic-associated-types/issue-88287.rs b/src/test/ui/generic-associated-types/issue-88287.rs new file mode 100644 index 0000000000000..2e65af594a6bd --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-88287.rs @@ -0,0 +1,39 @@ +// check-pass +// edition:2018 + +#![feature(generic_associated_types)] +#![feature(type_alias_impl_trait)] + +use std::future::Future; + +trait SearchableResource { + type SearchResult; +} + +trait SearchableResourceExt: SearchableResource { + type Future<'f, A: 'f + ?Sized, B: 'f>: Future, ()>> + 'f + where + A: SearchableResource; + + fn search<'c>(&'c self, client: &'c ()) -> Self::Future<'c, Self, Criteria>; +} + +type SearchFutureTy<'f, A, B: 'f> +where + A: SearchableResource + ?Sized + 'f, += impl Future, ()>> + 'f; +impl SearchableResourceExt for T +where + T: SearchableResource, +{ + type Future<'f, A, B: 'f> + where + A: SearchableResource + ?Sized + 'f, + = SearchFutureTy<'f, A, B>; + + fn search<'c>(&'c self, _client: &'c ()) -> Self::Future<'c, Self, Criteria> { + async move { todo!() } + } +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-88405.rs b/src/test/ui/generic-associated-types/issue-88405.rs new file mode 100644 index 0000000000000..4a405bd3625c1 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-88405.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(generic_associated_types)] + +trait SomeTrait {} +trait OtherTrait { + type Item; +} + +trait ErrorSimpleExample { + type AssociatedType: SomeTrait; + type GatBounded; + type ErrorMinimal: OtherTrait>; +} + +fn main() {} From 024baa9c3229dfb32ce8db2f5434c4c24bd3dea6 Mon Sep 17 00:00:00 2001 From: Joshua Seaton Date: Fri, 15 Oct 2021 10:24:52 -0700 Subject: [PATCH 120/181] [fuchsia] Update process info struct The fuchsia platform is in the process of softly transitioning over to using a new value for ZX_INFO_PROCESS with a new corresponding struct. This change migrates libstd. See fxrev.dev/510478 and fxbug.dev/30751 for more detail. --- library/std/src/sys/unix/process/zircon.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/unix/process/zircon.rs b/library/std/src/sys/unix/process/zircon.rs index 58427bb8b69d9..4dfa2b4ff1eb4 100644 --- a/library/std/src/sys/unix/process/zircon.rs +++ b/library/std/src/sys/unix/process/zircon.rs @@ -25,9 +25,12 @@ pub const ZX_TASK_TERMINATED: zx_signals_t = ZX_OBJECT_SIGNAL_3; pub const ZX_RIGHT_SAME_RIGHTS: zx_rights_t = 1 << 31; +// The upper four bits gives the minor version. pub type zx_object_info_topic_t = u32; -pub const ZX_INFO_PROCESS: zx_object_info_topic_t = 3; +pub const ZX_INFO_PROCESS: zx_object_info_topic_t = 3 | (1 << 28); + +pub type zx_info_process_flags_t = u32; pub fn zx_cvt(t: T) -> io::Result where @@ -68,9 +71,9 @@ impl Drop for Handle { #[repr(C)] pub struct zx_info_process_t { pub return_code: i64, - pub started: bool, - pub exited: bool, - pub debugger_attached: bool, + pub start_time: zx_time_t, + pub flags: zx_info_process_flags_t, + pub reserved1: u32, } extern "C" { From 094a9c743efe73d715024166f41d6e5267edda43 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 23 Sep 2021 11:21:01 -0400 Subject: [PATCH 121/181] simplify constrain_opaque_types --- .../rustc_borrowck/src/region_infer/mod.rs | 10 ++ compiler/rustc_borrowck/src/type_check/mod.rs | 27 +---- .../rustc_trait_selection/src/opaque_types.rs | 106 +++-------------- compiler/rustc_typeck/src/check/regionck.rs | 2 +- .../ret-impl-trait-one.nll.stderr | 32 +++-- .../multiple-lifetimes/ret-impl-trait-one.rs | 9 +- .../ret-impl-trait-one.stderr | 41 +++++-- .../ui/impl-trait/hidden-lifetimes.nll.stderr | 29 +++++ .../ui/impl-trait/hidden-lifetimes.stderr | 2 +- ...t_outlive_least_region_or_bound.nll.stderr | 49 ++++---- .../must_outlive_least_region_or_bound.rs | 11 +- .../must_outlive_least_region_or_bound.stderr | 111 +++++++++--------- .../static-return-lifetime-infered.nll.stderr | 47 ++++++-- .../static-return-lifetime-infered.rs | 12 +- .../static-return-lifetime-infered.stderr | 106 +++++++++++++---- src/test/ui/nll/issue-73159-rpit-static.rs | 3 +- .../ui/nll/issue-73159-rpit-static.stderr | 7 +- .../ui/nll/ty-outlives/impl-trait-captures.rs | 2 +- .../ty-outlives/impl-trait-captures.stderr | 14 ++- ...s_pin_lifetime_impl_trait-async.nll.stderr | 9 +- ...elf_types_pin_lifetime_impl_trait-async.rs | 3 +- ...types_pin_lifetime_impl_trait-async.stderr | 30 +++-- ...f_types_pin_lifetime_impl_trait.nll.stderr | 9 +- ...rary_self_types_pin_lifetime_impl_trait.rs | 3 +- ..._self_types_pin_lifetime_impl_trait.stderr | 16 +-- ...-bound-needing-more-suggestions.nll.stderr | 16 +-- ...t-static-bound-needing-more-suggestions.rs | 2 +- ...atic-bound-needing-more-suggestions.stderr | 16 +-- ...ait-object-nested-in-impl-trait.nll.stderr | 26 ++-- 29 files changed, 419 insertions(+), 331 deletions(-) create mode 100644 src/test/ui/impl-trait/hidden-lifetimes.nll.stderr diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 21c26af8178ff..22bb3a29425ee 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -689,6 +689,16 @@ impl<'tcx> RegionInferenceContext<'tcx> { // them down. let mut choice_regions: Vec = choice_regions.to_vec(); + // Convert to the SCC representative: sometimes we have inference + // variables in the member constraint that wind up equated with + // universal regions. The scc representative is the minimal numbered + // one from the corresponding scc so it will be the universal region + // if one exists. + for c_r in &mut choice_regions { + let scc = self.constraint_sccs.scc(*c_r); + *c_r = self.scc_representatives[scc]; + } + // The 'member region' in a member constraint is part of the // hidden type, which must be in the root universe. Therefore, // it cannot have any placeholders in its value. diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 7bf119863fdc7..7e69e710d6868 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -36,7 +36,7 @@ use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::VariantIdx; use rustc_trait_selection::infer::InferCtxtExt as _; -use rustc_trait_selection::opaque_types::{GenerateMemberConstraints, InferCtxtExt}; +use rustc_trait_selection::opaque_types::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; use rustc_trait_selection::traits::query::type_op; use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; @@ -185,7 +185,6 @@ pub(crate) fn type_check<'mir, 'tcx>( ®ion_bound_pairs, implicit_region_bound, &mut borrowck_context, - &universal_region_relations, |mut cx| { cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output); liveness::generate(&mut cx, body, elements, flow_inits, move_data, location_table); @@ -253,15 +252,7 @@ pub(crate) fn type_check<'mir, 'tcx>( } #[instrument( - skip( - infcx, - body, - promoted, - region_bound_pairs, - borrowck_context, - universal_region_relations, - extra - ), + skip(infcx, body, promoted, region_bound_pairs, borrowck_context, extra), level = "debug" )] fn type_check_internal<'a, 'tcx, R>( @@ -272,7 +263,6 @@ fn type_check_internal<'a, 'tcx, R>( region_bound_pairs: &'a RegionBoundPairs<'tcx>, implicit_region_bound: ty::Region<'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, - universal_region_relations: &'a UniversalRegionRelations<'tcx>, extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R, ) -> R { let mut checker = TypeChecker::new( @@ -282,7 +272,6 @@ fn type_check_internal<'a, 'tcx, R>( region_bound_pairs, implicit_region_bound, borrowck_context, - universal_region_relations, ); let errors_reported = { let mut verifier = TypeVerifier::new(&mut checker, body, promoted); @@ -901,7 +890,6 @@ struct TypeChecker<'a, 'tcx> { implicit_region_bound: ty::Region<'tcx>, reported_errors: FxHashSet<(Ty<'tcx>, Span)>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, - universal_region_relations: &'a UniversalRegionRelations<'tcx>, } struct BorrowCheckContext<'a, 'tcx> { @@ -1050,7 +1038,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { region_bound_pairs: &'a RegionBoundPairs<'tcx>, implicit_region_bound: ty::Region<'tcx>, borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>, - universal_region_relations: &'a UniversalRegionRelations<'tcx>, ) -> Self { let mut checker = Self { infcx, @@ -1062,7 +1049,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { implicit_region_bound, borrowck_context, reported_errors: Default::default(), - universal_region_relations, }; checker.check_user_type_annotations(); checker @@ -1322,8 +1308,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ), )?; - let universal_region_relations = self.universal_region_relations; - // Finally, if we instantiated the anon types successfully, we // have to solve any bounds (e.g., `-> impl Iterator` needs to // prove that `T: Iterator` where `T` is the type we @@ -1335,12 +1319,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ConstraintCategory::OpaqueType, CustomTypeOp::new( |infcx| { - infcx.constrain_opaque_type( - opaque_type_key, - &opaque_decl, - GenerateMemberConstraints::IfNoStaticBound, - universal_region_relations, - ); + infcx.constrain_opaque_type(opaque_type_key, &opaque_decl); Ok(InferOk { value: (), obligations: vec![] }) }, || "opaque_type_map".to_string(), diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index c2205462680fc..db217cc61378b 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -4,7 +4,6 @@ use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic; -use rustc_infer::infer::free_regions::FreeRegionRelations; use rustc_infer::infer::opaque_types::OpaqueTypeDecl; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{self, InferCtxt, InferOk}; @@ -37,14 +36,12 @@ pub trait InferCtxtExt<'tcx> { value_span: Span, ) -> InferOk<'tcx, T>; - fn constrain_opaque_types>(&self, free_region_relations: &FRR); + fn constrain_opaque_types(&self); - fn constrain_opaque_type>( + fn constrain_opaque_type( &self, opaque_type_key: OpaqueTypeKey<'tcx>, opaque_defn: &OpaqueTypeDecl<'tcx>, - mode: GenerateMemberConstraints, - free_region_relations: &FRR, ); /*private*/ @@ -270,26 +267,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// - `opaque_types` -- the map produced by `instantiate_opaque_types` /// - `free_region_relations` -- something that can be used to relate /// the free regions (`'a`) that appear in the impl trait. - fn constrain_opaque_types>(&self, free_region_relations: &FRR) { + fn constrain_opaque_types(&self) { let opaque_types = self.inner.borrow().opaque_types.clone(); for (opaque_type_key, opaque_defn) in opaque_types { - self.constrain_opaque_type( - opaque_type_key, - &opaque_defn, - GenerateMemberConstraints::WhenRequired, - free_region_relations, - ); + self.constrain_opaque_type(opaque_type_key, &opaque_defn); } } /// See `constrain_opaque_types` for documentation. - #[instrument(level = "debug", skip(self, free_region_relations))] - fn constrain_opaque_type>( + #[instrument(level = "debug", skip(self))] + fn constrain_opaque_type( &self, opaque_type_key: OpaqueTypeKey<'tcx>, opaque_defn: &OpaqueTypeDecl<'tcx>, - mode: GenerateMemberConstraints, - free_region_relations: &FRR, ) { let def_id = opaque_type_key.def_id; @@ -347,6 +337,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { debug!("{:#?}", bounds); let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs); + // (A) The regions that appear in the hidden type must be equal to + // one of the regions in scope for the opaque type. + self.generate_member_constraint( + concrete_ty, + opaque_defn, + opaque_type_key, + first_own_region, + ); + + // (B) We can also generate outlives bounds that must be enforced. let required_region_bounds = required_region_bounds(tcx, opaque_type, bounds); if !required_region_bounds.is_empty() { for required_region in required_region_bounds { @@ -355,81 +355,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { op: |r| self.sub_regions(infer::CallReturn(span), required_region, r), }); } - if let GenerateMemberConstraints::IfNoStaticBound = mode { - self.generate_member_constraint( - concrete_ty, - opaque_defn, - opaque_type_key, - first_own_region, - ); - } - return; } - - // There were no `required_region_bounds`, - // so we have to search for a `least_region`. - // Go through all the regions used as arguments to the - // opaque type. These are the parameters to the opaque - // type; so in our example above, `substs` would contain - // `['a]` for the first impl trait and `'b` for the - // second. - let mut least_region = None; - - for subst_arg in &opaque_type_key.substs[first_own_region..] { - let subst_region = match subst_arg.unpack() { - GenericArgKind::Lifetime(r) => r, - GenericArgKind::Type(_) | GenericArgKind::Const(_) => continue, - }; - - // Compute the least upper bound of it with the other regions. - debug!(?least_region); - debug!(?subst_region); - match least_region { - None => least_region = Some(subst_region), - Some(lr) => { - if free_region_relations.sub_free_regions(self.tcx, lr, subst_region) { - // keep the current least region - } else if free_region_relations.sub_free_regions(self.tcx, subst_region, lr) { - // switch to `subst_region` - least_region = Some(subst_region); - } else { - // There are two regions (`lr` and - // `subst_region`) which are not relatable. We - // can't find a best choice. Therefore, - // instead of creating a single bound like - // `'r: 'a` (which is our preferred choice), - // we will create a "in bound" like `'r in - // ['a, 'b, 'c]`, where `'a..'c` are the - // regions that appear in the impl trait. - - return self.generate_member_constraint( - concrete_ty, - opaque_defn, - opaque_type_key, - first_own_region, - ); - } - } - } - } - - let least_region = least_region.unwrap_or(tcx.lifetimes.re_static); - debug!(?least_region); - - if let GenerateMemberConstraints::IfNoStaticBound = mode { - if least_region != tcx.lifetimes.re_static { - self.generate_member_constraint( - concrete_ty, - opaque_defn, - opaque_type_key, - first_own_region, - ); - } - } - concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor { - tcx, - op: |r| self.sub_regions(infer::CallReturn(span), least_region, r), - }); } /// As a fallback, we sometimes generate an "in constraint". For diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index 79443010fbb3d..85602f1159392 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -296,7 +296,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { self.visit_body(body); self.visit_region_obligations(body_id.hir_id); - self.constrain_opaque_types(self.outlives_environment.free_region_map()); + self.constrain_opaque_types(); } fn visit_region_obligations(&mut self, hir_id: hir::HirId) { diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr index b6841da1f0ba9..9b0018d8904ac 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr @@ -1,13 +1,31 @@ error: lifetime may not live long enough - --> $DIR/ret-impl-trait-one.rs:10:65 + --> $DIR/ret-impl-trait-one.rs:10:85 + | +LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | ________________________________--__--_______________________________________________^ + | | | | + | | | lifetime `'b` defined here + | | lifetime `'a` defined here +LL | | +LL | | (a, b) +LL | | } + | |_^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/ret-impl-trait-one.rs:16:65 | LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { - | -- -- ^^^^^^^^^^^^^^ opaque type requires that `'b` must outlive `'a` - | | | - | | lifetime `'b` defined here - | lifetime `'a` defined here + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | - = help: consider adding the following bound: `'b: 'a` +LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | ++++ -error: aborting due to previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs index 7e084217c2607..e2d00d8c9c4f2 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs @@ -6,9 +6,16 @@ trait Trait<'a> { } impl Trait<'_> for T { } +// Fails to recognize that both 'a and 'b are mentioned and should thus be accepted +async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + //~^ ERROR lifetime mismatch + (a, b) +} + // Only `'a` permitted in return type, not `'b`. async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { - //~^ ERROR lifetime mismatch + //~^ ERROR captures lifetime that does not appear in bounds + //~| ERROR captures lifetime that does not appear in bounds (a, b) } diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr index 8e28605721cb5..8d2a8e8f1d869 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr @@ -1,13 +1,40 @@ error[E0623]: lifetime mismatch --> $DIR/ret-impl-trait-one.rs:10:65 | +LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | ------ ^^^^^^^^^^^^^^^^^^^ + | | | + | | ...but data from `a` is held across an await point here + | | this `async fn` implicitly returns an `impl Future + 'b>` + | this parameter and the returned future are declared with different lifetimes... + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/ret-impl-trait-one.rs:16:65 + | LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { - | ------ ^^^^^^^^^^^^^^ - | | | - | | ...but data from `b` is held across an await point here - | | this `async fn` implicitly returns an `impl Future>` - | this parameter and the returned future are declared with different lifetimes... + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | ++++ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/ret-impl-trait-one.rs:16:65 + | +LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | ++++ -error: aborting due to previous error +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0623`. +Some errors have detailed explanations: E0623, E0700. +For more information about an error, try `rustc --explain E0623`. diff --git a/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr b/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr new file mode 100644 index 0000000000000..60d3409a8accf --- /dev/null +++ b/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr @@ -0,0 +1,29 @@ +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/hidden-lifetimes.rs:28:54 + | +LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { + | ++++ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/hidden-lifetimes.rs:45:70 + | +LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { + | -- ^^^^^^^^^^^^^^ + | | + | hidden type `Rc>` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound + | +LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a + 'b { + | ++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index 60d3409a8accf..bba9203870025 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | -- ^^^^^^^^^^^^^^ | | - | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here + | hidden type `&mut &'b T` captures the lifetime `'b` as defined here | help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index 812093e6e7621..479874695a7fc 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -1,31 +1,31 @@ -error: lifetime may not live long enough +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/must_outlive_least_region_or_bound.rs:3:23 | LL | fn elided(x: &i32) -> impl Copy { x } - | - ^^^^^^^^^ opaque type requires that `'1` must outlive `'static` + | ---- ^^^^^^^^^ | | - | let's call the lifetime of this reference `'1` + | hidden type `&i32` captures the anonymous lifetime defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ++++ -error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:5:32 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:6:32 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } - | -- ^^^^^^^^^ opaque type requires that `'a` must outlive `'static` + | -- ^^^^^^^^^ | | - | lifetime `'a` defined here + | hidden type `&'a i32` captures the lifetime `'a` as defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ++++ error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:7:46 + --> $DIR/must_outlive_least_region_or_bound.rs:9:46 | LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | - ^ returning this value requires that `'1` must outlive `'static` @@ -35,7 +35,7 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x } = help: consider replacing `'1` with `'static` error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:9:55 + --> $DIR/must_outlive_least_region_or_bound.rs:11:55 | LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` @@ -43,7 +43,7 @@ LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } = help: consider replacing `'a` with `'static` error[E0621]: explicit lifetime required in the type of `x` - --> $DIR/must_outlive_least_region_or_bound.rs:11:41 + --> $DIR/must_outlive_least_region_or_bound.rs:13:41 | LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | ---- ^ lifetime `'a` required @@ -51,33 +51,36 @@ LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:22:24 + --> $DIR/must_outlive_least_region_or_bound.rs:24:55 | LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'1` must outlive `'static` + | - ^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static` | | | let's call the lifetime of this reference `'1` error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:28:69 + --> $DIR/must_outlive_least_region_or_bound.rs:30:69 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` | = help: consider replacing `'a` with `'static` -error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:32:61 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:34:61 | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | -- -- lifetime `'b` defined here ^^^^^^^^^^^^^^^^ opaque type requires that `'b` must outlive `'a` - | | - | lifetime `'a` defined here + | -- ^^^^^^^^^^^^^^^^ + | | + | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures the lifetime `'b` as defined here + | +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | - = help: consider adding the following bound: `'b: 'a` +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { + | ++++ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:37:51 + --> $DIR/must_outlive_least_region_or_bound.rs:40:51 | LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | ^^^^^^^^^^^^^^^^^^^^ @@ -86,5 +89,5 @@ LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { error: aborting due to 9 previous errors -Some errors have detailed explanations: E0310, E0621. +Some errors have detailed explanations: E0310, E0621, E0700. For more information about an error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs index 51f488e45a6f3..d30e019184091 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs @@ -1,8 +1,10 @@ use std::fmt::Debug; -fn elided(x: &i32) -> impl Copy { x } //~ ERROR E0759 +fn elided(x: &i32) -> impl Copy { x } +//~^ ERROR: captures lifetime that does not appear in bounds -fn explicit<'a>(x: &'a i32) -> impl Copy { x } //~ ERROR E0759 +fn explicit<'a>(x: &'a i32) -> impl Copy { x } +//~^ ERROR: captures lifetime that does not appear in bounds fn elided2(x: &i32) -> impl Copy + 'static { x } //~ ERROR E0759 @@ -20,7 +22,7 @@ fn elided4(x: &i32) -> Box { Box::new(x) } //~ ERROR E0759 fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } //~ ERROR E0759 fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } //~ ERROR E0759 -//~^ ERROR E0759 +//~^ ERROR: captures lifetime that does not appear in bounds trait LifetimeTrait<'a> {} impl<'a> LifetimeTrait<'a> for &'a i32 {} @@ -30,7 +32,8 @@ fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } //~ ERRO // Tests that a closure type containing 'b cannot be returned from a type where // only 'a was expected. fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - //~^ ERROR lifetime mismatch + //~^ ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds move |_| println!("{}", y) } diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index 81ba89b0e05f7..b472132a12b52 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -1,41 +1,29 @@ -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:3:35 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:3:23 | LL | fn elided(x: &i32) -> impl Copy { x } - | ---- ^ ...is captured here... - | | - | this data with an anonymous lifetime `'_`... + | ^^^^^^^^^ | -note: ...and is required to live as long as `'static` here +note: hidden type `&i32` captures lifetime smaller than the function body --> $DIR/must_outlive_least_region_or_bound.rs:3:23 | LL | fn elided(x: &i32) -> impl Copy { x } | ^^^^^^^^^ -help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound - | -LL | fn elided(x: &i32) -> impl Copy + '_ { x } - | ++++ -error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:5:44 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:6:32 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } - | ------- ^ ...is captured here... - | | - | this data with lifetime `'a`... + | ^^^^^^^^^ | -note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:5:32 +note: hidden type `&i32` captures lifetime smaller than the function body + --> $DIR/must_outlive_least_region_or_bound.rs:6:32 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | ^^^^^^^^^ -help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'a` lifetime bound - | -LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } - | ++++ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:7:46 + --> $DIR/must_outlive_least_region_or_bound.rs:9:46 | LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | ---- ^ ...is captured here... @@ -43,7 +31,7 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | this data with an anonymous lifetime `'_`... | note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:7:24 + --> $DIR/must_outlive_least_region_or_bound.rs:9:24 | LL | fn elided2(x: &i32) -> impl Copy + 'static { x } | ^^^^^^^^^^^^^^^^^^^ @@ -57,7 +45,7 @@ LL | fn elided2(x: &'static i32) -> impl Copy + 'static { x } | ~~~~~~~~~~~~ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:9:55 + --> $DIR/must_outlive_least_region_or_bound.rs:11:55 | LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | ------- ^ ...is captured here... @@ -65,7 +53,7 @@ LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | this data with lifetime `'a`... | note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:9:33 + --> $DIR/must_outlive_least_region_or_bound.rs:11:33 | LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x } | ^^^^^^^^^^^^^^^^^^^ @@ -79,39 +67,31 @@ LL | fn explicit2<'a>(x: &'static i32) -> impl Copy + 'static { x } | ~~~~~~~~~~~~ error[E0621]: explicit lifetime required in the type of `x` - --> $DIR/must_outlive_least_region_or_bound.rs:11:24 + --> $DIR/must_outlive_least_region_or_bound.rs:13:24 | LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | ---- ^^^^^^^^^^^^^^ lifetime `'a` required | | | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` -error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:22:65 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:24:41 | LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ---- this data with an anonymous lifetime `'_`... ^ ...is captured here, requiring it to live as long as `'static` + | ^^^^^^^^^^ | -help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound +note: hidden type `&i32` captures lifetime smaller than the function body + --> $DIR/must_outlive_least_region_or_bound.rs:24:41 | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ++++ -help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound - | -LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) } - | ++++ +LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } + | ^^^^^^^^^^ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:22:69 + --> $DIR/must_outlive_least_region_or_bound.rs:24:65 | LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ---- this data with an anonymous lifetime `'_`... ^ ...is captured here... - | -note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:22:41 + | ---- this data with an anonymous lifetime `'_`... ^ ...is captured here, requiring it to live as long as `'static` | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ^^^^^^^^^^ help: to declare that the trait object captures data from argument `x`, you can add an explicit `'_` lifetime bound | LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } @@ -122,13 +102,13 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) | ++++ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:28:69 + --> $DIR/must_outlive_least_region_or_bound.rs:30:69 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ------- this data with lifetime `'a`... ^ ...is captured here... | note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:28:34 + --> $DIR/must_outlive_least_region_or_bound.rs:30:34 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -141,17 +121,32 @@ help: alternatively, add an explicit `'static` bound to this reference LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x } | ~~~~~~~~~~~~ -error[E0623]: lifetime mismatch - --> $DIR/must_outlive_least_region_or_bound.rs:32:61 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:34:61 | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | ------- ^^^^^^^^^^^^^^^^ - | | | - | | ...but data from `y` is returned here - | this parameter and the return type are declared with different lifetimes... + | ^^^^^^^^^^^^^^^^ + | +note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body + --> $DIR/must_outlive_least_region_or_bound.rs:34:61 + | +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { + | ^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/must_outlive_least_region_or_bound.rs:34:61 + | +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { + | ^^^^^^^^^^^^^^^^ + | +note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body + --> $DIR/must_outlive_least_region_or_bound.rs:34:61 + | +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { + | ^^^^^^^^^^^^^^^^ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:37:51 + --> $DIR/must_outlive_least_region_or_bound.rs:40:51 | LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | -- ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds @@ -159,7 +154,7 @@ LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | help: consider adding an explicit lifetime bound...: `T: 'static +` error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:14:50 + --> $DIR/must_outlive_least_region_or_bound.rs:16:50 | LL | fn elided3(x: &i32) -> Box { Box::new(x) } | ---- ^ ...is captured here, requiring it to live as long as `'static` @@ -172,7 +167,7 @@ LL | fn elided3(x: &i32) -> Box { Box::new(x) } | ++++ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:16:59 + --> $DIR/must_outlive_least_region_or_bound.rs:18:59 | LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } | ------- ^ ...is captured here, requiring it to live as long as `'static` @@ -185,7 +180,7 @@ LL | fn explicit3<'a>(x: &'a i32) -> Box { Box::new(x) } | ++++ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:18:60 + --> $DIR/must_outlive_least_region_or_bound.rs:20:60 | LL | fn elided4(x: &i32) -> Box { Box::new(x) } | ---- ^ ...is captured here, requiring it to live as long as `'static` @@ -202,7 +197,7 @@ LL | fn elided4(x: &'static i32) -> Box { Box::new(x) } | ~~~~~~~~~~~~ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:20:69 + --> $DIR/must_outlive_least_region_or_bound.rs:22:69 | LL | fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } | ------- this data with lifetime `'a`... ^ ...is captured here, requiring it to live as long as `'static` @@ -216,7 +211,7 @@ help: alternatively, add an explicit `'static` bound to this reference LL | fn explicit4<'a>(x: &'static i32) -> Box { Box::new(x) } | ~~~~~~~~~~~~ -error: aborting due to 14 previous errors +error: aborting due to 15 previous errors -Some errors have detailed explanations: E0310, E0621, E0623, E0759. +Some errors have detailed explanations: E0310, E0621, E0700, E0759. For more information about an error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr index a3aeff50eee4c..3d435bd1c3ffd 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr @@ -1,28 +1,55 @@ -error: lifetime may not live long enough +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/static-return-lifetime-infered.rs:6:35 | LL | fn iter_values_anon(&self) -> impl Iterator { - | - ^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'1` must outlive `'static` + | ----- ^^^^^^^^^^^^^^^^^^^^^^^ | | - | let's call the lifetime of this reference `'1` + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ++++ -error: lifetime may not live long enough - --> $DIR/static-return-lifetime-infered.rs:9:37 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ----- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here + | +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound + | +LL | fn iter_values_anon(&self) -> impl Iterator + '_ { + | ++++ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here + | +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { + | ++++ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | -- ^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static` + | -- ^^^^^^^^^^^^^^^^^^^^^^^ | | - | lifetime `'a` defined here + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ++++ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.rs b/src/test/ui/impl-trait/static-return-lifetime-infered.rs index 518c52f5de4d7..e204cb0f7a7ff 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.rs +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.rs @@ -4,10 +4,18 @@ struct A { impl A { fn iter_values_anon(&self) -> impl Iterator { - self.x.iter().map(|a| a.0) //~ ERROR E0759 + //~^ ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + self.x.iter().map(|a| a.0) } fn iter_values<'a>(&'a self) -> impl Iterator { - self.x.iter().map(|a| a.0) //~ ERROR E0759 + //~^ ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds + self.x.iter().map(|a| a.0) } } diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index ebd0b6a128180..33502bcf7d056 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -1,43 +1,99 @@ -error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/static-return-lifetime-infered.rs:7:16 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:6:35 | LL | fn iter_values_anon(&self) -> impl Iterator { - | ----- this data with an anonymous lifetime `'_`... -LL | self.x.iter().map(|a| a.0) - | ------ ^^^^ - | | - | ...is captured here... + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:6:35 | -note: ...and is required to live as long as `'static` here +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/static-return-lifetime-infered.rs:6:35 | LL | fn iter_values_anon(&self) -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^ -help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound | -LL | fn iter_values_anon(&self) -> impl Iterator + '_ { - | ++++ +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ -error[E0759]: `self` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/static-return-lifetime-infered.rs:10:16 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:6:35 + | +LL | fn iter_values_anon(&self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:13:37 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | -------- this data with lifetime `'a`... -LL | self.x.iter().map(|a| a.0) - | ------ ^^^^ - | | - | ...is captured here... + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 | -note: ...and is required to live as long as `'static` here - --> $DIR/static-return-lifetime-infered.rs:9:37 +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:13:37 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^ -help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 | -LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { - | ++++ +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:13:37 + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/static-return-lifetime-infered.rs:13:37 + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body + --> $DIR/static-return-lifetime-infered.rs:13:37 + | +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | ^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 8 previous errors -For more information about this error, try `rustc --explain E0759`. +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/nll/issue-73159-rpit-static.rs b/src/test/ui/nll/issue-73159-rpit-static.rs index a5455a3f9eb7b..e29ba09b3694d 100644 --- a/src/test/ui/nll/issue-73159-rpit-static.rs +++ b/src/test/ui/nll/issue-73159-rpit-static.rs @@ -6,7 +6,8 @@ struct Foo<'a>(&'a [u8]); impl<'a> Foo<'a> { - fn make_it(&self) -> impl Iterator { //~ ERROR lifetime may not live + fn make_it(&self) -> impl Iterator { + //~^ ERROR: captures lifetime that does not appear in bounds self.0.iter().copied() } } diff --git a/src/test/ui/nll/issue-73159-rpit-static.stderr b/src/test/ui/nll/issue-73159-rpit-static.stderr index 60b1552701af9..6c7cd0c825493 100644 --- a/src/test/ui/nll/issue-73159-rpit-static.stderr +++ b/src/test/ui/nll/issue-73159-rpit-static.stderr @@ -1,10 +1,11 @@ -error: lifetime may not live long enough +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/issue-73159-rpit-static.rs:9:26 | LL | impl<'a> Foo<'a> { - | -- lifetime `'a` defined here + | -- hidden type `Copied>` captures the lifetime `'a` as defined here LL | fn make_it(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static` + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.rs b/src/test/ui/nll/ty-outlives/impl-trait-captures.rs index bcdf643c0b9d1..8af23aad7261b 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.rs +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.rs @@ -8,7 +8,7 @@ trait Foo<'a> { impl<'a, T> Foo<'a> for T { } fn foo<'a, T>(x: &T) -> impl Foo<'a> { -//~^ ERROR explicit lifetime required in the type of `x` [E0621] +//~^ ERROR captures lifetime that does not appear in bounds x } diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr index d05fc793967ae..21d1eea54e6c5 100644 --- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr +++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr @@ -1,14 +1,16 @@ -error[E0621]: explicit lifetime required in the type of `x` +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/impl-trait-captures.rs:10:25 | LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> { - | ^^^^^^^^^^^^ lifetime `ReEarlyBound(0, 'a)` required + | -- ^^^^^^^^^^^^ + | | + | hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[e9f4]::foo), BrAnon(0)) T` captures the anonymous lifetime defined here | -help: add explicit lifetime `ReEarlyBound(0, 'a)` to the type of `x` +help: to declare that the `impl Trait` captures ReFree(DefId(0:8 ~ impl_trait_captures[e9f4]::foo), BrAnon(0)), you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[e9f4]::foo), BrAnon(0))` lifetime bound | -LL | fn foo<'a, T>(x: &ReEarlyBound(0, 'a) T) -> impl Foo<'a> { - | ~~~~~~~~~~~~~~~~~~~~~~ +LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[e9f4]::foo), BrAnon(0)) { + | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0621`. +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr index 5d0b2c2ebdf68..953d7cd6a0769 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr @@ -1,15 +1,16 @@ -error: lifetime may not live long enough +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37 | LL | async fn f(self: Pin<&Self>) -> impl Clone { self } - | - ^^^^^^^^^^ opaque type requires that `'1` must outlive `'static` + | - ^^^^^^^^^^ | | - | let's call the lifetime of this reference `'1` + | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ error: aborting due to previous error +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs index 43998ca8c5784..e3483e4e62abe 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs @@ -6,7 +6,8 @@ struct Foo; impl Foo { async fn f(self: Pin<&Self>) -> impl Clone { self } - //~^ ERROR E0759 + //~^ ERROR: captures lifetime that does not appear in bounds + //~| ERROR: captures lifetime that does not appear in bounds } fn main() { diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr index 04cd2b78da124..aac585ca414ca 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr @@ -1,17 +1,29 @@ -error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:16 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37 | LL | async fn f(self: Pin<&Self>) -> impl Clone { self } - | ^^^^ ---------- ---------- ...and is required to live as long as `'static` here - | | | - | | this data with an anonymous lifetime `'_`... - | ...is captured here... + | - ^^^^^^^^^^ + | | + | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here | -help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ -error: aborting due to previous error +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37 + | +LL | async fn f(self: Pin<&Self>) -> impl Clone { self } + | - ^^^^^^^^^^ + | | + | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here + | +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound + | +LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } + | ++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0759`. +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr index 4301d8f767a51..faa1233ffde63 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr @@ -1,15 +1,16 @@ -error: lifetime may not live long enough +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } - | - ^^^^^^^^^^ opaque type requires that `'1` must outlive `'static` + | ----- ^^^^^^^^^^ | | - | let's call the lifetime of this reference `'1` + | hidden type `Pin<&Foo>` captures the anonymous lifetime defined here | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ error: aborting due to previous error +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs index 04935fc52ab9e..4db2fa7dcb81e 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.rs @@ -3,7 +3,8 @@ use std::pin::Pin; struct Foo; impl Foo { - fn f(self: Pin<&Self>) -> impl Clone { self } //~ ERROR E0759 + fn f(self: Pin<&Self>) -> impl Clone { self } + //~^ ERROR: captures lifetime that does not appear in bounds } fn main() { diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index 54e75aeec3e36..7b645f51fe089 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -1,21 +1,15 @@ -error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:44 +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } - | ---------- ^^^^ ...is captured here... - | | - | this data with an anonymous lifetime `'_`... + | ^^^^^^^^^^ | -note: ...and is required to live as long as `'static` here +note: hidden type `Pin<&Foo>` captures lifetime smaller than the function body --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } | ^^^^^^^^^^ -help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound - | -LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ++++ error: aborting due to previous error -For more information about this error, try `rustc --explain E0759`. +For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.nll.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.nll.stderr index 80d3c940eb7c6..2dc300ac76f27 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.nll.stderr +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.nll.stderr @@ -1,17 +1,8 @@ -error[E0597]: `val` does not live long enough +error[E0515]: cannot return reference to function parameter `val` --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:21:9 | -LL | fn use_it<'a>(val: Box>) -> impl OtherTrait<'a> { - | -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a` LL | val.use_self() - | ^^^^^^^^^^^^^^ borrowed value does not live long enough -LL | } - | - `val` dropped here while still borrowed - | -help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` - | -LL | fn use_it<'a>(val: Box>) -> impl OtherTrait<'a> + 'a { - | ++++ + | ^^^^^^^^^^^^^^ returns a reference to data owned by the current function error[E0515]: cannot return reference to function parameter `val` --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:43:9 @@ -27,5 +18,4 @@ LL | val.use_self() error: aborting due to 3 previous errors -Some errors have detailed explanations: E0515, E0597. -For more information about an error, try `rustc --explain E0515`. +For more information about this error, try `rustc --explain E0515`. diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs index b2dc16a27e310..0045d3fcf1c7b 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs @@ -18,7 +18,7 @@ mod bav { impl Bar for i32 {} fn use_it<'a>(val: Box>) -> impl OtherTrait<'a> { - val.use_self() //~ ERROR E0597 + val.use_self() //~ ERROR cannot return reference to function parameter } } diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr index e8c3a7908f521..2961d8d7eacc9 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.stderr @@ -1,17 +1,8 @@ -error[E0597]: `val` does not live long enough +error[E0515]: cannot return reference to function parameter `val` --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:21:9 | -LL | fn use_it<'a>(val: Box>) -> impl OtherTrait<'a> { - | -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a` LL | val.use_self() - | ^^^^^^^^^^^^^^ borrowed value does not live long enough -LL | } - | - `val` dropped here while still borrowed - | -help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` - | -LL | fn use_it<'a>(val: Box>) -> impl OtherTrait<'a> + 'a { - | ++++ + | ^^^^^^^^^^^^^^ returns a reference to data owned by the current function error[E0515]: cannot return reference to function parameter `val` --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:43:9 @@ -47,5 +38,4 @@ LL | impl MyTrait for Box + '_> { error: aborting due to 4 previous errors -Some errors have detailed explanations: E0515, E0597. -For more information about an error, try `rustc --explain E0515`. +For more information about this error, try `rustc --explain E0515`. diff --git a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr index b579635ca7c08..3ed3827b97da3 100644 --- a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr @@ -1,10 +1,13 @@ error: lifetime may not live long enough - --> $DIR/trait-object-nested-in-impl-trait.rs:27:23 + --> $DIR/trait-object-nested-in-impl-trait.rs:28:9 | -LL | fn iter(&self) -> impl Iterator> { - | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'1` must outlive `'static` - | | - | let's call the lifetime of this reference `'1` +LL | fn iter(&self) -> impl Iterator> { + | - let's call the lifetime of this reference `'1` +LL | / Iter { +LL | | current: None, +LL | | remaining: self.0.iter(), +LL | | } + | |_________^ returning this value requires that `'1` must outlive `'static` | help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | @@ -34,12 +37,15 @@ LL | | } | |_________^ returning this value requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/trait-object-nested-in-impl-trait.rs:60:30 + --> $DIR/trait-object-nested-in-impl-trait.rs:61:9 | -LL | fn iter<'a>(&'a self) -> impl Iterator> { - | -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ opaque type requires that `'a` must outlive `'static` - | | - | lifetime `'a` defined here +LL | fn iter<'a>(&'a self) -> impl Iterator> { + | -- lifetime `'a` defined here +LL | / Iter { +LL | | current: None, +LL | | remaining: self.0.iter(), +LL | | } + | |_________^ returning this value requires that `'a` must outlive `'static` | help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | From 16868d90962681109664e8ea5faf43fa818ea883 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:30:01 +0000 Subject: [PATCH 122/181] Remove a now-unused struct --- compiler/rustc_trait_selection/src/opaque_types.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index db217cc61378b..0ccdcf68ee622 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -14,19 +14,6 @@ use rustc_span::Span; use std::ops::ControlFlow; -/// Whether member constraints should be generated for all opaque types -#[derive(Debug)] -pub enum GenerateMemberConstraints { - /// The default, used by typeck - WhenRequired, - /// The borrow checker needs member constraints in any case where we don't - /// have a `'static` bound. This is because the borrow checker has more - /// flexibility in the values of regions. For example, given `f<'a, 'b>` - /// the borrow checker can have an inference variable outlive `'a` and `'b`, - /// but not be equal to `'static`. - IfNoStaticBound, -} - pub trait InferCtxtExt<'tcx> { fn instantiate_opaque_types>( &self, From 5115069ccd46e8ce18d177f8181e06f1ae14bb44 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:31:32 +0000 Subject: [PATCH 123/181] Add some more instrumentation --- .../src/infer/lexical_region_resolve/mod.rs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 869fd225d5114..15f41c231e0da 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -28,13 +28,13 @@ use std::fmt; /// iteration to find region values which satisfy all constraints, /// assuming such values can be found. It returns the final values of /// all the variables as well as a set of errors that must be reported. +#[instrument(level = "debug", skip(region_rels, var_infos, data))] pub fn resolve<'tcx>( region_rels: &RegionRelations<'_, 'tcx>, var_infos: VarInfos, data: RegionConstraintData<'tcx>, mode: RegionckMode, ) -> (LexicalRegionResolutions<'tcx>, Vec>) { - debug!("RegionConstraintData: resolve_regions()"); let mut errors = vec![]; let mut resolver = LexicalResolver { region_rels, var_infos, data }; match mode { @@ -266,13 +266,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { /// /// From that list, we look for a *minimal* option `'c_min`. If we /// find one, then we can enforce that `'r: 'c_min`. + #[instrument(level = "debug", skip(self, graph, member_constraint, var_values))] fn enforce_member_constraint( &self, graph: &RegionGraph<'tcx>, member_constraint: &MemberConstraint<'tcx>, var_values: &mut LexicalRegionResolutions<'tcx>, ) -> bool { - debug!("enforce_member_constraint(member_constraint={:#?})", member_constraint); + debug!("member_constraint={:#?}", member_constraint); // The constraint is some inference variable (`vid`) which // must be equal to one of the options. @@ -311,15 +312,15 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { Some(&r) => r, None => return false, }; - debug!("enforce_member_constraint: least_choice={:?}", least_choice); + debug!(?least_choice); for &option in options { - debug!("enforce_member_constraint: option={:?}", option); + debug!(?option); if !self.sub_concrete_regions(least_choice, option) { if self.sub_concrete_regions(option, least_choice) { - debug!("enforce_member_constraint: new least choice"); + debug!("new least choice"); least_choice = option; } else { - debug!("enforce_member_constraint: no least choice"); + debug!("no least choice"); return false; } } @@ -461,6 +462,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } /// True if `a <= b`, but not defined over inference variables. + #[instrument(level = "trace", skip(self))] fn sub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> bool { let tcx = self.tcx(); let sub_free_regions = |r1, r2| self.region_rels.free_regions.sub_free_regions(tcx, r1, r2); @@ -492,6 +494,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { /// /// Neither `a` nor `b` may be an inference variable (hence the /// term "concrete regions"). + #[instrument(level = "trace", skip(self))] fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> { let r = match (a, b) { (&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => { @@ -562,13 +565,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { /// After expansion is complete, go and check upper bounds (i.e., /// cases where the region cannot grow larger than a fixed point) /// and check that they are satisfied. + #[instrument(skip(self, var_data, errors))] fn collect_errors( &self, var_data: &mut LexicalRegionResolutions<'tcx>, errors: &mut Vec>, ) { for (constraint, origin) in &self.data.constraints { - debug!("collect_errors: constraint={:?} origin={:?}", constraint, origin); + debug!(?constraint, ?origin); match *constraint { Constraint::RegSubVar(..) | Constraint::VarSubVar(..) => { // Expansion will ensure that these constraints hold. Ignore. @@ -580,7 +584,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } debug!( - "collect_errors: region error at {:?}: \ + "region error at {:?}: \ cannot verify that {:?} <= {:?}", origin, sub, sup ); @@ -606,7 +610,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // collect them later. if !self.sub_concrete_regions(a_region, b_region) { debug!( - "collect_errors: region error at {:?}: \ + "region error at {:?}: \ cannot verify that {:?}={:?} <= {:?}", origin, a_vid, a_region, b_region ); From 6f71cab3b0d5c1fb88f5850642bb036677e3484e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:32:30 +0000 Subject: [PATCH 124/181] Normalize regions before comparing them for member constraints --- .../src/infer/lexical_region_resolve/mod.rs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 15f41c231e0da..2fa69083b8da1 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -297,13 +297,23 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // Get an iterator over the *available choice* -- that is, // each choice region `c` where `lb <= c` and `c <= ub` for all the // upper bounds `ub`. - debug!("enforce_member_constraint: upper_bounds={:#?}", member_upper_bounds); - let mut options = member_constraint.choice_regions.iter().filter(|option| { - self.sub_concrete_regions(member_lower_bound, option) - && member_upper_bounds - .iter() - .all(|upper_bound| self.sub_concrete_regions(option, upper_bound.region)) - }); + debug!("upper_bounds={:#?}", member_upper_bounds); + let mut options = member_constraint + .choice_regions + .iter() + .filter_map(|option| match option { + ty::ReVar(vid) => match var_values.value(*vid) { + VarValue::ErrorValue => None, + VarValue::Value(r) => Some(r), + }, + r => Some(r), + }) + .filter(|option| { + self.sub_concrete_regions(member_lower_bound, option) + && member_upper_bounds + .iter() + .all(|upper_bound| self.sub_concrete_regions(option, upper_bound.region)) + }); // If there is more than one option, we only make a choice if // there is a single *least* choice -- i.e., some available From 07b8bbb1f6ecbdcd30f6fb0fdf9b29e169a19451 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:32:58 +0000 Subject: [PATCH 125/181] Equality of regions is not just on identity, but if both regions outlive each other --- .../src/infer/lexical_region_resolve/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 2fa69083b8da1..2f545ef66ac3d 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -637,7 +637,15 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { .choice_regions .iter() .map(|&choice_region| var_data.normalize(self.tcx(), choice_region)); - if !choice_regions.clone().any(|choice_region| member_region == choice_region) { + let fr = &self.region_rels.free_regions; + let sub = |a, b| { + fr.is_free_or_static(a) + && fr.is_free_or_static(b) + && fr.sub_free_regions(self.tcx(), a, b) + }; + if !choice_regions.clone().any(|choice_region| { + sub(member_region, choice_region) && sub(choice_region, member_region) + }) { let span = self.tcx().def_span(member_constraint.opaque_type_def_id); errors.push(RegionResolutionError::MemberConstraintFailure { span, From 3ea956b8c5ea3987b826c0b36e81bc713a15fce3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:44:32 +0000 Subject: [PATCH 126/181] Remove a now-unused trait --- .../src/type_check/free_region_relations.rs | 22 +----------------- .../rustc_infer/src/infer/free_regions.rs | 23 ------------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 70c74940d6235..f71cf09ecf630 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -1,20 +1,18 @@ use rustc_data_structures::frozen::Frozen; use rustc_data_structures::transitive_relation::TransitiveRelation; use rustc_infer::infer::canonical::QueryRegionConstraints; -use rustc_infer::infer::free_regions::FreeRegionRelations; use rustc_infer::infer::outlives; use rustc_infer::infer::region_constraints::GenericKind; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::ConstraintCategory; use rustc_middle::traits::query::OutlivesBound; -use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; +use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; use std::rc::Rc; use type_op::TypeOpOutput; use crate::{ - nll::ToRegionVid, type_check::constraint_conversion, type_check::{Locations, MirTypeckRegionConstraints}, universal_regions::UniversalRegions, @@ -383,21 +381,3 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> { } } } - -/// This trait is used by the `impl-trait` constraint code to abstract -/// over the `FreeRegionMap` from lexical regions and -/// `UniversalRegions` (from NLL)`. -impl<'tcx> FreeRegionRelations<'tcx> for UniversalRegionRelations<'tcx> { - fn sub_free_regions( - &self, - _tcx: TyCtxt<'tcx>, - shorter: ty::Region<'tcx>, - longer: ty::Region<'tcx>, - ) -> bool { - let shorter = shorter.to_region_vid(); - assert!(self.universal_regions.is_universal_region(shorter)); - let longer = longer.to_region_vid(); - assert!(self.universal_regions.is_universal_region(longer)); - self.outlives(longer, shorter) - } -} diff --git a/compiler/rustc_infer/src/infer/free_regions.rs b/compiler/rustc_infer/src/infer/free_regions.rs index 728dc2de37031..4814b65e320ab 100644 --- a/compiler/rustc_infer/src/infer/free_regions.rs +++ b/compiler/rustc_infer/src/infer/free_regions.rs @@ -66,8 +66,6 @@ impl<'tcx> FreeRegionMap<'tcx> { /// follows. If we know that `r_b: 'static`, then this function /// will return true, even though we don't know anything that /// directly relates `r_a` and `r_b`. - /// - /// Also available through the `FreeRegionRelations` trait below. pub fn sub_free_regions( &self, tcx: TyCtxt<'tcx>, @@ -131,27 +129,6 @@ impl<'tcx> FreeRegionMap<'tcx> { } } -/// The NLL region handling code represents free region relations in a -/// slightly different way; this trait allows functions to be abstract -/// over which version is in use. -pub trait FreeRegionRelations<'tcx> { - /// Tests whether `r_a <= r_b`. Both must be free regions or - /// `'static`. - fn sub_free_regions( - &self, - tcx: TyCtxt<'tcx>, - shorter: ty::Region<'tcx>, - longer: ty::Region<'tcx>, - ) -> bool; -} - -impl<'tcx> FreeRegionRelations<'tcx> for FreeRegionMap<'tcx> { - fn sub_free_regions(&self, tcx: TyCtxt<'tcx>, r_a: Region<'tcx>, r_b: Region<'tcx>) -> bool { - // invoke the "inherent method" - self.sub_free_regions(tcx, r_a, r_b) - } -} - impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> { type Lifted = FreeRegionMap<'tcx>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option> { From 38b9e6a393ee62733e7d7d98629a46ebff3f3a63 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 24 Sep 2021 17:48:06 +0000 Subject: [PATCH 127/181] Document the new logic --- compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 2f545ef66ac3d..bae6103cad53b 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -301,6 +301,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let mut options = member_constraint .choice_regions .iter() + // If any of the regions are inference vars, resolve them, as far + // as possible. .filter_map(|option| match option { ty::ReVar(vid) => match var_values.value(*vid) { VarValue::ErrorValue => None, @@ -644,6 +646,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { && fr.sub_free_regions(self.tcx(), a, b) }; if !choice_regions.clone().any(|choice_region| { + // This is really checking if the regions are equal. After member constraint + // resolution, one region must be equal, or a lifetime has been leaked into + // the hidden type, but does not appear in the corresponding impl trait. sub(member_region, choice_region) && sub(choice_region, member_region) }) { let span = self.tcx().def_span(member_constraint.opaque_type_def_id); From d3bddf3ea1b1717c8dc61056588162e4964ce3c9 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 15 Oct 2021 20:43:52 +0100 Subject: [PATCH 128/181] updating docs to reflect current situation --- library/core/src/sync/atomic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index b07752116e514..1247f33087558 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -62,7 +62,7 @@ //! some atomic operations. Maximally portable code will want to be careful //! about which atomic types are used. `AtomicUsize` and `AtomicIsize` are //! generally the most portable, but even then they're not available everywhere. -//! For reference, the `std` library requires pointer-sized atomics, although +//! For reference, the `std` library requires `AtomicBool`s and pointer-sized atomics, although //! `core` does not. //! //! Currently you'll need to use `#[cfg(target_arch)]` primarily to From 1418df5888131578eae04b39360f30df4ffe5599 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 16 Oct 2021 03:45:14 +0200 Subject: [PATCH 129/181] Adopt let_else across the compiler This performs a substitution of code following the pattern: let = if let = ... { identity } else { ... : ! }; To simplify it to: let = ... { identity } else { ... : ! }; By adopting the let_else feature. --- compiler/rustc_borrowck/src/borrow_set.rs | 4 +--- .../src/diagnostics/outlives_suggestion.rs | 4 +--- compiler/rustc_borrowck/src/lib.rs | 1 + compiler/rustc_codegen_ssa/src/back/link.rs | 5 ++--- compiler/rustc_codegen_ssa/src/lib.rs | 1 + compiler/rustc_codegen_ssa/src/mir/operand.rs | 4 +--- compiler/rustc_const_eval/src/lib.rs | 1 + .../src/transform/check_consts/qualifs.rs | 4 +--- compiler/rustc_errors/src/emitter.rs | 6 +----- compiler/rustc_errors/src/lib.rs | 1 + compiler/rustc_expand/src/expand.rs | 4 +--- compiler/rustc_expand/src/lib.rs | 1 + compiler/rustc_expand/src/mbe/transcribe.rs | 10 +++------- compiler/rustc_incremental/src/lib.rs | 1 + compiler/rustc_incremental/src/persist/fs.rs | 13 +++++-------- .../nice_region_error/static_impl_trait.rs | 4 +--- compiler/rustc_infer/src/lib.rs | 1 + compiler/rustc_metadata/src/lib.rs | 1 + compiler/rustc_metadata/src/rmeta/decoder.rs | 4 +--- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/ty/diagnostics.rs | 4 +--- compiler/rustc_middle/src/ty/layout.rs | 13 ++++--------- compiler/rustc_mir_build/src/build/expr/as_place.rs | 6 ++---- compiler/rustc_mir_build/src/build/scope.rs | 6 +----- compiler/rustc_mir_build/src/lib.rs | 1 + compiler/rustc_mir_dataflow/src/lib.rs | 1 + compiler/rustc_mir_dataflow/src/rustc_peek.rs | 8 ++------ compiler/rustc_mir_transform/src/inline.rs | 4 +--- compiler/rustc_mir_transform/src/lib.rs | 1 + compiler/rustc_mir_transform/src/lower_slice_len.rs | 4 +--- .../rustc_mir_transform/src/normalize_array_len.rs | 6 ++---- .../src/uninhabited_enum_branching.rs | 9 +++------ compiler/rustc_monomorphize/src/lib.rs | 1 + .../rustc_monomorphize/src/partitioning/default.rs | 4 +--- compiler/rustc_query_system/src/lib.rs | 1 + compiler/rustc_query_system/src/query/job.rs | 4 +--- compiler/rustc_query_system/src/query/plumbing.rs | 6 ++---- compiler/rustc_resolve/src/diagnostics.rs | 4 +--- compiler/rustc_resolve/src/lib.rs | 1 + compiler/rustc_trait_selection/src/lib.rs | 1 + .../src/traits/error_reporting/suggestions.rs | 6 ++---- .../src/traits/object_safety.rs | 4 +--- .../src/traits/on_unimplemented.rs | 4 +--- .../src/traits/select/candidate_assembly.rs | 4 +--- compiler/rustc_typeck/src/astconv/mod.rs | 4 +--- compiler/rustc_typeck/src/check/demand.rs | 4 +--- compiler/rustc_typeck/src/check/op.rs | 4 +--- compiler/rustc_typeck/src/check/pat.rs | 5 +---- compiler/rustc_typeck/src/check/place_op.rs | 4 +--- compiler/rustc_typeck/src/check/upvar.rs | 10 ++-------- compiler/rustc_typeck/src/lib.rs | 1 + 51 files changed, 69 insertions(+), 137 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index ee2ce1d3f74c3..e30d6c7fca731 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -315,9 +315,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> { // TEMP = &foo // // so extract `temp`. - let temp = if let Some(temp) = assigned_place.as_local() { - temp - } else { + let Some(temp) = assigned_place.as_local() else { span_bug!( self.body.source_info(start_location).span, "expected 2-phase borrow to assign to a local, not `{:?}`", diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index b15e55cd6675e..723b57ed970ad 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -90,9 +90,7 @@ impl OutlivesSuggestionBuilder { let mut unified_already = FxHashSet::default(); for (fr, outlived) in &self.constraints_to_add { - let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) { - fr_name - } else { + let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else { continue; }; diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index e6260157d11a7..08df87e0488b8 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -7,6 +7,7 @@ #![feature(format_args_capture)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(min_specialization)] #![feature(stmt_expr_attributes)] #![feature(trusted_step)] diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index cf1c60588978c..be50911f4e143 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -174,9 +174,8 @@ pub fn each_linked_rlib( _ => {} } } - let fmts = match fmts { - Some(f) => f, - None => return Err("could not find formats for rlibs".to_string()), + let Some(fmts) = fmts else { + return Err("could not find formats for rlibs".to_string()); }; for &cnum in crates { match fmts.get(cnum.as_usize() - 1) { diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index b759e3a7a7a33..f78196d7ec58e 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -3,6 +3,7 @@ #![feature(box_patterns)] #![feature(try_blocks)] #![feature(in_band_lifetimes)] +#![feature(let_else)] #![feature(once_cell)] #![feature(nll)] #![feature(associated_type_bounds)] diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index ce6cec67ad41e..bea55bbc87965 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -343,9 +343,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue { .unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest)) .ty; - let (llptr, llextra) = if let OperandValue::Ref(llptr, Some(llextra), _) = self { - (llptr, llextra) - } else { + let OperandValue::Ref(llptr, Some(llextra), _) = self else { bug!("store_unsized called with a sized value") }; diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 7ce40b319a1e5..f308e764e861d 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -13,6 +13,7 @@ Rust MIR: a lowered representation of Rust. #![feature(exact_size_is_empty)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(slice_ptr_get)] diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 5eb7d7a91cc76..14e97f6ea0ffd 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -122,9 +122,7 @@ impl Qualif for NeedsNonConstDrop { Ok([..]) => {} } - let drop_trait = if let Some(did) = cx.tcx.lang_items().drop_trait() { - did - } else { + let Some(drop_trait) = cx.tcx.lang_items().drop_trait() else { // there is no way to define a type that needs non-const drop // without having the lang item present. return false; diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 778d58eeadcf0..849ffa881df7d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -449,11 +449,7 @@ pub trait Emitter { span: &mut MultiSpan, children: &mut Vec, ) { - let source_map = if let Some(ref sm) = source_map { - sm - } else { - return; - }; + let Some(source_map) = source_map else { return }; debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children); self.fix_multispan_in_extern_macros(source_map, span); for child in children.iter_mut() { diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 60a48b5a2d9c1..1ccfa06ff6729 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -8,6 +8,7 @@ #![feature(if_let_guard)] #![feature(format_args_capture)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(nll)] #[macro_use] diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 1d6703077acff..2c78acfd186e2 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -447,9 +447,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let mut undetermined_invocations = Vec::new(); let (mut progress, mut force) = (false, !self.monotonic); loop { - let (invoc, ext) = if let Some(invoc) = invocations.pop() { - invoc - } else { + let Some((invoc, ext)) = invocations.pop() else { self.resolve_imports(); if undetermined_invocations.is_empty() { break; diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 6dfeb047ec94c..521ca2135c6f2 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -4,6 +4,7 @@ #![feature(format_args_capture)] #![feature(if_let_guard)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] #![feature(proc_macro_span)] diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 9ed5c8b8ffba5..4663dd80fa8bb 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -116,10 +116,8 @@ pub(super) fn transcribe<'a>( loop { // Look at the last frame on the stack. - let tree = if let Some(tree) = stack.last_mut().unwrap().next() { - // If it still has a TokenTree we have not looked at yet, use that tree. - tree - } else { + // If it still has a TokenTree we have not looked at yet, use that tree. + let Some(tree) = stack.last_mut().unwrap().next() else { // This else-case never produces a value for `tree` (it `continue`s or `return`s). // Otherwise, if we have just reached the end of a sequence and we can keep repeating, @@ -190,9 +188,7 @@ pub(super) fn transcribe<'a>( LockstepIterSize::Constraint(len, _) => { // We do this to avoid an extra clone above. We know that this is a // sequence already. - let (sp, seq) = if let mbe::TokenTree::Sequence(sp, seq) = seq { - (sp, seq) - } else { + let mbe::TokenTree::Sequence(sp, seq) = seq else { unreachable!() }; diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index f089cbcfca6e5..dd3f8c937f81a 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -2,6 +2,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(in_band_lifetimes)] +#![feature(let_else)] #![feature(nll)] #![recursion_limit = "256"] diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index 2ed0539841aa3..38cbf5314ef31 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -241,9 +241,7 @@ pub fn prepare_session_directory( // have already tried before. let source_directory = find_source_directory(&crate_dir, &source_directories_already_tried); - let source_directory = if let Some(dir) = source_directory { - dir - } else { + let Some(source_directory) = source_directory else { // There's nowhere to copy from, we're done debug!( "no source directory found. Continuing with empty session \ @@ -397,15 +395,14 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result { let item = tcx.hir().item(item_id); - let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind { - opaque - } else { + let ItemKind::OpaqueTy(opaque) = &item.kind else { return; }; diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index a4cfaddeeb96f..d0f1ff649d058 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -17,6 +17,7 @@ #![feature(box_patterns)] #![feature(extend_one)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(never_type)] #![feature(in_band_lifetimes)] #![feature(control_flow_enum)] diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 644b849a9f899..6cf0dd8b1addb 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -2,6 +2,7 @@ #![feature(crate_visibility_modifier)] #![feature(drain_filter)] #![feature(in_band_lifetimes)] +#![feature(let_else)] #![feature(nll)] #![feature(once_cell)] #![feature(proc_macro_internals)] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 89bb5797a828f..ca9daa49aa2d2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -472,9 +472,7 @@ impl<'a, 'tcx> Decodable> for Span { let len = BytePos::decode(decoder)?; let hi = lo + len; - let sess = if let Some(sess) = decoder.sess { - sess - } else { + let Some(sess) = decoder.sess else { bug!("Cannot decode Span without Session.") }; diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index e41f5add457fb..0894b80507581 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -39,6 +39,7 @@ #![feature(new_uninit)] #![feature(nll)] #![feature(once_cell)] +#![feature(let_else)] #![feature(min_specialization)] #![feature(trusted_len)] #![feature(in_band_lifetimes)] diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 092eae0fc5c23..1b32c8a66989f 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -221,9 +221,7 @@ pub fn suggest_constraining_type_param( ) -> bool { let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name); - let param = if let Some(param) = param { - param - } else { + let Some(param) = param else { return false; }; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index d0c7379c2d94d..8ec5f4c79781f 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -755,17 +755,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } // Extract the number of elements from the layout of the array field: - let len = if let Ok(TyAndLayout { + let Ok(TyAndLayout { layout: Layout { fields: FieldsShape::Array { count, .. }, .. }, .. - }) = self.layout_of(f0_ty) - { - count - } else { + }) = self.layout_of(f0_ty) else { return Err(LayoutError::Unknown(ty)); }; - (*e_ty, *len, true) + (*e_ty, *count, true) } else { // First ADT field is not an array: (f0_ty, def.non_enum_variant().fields.len() as _, false) @@ -787,9 +784,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Compute the ABI of the element type: let e_ly = self.layout_of(e_ty)?; - let e_abi = if let Abi::Scalar(scalar) = e_ly.abi { - scalar - } else { + let Abi::Scalar(e_abi) = e_ly.abi else { // This error isn't caught in typeck, e.g., if // the element type of the vector is generic. tcx.sess.fatal(&format!( diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 05995ddcc0051..c6a34ece24576 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -221,15 +221,13 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()); let closure_span = tcx.hir().span(closure_hir_id); - let (capture_index, capture) = if let Some(capture_details) = + let Some((capture_index, capture)) = find_capture_matching_projections( typeck_results, var_hir_id, closure_def_id, &from_builder.projection, - ) { - capture_details - } else { + ) else { if !enable_precise_capture(tcx, closure_span) { bug!( "No associated capture found for {:?}[{:#?}] even though \ diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index b74208edafea6..8dadbf5f02bd1 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -362,11 +362,7 @@ impl DropTree { blocks: &IndexVec>, ) { for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() { - let block = if let Some(block) = blocks[drop_idx] { - block - } else { - continue; - }; + let Some(block) = blocks[drop_idx] else { continue }; match drop_data.0.kind { DropKind::Value => { let terminator = TerminatorKind::Drop { diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 02023c48a6c98..b0f1e08562c16 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -6,6 +6,7 @@ #![feature(crate_visibility_modifier)] #![feature(bool_to_option)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(once_cell)] #![feature(min_specialization)] #![recursion_limit = "256"] diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 402391b87eaa9..2f3de52965db1 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -6,6 +6,7 @@ #![feature(exact_size_is_empty)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(min_specialization)] #![feature(once_cell)] #![feature(stmt_expr_attributes)] diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index c0bf4b659aa96..2d27d085b4893 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -290,9 +290,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> { call: PeekCall, ) { info!(?place, "peek_at"); - let local = if let Some(l) = place.as_local() { - l - } else { + let Some(local) = place.as_local() else { tcx.sess.span_err(call.span, "rustc_peek: argument was not a local"); return; }; @@ -312,9 +310,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals { call: PeekCall, ) { info!(?place, "peek_at"); - let local = if let Some(l) = place.as_local() { - l - } else { + let Some(local) = place.as_local() else { tcx.sess.span_err(call.span, "rustc_peek: argument was not a local"); return; }; diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index ee4e91ecb62b0..84a1e3fb600fd 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -673,9 +673,7 @@ impl Inliner<'tcx> { assert!(args.next().is_none()); let tuple = Place::from(tuple); - let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.kind() { - s - } else { + let ty::Tuple(tuple_tys) = tuple.ty(caller_body, tcx).ty.kind() else { bug!("Closure arguments are not passed as a tuple"); }; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 9b11c8f0b24c0..60135ef2d8571 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -4,6 +4,7 @@ #![cfg_attr(bootstrap, feature(const_panic))] #![feature(in_band_lifetimes)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(option_get_or_insert_default)] diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index a2cce9f1eda07..822a372d8ce90 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -17,9 +17,7 @@ impl<'tcx> MirPass<'tcx> for LowerSliceLenCalls { pub fn lower_slice_len_calls<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let language_items = tcx.lang_items(); - let slice_len_fn_item_def_id = if let Some(slice_len_fn_item) = language_items.slice_len_fn() { - slice_len_fn_item - } else { + let Some(slice_len_fn_item_def_id) = language_items.slice_len_fn() else { // there is no language item to compare to :) return; }; diff --git a/compiler/rustc_mir_transform/src/normalize_array_len.rs b/compiler/rustc_mir_transform/src/normalize_array_len.rs index 76f0e83c8c3d5..a04a0b5153150 100644 --- a/compiler/rustc_mir_transform/src/normalize_array_len.rs +++ b/compiler/rustc_mir_transform/src/normalize_array_len.rs @@ -208,7 +208,7 @@ fn normalize_array_len_call<'tcx>( operand, cast_ty, ) => { - let local = if let Some(local) = place.as_local() { local } else { return }; + let Some(local) = place.as_local() else { return }; match operand { Operand::Copy(place) | Operand::Move(place) => { let operand_local = @@ -255,9 +255,7 @@ fn normalize_array_len_call<'tcx>( } } Rvalue::Len(place) => { - let local = if let Some(local) = place.local_or_deref_local() { - local - } else { + let Some(local) = place.local_or_deref_local() else { return; }; if let Some(cast_statement_idx) = state.get(&local).copied() { diff --git a/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs b/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs index 5cef64d7786b3..2aa506112909d 100644 --- a/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs +++ b/compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs @@ -83,12 +83,9 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching { let bb = BasicBlock::from_usize(bb); trace!("processing block {:?}", bb); - let discriminant_ty = - if let Some(ty) = get_switched_on_type(&body.basic_blocks()[bb], tcx, body) { - ty - } else { - continue; - }; + let Some(discriminant_ty) = get_switched_on_type(&body.basic_blocks()[bb], tcx, body) else { + continue; + }; let layout = tcx.layout_of(tcx.param_env(body.source.def_id()).and(discriminant_ty)); diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 08b1d7b7fabd7..f4082153b6840 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -2,6 +2,7 @@ #![feature(bool_to_option)] #![feature(crate_visibility_modifier)] #![feature(control_flow_enum)] +#![feature(let_else)] #![feature(in_band_lifetimes)] #![recursion_limit = "256"] diff --git a/compiler/rustc_monomorphize/src/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs index 429ed53d37977..59997e9dc53cb 100644 --- a/compiler/rustc_monomorphize/src/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -451,9 +451,7 @@ fn mono_item_visibility( let is_generic = instance.substs.non_erasable_generics().next().is_some(); // Upstream `DefId` instances get different handling than local ones. - let def_id = if let Some(def_id) = def_id.as_local() { - def_id - } else { + let Some(def_id) = def_id.as_local() else { return if export_generics && is_generic { // If it is an upstream monomorphization and we export generics, we must make // it available to downstream crates. diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index bc23de069b0d9..1b992cdb0c94b 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -3,6 +3,7 @@ #![feature(core_intrinsics)] #![feature(hash_raw_entry)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(min_specialization)] #![feature(thread_local_const_init)] diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 98b2a450b19df..bd67303099220 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -644,9 +644,7 @@ pub fn print_query_stack( if Some(i) == num_frames { break; } - let query_info = if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) { - info - } else { + let Some(query_info) = query_map.as_ref().and_then(|map| map.get(&query)) else { break; }; let mut diag = Diagnostic::new( diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 07d7205997596..d3c75635783fa 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -761,11 +761,9 @@ where return false; } - let key = if let Some(key) = + let Some(key) = >::recover(*tcx.dep_context(), &dep_node) - { - key - } else { + else { return false; }; diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index e3970038a33b0..ad4231094d331 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1471,9 +1471,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { module: ModuleOrUniformRoot<'b>, ident: Ident, ) -> Option<(Option, Vec)> { - let mut crate_module = if let ModuleOrUniformRoot::Module(module) = module { - module - } else { + let ModuleOrUniformRoot::Module(mut crate_module) = module else { return None; }; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 9652c483686f0..168191032e93a 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -15,6 +15,7 @@ #![feature(crate_visibility_modifier)] #![feature(format_args_capture)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(never_type)] #![feature(nll)] #![recursion_limit = "256"] diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index 017a7c45bbf9d..1a049e6ec649d 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -17,6 +17,7 @@ #![feature(hash_drain_filter)] #![feature(in_band_lifetimes)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(never_type)] #![feature(crate_visibility_modifier)] #![feature(control_flow_enum)] diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 1a8f863952e6a..970fb30487963 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1038,13 +1038,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let hir = self.tcx.hir(); let parent_node = hir.get_parent_node(obligation.cause.body_id); let node = hir.find(parent_node); - let (sig, body_id) = if let Some(hir::Node::Item(hir::Item { + let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node - { - (sig, body_id) - } else { + else { return false; }; let body = hir.body(*body_id); diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 0bb00dfeb43ad..ad9fd0ca62cfa 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -647,9 +647,7 @@ fn receiver_is_dispatchable<'tcx>( debug!("receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}", method, receiver_ty); let traits = (tcx.lang_items().unsize_trait(), tcx.lang_items().dispatch_from_dyn_trait()); - let (unsize_did, dispatch_from_dyn_did) = if let (Some(u), Some(cu)) = traits { - (u, cu) - } else { + let (Some(unsize_did), Some(dispatch_from_dyn_did)) = traits else { debug!("receiver_is_dispatchable: Missing Unsize or DispatchFromDyn traits"); return false; }; diff --git a/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs index 209fd83b3ab34..85ca4db7d747d 100644 --- a/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/on_unimplemented.rs @@ -164,9 +164,7 @@ impl<'tcx> OnUnimplementedDirective { ) -> Result, ErrorReported> { let attrs = tcx.get_attrs(impl_def_id); - let attr = if let Some(item) = tcx.sess.find_by_name(&attrs, sym::rustc_on_unimplemented) { - item - } else { + let Some(attr) = tcx.sess.find_by_name(&attrs, sym::rustc_on_unimplemented) else { return Ok(None); }; diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 856ea43b1ff4e..74e132097cc55 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -716,9 +716,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { cause.clone(), ); - let data = if let ty::Dynamic(ref data, ..) = normalized_ty.kind() { - data - } else { + let ty::Dynamic(data, ..) = normalized_ty.kind() else { return None; }; diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 889b68773c27b..da751f2075399 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1916,9 +1916,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!("qpath_to_ty: trait_def_id={:?}", trait_def_id); - let self_ty = if let Some(ty) = opt_self_ty { - ty - } else { + let Some(self_ty) = opt_self_ty else { let path_str = tcx.def_path_str(trait_def_id); let def_id = self.item_def_id(); diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 540365956a8fb..2b3672211e4f5 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -743,9 +743,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return false; } - let src = if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) { - src - } else { + let Ok(src) = self.tcx.sess.source_map().span_to_snippet(expr.span) else { return false; }; diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 79e004a47db53..ec4b32b43a98c 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -502,9 +502,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // FIXME: Instead of exiting early when encountering bound vars in // the function signature, consider keeping the binder here and // propagating it downwards. - let fn_sig = if let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() { - fn_sig - } else { + let Some(fn_sig) = self.tcx.fn_sig(def_id).no_bound_vars() else { return false; }; diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 635219146d0f5..5aa11cce25fb6 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -718,10 +718,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ti: TopInfo<'tcx>, ) -> Ty<'tcx> { // Resolve the path and check the definition for errors. - let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.hir_id) - { - variant_ty - } else { + let Some((variant, pat_ty)) = self.check_struct_path(qpath, pat.hir_id) else { let err = self.tcx.ty_error(); for field in fields { let ti = TopInfo { parent_pat: Some(pat), ..ti }; diff --git a/compiler/rustc_typeck/src/check/place_op.rs b/compiler/rustc_typeck/src/check/place_op.rs index 849bf1e455cbf..5d9e6ebd50c85 100644 --- a/compiler/rustc_typeck/src/check/place_op.rs +++ b/compiler/rustc_typeck/src/check/place_op.rs @@ -411,9 +411,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("convert_place_op_to_mutable: method={:?}", method); self.write_method_call(expr.hir_id, method); - let region = if let ty::Ref(r, _, hir::Mutability::Mut) = method.sig.inputs()[0].kind() { - r - } else { + let ty::Ref(region, _, hir::Mutability::Mut) = method.sig.inputs()[0].kind() else { span_bug!(expr.span, "input to mutable place op is not a mut ref?"); }; diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 3a10988bba0b9..a5ee557452f50 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -1000,11 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return None; } - let root_var_min_capture_list = if let Some(root_var_min_capture_list) = - min_captures.and_then(|m| m.get(&var_hir_id)) - { - root_var_min_capture_list - } else { + let Some(root_var_min_capture_list) = min_captures.and_then(|m| m.get(&var_hir_id)) else { // The upvar is mentioned within the closure but no path starting from it is // used. @@ -1077,9 +1073,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { closure_clause: hir::CaptureBy, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, ) -> (Vec, String) { - let upvars = if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) { - upvars - } else { + let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) else { return (Vec::new(), format!("")); }; diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 971776c882a15..017e7ad8ca74a 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -63,6 +63,7 @@ This API is completely unstable and subject to change. #![feature(in_band_lifetimes)] #![feature(is_sorted)] #![feature(iter_zip)] +#![feature(let_else)] #![feature(min_specialization)] #![feature(nll)] #![feature(try_blocks)] From ef018be5c49d7a0bb8ad8e3485111e8b2ab9c5ac Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 16 Oct 2021 04:37:30 +0200 Subject: [PATCH 130/181] Update the syn crate and adopt let_else in three more places The syn crate has gained support for let_else syntax in version 1.0.76, see https://github.com/dtolnay/syn/pull/1057 . In the three instances that use let_else, we've sent code through an attr macro, which would create compile errors when there was no let_else support in syn. To avoid this, we ran `cargo +nightly update -p syn` for updating the syn crate. --- Cargo.lock | 8 ++++---- compiler/rustc_resolve/src/late/lifetimes.rs | 4 +--- compiler/rustc_typeck/src/check/coercion.rs | 4 +--- compiler/rustc_typeck/src/check/upvar.rs | 4 +--- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 102450188aacd..9536e6f4269bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2728,9 +2728,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70" dependencies = [ "unicode-xid", ] @@ -5090,9 +5090,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.65" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663" +checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" dependencies = [ "proc-macro2", "quote", diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index eb6f302a11da8..94563400a8b53 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1057,9 +1057,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { match param.kind { GenericParamKind::Lifetime { .. } => { let (name, reg) = Region::early(&self.tcx.hir(), &mut index, ¶m); - let def_id = if let Region::EarlyBound(_, def_id, _) = reg { - def_id - } else { + let Region::EarlyBound(_, def_id, _) = reg else { bug!(); }; // We cannot predict what lifetimes are unused in opaque type. diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index a87318ff34e6d..40f456de18332 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -521,9 +521,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let traits = (self.tcx.lang_items().unsize_trait(), self.tcx.lang_items().coerce_unsized_trait()); - let (unsize_did, coerce_unsized_did) = if let (Some(u), Some(cu)) = traits { - (u, cu) - } else { + let (Some(unsize_did), Some(coerce_unsized_did)) = traits else { debug!("missing Unsize or CoerceUnsized traits"); return Err(TypeError::Mismatch); }; diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index a5ee557452f50..caad28ff2b21f 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -1678,9 +1678,7 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> { diag_expr_id: hir::HirId, ) { let tcx = self.fcx.tcx; - let upvar_id = if let PlaceBase::Upvar(upvar_id) = place_with_id.place.base { - upvar_id - } else { + let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return; }; From 7f34cedaef6b5fe1127e0ed95887e993125e3ca6 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 16 Oct 2021 09:41:59 +0200 Subject: [PATCH 131/181] HermitCore's kernel itself doesn't support TLS HermitCore's kernel itself doesn't support TLS. Consequently, the entries in x86_64-unknown-none-hermitkernel should be removed. This commit should help to finalize #89062. --- compiler/rustc_target/src/spec/hermit_kernel_base.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/hermit_kernel_base.rs b/compiler/rustc_target/src/spec/hermit_kernel_base.rs index c55a46e69a833..414b0f7ff230c 100644 --- a/compiler/rustc_target/src/spec/hermit_kernel_base.rs +++ b/compiler/rustc_target/src/spec/hermit_kernel_base.rs @@ -1,4 +1,4 @@ -use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions, TlsModel}; +use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions}; pub fn opts() -> TargetOptions { let mut pre_link_args = LinkArgs::new(); @@ -13,12 +13,10 @@ pub fn opts() -> TargetOptions { disable_redzone: true, linker: Some("rust-lld".to_owned()), executables: true, - has_elf_tls: true, pre_link_args, panic_strategy: PanicStrategy::Abort, position_independent_executables: true, static_position_independent_executables: true, - tls_model: TlsModel::InitialExec, ..Default::default() } } From 2f4cbf003fdfcd9763c24f09bbe8aae829fbd060 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 16 Oct 2021 09:45:05 +0200 Subject: [PATCH 132/181] remove compiler warnings --- library/std/src/sys/hermit/net.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/hermit/net.rs b/library/std/src/sys/hermit/net.rs index 880ef678a4f7a..1a6b3bc63e6de 100644 --- a/library/std/src/sys/hermit/net.rs +++ b/library/std/src/sys/hermit/net.rs @@ -182,7 +182,7 @@ impl TcpStream { Ok(self.clone()) } - pub fn set_linger(&self, linger: Option) -> io::Result<()> { + pub fn set_linger(&self, _linger: Option) -> io::Result<()> { unsupported() } From 1df185ac02c53ff206ce75aef3ab0bcfa3e0eda4 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Oct 2021 17:30:34 +0900 Subject: [PATCH 133/181] Remove a mention to `copy_from_slice` from `clone_from_slice` doc --- library/core/src/slice/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index c0e0589d5edee..664875a8773ed 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2953,9 +2953,6 @@ impl [T] { /// /// The length of `src` must be the same as `self`. /// - /// If `T` implements `Copy`, it can be more performant to use - /// [`copy_from_slice`]. - /// /// # Panics /// /// This function will panic if the two slices have different lengths. From f001e8c519c68a2233e56ea64b4bfe8c7fedf0ea Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Oct 2021 18:30:37 +0900 Subject: [PATCH 134/181] Fix an ICE with TAITs and Future --- compiler/rustc_middle/src/ty/error.rs | 15 +++++--- .../ui/type-alias-impl-trait/issue-89686.rs | 24 +++++++++++++ .../type-alias-impl-trait/issue-89686.stderr | 34 +++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/type-alias-impl-trait/issue-89686.rs create mode 100644 src/test/ui/type-alias-impl-trait/issue-89686.stderr diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 08b4d3aecda0a..bac681bd96fb1 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -769,11 +769,16 @@ fn foo(&self) -> Self::T { String::new() } ) -> bool { let assoc = self.associated_item(proj_ty.item_def_id); if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() { - let opaque_local_def_id = def_id.expect_local(); - let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id); - let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind { - hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty, - _ => bug!("The HirId comes from a `ty::Opaque`"), + let opaque_local_def_id = def_id.as_local(); + let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { + let hir = self.hir(); + let opaque_hir_id = hir.local_def_id_to_hir_id(opaque_local_def_id); + match &hir.expect_item(opaque_hir_id).kind { + hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty, + _ => bug!("The HirId comes from a `ty::Opaque`"), + } + } else { + return false; }; let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self); diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.rs b/src/test/ui/type-alias-impl-trait/issue-89686.rs new file mode 100644 index 0000000000000..2b6ce49e7e2d7 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-89686.rs @@ -0,0 +1,24 @@ +// edition:2018 + +#![feature(type_alias_impl_trait)] + +use std::future::Future; + +type G<'a, T> = impl Future; +//~^ ERROR: type mismatch resolving `::Output == ()` +//~| ERROR: the trait bound `T: Trait` is not satisfied + +trait Trait { + type F: Future; + + fn f(&self) -> Self::F; + + fn g<'a>(&'a self) -> G<'a, Self> + where + Self: Sized, + { + async move { self.f().await } + } +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.stderr b/src/test/ui/type-alias-impl-trait/issue-89686.stderr new file mode 100644 index 0000000000000..accc84d30a7bd --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-89686.stderr @@ -0,0 +1,34 @@ +error[E0271]: type mismatch resolving `::Output == ()` + --> $DIR/issue-89686.rs:7:17 + | +LL | type G<'a, T> = impl Future; + | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type +... +LL | async move { self.f().await } + | ------------------ the found `async` block + | + ::: $SRC_DIR/core/src/future/mod.rs:LL:COL + | +LL | pub const fn from_generator(gen: T) -> impl Future + | ------------------------------- the found opaque type + | + = note: expected unit type `()` + found associated type `::Output` + = help: consider constraining the associated type `::Output` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error[E0277]: the trait bound `T: Trait` is not satisfied + --> $DIR/issue-89686.rs:7:17 + | +LL | type G<'a, T> = impl Future; + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` + | +help: consider restricting type parameter `T` + | +LL | type G<'a, T: Trait> = impl Future; + | +++++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. From d78559ac1192553c3bda717a00f2887943144719 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Sat, 16 Oct 2021 13:30:24 +0100 Subject: [PATCH 135/181] bootstrap: tweak verbosity settings Currently the verbosity settings are: - 2: RUSTC-SHIM envvars get spammed on every invocation, O(30) lines cargo is passed -v which outputs CLI invocations, O(5) lines - 3: cargo is passed -vv which outputs build script output, O(0-10) lines This commit changes it to: - 1: cargo is passed -v, O(5) lines - 2: cargo is passed -vv, O(10) lines - 3: RUSTC-SHIM envvars get spammed, O(30) lines --- src/bootstrap/bin/rustc.rs | 2 +- src/bootstrap/bootstrap.py | 2 +- src/bootstrap/builder.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index ac8bbfe102dfe..ed53a98e9a53f 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -146,7 +146,7 @@ fn main() { } let is_test = args.iter().any(|a| a == "--test"); - if verbose > 1 { + if verbose > 2 { let rust_env_vars = env::vars().filter(|(k, _)| k.starts_with("RUST") || k.starts_with("CARGO")); let prefix = if is_test { "[RUSTC-SHIM] rustc --test" } else { "[RUSTC-SHIM] rustc" }; diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 0170be967e1e3..532853cba0dd0 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -959,7 +959,7 @@ def build_bootstrap(self): self.cargo())) args = [self.cargo(), "build", "--manifest-path", os.path.join(self.rust_root, "src/bootstrap/Cargo.toml")] - for _ in range(1, self.verbose): + for _ in range(0, self.verbose): args.append("--verbose") if self.use_locked_deps: args.append("--locked") diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 6750f7a549dd6..ac1841b691334 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1483,7 +1483,7 @@ impl<'a> Builder<'a> { cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1"); } - for _ in 1..self.verbosity { + for _ in 0..self.verbosity { cargo.arg("-v"); } From 00dba3a6938fb996b5d3b7f67823fc5272b38f59 Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 17 Oct 2021 00:02:42 +0900 Subject: [PATCH 136/181] Make Option::as_mut const --- library/core/src/option.rs | 3 ++- library/core/tests/option.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 401267f5613ee..885058321589c 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -646,7 +646,8 @@ impl Option { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_mut(&mut self) -> Option<&mut T> { + #[rustc_const_unstable(feature = "const_option", issue = "67441")] + pub const fn as_mut(&mut self) -> Option<&mut T> { match *self { Some(ref mut x) => Some(x), None => None, diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index 8995f96b1238a..c9508c145258c 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -380,6 +380,14 @@ const fn option_const_mut() { let _take = option.take(); let _replace = option.replace(42); + + { + let as_mut = option.as_mut(); + match as_mut { + Some(v) => *v = 32, + None => unreachable!(), + } + } } #[test] From d1f7608699e07e345caf4188ecbf415914c3241b Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 17 Oct 2021 00:32:01 +0900 Subject: [PATCH 137/181] Add `#![cfg_attr(bootstrap, feature(const_panic))]` to `library/core/tests/lib.rs` --- library/core/tests/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 3608853dce4e0..cf669163d3ef2 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -10,6 +10,7 @@ #![feature(const_assume)] #![feature(const_cell_into_inner)] #![feature(const_maybe_uninit_assume_init)] +#![cfg_attr(bootstrap, feature(const_panic))] #![feature(const_ptr_read)] #![feature(const_ptr_write)] #![feature(const_ptr_offset)] From c645d3f3b99da97b802b1c757fcd1a3c21c84e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 16 Oct 2021 10:18:17 +0200 Subject: [PATCH 138/181] clippy::complexity changes --- compiler/rustc_expand/src/config.rs | 2 +- compiler/rustc_middle/src/mir/interpret/allocation.rs | 6 +++--- compiler/rustc_resolve/src/diagnostics.rs | 2 +- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/visit_ast.rs | 8 +++----- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 38c099fa4f59c..1b123520961a6 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -171,7 +171,7 @@ fn get_features( } if let Some(allowed) = sess.opts.debugging_opts.allow_features.as_ref() { - if allowed.iter().find(|&f| name.as_str() == *f).is_none() { + if allowed.iter().all(|f| name.as_str() != *f) { struct_span_err!( span_handler, mi.span(), diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index b6358f9929448..a36c9b6ed7304 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -1004,13 +1004,13 @@ impl Allocation { /// Checks that a range of bytes is initialized. If not, returns the `InvalidUninitBytes` /// error which will report the first range of bytes which is uninitialized. fn check_init(&self, range: AllocRange) -> AllocResult { - self.is_init(range).or_else(|idx_range| { - Err(AllocError::InvalidUninitBytes(Some(UninitBytesAccess { + self.is_init(range).map_err(|idx_range| { + AllocError::InvalidUninitBytes(Some(UninitBytesAccess { access_offset: range.start, access_size: range.size, uninit_offset: idx_range.start, uninit_size: idx_range.end - idx_range.start, // `Size` subtraction - }))) + })) }) } diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index e3970038a33b0..05675e086d777 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1837,7 +1837,7 @@ crate fn show_candidates( .skip(1) .all(|(_, descr, _)| descr == descr_first) { - format!("{}", descr_first) + descr_first.to_string() } else { "item".to_string() }; diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 9f2e282fce1c3..c46439b851050 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -765,7 +765,7 @@ crate fn find_testable_code( // If there are characters between the preceding line ending and // this code block, `str::lines` will return an additional line, // which we subtract here. - if nb_lines != 0 && !&doc[prev_offset..offset.start].ends_with("\n") { + if nb_lines != 0 && !&doc[prev_offset..offset.start].ends_with('\n') { nb_lines -= 1; } let line = tests.get_line() + nb_lines + 1; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 36b1a14f6c1ea..b13ab64011dc1 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -113,11 +113,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { .unwrap_or(&[]) .iter() .filter_map(|attr| { - Some( - Cfg::parse(attr.meta_item()?) - .map_err(|e| self.cx.sess().diagnostic().span_err(e.span, e.msg)) - .ok()?, - ) + Cfg::parse(attr.meta_item()?) + .map_err(|e| self.cx.sess().diagnostic().span_err(e.span, e.msg)) + .ok() }) .collect::>() }) From d4cc8774d598dd496a3dee393271c9c69a07e2fa Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 17 Oct 2021 04:51:22 +0900 Subject: [PATCH 139/181] Suggest a case insensitive match name regardless of levenshtein distance --- compiler/rustc_span/src/lev_distance.rs | 36 ++++++++----------- compiler/rustc_span/src/lev_distance/tests.rs | 10 ++---- .../hygiene/rustc-macro-transparency.stderr | 16 ++++++++- src/test/ui/issues/issue-22933-2.stderr | 5 ++- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_span/src/lev_distance.rs b/compiler/rustc_span/src/lev_distance.rs index cea7871923bc6..c10968e06d79a 100644 --- a/compiler/rustc_span/src/lev_distance.rs +++ b/compiler/rustc_span/src/lev_distance.rs @@ -58,34 +58,28 @@ pub fn find_best_match_for_name( let lookup = &lookup.as_str(); let max_dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3); - let (case_insensitive_match, levenshtein_match) = name_vec + // Priority of matches: + // 1. Exact case insensitive match + // 2. Levenshtein distance match + // 3. Sorted word match + if let Some(case_insensitive_match) = + name_vec.iter().find(|candidate| candidate.as_str().to_uppercase() == lookup.to_uppercase()) + { + return Some(*case_insensitive_match); + } + let levenshtein_match = name_vec .iter() .filter_map(|&name| { let dist = lev_distance(lookup, &name.as_str()); if dist <= max_dist { Some((name, dist)) } else { None } }) // Here we are collecting the next structure: - // (case_insensitive_match, (levenshtein_match, levenshtein_distance)) - .fold((None, None), |result, (candidate, dist)| { - ( - if candidate.as_str().to_uppercase() == lookup.to_uppercase() { - Some(candidate) - } else { - result.0 - }, - match result.1 { - None => Some((candidate, dist)), - Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }), - }, - ) + // (levenshtein_match, levenshtein_distance) + .fold(None, |result, (candidate, dist)| match result { + None => Some((candidate, dist)), + Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }), }); - // Priority of matches: - // 1. Exact case insensitive match - // 2. Levenshtein distance match - // 3. Sorted word match - if let Some(candidate) = case_insensitive_match { - Some(candidate) - } else if levenshtein_match.is_some() { + if levenshtein_match.is_some() { levenshtein_match.map(|(candidate, _)| candidate) } else { find_match_by_sorted_words(name_vec, lookup) diff --git a/compiler/rustc_span/src/lev_distance/tests.rs b/compiler/rustc_span/src/lev_distance/tests.rs index 11822e9ef9742..b32f8d32c1391 100644 --- a/compiler/rustc_span/src/lev_distance/tests.rs +++ b/compiler/rustc_span/src/lev_distance/tests.rs @@ -31,16 +31,12 @@ fn test_find_best_match_for_name() { assert_eq!(find_best_match_for_name(&input, Symbol::intern("1111111111"), None), None); - let input = vec![Symbol::intern("aAAA")]; + let input = vec![Symbol::intern("AAAA")]; assert_eq!( - find_best_match_for_name(&input, Symbol::intern("AAAA"), None), - Some(Symbol::intern("aAAA")) + find_best_match_for_name(&input, Symbol::intern("aaaa"), None), + Some(Symbol::intern("AAAA")) ); - let input = vec![Symbol::intern("AAAA")]; - // Returns None because `lev_distance > max_dist / 3` - assert_eq!(find_best_match_for_name(&input, Symbol::intern("aaaa"), None), None); - let input = vec![Symbol::intern("AAAA")]; assert_eq!( find_best_match_for_name(&input, Symbol::intern("aaaa"), Some(4)), diff --git a/src/test/ui/hygiene/rustc-macro-transparency.stderr b/src/test/ui/hygiene/rustc-macro-transparency.stderr index ef650b75b5634..e4c1c8ad293b7 100644 --- a/src/test/ui/hygiene/rustc-macro-transparency.stderr +++ b/src/test/ui/hygiene/rustc-macro-transparency.stderr @@ -2,11 +2,14 @@ error[E0425]: cannot find value `Opaque` in this scope --> $DIR/rustc-macro-transparency.rs:26:5 | LL | Opaque; - | ^^^^^^ help: a local variable with a similar name exists (notice the capitalization): `opaque` + | ^^^^^^ not found in this scope error[E0423]: expected value, found macro `semitransparent` --> $DIR/rustc-macro-transparency.rs:29:5 | +LL | struct SemiTransparent; + | ----------------------- similarly named unit struct `SemiTransparent` defined here +... LL | semitransparent; | ^^^^^^^^^^^^^^^ not a value | @@ -14,10 +17,17 @@ help: use `!` to invoke the macro | LL | semitransparent!; | + +help: a unit struct with a similar name exists + | +LL | SemiTransparent; + | ~~~~~~~~~~~~~~~ error[E0423]: expected value, found macro `opaque` --> $DIR/rustc-macro-transparency.rs:30:5 | +LL | struct Opaque; + | -------------- similarly named unit struct `Opaque` defined here +... LL | opaque; | ^^^^^^ not a value | @@ -25,6 +35,10 @@ help: use `!` to invoke the macro | LL | opaque!; | + +help: a unit struct with a similar name exists + | +LL | Opaque; + | ~~~~~~ error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-22933-2.stderr b/src/test/ui/issues/issue-22933-2.stderr index 584b05ec44d3f..0bfbf538486de 100644 --- a/src/test/ui/issues/issue-22933-2.stderr +++ b/src/test/ui/issues/issue-22933-2.stderr @@ -5,7 +5,10 @@ LL | enum Delicious { | -------------- variant or associated item `PIE` not found here ... LL | ApplePie = Delicious::Apple as isize | Delicious::PIE as isize, - | ^^^ variant or associated item not found in `Delicious` + | ^^^ + | | + | variant or associated item not found in `Delicious` + | help: there is a variant with a similar name: `Pie` error: aborting due to previous error From 7bad85e815346dfbfabab8179a941b6f4031ea91 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 15 Oct 2021 21:37:31 +0200 Subject: [PATCH 140/181] Remove FIXME since there is nothing to be fixed. The errors are deduplicated when displayed to users. They only appear multiple times in UI tests. --- src/test/rustdoc-ui/ambiguous-inherent-assoc-ty.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/rustdoc-ui/ambiguous-inherent-assoc-ty.rs b/src/test/rustdoc-ui/ambiguous-inherent-assoc-ty.rs index 3ad56aebc21c5..e58bba6405853 100644 --- a/src/test/rustdoc-ui/ambiguous-inherent-assoc-ty.rs +++ b/src/test/rustdoc-ui/ambiguous-inherent-assoc-ty.rs @@ -11,7 +11,6 @@ impl Struct { pub const AssocConst: Self::AssocTy = 42; //~^ ERROR ambiguous associated type //~| HELP use fully-qualified syntax - // FIXME: for some reason, the error is shown twice with rustdoc but only once with rustc //~| ERROR ambiguous associated type //~| HELP use fully-qualified syntax } From 2b3685a6cb286149e50d49f9da455804320b0cb9 Mon Sep 17 00:00:00 2001 From: nhamovitz <18648574+nhamovitz@users.noreply.github.com> Date: Sat, 16 Oct 2021 13:36:05 -0700 Subject: [PATCH 141/181] Correct typo --- compiler/rustc_attr/src/builtin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 8d7f2b65c5a82..719caaabbbf0a 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -802,7 +802,7 @@ impl IntType { /// Valid repr contents: any of the primitive integral type names (see /// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use /// the same discriminant size that the corresponding C enum would or C -/// structure layout, `packed` to remove padding, and `transparent` to elegate representation +/// structure layout, `packed` to remove padding, and `transparent` to delegate representation /// concerns to the only non-ZST field. pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec { use ReprAttr::*; From bf7c32a4477a76bfd18fdcd8f45a939cbed82d34 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 17 Oct 2021 07:12:22 +0900 Subject: [PATCH 142/181] Fix ICE with `let...else` and `ref mut` --- .../src/diagnostics/mutability_errors.rs | 16 ++++++++-------- src/test/ui/let-else/issue-89960.rs | 7 +++++++ src/test/ui/let-else/issue-89960.stderr | 12 ++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/let-else/issue-89960.rs create mode 100644 src/test/ui/let-else/issue-89960.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 246d2e3208cf2..d5ff4c6766f0f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -45,12 +45,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let item_msg; let reason; let mut opt_source = None; - let access_place_desc = self.describe_place(access_place.as_ref()); + let access_place_desc = self.describe_any_place(access_place.as_ref()); debug!("report_mutability_error: access_place_desc={:?}", access_place_desc); match the_place_err { PlaceRef { local, projection: [] } => { - item_msg = format!("`{}`", access_place_desc.unwrap()); + item_msg = access_place_desc; if access_place.as_local().is_some() { reason = ", as it is not declared as mutable".to_string(); } else { @@ -83,7 +83,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // If we deref an immutable ref then the suggestion here doesn't help. return; } else { - item_msg = format!("`{}`", access_place_desc.unwrap()); + item_msg = access_place_desc; if self.is_upvar_field_projection(access_place.as_ref()).is_some() { reason = ", as it is not declared as mutable".to_string(); } else { @@ -96,17 +96,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { PlaceRef { local, projection: [ProjectionElem::Deref] } if self.body.local_decls[local].is_ref_for_guard() => { - item_msg = format!("`{}`", access_place_desc.unwrap()); + item_msg = access_place_desc; reason = ", as it is immutable for the pattern guard".to_string(); } PlaceRef { local, projection: [ProjectionElem::Deref] } if self.body.local_decls[local].is_ref_to_static() => { if access_place.projection.len() == 1 { - item_msg = format!("immutable static item `{}`", access_place_desc.unwrap()); + item_msg = format!("immutable static item {}", access_place_desc); reason = String::new(); } else { - item_msg = format!("`{}`", access_place_desc.unwrap()); + item_msg = access_place_desc; let local_info = &self.body.local_decls[local].local_info; if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info { let static_name = &self.infcx.tcx.item_name(def_id); @@ -121,7 +121,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { && proj_base.is_empty() && !self.upvars.is_empty() { - item_msg = format!("`{}`", access_place_desc.unwrap()); + item_msg = access_place_desc; debug_assert!( self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr() ); @@ -147,7 +147,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { }); let pointer_type = source.describe_for_immutable_place(self.infcx.tcx); opt_source = Some(source); - if let Some(desc) = access_place_desc { + if let Some(desc) = self.describe_place(access_place.as_ref()) { item_msg = format!("`{}`", desc); reason = match error_access { AccessKind::Mutate => format!(", which is behind {}", pointer_type), diff --git a/src/test/ui/let-else/issue-89960.rs b/src/test/ui/let-else/issue-89960.rs new file mode 100644 index 0000000000000..8fd55adbfd428 --- /dev/null +++ b/src/test/ui/let-else/issue-89960.rs @@ -0,0 +1,7 @@ +#![feature(let_else)] + +fn main() { + // FIXME: more precise diagnostics + let Some(ref mut meow) = Some(()) else { return }; + //~^ ERROR: cannot borrow value as mutable, as `val` is not declared as mutable +} diff --git a/src/test/ui/let-else/issue-89960.stderr b/src/test/ui/let-else/issue-89960.stderr new file mode 100644 index 0000000000000..697f04d6d2735 --- /dev/null +++ b/src/test/ui/let-else/issue-89960.stderr @@ -0,0 +1,12 @@ +error[E0596]: cannot borrow value as mutable, as `val` is not declared as mutable + --> $DIR/issue-89960.rs:5:14 + | +LL | let Some(ref mut meow) = Some(()) else { return }; + | ---------^^^^^^^^^^^^----------------------------- + | | | + | | cannot borrow as mutable + | help: consider changing this to be mutable: `mut val` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. From 6bcf0e471b77ccecc4c7e151bcbe463414796ebd Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 17 Oct 2021 16:09:49 +0900 Subject: [PATCH 143/181] Add a regression test for #85921 --- .../generic-associated-types/issue-85921.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-85921.rs diff --git a/src/test/ui/generic-associated-types/issue-85921.rs b/src/test/ui/generic-associated-types/issue-85921.rs new file mode 100644 index 0000000000000..df59f497d7841 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-85921.rs @@ -0,0 +1,19 @@ +// check-pass + +#![feature(generic_associated_types)] + +trait Trait { + type Assoc<'a>; + + fn with_assoc(f: impl FnOnce(Self::Assoc<'_>)); +} + +impl Trait for () { + type Assoc<'a> = i32; + + fn with_assoc(f: impl FnOnce(Self::Assoc<'_>)) { + f(5i32) + } +} + +fn main() {} From ea28abee2877dcd08c14097d4c12c05da1b581bf Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 17 Oct 2021 01:18:00 +0900 Subject: [PATCH 144/181] Make Result::as_mut const --- library/core/src/result.rs | 3 ++- library/core/tests/lib.rs | 1 + library/core/tests/result.rs | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index dda827900d959..75f2c222ba834 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -729,7 +729,8 @@ impl Result { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn as_mut(&mut self) -> Result<&mut T, &mut E> { + #[rustc_const_unstable(feature = "const_result", issue = "82814")] + pub const fn as_mut(&mut self) -> Result<&mut T, &mut E> { match *self { Ok(ref mut x) => Ok(x), Err(ref mut x) => Err(x), diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index cf669163d3ef2..6958f07227afe 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -65,6 +65,7 @@ #![feature(once_cell)] #![feature(unsized_tuple_coercion)] #![feature(const_option)] +#![feature(const_result)] #![feature(integer_atomics)] #![feature(int_roundings)] #![feature(slice_group_by)] diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs index 612f083a5c178..1652c1b83de33 100644 --- a/library/core/tests/result.rs +++ b/library/core/tests/result.rs @@ -352,6 +352,29 @@ fn result_const() { assert!(!IS_ERR) } +#[test] +const fn result_const_mut() { + let mut result: Result = Ok(32); + + { + let as_mut = result.as_mut(); + match as_mut { + Ok(v) => *v = 42, + Err(_) => unreachable!(), + } + } + + let mut result_err: Result = Err(false); + + { + let as_mut = result_err.as_mut(); + match as_mut { + Ok(_) => unreachable!(), + Err(v) => *v = true, + } + } +} + #[test] fn result_opt_conversions() { #[derive(Copy, Clone, Debug, PartialEq)] From 3c1d55422a695204b70cbd23da582e3ab770a53c Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Sun, 17 Oct 2021 12:04:01 +0200 Subject: [PATCH 145/181] Some "parenthesis" and "parentheses" fixes --- compiler/rustc_ast/src/util/parser.rs | 4 +- .../rustc_ast_passes/src/ast_validation.rs | 2 +- compiler/rustc_ast_pretty/src/pprust/state.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_lint/src/unused.rs | 2 +- .../rustc_parse/src/parser/diagnostics.rs | 4 +- compiler/rustc_parse/src/parser/mod.rs | 2 +- compiler/rustc_parse/src/parser/stmt.rs | 4 +- compiler/rustc_parse/src/parser/ty.rs | 2 +- .../rustc_resolve/src/late/diagnostics.rs | 2 +- compiler/rustc_typeck/src/check/callee.rs | 4 +- compiler/rustc_typeck/src/check/op.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 2 +- .../ui/empty/empty-struct-unit-expr.stderr | 4 +- src/test/ui/error-codes/E0618.stderr | 2 +- .../let-else/let-else-bool-binop-init.stderr | 4 +- .../let-else-brace-before-else.stderr | 8 +- .../recover-for-loop-parens-around-head.rs | 2 +- ...recover-for-loop-parens-around-head.stderr | 4 +- ...67037-pat-tup-scrut-ty-diff-less-fields.rs | 2 +- src/test/ui/resolve/privacy-enum-ctor.stderr | 6 +- .../disallowed-positions.stderr | 110 +++++++++--------- .../suggest-on-bare-closure-call.stderr | 2 +- ...t-variant-form-through-alias-caught.stderr | 2 +- .../clippy_lints/src/manual_unwrap_or.rs | 2 +- src/tools/clippy/clippy_utils/src/sugg.rs | 6 +- .../clippy/tests/ui/manual_unwrap_or.fixed | 4 +- src/tools/clippy/tests/ui/manual_unwrap_or.rs | 4 +- .../clippy/tests/ui/useless_conversion.fixed | 2 +- .../clippy/tests/ui/useless_conversion.rs | 2 +- 30 files changed, 100 insertions(+), 100 deletions(-) diff --git a/compiler/rustc_ast/src/util/parser.rs b/compiler/rustc_ast/src/util/parser.rs index 078dd4bd6e602..500c97e65ef9c 100644 --- a/compiler/rustc_ast/src/util/parser.rs +++ b/compiler/rustc_ast/src/util/parser.rs @@ -357,13 +357,13 @@ impl ExprPrecedence { } } -/// In `let p = e`, operators with precedence `<=` this one requires parenthesis in `e`. +/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`. pub fn prec_let_scrutinee_needs_par() -> usize { AssocOp::LAnd.precedence() } /// Suppose we have `let _ = e` and the `order` of `e`. -/// Is the `order` such that `e` in `let _ = e` needs parenthesis when it is on the RHS? +/// Is the `order` such that `e` in `let _ = e` needs parentheses when it is on the RHS? /// /// Conversely, suppose that we have `(let _ = a) OP b` and `order` is that of `OP`. /// Can we print this as `let _ = a OP b`? diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 968e9fa3e2480..793f6504be6f7 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -113,7 +113,7 @@ impl<'a> AstValidator<'a> { if sess.opts.unstable_features.is_nightly_build() { sess.struct_span_err(expr.span, "`let` expressions are not supported here") .note("only supported directly in conditions of `if`- and `while`-expressions") - .note("as well as when nested within `&&` and parenthesis in those conditions") + .note("as well as when nested within `&&` and parentheses in those conditions") .emit(); } else { sess.struct_span_err(expr.span, "expected expression, found statement (`let`)") diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index c24882086e12d..6d0589b7ba1af 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1675,7 +1675,7 @@ impl<'a> State<'a> { self.print_expr_cond_paren(expr, Self::cond_needs_par(expr)) } - // Does `expr` need parenthesis when printed in a condition position? + // Does `expr` need parentheses when printed in a condition position? // // These cases need parens due to the parse error observed in #26461: `if return {}` // parses as the erroneous construct `if (return {})`, not `if (return) {}`. diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 9196344cb3ffd..532f158297000 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1168,7 +1168,7 @@ impl<'a> State<'a> { self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals()) } - // Does `expr` need parenthesis when printed in a condition position? + // Does `expr` need parentheses when printed in a condition position? // // These cases need parens due to the parse error observed in #26461: `if return {}` // parses as the erroneous construct `if (return {})`, not `if (return) {}`. diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 48b955e41ac69..da1edcf6fe3b4 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -670,7 +670,7 @@ declare_lint! { /// /// ### Explanation /// - /// The parenthesis are not needed, and should be removed. This is the + /// The parentheses are not needed, and should be removed. This is the /// preferred style for writing these expressions. pub(super) UNUSED_PARENS, Warn, diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 8095f386fa361..81328e09156a1 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1342,10 +1342,10 @@ impl<'a> Parser<'a> { self.struct_span_err( MultiSpan::from_spans(vec![begin_par_sp, self.prev_token.span]), - "unexpected parenthesis surrounding `for` loop head", + "unexpected parentheses surrounding `for` loop head", ) .multipart_suggestion( - "remove parenthesis in `for` loop", + "remove parentheses in `for` loop", vec![(begin_par_sp, String::new()), (self.prev_token.span, String::new())], // With e.g. `for (x) in y)` this would replace `(x) in y)` // with `x) in y)` which is syntactically invalid. diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 5c701fefd17de..e50b983ec6216 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1258,7 +1258,7 @@ impl<'a> Parser<'a> { /// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`, /// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`. /// If the following element can't be a tuple (i.e., it's a function definition), then - /// it's not a tuple struct field), and the contents within the parentheses isn't valid, + /// it's not a tuple struct field), and the contents within the parentheses aren't valid, /// so emit a proper diagnostic. // Public for rustfmt usage. pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> { diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 9ec6effeb4e03..c4569c07db476 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -328,7 +328,7 @@ impl<'a> Parser<'a> { ), ) .multipart_suggestion( - "wrap the expression in parenthesis", + "wrap the expression in parentheses", suggs, Applicability::MachineApplicable, ) @@ -349,7 +349,7 @@ impl<'a> Parser<'a> { "right curly brace `}` before `else` in a `let...else` statement not allowed", ) .multipart_suggestion( - "try wrapping the expression in parenthesis", + "try wrapping the expression in parentheses", suggs, Applicability::MachineApplicable, ) diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 98400372c36a6..c4c0c17addf10 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -430,7 +430,7 @@ impl<'a> Parser<'a> { } // Parses the `typeof(EXPR)`. - // To avoid ambiguity, the type is surrounded by parenthesis. + // To avoid ambiguity, the type is surrounded by parentheses. fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> { self.expect(&token::OpenDelim(token::Paren))?; let expr = self.parse_anon_const_expr()?; diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 7b0dd82f0e6d1..1748a9be8e13e 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1552,7 +1552,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { matches!(source, PathSource::TupleStruct(..)) || source.is_call(); if suggest_only_tuple_variants { // Suggest only tuple variants regardless of whether they have fields and do not - // suggest path with added parenthesis. + // suggest path with added parentheses. let mut suggestable_variants = variants .iter() .filter(|(.., kind)| *kind == CtorKind::Fn) diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 06c42098791ef..5d22e300774d3 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let end = callee_span.shrink_to_hi(); err.multipart_suggestion( "if you meant to create this closure and immediately call it, surround the \ - closure with parenthesis", + closure with parentheses", vec![(start, "(".to_string()), (end, ")".to_string())], Applicability::MaybeIncorrect, ); @@ -383,7 +383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { call_expr.span, &format!( "`{}` is a unit variant, you need to write it \ - without the parenthesis", + without the parentheses", path ), path.to_string(), diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 79e004a47db53..1bbdf910e420a 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { other_ty: Ty<'tcx>, op: hir::BinOp, is_assign: IsAssign, - ) -> bool /* did we suggest to call a function because of missing parenthesis? */ { + ) -> bool /* did we suggest to call a function because of missing parentheses? */ { err.span_label(span, ty.to_string()); if let FnDef(def_id, _) = *ty.kind() { let source_map = self.tcx.sess.source_map(); diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index f9d1666977134..05817e1b1d99e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -576,7 +576,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { rhs, }); continue; // If something other than a Fn ends up - // with parenthesis, leave it alone + // with parentheses, leave it alone } } diff --git a/src/test/ui/empty/empty-struct-unit-expr.stderr b/src/test/ui/empty/empty-struct-unit-expr.stderr index 1023950639a66..26bfc4355fa11 100644 --- a/src/test/ui/empty/empty-struct-unit-expr.stderr +++ b/src/test/ui/empty/empty-struct-unit-expr.stderr @@ -20,7 +20,7 @@ LL | let e4 = E::Empty4(); | | | call expression requires function | -help: `E::Empty4` is a unit variant, you need to write it without the parenthesis +help: `E::Empty4` is a unit variant, you need to write it without the parentheses | LL | let e4 = E::Empty4; | ~~~~~~~~~ @@ -41,7 +41,7 @@ LL | let xe4 = XE::XEmpty4(); | | | call expression requires function | -help: `XE::XEmpty4` is a unit variant, you need to write it without the parenthesis +help: `XE::XEmpty4` is a unit variant, you need to write it without the parentheses | LL | let xe4 = XE::XEmpty4; | ~~~~~~~~~~~ diff --git a/src/test/ui/error-codes/E0618.stderr b/src/test/ui/error-codes/E0618.stderr index 19a1a8e20ccfa..db1b3f098374e 100644 --- a/src/test/ui/error-codes/E0618.stderr +++ b/src/test/ui/error-codes/E0618.stderr @@ -9,7 +9,7 @@ LL | X::Entry(); | | | call expression requires function | -help: `X::Entry` is a unit variant, you need to write it without the parenthesis +help: `X::Entry` is a unit variant, you need to write it without the parentheses | LL | X::Entry; | ~~~~~~~~ diff --git a/src/test/ui/let-else/let-else-bool-binop-init.stderr b/src/test/ui/let-else/let-else-bool-binop-init.stderr index 6551e24cc83d0..edee657624472 100644 --- a/src/test/ui/let-else/let-else-bool-binop-init.stderr +++ b/src/test/ui/let-else/let-else-bool-binop-init.stderr @@ -4,7 +4,7 @@ error: a `&&` expression cannot be directly assigned in `let...else` LL | let true = true && false else { return }; | ^^^^^^^^^^^^^ | -help: wrap the expression in parenthesis +help: wrap the expression in parentheses | LL | let true = (true && false) else { return }; | + + @@ -15,7 +15,7 @@ error: a `||` expression cannot be directly assigned in `let...else` LL | let true = true || false else { return }; | ^^^^^^^^^^^^^ | -help: wrap the expression in parenthesis +help: wrap the expression in parentheses | LL | let true = (true || false) else { return }; | + + diff --git a/src/test/ui/let-else/let-else-brace-before-else.stderr b/src/test/ui/let-else/let-else-brace-before-else.stderr index eac029c848b20..51051bbd4d8d6 100644 --- a/src/test/ui/let-else/let-else-brace-before-else.stderr +++ b/src/test/ui/let-else/let-else-brace-before-else.stderr @@ -4,7 +4,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow LL | let Some(1) = { Some(1) } else { | ^ | -help: try wrapping the expression in parenthesis +help: try wrapping the expression in parentheses | LL | let Some(1) = ({ Some(1) }) else { | + + @@ -15,7 +15,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow LL | let Some(1) = loop { break Some(1) } else { | ^ | -help: try wrapping the expression in parenthesis +help: try wrapping the expression in parentheses | LL | let Some(1) = (loop { break Some(1) }) else { | + + @@ -26,7 +26,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow LL | let 2 = 1 + match 1 { n => n } else { | ^ | -help: try wrapping the expression in parenthesis +help: try wrapping the expression in parentheses | LL | let 2 = 1 + (match 1 { n => n }) else { | + + @@ -37,7 +37,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow LL | let Some(1) = unsafe { unsafe_fn() } else { | ^ | -help: try wrapping the expression in parenthesis +help: try wrapping the expression in parentheses | LL | let Some(1) = (unsafe { unsafe_fn() }) else { | + + diff --git a/src/test/ui/parser/recover-for-loop-parens-around-head.rs b/src/test/ui/parser/recover-for-loop-parens-around-head.rs index 8080dbc332ae7..053b428bd12cc 100644 --- a/src/test/ui/parser/recover-for-loop-parens-around-head.rs +++ b/src/test/ui/parser/recover-for-loop-parens-around-head.rs @@ -9,7 +9,7 @@ fn main() { for ( elem in vec ) { //~^ ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `in` - //~| ERROR unexpected parenthesis surrounding `for` loop head + //~| ERROR unexpected parentheses surrounding `for` loop head const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types } } diff --git a/src/test/ui/parser/recover-for-loop-parens-around-head.stderr b/src/test/ui/parser/recover-for-loop-parens-around-head.stderr index 21991348327b3..fa55970dbd129 100644 --- a/src/test/ui/parser/recover-for-loop-parens-around-head.stderr +++ b/src/test/ui/parser/recover-for-loop-parens-around-head.stderr @@ -4,13 +4,13 @@ error: expected one of `)`, `,`, `@`, or `|`, found keyword `in` LL | for ( elem in vec ) { | ^^ expected one of `)`, `,`, `@`, or `|` -error: unexpected parenthesis surrounding `for` loop head +error: unexpected parentheses surrounding `for` loop head --> $DIR/recover-for-loop-parens-around-head.rs:10:9 | LL | for ( elem in vec ) { | ^ ^ | -help: remove parenthesis in `for` loop +help: remove parentheses in `for` loop | LL - for ( elem in vec ) { LL + for elem in vec { diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs index a3023ee906de8..ae28c1403753a 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs @@ -5,7 +5,7 @@ // the tuple struct pattern, has 0 fields, but requires 1 field. // // In emitting E0023, we try to see if this is a case of e.g., `Some(a, b, c)` but where -// the scrutinee was of type `Some((a, b, c))`, and suggest that parenthesis be added. +// the scrutinee was of type `Some((a, b, c))`, and suggest that parentheses be added. // // However, we did not account for the expected type being different than the tuple pattern type. // This caused an issue when the tuple pattern type (`P`) was generic. diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index ff72b0b563ab1..06c52befd52b2 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -338,7 +338,7 @@ LL | let _ = Z::Unit(); | | | call expression requires function | -help: `Z::Unit` is a unit variant, you need to write it without the parenthesis +help: `Z::Unit` is a unit variant, you need to write it without the parentheses | LL | let _ = Z::Unit; | ~~~~~~~ @@ -372,7 +372,7 @@ LL | let _: E = m::E::Unit(); | | | call expression requires function | -help: `m::E::Unit` is a unit variant, you need to write it without the parenthesis +help: `m::E::Unit` is a unit variant, you need to write it without the parentheses | LL | let _: E = m::E::Unit; | ~~~~~~~~~~ @@ -406,7 +406,7 @@ LL | let _: E = E::Unit(); | | | call expression requires function | -help: `E::Unit` is a unit variant, you need to write it without the parenthesis +help: `E::Unit` is a unit variant, you need to write it without the parentheses | LL | let _: E = E::Unit; | ~~~~~~~ diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr index 5ec4352919ea0..513b473c4de43 100644 --- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr @@ -16,7 +16,7 @@ LL | if &let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:33:9 @@ -25,7 +25,7 @@ LL | if !let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:34:9 @@ -34,7 +34,7 @@ LL | if *let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:36:9 @@ -43,7 +43,7 @@ LL | if -let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:44:9 @@ -52,7 +52,7 @@ LL | if (let 0 = 0)? {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:48:16 @@ -61,7 +61,7 @@ LL | if true || let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:49:17 @@ -70,7 +70,7 @@ LL | if (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:50:25 @@ -79,7 +79,7 @@ LL | if true && (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:51:25 @@ -88,7 +88,7 @@ LL | if true || (true && let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:54:12 @@ -97,7 +97,7 @@ LL | if x = let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:57:15 @@ -106,7 +106,7 @@ LL | if true..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:59:11 @@ -115,7 +115,7 @@ LL | if ..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:61:9 @@ -124,7 +124,7 @@ LL | if (let 0 = 0).. {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:65:8 @@ -133,7 +133,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:69:8 @@ -142,7 +142,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:76:8 @@ -151,7 +151,7 @@ LL | if let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:84:8 @@ -160,7 +160,7 @@ LL | if let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:90:19 @@ -169,7 +169,7 @@ LL | if let true = let true = true {} | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:94:12 @@ -178,7 +178,7 @@ LL | while &let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:97:12 @@ -187,7 +187,7 @@ LL | while !let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:98:12 @@ -196,7 +196,7 @@ LL | while *let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:100:12 @@ -205,7 +205,7 @@ LL | while -let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:108:12 @@ -214,7 +214,7 @@ LL | while (let 0 = 0)? {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:112:19 @@ -223,7 +223,7 @@ LL | while true || let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:113:20 @@ -232,7 +232,7 @@ LL | while (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:114:28 @@ -241,7 +241,7 @@ LL | while true && (true || let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:115:28 @@ -250,7 +250,7 @@ LL | while true || (true && let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:118:15 @@ -259,7 +259,7 @@ LL | while x = let 0 = 0 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:121:18 @@ -268,7 +268,7 @@ LL | while true..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:123:14 @@ -277,7 +277,7 @@ LL | while ..(let 0 = 0) {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:125:12 @@ -286,7 +286,7 @@ LL | while (let 0 = 0).. {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:129:11 @@ -295,7 +295,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:133:11 @@ -304,7 +304,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:140:11 @@ -313,7 +313,7 @@ LL | while let Range { start: F, end } = F..|| true {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:148:11 @@ -322,7 +322,7 @@ LL | while let Range { start: true, end } = t..&&false {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:154:22 @@ -331,7 +331,7 @@ LL | while let true = let true = true {} | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:168:6 @@ -340,7 +340,7 @@ LL | &let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:170:6 @@ -349,7 +349,7 @@ LL | !let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:171:6 @@ -358,7 +358,7 @@ LL | *let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:173:6 @@ -367,7 +367,7 @@ LL | -let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:181:6 @@ -376,7 +376,7 @@ LL | (let 0 = 0)?; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:185:13 @@ -385,7 +385,7 @@ LL | true || let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:186:14 @@ -394,7 +394,7 @@ LL | (true || let 0 = 0); | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:187:22 @@ -403,7 +403,7 @@ LL | true && (true || let 0 = 0); | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:190:9 @@ -412,7 +412,7 @@ LL | x = let 0 = 0; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:192:12 @@ -421,7 +421,7 @@ LL | true..(let 0 = 0); | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:193:8 @@ -430,7 +430,7 @@ LL | ..(let 0 = 0); | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:194:6 @@ -439,7 +439,7 @@ LL | (let 0 = 0)..; | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:196:6 @@ -448,7 +448,7 @@ LL | (let Range { start: _, end: _ } = true..true || false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:200:6 @@ -457,7 +457,7 @@ LL | (let true = let true = true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:204:6 @@ -466,7 +466,7 @@ LL | &let 0 = 0 | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:215:17 @@ -475,7 +475,7 @@ LL | true && let 1 = 1 | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:219:17 @@ -484,7 +484,7 @@ LL | true && let 1 = 1 | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:223:17 @@ -493,7 +493,7 @@ LL | true && let 1 = 1 | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions error: `let` expressions are not supported here --> $DIR/disallowed-positions.rs:233:17 @@ -502,7 +502,7 @@ LL | true && let 1 = 1 | ^^^^^^^^^ | = note: only supported directly in conditions of `if`- and `while`-expressions - = note: as well as when nested within `&&` and parenthesis in those conditions + = note: as well as when nested within `&&` and parentheses in those conditions warning: the feature `let_chains` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/disallowed-positions.rs:20:12 diff --git a/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr b/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr index 0c91e2feed3ad..81f2e498fe5de 100644 --- a/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr +++ b/src/test/ui/suggestions/suggest-on-bare-closure-call.stderr @@ -6,7 +6,7 @@ LL | let _ = ||{}(); | | | call expression requires function | -help: if you meant to create this closure and immediately call it, surround the closure with parenthesis +help: if you meant to create this closure and immediately call it, surround the closure with parentheses | LL | let _ = (||{})(); | + + diff --git a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr index 2e12b768f7066..e918551020c31 100644 --- a/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr +++ b/src/test/ui/type-alias-enum-variants/incorrect-variant-form-through-alias-caught.stderr @@ -27,7 +27,7 @@ LL | Alias::Unit(); | | | call expression requires function | -help: `Alias::Unit` is a unit variant, you need to write it without the parenthesis +help: `Alias::Unit` is a unit variant, you need to write it without the parentheses | LL | Alias::Unit; | ~~~~~~~~~~~ diff --git a/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs index 2ae9cb4f9c132..42478e3416ece 100644 --- a/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs +++ b/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs @@ -98,7 +98,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { reindent_multiline(or_body_snippet.into(), true, Some(indent)); let suggestion = if scrutinee.span.from_expansion() { - // we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)` + // we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)` sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..") } else { diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs index 5b0efb1fd7132..01fb944cc36f6 100644 --- a/src/tools/clippy/clippy_utils/src/sugg.rs +++ b/src/tools/clippy/clippy_utils/src/sugg.rs @@ -16,10 +16,10 @@ use std::convert::TryInto; use std::fmt::Display; use std::ops::{Add, Neg, Not, Sub}; -/// A helper type to build suggestion correctly handling parenthesis. +/// A helper type to build suggestion correctly handling parentheses. #[derive(Clone, PartialEq)] pub enum Sugg<'a> { - /// An expression that never needs parenthesis such as `1337` or `[0; 42]`. + /// An expression that never needs parentheses such as `1337` or `[0; 42]`. NonParen(Cow<'a, str>), /// An expression that does not fit in other variants. MaybeParen(Cow<'a, str>), @@ -283,7 +283,7 @@ impl<'a> Sugg<'a> { } } - /// Adds parenthesis to any expression that might need them. Suitable to the + /// Adds parentheses to any expression that might need them. Suitable to the /// `self` argument of a method call /// (e.g., to build `bar.foo()` or `(1 + 2).foo()`). pub fn maybe_par(self) -> Self { diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed index 3717f962745fb..05d6c56f2aca0 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.fixed +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.fixed @@ -74,10 +74,10 @@ fn result_unwrap_or() { let a = Ok::(1); a.unwrap_or(42); - // int case, suggestion must surround Result expr with parenthesis + // int case, suggestion must surround Result expr with parentheses (Ok(1) as Result).unwrap_or(42); - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis + // method call case, suggestion must not surround Result expr `s.method()` with parentheses struct S {} impl S { fn method(self) -> Option { diff --git a/src/tools/clippy/tests/ui/manual_unwrap_or.rs b/src/tools/clippy/tests/ui/manual_unwrap_or.rs index 989adde1f5bbb..09f62c69b71de 100644 --- a/src/tools/clippy/tests/ui/manual_unwrap_or.rs +++ b/src/tools/clippy/tests/ui/manual_unwrap_or.rs @@ -95,13 +95,13 @@ fn result_unwrap_or() { Err(_) => 42, }; - // int case, suggestion must surround Result expr with parenthesis + // int case, suggestion must surround Result expr with parentheses match Ok(1) as Result { Ok(i) => i, Err(_) => 42, }; - // method call case, suggestion must not surround Result expr `s.method()` with parenthesis + // method call case, suggestion must not surround Result expr `s.method()` with parentheses struct S {} impl S { fn method(self) -> Option { diff --git a/src/tools/clippy/tests/ui/useless_conversion.fixed b/src/tools/clippy/tests/ui/useless_conversion.fixed index 76aa82068d62e..70ff08f365518 100644 --- a/src/tools/clippy/tests/ui/useless_conversion.fixed +++ b/src/tools/clippy/tests/ui/useless_conversion.fixed @@ -66,7 +66,7 @@ fn main() { let _ = vec![1, 2, 3].into_iter(); let _: String = format!("Hello {}", "world"); - // keep parenthesis around `a + b` for suggestion (see #4750) + // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = (a + b) * 3; diff --git a/src/tools/clippy/tests/ui/useless_conversion.rs b/src/tools/clippy/tests/ui/useless_conversion.rs index ccee7abb404e6..f2444a8f436bf 100644 --- a/src/tools/clippy/tests/ui/useless_conversion.rs +++ b/src/tools/clippy/tests/ui/useless_conversion.rs @@ -66,7 +66,7 @@ fn main() { let _ = vec![1, 2, 3].into_iter().into_iter(); let _: String = format!("Hello {}", "world").into(); - // keep parenthesis around `a + b` for suggestion (see #4750) + // keep parentheses around `a + b` for suggestion (see #4750) let a: i32 = 1; let b: i32 = 1; let _ = i32::from(a + b) * 3; From 52f52c4fa1d5fbd28147413e5490588279e60bef Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Sun, 17 Oct 2021 16:04:44 +0200 Subject: [PATCH 146/181] bump version to rust 1.58.0 --- src/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version b/src/version index 373aea97570a7..79f82f6b8e0ce 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -1.57.0 +1.58.0 From a6808335d49522e0fe3758753af1ea721130696a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 17 Oct 2021 23:20:30 +0300 Subject: [PATCH 147/181] rustc_span: `Ident::invalid` -> `Ident::empty` The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s. --- compiler/rustc_ast/src/attr/mod.rs | 6 +++--- compiler/rustc_ast/src/mut_visit.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_builtin_macros/src/asm.rs | 2 +- compiler/rustc_builtin_macros/src/derive.rs | 2 +- .../rustc_builtin_macros/src/deriving/generic/mod.rs | 2 +- compiler/rustc_builtin_macros/src/deriving/mod.rs | 2 +- .../rustc_builtin_macros/src/standard_library_imports.rs | 2 +- compiler/rustc_expand/src/expand.rs | 6 +++--- compiler/rustc_expand/src/mbe/quoted.rs | 2 +- compiler/rustc_expand/src/placeholders.rs | 2 +- compiler/rustc_hir/src/hir.rs | 6 +++--- compiler/rustc_middle/src/hir/map/mod.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 8 ++++---- compiler/rustc_resolve/src/diagnostics.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- .../tests/ui-internal/unnecessary_symbol_str.fixed | 4 ++-- .../clippy/tests/ui-internal/unnecessary_symbol_str.rs | 4 ++-- .../tests/ui-internal/unnecessary_symbol_str.stderr | 9 ++++----- 20 files changed, 34 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 5f17008bdc2b0..927d7c6aaf6a4 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -62,7 +62,7 @@ impl NestedMetaItem { self.meta_item().and_then(|meta_item| meta_item.ident()) } pub fn name_or_empty(&self) -> Symbol { - self.ident().unwrap_or_else(Ident::invalid).name + self.ident().unwrap_or_else(Ident::empty).name } /// Gets the string value if `self` is a `MetaItem` and the `MetaItem` is a @@ -131,7 +131,7 @@ impl Attribute { } } pub fn name_or_empty(&self) -> Symbol { - self.ident().unwrap_or_else(Ident::invalid).name + self.ident().unwrap_or_else(Ident::empty).name } pub fn value_str(&self) -> Option { @@ -166,7 +166,7 @@ impl MetaItem { if self.path.segments.len() == 1 { Some(self.path.segments[0].ident) } else { None } } pub fn name_or_empty(&self) -> Symbol { - self.ident().unwrap_or_else(Ident::invalid).name + self.ident().unwrap_or_else(Ident::empty).name } // Example: diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index ba86036577ac5..f673ab2f3efde 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1060,7 +1060,7 @@ pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { let item_vis = Visibility { kind: VisibilityKind::Public, span: span.shrink_to_lo(), tokens: None }; let item = P(Item { - ident: Ident::invalid(), + ident: Ident::empty(), attrs, id: DUMMY_NODE_ID, vis: item_vis, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 245199e375113..92b482e90ee2f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1435,7 +1435,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { trace!("registering opaque type with id {:#?}", opaque_ty_id); let opaque_ty_item = hir::Item { def_id: opaque_ty_id, - ident: Ident::invalid(), + ident: Ident::empty(), kind: opaque_ty_item_kind, vis: respan(self.lower_span(span.shrink_to_lo()), hir::VisibilityKind::Inherited), span: self.lower_span(opaque_ty_span), diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index c032364c008f3..198287f608e39 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -812,7 +812,7 @@ pub fn expand_global_asm<'cx>( Ok(args) => { if let Some(inline_asm) = expand_preparsed_asm(ecx, args) { MacEager::items(smallvec![P(ast::Item { - ident: Ident::invalid(), + ident: Ident::empty(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, kind: ast::ItemKind::GlobalAsm(inline_asm), diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs index 241c90c157125..31a35b9b7b45e 100644 --- a/compiler/rustc_builtin_macros/src/derive.rs +++ b/compiler/rustc_builtin_macros/src/derive.rs @@ -85,7 +85,7 @@ impl MultiItemModifier for Expander { fn dummy_annotatable() -> Annotatable { Annotatable::GenericParam(ast::GenericParam { id: ast::DUMMY_NODE_ID, - ident: Ident::invalid(), + ident: Ident::empty(), attrs: Default::default(), bounds: Default::default(), is_placeholder: false, diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index cd78c016caa4f..a225b328ab6a4 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -724,7 +724,7 @@ impl<'a> TraitDef<'a> { cx.item( self.span, - Ident::invalid(), + Ident::empty(), a, ast::ItemKind::Impl(Box::new(ast::ImplKind { unsafety, diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index bcf95719db56b..fa389a5111578 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -178,7 +178,7 @@ fn inject_impl_of_structural_trait( let newitem = cx.item( span, - Ident::invalid(), + Ident::empty(), attrs, ItemKind::Impl(Box::new(ImplKind { unsafety: ast::Unsafe::No, diff --git a/compiler/rustc_builtin_macros/src/standard_library_imports.rs b/compiler/rustc_builtin_macros/src/standard_library_imports.rs index e0d57267525d9..e106f6014a31d 100644 --- a/compiler/rustc_builtin_macros/src/standard_library_imports.rs +++ b/compiler/rustc_builtin_macros/src/standard_library_imports.rs @@ -77,7 +77,7 @@ pub fn inject( let use_item = cx.item( span, - Ident::invalid(), + Ident::empty(), vec![cx.attribute(cx.meta_word(span, sym::prelude_import))], ast::ItemKind::Use(ast::UseTree { prefix: cx.path(span, import_path), diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index f548e2848a771..65f0719ba99c2 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -383,7 +383,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { Unsafe::No, ModKind::Loaded(krate.items, Inline::Yes, krate.span) ), - ident: Ident::invalid(), + ident: Ident::empty(), id: ast::DUMMY_NODE_ID, vis: ast::Visibility { span: krate.span.shrink_to_lo(), @@ -1426,7 +1426,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { _ => unreachable!(), }) } - ast::ItemKind::Mod(_, ref mut mod_kind) if ident != Ident::invalid() => { + ast::ItemKind::Mod(_, ref mut mod_kind) if ident != Ident::empty() => { let (file_path, dir_path, dir_ownership) = match mod_kind { ModKind::Loaded(_, inline, _) => { // Inline `mod foo { ... }`, but we still need to push directories. @@ -1508,7 +1508,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { _ => { item.attrs = attrs; // The crate root is special - don't assign an ID to it. - if !(matches!(item.kind, ast::ItemKind::Mod(..)) && ident == Ident::invalid()) { + if !(matches!(item.kind, ast::ItemKind::Mod(..)) && ident == Ident::empty()) { assign_id!(self, &mut item.id, || noop_flat_map_item(item, self)) } else { noop_flat_map_item(item, self) diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index 363cc72b52c3e..dedc6c618b9a4 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -204,7 +204,7 @@ fn parse_tree( pprust::token_to_string(&token), ); sess.span_diagnostic.span_err(token.span, &msg); - TokenTree::MetaVar(token.span, Ident::invalid()) + TokenTree::MetaVar(token.span, Ident::empty()) } // There are no more tokens. Just return the `$` we already have. diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 8e78fcbb8dbc1..12b6bc7bbe768 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -23,7 +23,7 @@ pub fn placeholder( } } - let ident = Ident::invalid(); + let ident = Ident::empty(); let attrs = Vec::new(); let vis = vis.unwrap_or(ast::Visibility { span: DUMMY_SP, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 11d0178e93ba4..f0ee21645f3c1 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -121,7 +121,7 @@ impl LifetimeName { match *self { LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Implicit - | LifetimeName::Error => Ident::invalid(), + | LifetimeName::Error => Ident::empty(), LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime), LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime), LifetimeName::Param(param_name) => param_name.ident(), @@ -233,7 +233,7 @@ impl<'hir> PathSegment<'hir> { } pub fn invalid() -> Self { - Self::from_ident(Ident::invalid()) + Self::from_ident(Ident::empty()) } pub fn args(&self) -> &GenericArgs<'hir> { @@ -310,7 +310,7 @@ impl GenericArg<'_> { } pub fn is_synthetic(&self) -> bool { - matches!(self, GenericArg::Lifetime(lifetime) if lifetime.name.ident() == Ident::invalid()) + matches!(self, GenericArg::Lifetime(lifetime) if lifetime.name.ident() == Ident::empty()) } pub fn descr(&self) -> &'static str { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index e6f56b0be9303..c30ab4c957a19 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -443,7 +443,7 @@ impl<'hir> Map<'hir> { pub fn body_param_names(&self, id: BodyId) -> impl Iterator + 'hir { self.body(id).params.iter().map(|arg| match arg.pat.kind { PatKind::Binding(_, _, ident, _) => ident, - _ => Ident::new(kw::Empty, rustc_span::DUMMY_SP), + _ => Ident::empty(), }) } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 624390a406ff2..1d9c3a4f3cf2b 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -216,7 +216,7 @@ impl<'a> Parser<'a> { return Err(e); } - (Ident::invalid(), ItemKind::Use(tree)) + (Ident::empty(), ItemKind::Use(tree)) } else if self.check_fn_front_matter(def_final) { // FUNCTION ITEM let (ident, sig, generics, body) = self.parse_fn(attrs, req_name, lo)?; @@ -287,7 +287,7 @@ impl<'a> Parser<'a> { return Ok(None); } else if macros_allowed && self.check_path() { // MACRO INVOCATION ITEM - (Ident::invalid(), ItemKind::MacCall(self.parse_item_macro(vis)?)) + (Ident::empty(), ItemKind::MacCall(self.parse_item_macro(vis)?)) } else { return Ok(None); }; @@ -586,7 +586,7 @@ impl<'a> Parser<'a> { } }; - Ok((Ident::invalid(), item_kind)) + Ok((Ident::empty(), item_kind)) } fn parse_item_list( @@ -933,7 +933,7 @@ impl<'a> Parser<'a> { let abi = self.parse_abi(); // ABI? let items = self.parse_item_list(attrs, |p| p.parse_foreign_item(ForceCollect::No))?; let module = ast::ForeignMod { unsafety, abi, items }; - Ok((Ident::invalid(), ItemKind::ForeignMod(module))) + Ok((Ident::empty(), ItemKind::ForeignMod(module))) } /// Parses a foreign item (one in an `extern { ... }` block). diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 05675e086d777..38fb1c760bd4e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1327,7 +1327,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { if fst.ident.span.rust_2018() && !fst.ident.is_path_segment_keyword() => { // Insert a placeholder that's later replaced by `self`/`super`/etc. - path.insert(0, Segment::from_ident(Ident::invalid())); + path.insert(0, Segment::from_ident(Ident::empty())); } _ => return None, } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 515b2c3fd2790..936ab81914a99 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -978,7 +978,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { // HACK(eddyb) `lint_if_path_starts_with_module` needs at least // 2 segments, so the `resolve_path` above won't trigger it. let mut full_path = import.module_path.clone(); - full_path.push(Segment::from_ident(Ident::invalid())); + full_path.push(Segment::from_ident(Ident::empty())); self.r.lint_if_path_starts_with_module( import.crate_lint(), &full_path, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index fddb225345f49..ae148624a9068 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1453,7 +1453,7 @@ impl Ident { } #[inline] - pub fn invalid() -> Ident { + pub fn empty() -> Ident { Ident::with_dummy_span(kw::Empty) } diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed index 2ec0efe4c10a5..95b8c6dfe89ee 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.fixed @@ -11,6 +11,6 @@ fn main() { Symbol::intern("foo") == rustc_span::sym::clippy; Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower; Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper; - Ident::invalid().name == rustc_span::sym::clippy; - rustc_span::sym::clippy == Ident::invalid().name; + Ident::empty().name == rustc_span::sym::clippy; + rustc_span::sym::clippy == Ident::empty().name; } diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs index 87e1b3a2ee76a..ad6937cf60a65 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.rs @@ -11,6 +11,6 @@ fn main() { Symbol::intern("foo").as_str() == "clippy"; Symbol::intern("foo").to_string() == "self"; Symbol::intern("foo").to_ident_string() != "Self"; - &*Ident::invalid().as_str() == "clippy"; - "clippy" == Ident::invalid().to_string(); + &*Ident::empty().as_str() == "clippy"; + "clippy" == Ident::empty().to_string(); } diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr index b1284b7c8ffd0..8e04d447fbcaa 100644 --- a/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr +++ b/src/tools/clippy/tests/ui-internal/unnecessary_symbol_str.stderr @@ -26,14 +26,13 @@ LL | Symbol::intern("foo").to_ident_string() != "Self"; error: unnecessary `Symbol` to string conversion --> $DIR/unnecessary_symbol_str.rs:14:5 | -LL | &*Ident::invalid().as_str() == "clippy"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::invalid().name == rustc_span::sym::clippy` +LL | &*Ident::empty().as_str() == "clippy"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy` error: unnecessary `Symbol` to string conversion --> $DIR/unnecessary_symbol_str.rs:15:5 | -LL | "clippy" == Ident::invalid().to_string(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::invalid().name` +LL | "clippy" == Ident::empty().to_string(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name` error: aborting due to 5 previous errors - From 856541963ce95ef4f7d4a81784bb5002ccf63c93 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 17 Oct 2021 07:02:52 +0200 Subject: [PATCH 148/181] Nicer error message if the user attempts to do let...else if --- compiler/rustc_parse/src/parser/stmt.rs | 21 ++++++++++++++++----- src/test/ui/let-else/let-else-if.rs | 10 ++++++++++ src/test/ui/let-else/let-else-if.stderr | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/let-else/let-else-if.rs create mode 100644 src/test/ui/let-else/let-else-if.stderr diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 9ec6effeb4e03..356f4aa6d5f4e 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -16,7 +16,7 @@ use rustc_ast::{ }; use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt}; use rustc_ast::{StmtKind, DUMMY_NODE_ID}; -use rustc_errors::{Applicability, PResult}; +use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym}; @@ -300,6 +300,12 @@ impl<'a> Parser<'a> { None => LocalKind::Decl, Some(init) => { if self.eat_keyword(kw::Else) { + if self.token.is_keyword(kw::If) { + // `let...else if`. Emit the same error that `parse_block()` would, + // but explicitly point out that this pattern is not allowed. + let msg = "conditional `else if` is not supported for `let...else`"; + return Err(self.error_block_no_opening_brace_msg(msg)); + } let els = self.parse_block()?; self.check_let_else_init_bool_expr(&init); self.check_let_else_init_trailing_brace(&init); @@ -392,10 +398,9 @@ impl<'a> Parser<'a> { Ok(block) } - fn error_block_no_opening_brace(&mut self) -> PResult<'a, T> { + fn error_block_no_opening_brace_msg(&mut self, msg: &str) -> DiagnosticBuilder<'a> { let sp = self.token.span; - let tok = super::token_descr(&self.token); - let mut e = self.struct_span_err(sp, &format!("expected `{{`, found {}", tok)); + let mut e = self.struct_span_err(sp, msg); let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon; // Check to see if the user has written something like @@ -435,7 +440,13 @@ impl<'a> Parser<'a> { _ => {} } e.span_label(sp, "expected `{`"); - Err(e) + e + } + + fn error_block_no_opening_brace(&mut self) -> PResult<'a, T> { + let tok = super::token_descr(&self.token); + let msg = format!("expected `{{`, found {}", tok); + Err(self.error_block_no_opening_brace_msg(&msg)) } /// Parses a block. Inner attributes are allowed. diff --git a/src/test/ui/let-else/let-else-if.rs b/src/test/ui/let-else/let-else-if.rs new file mode 100644 index 0000000000000..c3a17330d6e2f --- /dev/null +++ b/src/test/ui/let-else/let-else-if.rs @@ -0,0 +1,10 @@ +#![feature(let_else)] + +fn main() { + let Some(_) = Some(()) else if true { + //~^ ERROR conditional `else if` is not supported for `let...else` + return; + } else { + return; + }; +} diff --git a/src/test/ui/let-else/let-else-if.stderr b/src/test/ui/let-else/let-else-if.stderr new file mode 100644 index 0000000000000..38c739fd85072 --- /dev/null +++ b/src/test/ui/let-else/let-else-if.stderr @@ -0,0 +1,18 @@ +error: conditional `else if` is not supported for `let...else` + --> $DIR/let-else-if.rs:4:33 + | +LL | let Some(_) = Some(()) else if true { + | ^^ expected `{` + | +help: try placing this code inside a block + | +LL ~ let Some(_) = Some(()) else { if true { +LL + +LL + return; +LL + } else { +LL + return; +LL ~ } }; + | + +error: aborting due to previous error + From 10b9b3d383482b55df985fb7fdc03be887b3039d Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 17 Oct 2021 13:20:43 -0700 Subject: [PATCH 149/181] Add static size assertion for `clean::Type` --- src/librustdoc/clean/types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d4cea8b4a9d28..9dab0023ba3f1 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1450,6 +1450,10 @@ crate enum Type { ImplTrait(Vec), } +// `Type` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +rustc_data_structures::static_assert_size!(Type, 72); + crate trait GetDefId { /// Use this method to get the [`DefId`] of a [`clean`] AST node. /// This will return [`None`] when called on a primitive [`clean::Type`]. From d39a1bec81f672f7bb270023f2eb91a51a22d319 Mon Sep 17 00:00:00 2001 From: pierwill Date: Sun, 17 Oct 2021 14:31:52 -0500 Subject: [PATCH 150/181] Check implementing type for `#[doc(hidden)]` Closes #85526. --- compiler/rustc_lint/src/builtin.rs | 18 ++++++++++++++++++ src/test/ui/hidden-doc-associated-item.rs | 15 +++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/ui/hidden-doc-associated-item.rs diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 57c1c8f3ecb5c..c228ecb03fdec 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -657,6 +657,24 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { return; } + // If the method is an impl for an item with docs_hidden, don't doc. + if method_context(cx, impl_item.hir_id()) == MethodLateContext::PlainImpl { + let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id()); + let impl_ty = cx.tcx.type_of(parent); + let outerdef = match impl_ty.kind() { + ty::Adt(def, _) => Some(def.did), + ty::Foreign(def_id) => Some(*def_id), + _ => None, + }; + let is_hidden = match outerdef { + Some(id) => cx.tcx.is_doc_hidden(id), + None => false, + }; + if is_hidden { + return; + } + } + let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, impl_item.def_id, impl_item.span, article, desc); } diff --git a/src/test/ui/hidden-doc-associated-item.rs b/src/test/ui/hidden-doc-associated-item.rs new file mode 100644 index 0000000000000..d431f9e899c02 --- /dev/null +++ b/src/test/ui/hidden-doc-associated-item.rs @@ -0,0 +1,15 @@ +// check-pass +// See issue #85526. +// This test should produce no warnings. + +#![deny(missing_docs)] +//! Crate docs + +#[doc(hidden)] +pub struct Foo; + +impl Foo { + pub fn bar() {} +} + +fn main() {} From b87a0b06c75808a7ff99177db8000bb4a9161d8e Mon Sep 17 00:00:00 2001 From: pierwill <19642016+pierwill@users.noreply.github.com> Date: Sun, 17 Oct 2021 17:50:35 -0500 Subject: [PATCH 151/181] Remove dead code from `compiletest::json` --- src/tools/compiletest/src/json.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index dc6d67983c5d2..a5ff779a4abfb 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -74,8 +74,6 @@ struct DiagnosticSpanMacroExpansion { struct DiagnosticCode { /// The code itself. code: String, - /// An explanation for the code. - explanation: Option, } pub fn rustfix_diagnostics_only(output: &str) -> String { From 3f87b7cc0bdd10b7d44f93abcc4e80957f5c7a4d Mon Sep 17 00:00:00 2001 From: Winter Date: Sun, 17 Oct 2021 21:20:18 -0400 Subject: [PATCH 152/181] bump backtrace https://github.com/rust-lang/backtrace-rs/pull/446 allows binaries built with Nix on macOS to be symbolized. --- library/backtrace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/backtrace b/library/backtrace index cc89bb66f91b2..7f14f76c8ba69 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit cc89bb66f91b2b4a640b0b525ca5d753e3346d7e +Subproject commit 7f14f76c8ba6945c052fab77022e6e768b58e0b4 From 72ca6cd99061469277d221b9392cf32b9f7efe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 18 Oct 2021 10:23:58 +0300 Subject: [PATCH 153/181] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index ed4b312fa777e..91cbda43c2af8 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit ed4b312fa777ebb39ba1348fe3df574c441a485e +Subproject commit 91cbda43c2af82b9377eff70a21f59ade18cd23c From f8b2f91c4879bbb37ed64623373a1b95b658bc20 Mon Sep 17 00:00:00 2001 From: cameron Date: Mon, 18 Oct 2021 08:41:18 +0100 Subject: [PATCH 154/181] add test for issue 84957 --- .../issue-84957-const-str-as-bytes.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs diff --git a/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs b/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs new file mode 100644 index 0000000000000..7e235c4911c31 --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs @@ -0,0 +1,28 @@ +// build-pass + +trait Foo {} + +struct Bar { + bytes: &'static [u8], + func: fn(&Box), +} +fn example(_: &Box) {} + +const BARS: &[Bar] = &[ + Bar { + bytes: "0".as_bytes(), + func: example, + }, + Bar { + bytes: "0".as_bytes(), + func: example, + }, +]; + +fn main() { + let x = todo!(); + + for bar in BARS { + (bar.func)(&x); + } +} From e3c3f4a09cc700ff06acef3d84bea0368e622da4 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Mon, 11 Oct 2021 12:31:43 +0200 Subject: [PATCH 155/181] RustWrapper: adapt for an LLVM API change No functional changes intended. The LLVM commit https://github.com/llvm/llvm-project/commit/89b57061f7b769e9ea9bf6ed686e284f3e55affe moved TargetRegistry.(h|cpp) from Support to MC. This adapts RustWrapper accordingly. --- compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h | 1 - compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h index 0b1b68d83b7b9..ebe495872c4a6 100644 --- a/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h +++ b/compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h @@ -18,7 +18,6 @@ #include "llvm/Support/Host.h" #include "llvm/Support/Memory.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 87f423fb2d56e..6d2e7d25336de 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -21,6 +21,11 @@ #include "llvm/Support/CBindingWrapping.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" +#if LLVM_VERSION_LT(14, 0) +#include "llvm/Support/TargetRegistry.h" +#else +#include "llvm/MC/TargetRegistry.h" +#endif #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" From 7936ecff4803e30ec0d3d85a531860025bb6b346 Mon Sep 17 00:00:00 2001 From: woppopo Date: Mon, 18 Oct 2021 19:19:28 +0900 Subject: [PATCH 156/181] Make more `From` impls `const` --- library/core/src/array/mod.rs | 3 ++- library/core/src/cell.rs | 9 ++++++--- library/core/src/char/convert.rs | 12 ++++++++---- library/core/src/convert/mod.rs | 9 ++++++--- library/core/src/lazy.rs | 2 +- library/core/src/num/error.rs | 5 +++-- library/core/src/num/nonzero.rs | 3 ++- library/core/src/option.rs | 11 +++++++---- library/core/src/ptr/non_null.rs | 9 ++++++--- library/core/src/ptr/unique.rs | 2 +- library/core/src/sync/atomic.rs | 9 ++++++--- library/core/src/task/poll.rs | 3 ++- library/core/tests/atomic.rs | 7 +++++++ library/core/tests/cell.rs | 9 +++++++++ library/core/tests/char.rs | 12 ++++++++++++ library/core/tests/lazy.rs | 6 ++++++ library/core/tests/lib.rs | 1 + library/core/tests/nonzero.rs | 3 +++ library/core/tests/option.rs | 15 +++++++++++++++ 19 files changed, 103 insertions(+), 27 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 8d5c0510404fb..b27c36baf37c5 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -125,7 +125,8 @@ impl TryFromSliceError { } #[stable(feature = "try_from_slice_error", since = "1.36.0")] -impl From for TryFromSliceError { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for TryFromSliceError { fn from(x: Infallible) -> TryFromSliceError { match x {} } diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 2ca077a98f8dc..ed464700cd357 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -308,7 +308,8 @@ impl Ord for Cell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for Cell { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for Cell { fn from(t: T) -> Cell { Cell::new(t) } @@ -1236,7 +1237,8 @@ impl Ord for RefCell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for RefCell { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for RefCell { fn from(t: T) -> RefCell { RefCell::new(t) } @@ -1976,7 +1978,8 @@ impl Default for UnsafeCell { } #[stable(feature = "cell_from", since = "1.12.0")] -impl From for UnsafeCell { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for UnsafeCell { fn from(t: T) -> UnsafeCell { UnsafeCell::new(t) } diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 72921414fb3f2..8fc6b1af92452 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -97,7 +97,8 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char { } #[stable(feature = "char_convert", since = "1.13.0")] -impl From for u32 { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for u32 { /// Converts a [`char`] into a [`u32`]. /// /// # Examples @@ -116,7 +117,8 @@ impl From for u32 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -impl From for u64 { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for u64 { /// Converts a [`char`] into a [`u64`]. /// /// # Examples @@ -137,7 +139,8 @@ impl From for u64 { } #[stable(feature = "more_char_conversions", since = "1.51.0")] -impl From for u128 { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for u128 { /// Converts a [`char`] into a [`u128`]. /// /// # Examples @@ -176,7 +179,8 @@ impl From for u128 { /// for a superset of Windows-1252 that fills the remaining blanks with corresponding /// C0 and C1 control codes. #[stable(feature = "char_convert", since = "1.13.0")] -impl From for char { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for char { /// Converts a [`u8`] into a [`char`]. /// /// # Examples diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index fb8305273a83c..5aa53deee343d 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -545,7 +545,8 @@ where // From (and thus Into) is reflexive #[stable(feature = "rust1", since = "1.0.0")] -impl From for T { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for T { fn from(t: T) -> T { t } @@ -560,7 +561,8 @@ impl From for T { #[allow(unused_attributes)] // FIXME(#58633): do a principled fix instead. #[rustc_reservation_impl = "permitting this impl would forbid us from adding \ `impl From for T` later; see rust-lang/rust#64715 for details"] -impl From for T { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for T { fn from(t: !) -> T { t } @@ -726,7 +728,8 @@ impl Ord for Infallible { } #[stable(feature = "convert_infallible", since = "1.34.0")] -impl From for Infallible { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for Infallible { fn from(x: !) -> Self { x } diff --git a/library/core/src/lazy.rs b/library/core/src/lazy.rs index d109141216aef..2b8a5f3cbf345 100644 --- a/library/core/src/lazy.rs +++ b/library/core/src/lazy.rs @@ -74,7 +74,7 @@ impl PartialEq for OnceCell { impl Eq for OnceCell {} #[unstable(feature = "once_cell", issue = "74465")] -impl From for OnceCell { +impl const From for OnceCell { fn from(value: T) -> Self { OnceCell { inner: UnsafeCell::new(Some(value)) } } diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index cdeba9c079273..2af61a0748236 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -29,14 +29,15 @@ impl fmt::Display for TryFromIntError { } #[stable(feature = "try_from", since = "1.34.0")] -impl From for TryFromIntError { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for TryFromIntError { fn from(x: Infallible) -> TryFromIntError { match x {} } } #[unstable(feature = "never_type", issue = "35121")] -impl From for TryFromIntError { +impl const From for TryFromIntError { fn from(never: !) -> TryFromIntError { // Match rather than coerce to make sure that code like // `From for TryFromIntError` above will keep working diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 89fd9fbaf455d..d28474c29232c 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -82,7 +82,8 @@ macro_rules! nonzero_integers { } #[stable(feature = "from_nonzero", since = "1.31.0")] - impl From<$Ty> for $Int { + #[rustc_const_unstable(feature = "const_convert", issue = "88674")] + impl const From<$Ty> for $Int { #[doc = concat!("Converts a `", stringify!($Ty), "` into an `", stringify!($Int), "`")] #[inline] fn from(nonzero: $Ty) -> Self { diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 885058321589c..f4ce7d1dfb334 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1723,7 +1723,8 @@ impl<'a, T> IntoIterator for &'a mut Option { } #[stable(since = "1.12.0", feature = "option_from")] -impl From for Option { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for Option { /// Moves `val` into a new [`Some`]. /// /// # Examples @@ -1739,7 +1740,8 @@ impl From for Option { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -impl<'a, T> From<&'a Option> for Option<&'a T> { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<'a, T> const From<&'a Option> for Option<&'a T> { /// Converts from `&Option` to `Option<&T>`. /// /// # Examples @@ -1766,7 +1768,8 @@ impl<'a, T> From<&'a Option> for Option<&'a T> { } #[stable(feature = "option_ref_from_ref_option", since = "1.30.0")] -impl<'a, T> From<&'a mut Option> for Option<&'a mut T> { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl<'a, T> const From<&'a mut Option> for Option<&'a mut T> { /// Converts from `&mut Option` to `Option<&mut T>` /// /// # Examples @@ -2052,7 +2055,7 @@ impl ops::Try for Option { } #[unstable(feature = "try_trait_v2", issue = "84277")] -impl ops::FromResidual for Option { +impl const ops::FromResidual for Option { #[inline] fn from_residual(residual: Option) -> Self { match residual { diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index ee93f00a7fb9b..8bae66ca007a7 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -698,7 +698,8 @@ impl hash::Hash for NonNull { } #[unstable(feature = "ptr_internals", issue = "none")] -impl From> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From> for NonNull { #[inline] fn from(unique: Unique) -> Self { // SAFETY: A Unique pointer cannot be null, so the conditions for @@ -708,7 +709,8 @@ impl From> for NonNull { } #[stable(feature = "nonnull", since = "1.25.0")] -impl From<&mut T> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From<&mut T> for NonNull { #[inline] fn from(reference: &mut T) -> Self { // SAFETY: A mutable reference cannot be null. @@ -717,7 +719,8 @@ impl From<&mut T> for NonNull { } #[stable(feature = "nonnull", since = "1.25.0")] -impl From<&T> for NonNull { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From<&T> for NonNull { #[inline] fn from(reference: &T) -> Self { // SAFETY: A reference cannot be null, so the conditions for diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs index 5baceefb504a5..f6eb48f2967c8 100644 --- a/library/core/src/ptr/unique.rs +++ b/library/core/src/ptr/unique.rs @@ -176,7 +176,7 @@ impl fmt::Pointer for Unique { } #[unstable(feature = "ptr_internals", issue = "none")] -impl From<&mut T> for Unique { +impl const From<&mut T> for Unique { #[inline] fn from(reference: &mut T) -> Self { // SAFETY: A mutable reference cannot be null diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 1247f33087558..0915dcffe6ef0 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -1273,7 +1273,8 @@ impl AtomicPtr { #[cfg(target_has_atomic_load_store = "8")] #[stable(feature = "atomic_bool_from", since = "1.24.0")] -impl From for AtomicBool { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for AtomicBool { /// Converts a `bool` into an `AtomicBool`. /// /// # Examples @@ -1291,7 +1292,8 @@ impl From for AtomicBool { #[cfg(target_has_atomic_load_store = "ptr")] #[stable(feature = "atomic_from", since = "1.23.0")] -impl From<*mut T> for AtomicPtr { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From<*mut T> for AtomicPtr { #[inline] fn from(p: *mut T) -> Self { Self::new(p) @@ -1363,7 +1365,8 @@ macro_rules! atomic_int { } #[$stable_from] - impl From<$int_type> for $atomic_type { + #[rustc_const_unstable(feature = "const_convert", issue = "88674")] + impl const From<$int_type> for $atomic_type { #[doc = concat!("Converts an `", stringify!($int_type), "` into an `", stringify!($atomic_type), "`.")] #[inline] fn from(v: $int_type) -> Self { Self::new(v) } diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 80e1458dc9421..72a030617ad8a 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -241,7 +241,8 @@ impl Poll>> { } #[stable(feature = "futures_api", since = "1.36.0")] -impl From for Poll { +#[rustc_const_unstable(feature = "const_convert", issue = "88674")] +impl const From for Poll { /// Convert to a `Ready` variant. /// /// # Example diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs index b735957666fc5..7f8672f035417 100644 --- a/library/core/tests/atomic.rs +++ b/library/core/tests/atomic.rs @@ -220,3 +220,10 @@ fn atomic_compare_exchange() { ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok(); ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok(); } + +#[test] +fn atomic_const_from() { + const _ATOMIC_U8: AtomicU8 = AtomicU8::from(1); + const _ATOMIC_BOOL: AtomicBool = AtomicBool::from(true); + const _ATOMIC_PTR: AtomicPtr = AtomicPtr::from(core::ptr::null_mut()); +} diff --git a/library/core/tests/cell.rs b/library/core/tests/cell.rs index 85a006c5d5bef..4707cc7076ec0 100644 --- a/library/core/tests/cell.rs +++ b/library/core/tests/cell.rs @@ -465,4 +465,13 @@ fn const_cells() { const CELL: Cell = Cell::new(3); const _: i32 = CELL.into_inner(); + + const UNSAFE_CELL_FROM: UnsafeCell = UnsafeCell::from(3); + const _: i32 = UNSAFE_CELL.into_inner(); + + const REF_CELL_FROM: RefCell = RefCell::from(3); + const _: i32 = REF_CELL.into_inner(); + + const CELL_FROM: Cell = Cell::from(3); + const _: i32 = CELL.into_inner(); } diff --git a/library/core/tests/char.rs b/library/core/tests/char.rs index 51eca1e05d343..6e434cf1a8d0f 100644 --- a/library/core/tests/char.rs +++ b/library/core/tests/char.rs @@ -5,6 +5,8 @@ use std::{char, str}; #[test] fn test_convert() { assert_eq!(u32::from('a'), 0x61); + assert_eq!(u64::from('b'), 0x62); + assert_eq!(u128::from('c'), 0x63); assert_eq!(char::from(b'\0'), '\0'); assert_eq!(char::from(b'a'), 'a'); assert_eq!(char::from(b'\xFF'), '\u{FF}'); @@ -19,6 +21,16 @@ fn test_convert() { assert!(char::try_from(0xFFFF_FFFF_u32).is_err()); } +#[test] +const fn test_convert_const() { + assert!(u32::from('a') == 0x61); + assert!(u64::from('b') == 0x62); + assert!(u128::from('c') == 0x63); + assert!(char::from(b'\0') == '\0'); + assert!(char::from(b'a') == 'a'); + assert!(char::from(b'\xFF') == '\u{FF}'); +} + #[test] fn test_from_str() { assert_eq!(char::from_str("a").unwrap(), 'a'); diff --git a/library/core/tests/lazy.rs b/library/core/tests/lazy.rs index 24f921ca7e4dc..064024ab87b28 100644 --- a/library/core/tests/lazy.rs +++ b/library/core/tests/lazy.rs @@ -47,6 +47,12 @@ fn unsync_once_cell_drop_empty() { drop(x); } +#[test] +const fn once_cell_const() { + let _once_cell: OnceCell = OnceCell::new(); + let _once_cell: OnceCell = OnceCell::from(32); +} + #[test] fn clone() { let s = OnceCell::new(); diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 6958f07227afe..ab0295c63143d 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -9,6 +9,7 @@ #![feature(cfg_target_has_atomic)] #![feature(const_assume)] #![feature(const_cell_into_inner)] +#![feature(const_convert)] #![feature(const_maybe_uninit_assume_init)] #![cfg_attr(bootstrap, feature(const_panic))] #![feature(const_ptr_read)] diff --git a/library/core/tests/nonzero.rs b/library/core/tests/nonzero.rs index c2c08522d0cae..4817d86ca6eb0 100644 --- a/library/core/tests/nonzero.rs +++ b/library/core/tests/nonzero.rs @@ -214,6 +214,9 @@ fn nonzero_const() { const ONE: Option = NonZeroU8::new(1); assert!(ONE.is_some()); + + const FROM_NONZERO: u8 = u8::from(NONZERO); + assert_eq!(FROM_NONZERO, 5); } #[test] diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index c9508c145258c..cd07d6c52c2ad 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -358,10 +358,17 @@ fn option_const() { // test that the methods of `Option` are usable in a const context const OPTION: Option = Some(32); + assert_eq!(OPTION, Some(32)); + + const OPTION_FROM: Option = Option::from(32); + assert_eq!(OPTION_FROM, Some(32)); const REF: Option<&usize> = OPTION.as_ref(); assert_eq!(REF, Some(&32)); + const REF_FROM: Option<&usize> = Option::from(&OPTION); + assert_eq!(REF_FROM, Some(&32)); + const IS_SOME: bool = OPTION.is_some(); assert!(IS_SOME); @@ -388,6 +395,14 @@ const fn option_const_mut() { None => unreachable!(), } } + + { + let as_mut: Option<&mut usize> = Option::from(&mut option); + match as_mut { + Some(v) => *v = 42, + None => unreachable!(), + } + } } #[test] From 8b7a2dd4626acf164e1ce8397878b3f5af83d585 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Oct 2021 14:49:25 +0200 Subject: [PATCH 157/181] * Remove left margin on items declaration at the top of their documentation page * Rename "type-decl" into "item-decl" to reflect the change of usage --- src/librustdoc/html/render/print_item.rs | 275 ++++++++++-------- src/librustdoc/html/static/css/rustdoc.css | 5 +- src/librustdoc/html/static/css/themes/ayu.css | 2 +- .../html/static/css/themes/dark.css | 2 +- .../html/static/css/themes/light.css | 2 +- src/test/rustdoc-gui/basic.goml | 2 +- src/test/rustdoc-gui/font-weight.goml | 8 +- .../rustdoc-gui/type-declation-overflow.goml | 2 +- src/test/rustdoc/attributes.rs | 2 +- src/test/rustdoc/reexports-priv.rs | 24 +- src/test/rustdoc/reexports.rs | 8 +- src/test/rustdoc/toggle-item-contents.rs | 2 +- src/test/rustdoc/trait_alias.rs | 9 +- 13 files changed, 190 insertions(+), 153 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 4cfc57ac99588..58cd1018c316f 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -482,24 +482,26 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean:: + name.as_str().len() + generics_len; - wrap_item(w, "fn", |w| { - render_attributes_in_pre(w, it, ""); - w.reserve(header_len); - write!( - w, - "{vis}{constness}{asyncness}{unsafety}{abi}fn \ - {name}{generics}{decl}{notable_traits}{where_clause}", - vis = vis, - constness = constness, - asyncness = asyncness, - unsafety = unsafety, - abi = abi, - name = name, - generics = f.generics.print(cx), - where_clause = print_where_clause(&f.generics, cx, 0, true), - decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx), - notable_traits = notable_traits_decl(&f.decl, cx), - ); + wrap_into_docblock(w, |w| { + wrap_item(w, "fn", |w| { + render_attributes_in_pre(w, it, ""); + w.reserve(header_len); + write!( + w, + "{vis}{constness}{asyncness}{unsafety}{abi}fn \ + {name}{generics}{decl}{notable_traits}{where_clause}", + vis = vis, + constness = constness, + asyncness = asyncness, + unsafety = unsafety, + abi = abi, + name = name, + generics = f.generics.print(cx), + where_clause = print_where_clause(&f.generics, cx, 0, true), + decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx), + notable_traits = notable_traits_decl(&f.decl, cx), + ); + }); }); document(w, cx, it, None, HeadingOffset::H2) } @@ -844,16 +846,18 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra } fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::TraitAlias) { - wrap_item(w, "trait-alias", |w| { - render_attributes_in_pre(w, it, ""); - write!( - w, - "trait {}{}{} = {};", - it.name.as_ref().unwrap(), - t.generics.print(cx), - print_where_clause(&t.generics, cx, 0, true), - bounds(&t.bounds, true, cx) - ); + wrap_into_docblock(w, |w| { + wrap_item(w, "trait-alias", |w| { + render_attributes_in_pre(w, it, ""); + write!( + w, + "trait {}{}{} = {};", + it.name.as_ref().unwrap(), + t.generics.print(cx), + print_where_clause(&t.generics, cx, 0, true), + bounds(&t.bounds, true, cx) + ); + }); }); document(w, cx, it, None, HeadingOffset::H2); @@ -866,16 +870,18 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea } fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) { - wrap_item(w, "opaque", |w| { - render_attributes_in_pre(w, it, ""); - write!( - w, - "type {}{}{where_clause} = impl {bounds};", - it.name.as_ref().unwrap(), - t.generics.print(cx), - where_clause = print_where_clause(&t.generics, cx, 0, true), - bounds = bounds(&t.bounds, false, cx), - ); + wrap_into_docblock(w, |w| { + wrap_item(w, "opaque", |w| { + render_attributes_in_pre(w, it, ""); + write!( + w, + "type {}{}{where_clause} = impl {bounds};", + it.name.as_ref().unwrap(), + t.generics.print(cx), + where_clause = print_where_clause(&t.generics, cx, 0, true), + bounds = bounds(&t.bounds, false, cx), + ); + }); }); document(w, cx, it, None, HeadingOffset::H2); @@ -894,20 +900,37 @@ fn item_typedef( t: &clean::Typedef, is_associated: bool, ) { - wrap_item(w, "typedef", |w| { - render_attributes_in_pre(w, it, ""); - if !is_associated { - write!(w, "{}", it.visibility.print_with_space(it.def_id, cx)); - } - write!( - w, - "type {}{}{where_clause} = {type_};", - it.name.as_ref().unwrap(), - t.generics.print(cx), - where_clause = print_where_clause(&t.generics, cx, 0, true), - type_ = t.type_.print(cx), - ); - }); + fn write_content( + w: &mut Buffer, + cx: &Context<'_>, + it: &clean::Item, + t: &clean::Typedef, + is_associated: bool, + ) { + wrap_item(w, "typedef", |w| { + render_attributes_in_pre(w, it, ""); + if !is_associated { + write!(w, "{}", it.visibility.print_with_space(it.def_id, cx)); + } + write!( + w, + "type {}{}{where_clause} = {type_};", + it.name.as_ref().unwrap(), + t.generics.print(cx), + where_clause = print_where_clause(&t.generics, cx, 0, true), + type_ = t.type_.print(cx), + ); + }); + } + + // If this is an associated typedef, we don't want to wrap it into a docblock. + if is_associated { + write_content(w, cx, it, t, is_associated); + } else { + wrap_into_docblock(w, |w| { + write_content(w, cx, it, t, is_associated); + }); + } document(w, cx, it, None, HeadingOffset::H2); @@ -1142,32 +1165,34 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac } fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) { - let name = it.name.as_ref().expect("proc-macros always have names"); - match m.kind { - MacroKind::Bang => { - wrap_item(w, "macro", |w| { - write!(w, "{}!() {{ /* proc-macro */ }}", name); - }); - } - MacroKind::Attr => { - wrap_item(w, "attr", |w| { - write!(w, "#[{}]", name); - }); - } - MacroKind::Derive => { - wrap_item(w, "derive", |w| { - write!(w, "#[derive({})]", name); - if !m.helpers.is_empty() { - w.push_str("\n{\n"); - w.push_str(" // Attributes available to this derive:\n"); - for attr in &m.helpers { - writeln!(w, " #[{}]", attr); + wrap_into_docblock(w, |w| { + let name = it.name.as_ref().expect("proc-macros always have names"); + match m.kind { + MacroKind::Bang => { + wrap_item(w, "macro", |w| { + write!(w, "{}!() {{ /* proc-macro */ }}", name); + }); + } + MacroKind::Attr => { + wrap_item(w, "attr", |w| { + write!(w, "#[{}]", name); + }); + } + MacroKind::Derive => { + wrap_item(w, "derive", |w| { + write!(w, "#[derive({})]", name); + if !m.helpers.is_empty() { + w.push_str("\n{\n"); + w.push_str(" // Attributes available to this derive:\n"); + for attr in &m.helpers { + writeln!(w, " #[{}]", attr); + } + w.push_str("}\n"); } - w.push_str("}\n"); - } - }); + }); + } } - } + }); document(w, cx, it, None, HeadingOffset::H2) } @@ -1177,38 +1202,40 @@ fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { } fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::Constant) { - wrap_item(w, "const", |w| { - render_attributes_in_code(w, it); + wrap_into_docblock(w, |w| { + wrap_item(w, "const", |w| { + render_attributes_in_code(w, it); - write!( - w, - "{vis}const {name}: {typ}", - vis = it.visibility.print_with_space(it.def_id, cx), - name = it.name.as_ref().unwrap(), - typ = c.type_.print(cx), - ); + write!( + w, + "{vis}const {name}: {typ}", + vis = it.visibility.print_with_space(it.def_id, cx), + name = it.name.as_ref().unwrap(), + typ = c.type_.print(cx), + ); - let value = c.value(cx.tcx()); - let is_literal = c.is_literal(cx.tcx()); - let expr = c.expr(cx.tcx()); - if value.is_some() || is_literal { - write!(w, " = {expr};", expr = Escape(&expr)); - } else { - w.write_str(";"); - } + let value = c.value(cx.tcx()); + let is_literal = c.is_literal(cx.tcx()); + let expr = c.expr(cx.tcx()); + if value.is_some() || is_literal { + write!(w, " = {expr};", expr = Escape(&expr)); + } else { + w.write_str(";"); + } - if !is_literal { - if let Some(value) = &value { - let value_lowercase = value.to_lowercase(); - let expr_lowercase = expr.to_lowercase(); + if !is_literal { + if let Some(value) = &value { + let value_lowercase = value.to_lowercase(); + let expr_lowercase = expr.to_lowercase(); - if value_lowercase != expr_lowercase - && value_lowercase.trim_end_matches("i32") != expr_lowercase - { - write!(w, " // {value}", value = Escape(value)); + if value_lowercase != expr_lowercase + && value_lowercase.trim_end_matches("i32") != expr_lowercase + { + write!(w, " // {value}", value = Escape(value)); + } } } - } + }); }); document(w, cx, it, None, HeadingOffset::H2) @@ -1268,30 +1295,34 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St } fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Static) { - wrap_item(w, "static", |w| { - render_attributes_in_code(w, it); - write!( - w, - "{vis}static {mutability}{name}: {typ}", - vis = it.visibility.print_with_space(it.def_id, cx), - mutability = s.mutability.print_with_space(), - name = it.name.as_ref().unwrap(), - typ = s.type_.print(cx) - ); + wrap_into_docblock(w, |w| { + wrap_item(w, "static", |w| { + render_attributes_in_code(w, it); + write!( + w, + "{vis}static {mutability}{name}: {typ}", + vis = it.visibility.print_with_space(it.def_id, cx), + mutability = s.mutability.print_with_space(), + name = it.name.as_ref().unwrap(), + typ = s.type_.print(cx) + ); + }); }); document(w, cx, it, None, HeadingOffset::H2) } fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { - wrap_item(w, "foreigntype", |w| { - w.write_str("extern {\n"); - render_attributes_in_code(w, it); - write!( - w, - " {}type {};\n}}", - it.visibility.print_with_space(it.def_id, cx), - it.name.as_ref().unwrap(), - ); + wrap_into_docblock(w, |w| { + wrap_item(w, "foreigntype", |w| { + w.write_str("extern {\n"); + render_attributes_in_code(w, it); + write!( + w, + " {}type {};\n}}", + it.visibility.print_with_space(it.def_id, cx), + it.name.as_ref().unwrap(), + ); + }); }); document(w, cx, it, None, HeadingOffset::H2); @@ -1374,7 +1405,7 @@ fn wrap_into_docblock(w: &mut Buffer, f: F) where F: FnOnce(&mut Buffer), { - w.write_str("

"); + w.write_str("
"); f(w); w.write_str("
") } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index cea3452780e6f..e178d8748bb33 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -253,7 +253,10 @@ code, pre, a.test-arrow, .code-header { pre { padding: 14px; } -.type-decl pre { +.docblock.item-decl { + margin-left: 0; +} +.item-decl pre { overflow-x: auto; } diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 0fd6462a8f5dd..ccb1a707032bb 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -220,7 +220,7 @@ body.source .example-wrap pre.rust a { background: #333; } -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock:not(.item-decl) a:not(.srclink):not(.test-arrow), .docblock-short a:not(.srclink):not(.test-arrow), .item-info a, #help a { color: #39AFD7; diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index d863701dd73c7..93801af46ecc5 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -181,7 +181,7 @@ body.source .example-wrap pre.rust a { background: #333; } -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock:not(.item-decl) a:not(.srclink):not(.test-arrow), .docblock-short a:not(.srclink):not(.test-arrow), .item-info a, #help a { color: #D2991D; diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 28d2e99a3d073..fba8231caac31 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -176,7 +176,7 @@ body.source .example-wrap pre.rust a { background: #eee; } -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock:not(.item-decl) a:not(.srclink):not(.test-arrow), .docblock-short a:not(.srclink):not(.test-arrow), .item-info a, #help a { color: #3873AD; diff --git a/src/test/rustdoc-gui/basic.goml b/src/test/rustdoc-gui/basic.goml index 44fcec3393744..239e51a91293f 100644 --- a/src/test/rustdoc-gui/basic.goml +++ b/src/test/rustdoc-gui/basic.goml @@ -1,4 +1,4 @@ goto: file://|DOC_PATH|/test_docs/index.html assert: ("#functions") goto: ./struct.Foo.html -assert: ("div.type-decl") +assert: ("div.item-decl") diff --git a/src/test/rustdoc-gui/font-weight.goml b/src/test/rustdoc-gui/font-weight.goml index d8411511c5aee..0459fd4b9c353 100644 --- a/src/test/rustdoc-gui/font-weight.goml +++ b/src/test/rustdoc-gui/font-weight.goml @@ -1,6 +1,6 @@ goto: file://|DOC_PATH|/lib2/struct.Foo.html // This test checks that the font weight is correctly applied. -assert-css: ("//*[@class='docblock type-decl']//a[text()='Alias']", {"font-weight": "400"}) +assert-css: ("//*[@class='docblock item-decl']//a[text()='Alias']", {"font-weight": "400"}) assert-css: ("//*[@class='structfield small-section-header']//a[text()='Alias']", {"font-weight": "400"}) assert-css: ("#method\.a_method > .code-header", {"font-weight": "600"}) assert-css: ("#associatedtype\.X > .code-header", {"font-weight": "600"}) @@ -16,7 +16,7 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html // This is a complex selector, so here's how it works: // -// * //*[@class='docblock type-decl'] — selects element of any tag with classes docblock and type-decl +// * //*[@class='docblock item-decl'] — selects element of any tag with classes docblock and item-decl // * /pre[@class='rust trait'] — selects immediate child with tag pre and classes rust and trait // * /code — selects immediate child with tag code // * /a[@class='constant'] — selects immediate child with tag a and class constant @@ -25,8 +25,8 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html // // This uses '/parent::*' as a proxy for the style of the text node. // We can't just select the '' because intermediate tags could be added. -assert-count: ("//*[@class='docblock type-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", 1) -assert-css: ("//*[@class='docblock type-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", {"font-weight": "400"}) +assert-count: ("//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", 1) +assert-css: ("//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", {"font-weight": "400"}) assert-count: (".methods .type", 1) assert-css: (".methods .type", {"font-weight": "600"}) diff --git a/src/test/rustdoc-gui/type-declation-overflow.goml b/src/test/rustdoc-gui/type-declation-overflow.goml index 0a316e220a42c..ab38b28ebfc1f 100644 --- a/src/test/rustdoc-gui/type-declation-overflow.goml +++ b/src/test/rustdoc-gui/type-declation-overflow.goml @@ -5,4 +5,4 @@ size: (1100, 800) // Logically, the scroll width should be the width of the window. assert-property: ("body", {"scrollWidth": "1100"}) // However, since there is overflow in the type declaration, its scroll width is bigger. -assert-property: (".type-decl pre", {"scrollWidth": "1324"}) +assert-property: (".item-decl pre", {"scrollWidth": "1324"}) diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs index 6a588fbd56e75..1c7f4b7241893 100644 --- a/src/test/rustdoc/attributes.rs +++ b/src/test/rustdoc/attributes.rs @@ -8,6 +8,6 @@ pub extern "C" fn f() {} #[export_name = "bar"] pub extern "C" fn g() {} -// @has foo/struct.Repr.html '//*[@class="docblock type-decl"]' '#[repr(C, align(8))]' +// @has foo/struct.Repr.html '//*[@class="docblock item-decl"]' '#[repr(C, align(8))]' #[repr(C, align(8))] pub struct Repr; diff --git a/src/test/rustdoc/reexports-priv.rs b/src/test/rustdoc/reexports-priv.rs index ff7424033aa49..509457f6c9649 100644 --- a/src/test/rustdoc/reexports-priv.rs +++ b/src/test/rustdoc/reexports-priv.rs @@ -5,25 +5,25 @@ extern crate reexports; -// @has 'foo/macro.addr_of.html' '//*[@class="docblock type-decl"]' 'pub macro addr_of($place : expr) {' +// @has 'foo/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place : expr) {' pub use reexports::addr_of; -// @has 'foo/macro.addr_of_crate.html' '//*[@class="docblock type-decl"]' 'pub(crate) macro addr_of_crate($place : expr) {' +// @has 'foo/macro.addr_of_crate.html' '//*[@class="docblock item-decl"]' 'pub(crate) macro addr_of_crate($place : expr) {' pub(crate) use reexports::addr_of_crate; -// @has 'foo/macro.addr_of_self.html' '//*[@class="docblock type-decl"]' 'pub(crate) macro addr_of_self($place : expr) {' +// @has 'foo/macro.addr_of_self.html' '//*[@class="docblock item-decl"]' 'pub(crate) macro addr_of_self($place : expr) {' pub(self) use reexports::addr_of_self; -// @has 'foo/struct.Foo.html' '//*[@class="docblock type-decl"]' 'pub struct Foo;' +// @has 'foo/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;' pub use reexports::Foo; -// @has 'foo/struct.FooCrate.html' '//*[@class="docblock type-decl"]' 'pub(crate) struct FooCrate;' +// @has 'foo/struct.FooCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) struct FooCrate;' pub(crate) use reexports::FooCrate; -// @has 'foo/struct.FooSelf.html' '//*[@class="docblock type-decl"]' 'pub(crate) struct FooSelf;' +// @has 'foo/struct.FooSelf.html' '//*[@class="docblock item-decl"]' 'pub(crate) struct FooSelf;' pub(self) use reexports::FooSelf; -// @has 'foo/enum.Bar.html' '//*[@class="docblock type-decl"]' 'pub enum Bar {' +// @has 'foo/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {' pub use reexports::Bar; -// @has 'foo/enum.BarCrate.html' '//*[@class="docblock type-decl"]' 'pub(crate) enum BarCrate {' +// @has 'foo/enum.BarCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) enum BarCrate {' pub(crate) use reexports::BarCrate; -// @has 'foo/enum.BarSelf.html' '//*[@class="docblock type-decl"]' 'pub(crate) enum BarSelf {' +// @has 'foo/enum.BarSelf.html' '//*[@class="docblock item-decl"]' 'pub(crate) enum BarSelf {' pub(self) use reexports::BarSelf; // @has 'foo/fn.foo.html' '//*[@class="rust fn"]' 'pub fn foo()' @@ -40,11 +40,11 @@ pub(crate) use reexports::TypeCrate; // @has 'foo/type.TypeSelf.html' '//*[@class="rust typedef"]' 'pub(crate) type TypeSelf =' pub(self) use reexports::TypeSelf; -// @has 'foo/union.Union.html' '//*[@class="docblock type-decl"]' 'pub union Union {' +// @has 'foo/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {' pub use reexports::Union; -// @has 'foo/union.UnionCrate.html' '//*[@class="docblock type-decl"]' 'pub(crate) union UnionCrate {' +// @has 'foo/union.UnionCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) union UnionCrate {' pub(crate) use reexports::UnionCrate; -// @has 'foo/union.UnionSelf.html' '//*[@class="docblock type-decl"]' 'pub(crate) union UnionSelf {' +// @has 'foo/union.UnionSelf.html' '//*[@class="docblock item-decl"]' 'pub(crate) union UnionSelf {' pub(self) use reexports::UnionSelf; pub mod foo { diff --git a/src/test/rustdoc/reexports.rs b/src/test/rustdoc/reexports.rs index ab4c5bc743907..c308d0c2f05cf 100644 --- a/src/test/rustdoc/reexports.rs +++ b/src/test/rustdoc/reexports.rs @@ -4,21 +4,21 @@ extern crate reexports; -// @has 'foo/macro.addr_of.html' '//*[@class="docblock type-decl"]' 'pub macro addr_of($place : expr) {' +// @has 'foo/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place : expr) {' pub use reexports::addr_of; // @!has 'foo/macro.addr_of_crate.html' pub(crate) use reexports::addr_of_crate; // @!has 'foo/macro.addr_of_self.html' pub(self) use reexports::addr_of_self; -// @has 'foo/struct.Foo.html' '//*[@class="docblock type-decl"]' 'pub struct Foo;' +// @has 'foo/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;' pub use reexports::Foo; // @!has 'foo/struct.FooCrate.html' pub(crate) use reexports::FooCrate; // @!has 'foo/struct.FooSelf.html' pub(self) use reexports::FooSelf; -// @has 'foo/enum.Bar.html' '//*[@class="docblock type-decl"]' 'pub enum Bar {' +// @has 'foo/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {' pub use reexports::Bar; // @!has 'foo/enum.BarCrate.html' pub(crate) use reexports::BarCrate; @@ -39,7 +39,7 @@ pub(crate) use reexports::TypeCrate; // @!has 'foo/type.TypeSelf.html' pub(self) use reexports::TypeSelf; -// @has 'foo/union.Union.html' '//*[@class="docblock type-decl"]' 'pub union Union {' +// @has 'foo/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {' pub use reexports::Union; // @!has 'foo/union.UnionCrate.html' pub(crate) use reexports::UnionCrate; diff --git a/src/test/rustdoc/toggle-item-contents.rs b/src/test/rustdoc/toggle-item-contents.rs index ae871e79d7f6b..937646987dd4f 100644 --- a/src/test/rustdoc/toggle-item-contents.rs +++ b/src/test/rustdoc/toggle-item-contents.rs @@ -55,7 +55,7 @@ pub union Union { // @has 'toggle_item_contents/struct.PrivStruct.html' // @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0 -// @has - '//div[@class="docblock type-decl"]' 'fields omitted' +// @has - '//div[@class="docblock item-decl"]' 'fields omitted' pub struct PrivStruct { a: usize, b: usize, diff --git a/src/test/rustdoc/trait_alias.rs b/src/test/rustdoc/trait_alias.rs index 6cd4a1a0afa08..c9fccf5a77cde 100644 --- a/src/test/rustdoc/trait_alias.rs +++ b/src/test/rustdoc/trait_alias.rs @@ -13,11 +13,14 @@ use std::fmt::Debug; // @has foo/index.html '//a[@class="traitalias"]' 'Alias2' // @has foo/index.html '//a[@class="traitalias"]' 'Foo' -// @has foo/traitalias.CopyAlias.html '//section[@id="main"]/pre' 'trait CopyAlias = Copy;' +// @has foo/traitalias.CopyAlias.html +// @has - '//section[@id="main"]/div[@class="docblock item-decl"]/pre' 'trait CopyAlias = Copy;' pub trait CopyAlias = Copy; -// @has foo/traitalias.Alias2.html '//section[@id="main"]/pre' 'trait Alias2 = Copy + Debug;' +// @has foo/traitalias.Alias2.html +// @has - '//section[@id="main"]/div[@class="docblock item-decl"]/pre' 'trait Alias2 = Copy + Debug;' pub trait Alias2 = Copy + Debug; -// @has foo/traitalias.Foo.html '//section[@id="main"]/pre' 'trait Foo = Into + Debug;' +// @has foo/traitalias.Foo.html +// @has - '//section[@id="main"]/div[@class="docblock item-decl"]/pre' 'trait Foo = Into + Debug;' pub trait Foo = Into + Debug; // @has foo/fn.bar.html '//a[@href="traitalias.Alias2.html"]' 'Alias2' pub fn bar() where T: Alias2 {} From 809330bda66120924964955c7e7b05aafc545d3c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Oct 2021 15:30:03 +0200 Subject: [PATCH 158/181] Prevent documentation page title to grow too big --- src/librustdoc/html/static/css/rustdoc.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e178d8748bb33..d66ddee320441 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -552,6 +552,7 @@ nav.sub { flex-grow: 1; margin: 0px; padding: 0px; + overflow-wrap: anywhere; } .in-band > code, .in-band > .code-header { From 20c286e268d0f77498ecbc542e23f81179fb94a4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Oct 2021 16:15:09 +0200 Subject: [PATCH 159/181] Add GUI overflow tests for constant and typedef --- src/test/rustdoc-gui/src/lib2/lib.rs | 17 +++++++++++++++++ .../rustdoc-gui/type-declation-overflow.goml | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index d5835b78d2fcf..f2e76b546c4af 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -84,3 +84,20 @@ pub mod summary_table { /// | content | content | pub struct Foo; } + +pub mod too_long { +pub type ReallyLongTypeNameLongLongLong = Option *const u8>; + +pub const ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong: u32 = 0; + +pub struct SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName { + pub a: u32, +} + +impl SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName { + /// ``` + /// let x = SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName { a: 0 }; + /// ``` + pub fn foo(&self) {} + } +} diff --git a/src/test/rustdoc-gui/type-declation-overflow.goml b/src/test/rustdoc-gui/type-declation-overflow.goml index ab38b28ebfc1f..63ab867fb1772 100644 --- a/src/test/rustdoc-gui/type-declation-overflow.goml +++ b/src/test/rustdoc-gui/type-declation-overflow.goml @@ -1,4 +1,4 @@ -// This test ensures that the type declaration content overflow is handled inside the
 directly.
+// This test ensures that the items declaration content overflow is handled inside the 
 directly.
 goto: file://|DOC_PATH|/lib2/long_trait/trait.ALongNameBecauseItHelpsTestingTheCurrentProblem.html
 // We set a fixed size so there is no chance of "random" resize.
 size: (1100, 800)
@@ -6,3 +6,20 @@ size: (1100, 800)
 assert-property: ("body", {"scrollWidth": "1100"})
 // However, since there is overflow in the type declaration, its scroll width is bigger.
 assert-property: (".item-decl pre", {"scrollWidth": "1324"})
+
+// We now make the same check on type declaration...
+goto: file://|DOC_PATH|/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html
+assert-property: ("body", {"scrollWidth": "1100"})
+// We now check that the section width hasn't grown because of it.
+assert-property: ("#main", {"scrollWidth": "840"})
+// And now checking that it has scrollable content.
+assert-property: (".item-decl pre", {"scrollWidth": "1103"})
+
+// ... and constant.
+// On a sidenote, it also checks that the (very) long title isn't changing the docblock width.
+goto: file://|DOC_PATH|/lib2/too_long/constant.ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong.html
+assert-property: ("body", {"scrollWidth": "1100"})
+// We now check that the section width hasn't grown because of it.
+assert-property: ("#main", {"scrollWidth": "840"})
+// And now checking that it has scrollable content.
+assert-property: (".item-decl pre", {"scrollWidth": "950"})

From 77c29294be4b7d25893eeb283c90d139f898c054 Mon Sep 17 00:00:00 2001
From: Guillaume Gomez 
Date: Mon, 18 Oct 2021 16:50:31 +0200
Subject: [PATCH 160/181] Add test to ensure that the docblock elements left
 margin is as expected

---
 src/test/rustdoc-gui/check-code-blocks-margin.goml | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 src/test/rustdoc-gui/check-code-blocks-margin.goml

diff --git a/src/test/rustdoc-gui/check-code-blocks-margin.goml b/src/test/rustdoc-gui/check-code-blocks-margin.goml
new file mode 100644
index 0000000000000..2de4768285679
--- /dev/null
+++ b/src/test/rustdoc-gui/check-code-blocks-margin.goml
@@ -0,0 +1,6 @@
+// This test ensures that the docblock elements have the appropriate left margin.
+goto: file://|DOC_PATH|/test_docs/fn.foo.html
+// The top docblock elements shouldn't have left margin...
+assert-css: ("#main .docblock.item-decl", {"margin-left": "0px"})
+// ... but all the others should!
+assert-css: ("#main .docblock:not(.item-decl)", {"margin-left": "24px"})

From b02f2982e72ceca83965ac0bd19ffed196110758 Mon Sep 17 00:00:00 2001
From: Oli Scherer 
Date: Sat, 25 Sep 2021 11:49:14 +0000
Subject: [PATCH 161/181] Remove regionck member constraint handling and leave
 it to mir borrowck

---
 .../src/infer/lexical_region_resolve/mod.rs   | 163 +-----------------
 .../multiple-lifetimes/ret-impl-trait-one.rs  |   1 -
 .../ret-impl-trait-one.stderr                 |  17 +-
 .../ui/impl-trait/hidden-lifetimes.nll.stderr |  29 ----
 .../ui/impl-trait/hidden-lifetimes.stderr     |   2 +-
 .../ordinary-bounds-unrelated.nll.stderr      |  16 --
 .../ordinary-bounds-unrelated.stderr          |  11 +-
 .../ordinary-bounds-unsuited.nll.stderr       |  16 --
 .../ordinary-bounds-unsuited.stderr           |  11 +-
 ...t_outlive_least_region_or_bound.nll.stderr |   8 +-
 .../must_outlive_least_region_or_bound.rs     |   2 -
 .../must_outlive_least_region_or_bound.stderr |  67 +++----
 .../static-return-lifetime-infered.nll.stderr |  55 ------
 .../static-return-lifetime-infered.rs         |   4 -
 .../static-return-lifetime-infered.stderr     |  98 +++--------
 ...s_pin_lifetime_impl_trait-async.nll.stderr |  16 --
 ...elf_types_pin_lifetime_impl_trait-async.rs |   1 -
 ...types_pin_lifetime_impl_trait-async.stderr |  15 +-
 ...f_types_pin_lifetime_impl_trait.nll.stderr |  16 --
 ..._self_types_pin_lifetime_impl_trait.stderr |  11 +-
 20 files changed, 77 insertions(+), 482 deletions(-)
 delete mode 100644 src/test/ui/impl-trait/hidden-lifetimes.nll.stderr
 delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr
 delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr
 delete mode 100644 src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr
 delete mode 100644 src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr
 delete mode 100644 src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr

diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
index bae6103cad53b..d7e1b4545b8c1 100644
--- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
+++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
@@ -2,7 +2,6 @@
 
 use crate::infer::region_constraints::Constraint;
 use crate::infer::region_constraints::GenericKind;
-use crate::infer::region_constraints::MemberConstraint;
 use crate::infer::region_constraints::RegionConstraintData;
 use crate::infer::region_constraints::VarInfos;
 use crate::infer::region_constraints::VerifyBound;
@@ -150,12 +149,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
 
         let graph = self.construct_graph();
         self.expand_givens(&graph);
-        loop {
-            self.expansion(&mut var_data);
-            if !self.enforce_member_constraints(&graph, &mut var_data) {
-                break;
-            }
-        }
+        self.expansion(&mut var_data);
         self.collect_errors(&mut var_data, errors);
         self.collect_var_errors(&var_data, &graph, errors);
         var_data
@@ -233,133 +227,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
         }
     }
 
-    /// Enforce all member constraints and return true if anything
-    /// changed. See `enforce_member_constraint` for more details.
-    fn enforce_member_constraints(
-        &self,
-        graph: &RegionGraph<'tcx>,
-        var_values: &mut LexicalRegionResolutions<'tcx>,
-    ) -> bool {
-        // Note: we don't use the `any` combinator because we don't
-        // want to stop at the first constraint that makes a change.
-        let mut any_changed = false;
-        for member_constraint in &self.data.member_constraints {
-            any_changed |= self.enforce_member_constraint(graph, member_constraint, var_values);
-        }
-        any_changed
-    }
-
-    /// Enforce a constraint like
-    ///
-    /// ```
-    /// 'r member of ['c...]
-    /// ```
-    ///
-    /// We look for all choice regions from the list `'c...` that:
-    ///
-    /// (a) are greater than the current value of `'r` (which is a lower bound)
-    ///
-    /// and
-    ///
-    /// (b) are compatible with the upper bounds of `'r` that we can
-    /// find by traversing the graph.
-    ///
-    /// From that list, we look for a *minimal* option `'c_min`. If we
-    /// find one, then we can enforce that `'r: 'c_min`.
-    #[instrument(level = "debug", skip(self, graph, member_constraint, var_values))]
-    fn enforce_member_constraint(
-        &self,
-        graph: &RegionGraph<'tcx>,
-        member_constraint: &MemberConstraint<'tcx>,
-        var_values: &mut LexicalRegionResolutions<'tcx>,
-    ) -> bool {
-        debug!("member_constraint={:#?}", member_constraint);
-
-        // The constraint is some inference variable (`vid`) which
-        // must be equal to one of the options.
-        let member_vid = match member_constraint.member_region {
-            ty::ReVar(vid) => *vid,
-            _ => return false,
-        };
-
-        // The current value of `vid` is a lower bound LB -- i.e., we
-        // know that `LB <= vid` must be true.
-        let member_lower_bound: ty::Region<'tcx> = match var_values.value(member_vid) {
-            VarValue::ErrorValue => return false,
-            VarValue::Value(r) => r,
-        };
-
-        // Find all the "upper bounds" -- that is, each region `b` such that
-        // `r0 <= b` must hold.
-        let (member_upper_bounds, ..) =
-            self.collect_bounding_regions(graph, member_vid, OUTGOING, None);
-
-        // Get an iterator over the *available choice* -- that is,
-        // each choice region `c` where `lb <= c` and `c <= ub` for all the
-        // upper bounds `ub`.
-        debug!("upper_bounds={:#?}", member_upper_bounds);
-        let mut options = member_constraint
-            .choice_regions
-            .iter()
-            // If any of the regions are inference vars, resolve them, as far
-            // as possible.
-            .filter_map(|option| match option {
-                ty::ReVar(vid) => match var_values.value(*vid) {
-                    VarValue::ErrorValue => None,
-                    VarValue::Value(r) => Some(r),
-                },
-                r => Some(r),
-            })
-            .filter(|option| {
-                self.sub_concrete_regions(member_lower_bound, option)
-                    && member_upper_bounds
-                        .iter()
-                        .all(|upper_bound| self.sub_concrete_regions(option, upper_bound.region))
-            });
-
-        // If there is more than one option, we only make a choice if
-        // there is a single *least* choice -- i.e., some available
-        // region that is `<=` all the others.
-        let mut least_choice: ty::Region<'tcx> = match options.next() {
-            Some(&r) => r,
-            None => return false,
-        };
-        debug!(?least_choice);
-        for &option in options {
-            debug!(?option);
-            if !self.sub_concrete_regions(least_choice, option) {
-                if self.sub_concrete_regions(option, least_choice) {
-                    debug!("new least choice");
-                    least_choice = option;
-                } else {
-                    debug!("no least choice");
-                    return false;
-                }
-            }
-        }
-
-        // (#72087) Different `ty::Regions` can be known to be equal, for
-        // example, we know that `'a` and `'static` are equal in a function
-        // with a parameter of type `&'static &'a ()`.
-        //
-        // When we have two equal regions like this `expansion` will use
-        // `lub_concrete_regions` to pick a canonical representative. The same
-        // choice is needed here so that we don't end up in a cycle of
-        // `expansion` changing the region one way and the code here changing
-        // it back.
-        let lub = self.lub_concrete_regions(least_choice, member_lower_bound);
-        debug!(
-            "enforce_member_constraint: final least choice = {:?}\nlub = {:?}",
-            least_choice, lub
-        );
-        if lub != member_lower_bound {
-            *var_values.value_mut(member_vid) = VarValue::Value(least_choice);
-            true
-        } else {
-            false
-        }
-    }
-
     fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
         let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len());
         let mut changes = Vec::new();
@@ -632,34 +499,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
             }
         }
 
-        // Check that all member constraints are satisfied.
-        for member_constraint in &self.data.member_constraints {
-            let member_region = var_data.normalize(self.tcx(), member_constraint.member_region);
-            let choice_regions = member_constraint
-                .choice_regions
-                .iter()
-                .map(|&choice_region| var_data.normalize(self.tcx(), choice_region));
-            let fr = &self.region_rels.free_regions;
-            let sub = |a, b| {
-                fr.is_free_or_static(a)
-                    && fr.is_free_or_static(b)
-                    && fr.sub_free_regions(self.tcx(), a, b)
-            };
-            if !choice_regions.clone().any(|choice_region| {
-                // This is really checking if the regions are equal. After member constraint
-                // resolution, one region must be equal, or a lifetime has been leaked into
-                // the hidden type, but does not appear in the corresponding impl trait.
-                sub(member_region, choice_region) && sub(choice_region, member_region)
-            }) {
-                let span = self.tcx().def_span(member_constraint.opaque_type_def_id);
-                errors.push(RegionResolutionError::MemberConstraintFailure {
-                    span,
-                    hidden_ty: member_constraint.hidden_ty,
-                    member_region,
-                });
-            }
-        }
-
         for verify in &self.data.verifys {
             debug!("collect_errors: verify={:?}", verify);
             let sub = var_data.normalize(self.tcx(), verify.region);
diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs
index e2d00d8c9c4f2..4f32489014d53 100644
--- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs
+++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs
@@ -15,7 +15,6 @@ async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> +
 // Only `'a` permitted in return type, not `'b`.
 async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
     //~^ ERROR captures lifetime that does not appear in bounds
-    //~| ERROR captures lifetime that does not appear in bounds
     (a, b)
 }
 
diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
index 8d2a8e8f1d869..bcd96367e2fae 100644
--- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
+++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
@@ -14,27 +14,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
 LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
    |                                    --                           ^^^^^^^^^^^^^^
    |                                    |
-   |                                    hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here
+   |                                    hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here
    |
 help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
 LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
    |                                                                                ++++
 
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ret-impl-trait-one.rs:16:65
-   |
-LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> {
-   |                                    --                           ^^^^^^^^^^^^^^
-   |                                    |
-   |                                    hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here
-   |
-help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
-   |
-LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
-   |                                                                                ++++
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
 Some errors have detailed explanations: E0623, E0700.
 For more information about an error, try `rustc --explain E0623`.
diff --git a/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr b/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr
deleted file mode 100644
index 60d3409a8accf..0000000000000
--- a/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr
+++ /dev/null
@@ -1,29 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/hidden-lifetimes.rs:28:54
-   |
-LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
-   |                 --                                   ^^^^^^^^^^^^^^
-   |                 |
-   |                 hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
-   |
-help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
-   |
-LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
-   |                                                                     ++++
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/hidden-lifetimes.rs:45:70
-   |
-LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a {
-   |                        --                                            ^^^^^^^^^^^^^^
-   |                        |
-   |                        hidden type `Rc>` captures the lifetime `'b` as defined here
-   |
-help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
-   |
-LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a + 'b {
-   |                                                                                     ++++
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr
index bba9203870025..60d3409a8accf 100644
--- a/src/test/ui/impl-trait/hidden-lifetimes.stderr
+++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr
@@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
 LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
    |                 --                                   ^^^^^^^^^^^^^^
    |                 |
-   |                 hidden type `&mut &'b T` captures the lifetime `'b` as defined here
+   |                 hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here
    |
 help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr
deleted file mode 100644
index bfe656c7e2b49..0000000000000
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ordinary-bounds-unrelated.rs:16:74
-   |
-LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
-   |                     --                                                   ^^^^^^^^^^^^^^^^^^
-   |                     |
-   |                     hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
-   |
-help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
-   |
-LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
-   |                                                                                             ++++
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
index a6bc8fec2838e..bfe656c7e2b49 100644
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
+++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
@@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
   --> $DIR/ordinary-bounds-unrelated.rs:16:74
    |
 LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
-   |                                                                          ^^^^^^^^^^^^^^^^^^
+   |                     --                                                   ^^^^^^^^^^^^^^^^^^
+   |                     |
+   |                     hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
    |
-note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body
-  --> $DIR/ordinary-bounds-unrelated.rs:16:74
+help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
-LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e>
-   |                                                                          ^^^^^^^^^^^^^^^^^^
+LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
+   |                                                                                             ++++
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr
deleted file mode 100644
index 75c2dd8e9d39e..0000000000000
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ordinary-bounds-unsuited.rs:18:62
-   |
-LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
-   |                     --                                       ^^^^^^^^^^^^^^^^^^
-   |                     |
-   |                     hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
-   |
-help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
-   |
-LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
-   |                                                                                 ++++
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
index a219e74741541..75c2dd8e9d39e 100644
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
+++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
@@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
   --> $DIR/ordinary-bounds-unsuited.rs:18:62
    |
 LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
-   |                                                              ^^^^^^^^^^^^^^^^^^
+   |                     --                                       ^^^^^^^^^^^^^^^^^^
+   |                     |
+   |                     hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here
    |
-note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body
-  --> $DIR/ordinary-bounds-unsuited.rs:18:62
+help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
-LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b>
-   |                                                              ^^^^^^^^^^^^^^^^^^
+LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
+   |                                                                                 ++++
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr
index 479874695a7fc..eaf341248a180 100644
--- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr
+++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr
@@ -59,7 +59,7 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) }
    |               let's call the lifetime of this reference `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/must_outlive_least_region_or_bound.rs:30:69
+  --> $DIR/must_outlive_least_region_or_bound.rs:29:69
    |
 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
    |               -- lifetime `'a` defined here                         ^ returning this value requires that `'a` must outlive `'static`
@@ -67,12 +67,12 @@ LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
    = help: consider replacing `'a` with `'static`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/must_outlive_least_region_or_bound.rs:34:61
+  --> $DIR/must_outlive_least_region_or_bound.rs:33:61
    |
 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
    |                              --                             ^^^^^^^^^^^^^^^^
    |                              |
-   |                              hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures the lifetime `'b` as defined here
+   |                              hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here
    |
 help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
@@ -80,7 +80,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32
    |                                                                              ++++
 
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/must_outlive_least_region_or_bound.rs:40:51
+  --> $DIR/must_outlive_least_region_or_bound.rs:38:51
    |
 LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static {
    |                                                   ^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs
index d30e019184091..69d2843ff3f01 100644
--- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs
+++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs
@@ -22,7 +22,6 @@ fn elided4(x: &i32) -> Box { Box::new(x) } //~ ERROR E0759
 fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } //~ ERROR E0759
 
 fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } //~ ERROR E0759
-//~^ ERROR: captures lifetime that does not appear in bounds
 
 trait LifetimeTrait<'a> {}
 impl<'a> LifetimeTrait<'a> for &'a i32 {}
@@ -33,7 +32,6 @@ fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } //~ ERRO
 // only 'a was expected.
 fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
     //~^ ERROR: captures lifetime that does not appear in bounds
-    //~| ERROR: captures lifetime that does not appear in bounds
     move |_| println!("{}", y)
 }
 
diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
index b472132a12b52..d65dea7adc90b 100644
--- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
+++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
@@ -2,25 +2,27 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
   --> $DIR/must_outlive_least_region_or_bound.rs:3:23
    |
 LL | fn elided(x: &i32) -> impl Copy { x }
-   |                       ^^^^^^^^^
+   |              ----     ^^^^^^^^^
+   |              |
+   |              hidden type `&i32` captures the anonymous lifetime defined here
    |
-note: hidden type `&i32` captures lifetime smaller than the function body
-  --> $DIR/must_outlive_least_region_or_bound.rs:3:23
+help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
    |
-LL | fn elided(x: &i32) -> impl Copy { x }
-   |                       ^^^^^^^^^
+LL | fn elided(x: &i32) -> impl Copy + '_ { x }
+   |                                 ++++
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
   --> $DIR/must_outlive_least_region_or_bound.rs:6:32
    |
 LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
-   |                                ^^^^^^^^^
+   |             --                 ^^^^^^^^^
+   |             |
+   |             hidden type `&'a i32` captures the lifetime `'a` as defined here
    |
-note: hidden type `&i32` captures lifetime smaller than the function body
-  --> $DIR/must_outlive_least_region_or_bound.rs:6:32
+help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound
    |
-LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
-   |                                ^^^^^^^^^
+LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
+   |                                          ++++
 
 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
   --> $DIR/must_outlive_least_region_or_bound.rs:9:46
@@ -74,18 +76,6 @@ LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x }
    |               |
    |               help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
 
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/must_outlive_least_region_or_bound.rs:24:41
-   |
-LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) }
-   |                                         ^^^^^^^^^^
-   |
-note: hidden type `&i32` captures lifetime smaller than the function body
-  --> $DIR/must_outlive_least_region_or_bound.rs:24:41
-   |
-LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) }
-   |                                         ^^^^^^^^^^
-
 error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
   --> $DIR/must_outlive_least_region_or_bound.rs:24:65
    |
@@ -102,13 +92,13 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x)
    |                                                    ++++
 
 error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
-  --> $DIR/must_outlive_least_region_or_bound.rs:30:69
+  --> $DIR/must_outlive_least_region_or_bound.rs:29:69
    |
 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
    |                      ------- this data with lifetime `'a`...        ^ ...is captured here...
    |
 note: ...and is required to live as long as `'static` here
-  --> $DIR/must_outlive_least_region_or_bound.rs:30:34
+  --> $DIR/must_outlive_least_region_or_bound.rs:29:34
    |
 LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -122,31 +112,20 @@ LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x
    |                      ~~~~~~~~~~~~
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/must_outlive_least_region_or_bound.rs:34:61
+  --> $DIR/must_outlive_least_region_or_bound.rs:33:61
    |
 LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
-   |                                                             ^^^^^^^^^^^^^^^^
-   |
-note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body
-  --> $DIR/must_outlive_least_region_or_bound.rs:34:61
+   |                              --                             ^^^^^^^^^^^^^^^^
+   |                              |
+   |                              hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here
    |
-LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
-   |                                                             ^^^^^^^^^^^^^^^^
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/must_outlive_least_region_or_bound.rs:34:61
+help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound
    |
-LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
-   |                                                             ^^^^^^^^^^^^^^^^
-   |
-note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body
-  --> $DIR/must_outlive_least_region_or_bound.rs:34:61
-   |
-LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
-   |                                                             ^^^^^^^^^^^^^^^^
+LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
+   |                                                                              ++++
 
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/must_outlive_least_region_or_bound.rs:40:51
+  --> $DIR/must_outlive_least_region_or_bound.rs:38:51
    |
 LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static {
    |                                 --                ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
@@ -211,7 +190,7 @@ help: alternatively, add an explicit `'static` bound to this reference
 LL | fn explicit4<'a>(x: &'static i32) -> Box { Box::new(x) }
    |                     ~~~~~~~~~~~~
 
-error: aborting due to 15 previous errors
+error: aborting due to 13 previous errors
 
 Some errors have detailed explanations: E0310, E0621, E0700, E0759.
 For more information about an error, try `rustc --explain E0310`.
diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr
deleted file mode 100644
index 3d435bd1c3ffd..0000000000000
--- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr
+++ /dev/null
@@ -1,55 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                         -----     ^^^^^^^^^^^^^^^^^^^^^^^
-   |                         |
-   |                         hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here
-   |
-help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator + '_ {
-   |                                                           ++++
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                         -----     ^^^^^^^^^^^^^^^^^^^^^^^
-   |                         |
-   |                         hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here
-   |
-help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator + '_ {
-   |                                                           ++++
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                    --               ^^^^^^^^^^^^^^^^^^^^^^^
-   |                    |
-   |                    hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here
-   |
-help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator + 'a {
-   |                                                             ++++
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                    --               ^^^^^^^^^^^^^^^^^^^^^^^
-   |                    |
-   |                    hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here
-   |
-help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator + 'a {
-   |                                                             ++++
-
-error: aborting due to 4 previous errors
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.rs b/src/test/ui/impl-trait/static-return-lifetime-infered.rs
index e204cb0f7a7ff..d792c6eafb32f 100644
--- a/src/test/ui/impl-trait/static-return-lifetime-infered.rs
+++ b/src/test/ui/impl-trait/static-return-lifetime-infered.rs
@@ -6,15 +6,11 @@ impl A {
     fn iter_values_anon(&self) -> impl Iterator {
         //~^ ERROR: captures lifetime that does not appear in bounds
         //~| ERROR: captures lifetime that does not appear in bounds
-        //~| ERROR: captures lifetime that does not appear in bounds
-        //~| ERROR: captures lifetime that does not appear in bounds
         self.x.iter().map(|a| a.0)
     }
     fn iter_values<'a>(&'a self) -> impl Iterator {
         //~^ ERROR: captures lifetime that does not appear in bounds
         //~| ERROR: captures lifetime that does not appear in bounds
-        //~| ERROR: captures lifetime that does not appear in bounds
-        //~| ERROR: captures lifetime that does not appear in bounds
         self.x.iter().map(|a| a.0)
     }
 }
diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
index 33502bcf7d056..0d68f8c825f70 100644
--- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
+++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
@@ -2,98 +2,54 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
   --> $DIR/static-return-lifetime-infered.rs:6:35
    |
 LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
+   |                         -----     ^^^^^^^^^^^^^^^^^^^^^^^
+   |                         |
+   |                         hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here
    |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:6:35
-   |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:6:35
+help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
    |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
+LL |     fn iter_values_anon(&self) -> impl Iterator + '_ {
+   |                                                           ++++
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
   --> $DIR/static-return-lifetime-infered.rs:6:35
    |
 LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
+   |                         -----     ^^^^^^^^^^^^^^^^^^^^^^^
+   |                         |
+   |                         hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here
    |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:6:35
+help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
    |
-LL |     fn iter_values_anon(&self) -> impl Iterator {
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^
+LL |     fn iter_values_anon(&self) -> impl Iterator + '_ {
+   |                                                           ++++
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
+  --> $DIR/static-return-lifetime-infered.rs:11:37
    |
 LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
+   |                    --               ^^^^^^^^^^^^^^^^^^^^^^^
+   |                    |
+   |                    hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here
    |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:13:37
+help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound
    |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
+LL |     fn iter_values<'a>(&'a self) -> impl Iterator + 'a {
+   |                                                             ++++
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:13:37
+  --> $DIR/static-return-lifetime-infered.rs:11:37
    |
 LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
+   |                    --               ^^^^^^^^^^^^^^^^^^^^^^^
+   |                    |
+   |                    hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here
    |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
+help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound
    |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body
-  --> $DIR/static-return-lifetime-infered.rs:13:37
-   |
-LL |     fn iter_values<'a>(&'a self) -> impl Iterator {
-   |                                     ^^^^^^^^^^^^^^^^^^^^^^^
+LL |     fn iter_values<'a>(&'a self) -> impl Iterator + 'a {
+   |                                                             ++++
 
-error: aborting due to 8 previous errors
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr
deleted file mode 100644
index 953d7cd6a0769..0000000000000
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
-   |
-LL |     async fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                          -          ^^^^^^^^^^
-   |                          |
-   |                          hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here
-   |
-help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
-   |
-LL |     async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
-   |                                                ++++
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs
index e3483e4e62abe..a1e7f4aa875ee 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs
@@ -7,7 +7,6 @@ struct Foo;
 impl Foo {
     async fn f(self: Pin<&Self>) -> impl Clone { self }
     //~^ ERROR: captures lifetime that does not appear in bounds
-    //~| ERROR: captures lifetime that does not appear in bounds
 }
 
 fn main() {
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
index aac585ca414ca..953d7cd6a0769 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
@@ -11,19 +11,6 @@ help: to declare that the `impl Trait` captures '_, you can add an explicit `'_`
 LL |     async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
    |                                                ++++
 
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37
-   |
-LL |     async fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                          -          ^^^^^^^^^^
-   |                          |
-   |                          hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here
-   |
-help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
-   |
-LL |     async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
-   |                                                ++++
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr
deleted file mode 100644
index faa1233ffde63..0000000000000
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31
-   |
-LL |     fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                    -----      ^^^^^^^^^^
-   |                    |
-   |                    hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
-   |
-help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
-   |
-LL |     fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
-   |                                          ++++
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0700`.
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
index 7b645f51fe089..faa1233ffde63 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
@@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea
   --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31
    |
 LL |     fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                               ^^^^^^^^^^
+   |                    -----      ^^^^^^^^^^
+   |                    |
+   |                    hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
    |
-note: hidden type `Pin<&Foo>` captures lifetime smaller than the function body
-  --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31
+help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound
    |
-LL |     fn f(self: Pin<&Self>) -> impl Clone { self }
-   |                               ^^^^^^^^^^
+LL |     fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
+   |                                          ++++
 
 error: aborting due to previous error
 

From 2431540b62e87ec03aaf9e61c139cd1931546283 Mon Sep 17 00:00:00 2001
From: Oli Scherer 
Date: Sat, 25 Sep 2021 12:06:29 +0000
Subject: [PATCH 162/181] Remove unused enum variant

---
 .../src/infer/error_reporting/mod.rs          | 19 +------------------
 .../src/infer/lexical_region_resolve/mod.rs   |  6 ------
 2 files changed, 1 insertion(+), 24 deletions(-)

diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index 126c25f0c38c7..2173ff1f9ab03 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -386,21 +386,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
 
                         self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
                     }
-
-                    RegionResolutionError::MemberConstraintFailure {
-                        hidden_ty,
-                        member_region,
-                        span,
-                    } => {
-                        let hidden_ty = self.resolve_vars_if_possible(hidden_ty);
-                        unexpected_hidden_region_diagnostic(
-                            self.tcx,
-                            span,
-                            hidden_ty,
-                            member_region,
-                        )
-                        .emit();
-                    }
                 }
             }
         }
@@ -438,8 +423,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
             RegionResolutionError::GenericBoundFailure(..) => true,
             RegionResolutionError::ConcreteFailure(..)
             | RegionResolutionError::SubSupConflict(..)
-            | RegionResolutionError::UpperBoundUniverseConflict(..)
-            | RegionResolutionError::MemberConstraintFailure { .. } => false,
+            | RegionResolutionError::UpperBoundUniverseConflict(..) => false,
         };
 
         let mut errors = if errors.iter().all(|e| is_bound_failure(e)) {
@@ -454,7 +438,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
             RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
             RegionResolutionError::SubSupConflict(_, ref rvo, _, _, _, _) => rvo.span(),
             RegionResolutionError::UpperBoundUniverseConflict(_, ref rvo, _, _, _) => rvo.span(),
-            RegionResolutionError::MemberConstraintFailure { span, .. } => span,
         });
         errors
     }
diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
index d7e1b4545b8c1..4c9dcab26b14f 100644
--- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
+++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
@@ -19,7 +19,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
 use rustc_middle::ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic};
 use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
 use rustc_middle::ty::{Region, RegionVid};
-use rustc_span::Span;
 use std::fmt;
 
 /// This function performs lexical region resolution given a complete
@@ -108,11 +107,6 @@ pub enum RegionResolutionError<'tcx> {
         SubregionOrigin<'tcx>, // cause of the constraint
         Region<'tcx>,          // the placeholder `'b`
     ),
-
-    /// Indicates a failure of a `MemberConstraint`. These arise during
-    /// impl trait processing explicitly -- basically, the impl trait's hidden type
-    /// included some region that it was not supposed to.
-    MemberConstraintFailure { span: Span, hidden_ty: Ty<'tcx>, member_region: Region<'tcx> },
 }
 
 struct RegionAndOrigin<'tcx> {

From 2220fafa8c902efba544a880b77f5fe0f5525f37 Mon Sep 17 00:00:00 2001
From: Oli Scherer 
Date: Thu, 30 Sep 2021 15:11:05 +0000
Subject: [PATCH 163/181] Guarding a loop with a check that it never runs is
 useless

---
 compiler/rustc_trait_selection/src/opaque_types.rs | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs
index 0ccdcf68ee622..8fb2a71e464b1 100644
--- a/compiler/rustc_trait_selection/src/opaque_types.rs
+++ b/compiler/rustc_trait_selection/src/opaque_types.rs
@@ -334,14 +334,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
         );
 
         // (B) We can also generate outlives bounds that must be enforced.
-        let required_region_bounds = required_region_bounds(tcx, opaque_type, bounds);
-        if !required_region_bounds.is_empty() {
-            for required_region in required_region_bounds {
-                concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
-                    tcx,
-                    op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
-                });
-            }
+        for required_region in required_region_bounds(tcx, opaque_type, bounds) {
+            concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
+                tcx,
+                op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
+            });
         }
     }
 

From 4413f8c709b0ef71033c2c5e6c8921610ba61577 Mon Sep 17 00:00:00 2001
From: Oli Scherer 
Date: Sat, 16 Oct 2021 13:54:08 +0000
Subject: [PATCH 164/181] Member constraints already covered all of E0482
 already, so that error never occurred anymore

---
 .../src/error_codes/E0482.md                  |  6 ++-
 .../src/infer/error_reporting/note.rs         | 20 ---------
 compiler/rustc_infer/src/infer/mod.rs         |  4 --
 .../rustc_trait_selection/src/opaque_types.rs | 41 +------------------
 4 files changed, 6 insertions(+), 65 deletions(-)

diff --git a/compiler/rustc_error_codes/src/error_codes/E0482.md b/compiler/rustc_error_codes/src/error_codes/E0482.md
index 58ebf43cc98ce..ad363816e1890 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0482.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0482.md
@@ -1,8 +1,10 @@
+#### Note: this error code is no longer emitted by the compiler.
+
 A lifetime of a returned value does not outlive the function call.
 
 Erroneous code example:
 
-```compile_fail,E0482
+```compile_fail,E0700
 fn prefix<'a>(
     words: impl Iterator
 ) -> impl Iterator { // error!
@@ -41,7 +43,7 @@ fn prefix(
 
 A similar lifetime problem might arise when returning closures:
 
-```compile_fail,E0482
+```compile_fail,E0700
 fn foo(
     x: &mut Vec
 ) -> impl FnMut(&mut Vec) -> &[i32] { // error!
diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs
index 5f99a23f86e88..167a8893a11c8 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/note.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs
@@ -53,9 +53,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
             infer::RelateObjectBound(span) => {
                 label_or_note(span, "...so that it can be closed over into an object");
             }
-            infer::CallReturn(span) => {
-                label_or_note(span, "...so that return value is valid for the call");
-            }
             infer::DataBorrowed(ty, span) => {
                 label_or_note(
                     span,
@@ -281,23 +278,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 );
                 err
             }
-            infer::CallReturn(span) => {
-                let mut err = struct_span_err!(
-                    self.tcx.sess,
-                    span,
-                    E0482,
-                    "lifetime of return value does not outlive the function call"
-                );
-                note_and_explain_region(
-                    self.tcx,
-                    &mut err,
-                    "the return value is only valid for ",
-                    sup,
-                    "",
-                    None,
-                );
-                err
-            }
             infer::DataBorrowed(ty, span) => {
                 let mut err = struct_span_err!(
                     self.tcx.sess,
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs
index 18836d5a68e26..6b905f67e683f 100644
--- a/compiler/rustc_infer/src/infer/mod.rs
+++ b/compiler/rustc_infer/src/infer/mod.rs
@@ -417,9 +417,6 @@ pub enum SubregionOrigin<'tcx> {
     /// (&'a &'b T) where a >= b
     ReferenceOutlivesReferent(Ty<'tcx>, Span),
 
-    /// Region in return type of invoked fn must enclose call
-    CallReturn(Span),
-
     /// Comparing the signature and requirements of an impl method against
     /// the containing trait.
     CompareImplMethodObligation {
@@ -1803,7 +1800,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
             ReborrowUpvar(a, _) => a,
             DataBorrowed(_, a) => a,
             ReferenceOutlivesReferent(_, a) => a,
-            CallReturn(a) => a,
             CompareImplMethodObligation { span, .. } => span,
             CompareImplTypeObligation { span, .. } => span,
         }
diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs
index 8fb2a71e464b1..6c5e6b1cfc385 100644
--- a/compiler/rustc_trait_selection/src/opaque_types.rs
+++ b/compiler/rustc_trait_selection/src/opaque_types.rs
@@ -6,7 +6,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
 use rustc_infer::infer::opaque_types::OpaqueTypeDecl;
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc_infer::infer::{self, InferCtxt, InferOk};
+use rustc_infer::infer::{InferCtxt, InferOk};
 use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
 use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst};
 use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
@@ -295,36 +295,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
             hir::OpaqueTyOrigin::TyAlias => 0,
         };
 
-        let span = tcx.def_span(def_id);
-
-        // Check if the `impl Trait` bounds include region bounds.
-        // For example, this would be true for:
-        //
-        //     fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
-        //
-        // but false for:
-        //
-        //     fn foo<'c>() -> impl Trait<'c>
-        //
-        // unless `Trait` was declared like:
-        //
-        //     trait Trait<'c>: 'c
-        //
-        // in which case it would be true.
-        //
-        // This is used during regionck to decide whether we need to
-        // impose any additional constraints to ensure that region
-        // variables in `concrete_ty` wind up being constrained to
-        // something from `substs` (or, at minimum, things that outlive
-        // the fn body). (Ultimately, writeback is responsible for this
-        // check.)
-        let bounds = tcx.explicit_item_bounds(def_id);
-        debug!("{:#?}", bounds);
-        let bounds = bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs));
-        debug!("{:#?}", bounds);
-        let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
-
-        // (A) The regions that appear in the hidden type must be equal to
+        // The regions that appear in the hidden type must be equal to
         // one of the regions in scope for the opaque type.
         self.generate_member_constraint(
             concrete_ty,
@@ -332,14 +303,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
             opaque_type_key,
             first_own_region,
         );
-
-        // (B) We can also generate outlives bounds that must be enforced.
-        for required_region in required_region_bounds(tcx, opaque_type, bounds) {
-            concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
-                tcx,
-                op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
-            });
-        }
     }
 
     /// As a fallback, we sometimes generate an "in constraint". For

From e2453dc2ff8ea5984b9eba40af8f8d13ee4e5da5 Mon Sep 17 00:00:00 2001
From: Yuki Okushi 
Date: Tue, 19 Oct 2021 02:33:38 +0900
Subject: [PATCH 165/181] Revert "Rollup merge of #86011 -
 tlyu:correct-sized-bound-spans, r=estebank"

This reverts commit 36a1076d24697621a3bb67ef654b4eb79647aa54, reversing
changes made to e1e9319d93aea755c444c8f8ff863b0936d7a4b6.
---
 compiler/rustc_typeck/src/bounds.rs           |  9 ++++---
 ...rives-span-Hash-enum-struct-variant.stderr |  2 +-
 .../ui/derives/derives-span-Hash-enum.stderr  |  2 +-
 .../derives/derives-span-Hash-struct.stderr   |  2 +-
 .../derives-span-Hash-tuple-struct.stderr     |  2 +-
 .../issue-74816.stderr                        | 24 +++++++++----------
 .../issue-86483.stderr                        |  4 ++--
 ...e-param-can-reference-self-in-trait.stderr |  4 ++--
 src/test/ui/issues/issue-16966.stderr         | 14 ++---------
 src/test/ui/issues/issue-21160.stderr         |  2 +-
 src/test/ui/issues/issue-23122-2.stderr       |  2 +-
 src/test/ui/issues/issue-54954.stderr         |  4 ++--
 .../trait-where-clause.stderr                 | 12 +++++-----
 .../suggestions/issue-84973-blacklist.stderr  |  4 ++--
 .../ui/suggestions/slice-issue-87994.stderr   |  8 +++----
 .../generic_duplicate_param_use9.rs           |  2 +-
 .../generic_duplicate_param_use9.stderr       | 24 +++++++++----------
 src/test/ui/unique-object-noncopyable.stderr  |  4 ++--
 .../ui/unsized/unsized-bare-typaram.stderr    |  4 ++--
 src/test/ui/unsized/unsized-struct.stderr     |  4 ++--
 20 files changed, 61 insertions(+), 72 deletions(-)

diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs
index ff04e07acc4f6..24474e163b9da 100644
--- a/compiler/rustc_typeck/src/bounds.rs
+++ b/compiler/rustc_typeck/src/bounds.rs
@@ -64,16 +64,16 @@ impl<'tcx> Bounds<'tcx> {
             })
         });
 
-        self.region_bounds
-            .iter()
-            .map(|&(region_bound, span)| {
+        sized_predicate
+            .into_iter()
+            .chain(self.region_bounds.iter().map(|&(region_bound, span)| {
                 (
                     region_bound
                         .map_bound(|region_bound| ty::OutlivesPredicate(param_ty, region_bound))
                         .to_predicate(tcx),
                     span,
                 )
-            })
+            }))
             .chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| {
                 let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx);
                 (predicate, span)
@@ -83,7 +83,6 @@ impl<'tcx> Bounds<'tcx> {
                     .iter()
                     .map(|&(projection, span)| (projection.to_predicate(tcx), span)),
             )
-            .chain(sized_predicate.into_iter())
             .collect()
     }
 }
diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr
index 89186817e099c..47c7f1c2c3340 100644
--- a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr
+++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr
@@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash`
   --> $SRC_DIR/core/src/hash/mod.rs:LL:COL
    |
 LL |     fn hash(&self, state: &mut H);
-   |                ^^^^^^ required by this bound in `std::hash::Hash::hash`
+   |             ^ required by this bound in `std::hash::Hash::hash`
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
diff --git a/src/test/ui/derives/derives-span-Hash-enum.stderr b/src/test/ui/derives/derives-span-Hash-enum.stderr
index 6abb7e78b1330..92f084b58e35b 100644
--- a/src/test/ui/derives/derives-span-Hash-enum.stderr
+++ b/src/test/ui/derives/derives-span-Hash-enum.stderr
@@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash`
   --> $SRC_DIR/core/src/hash/mod.rs:LL:COL
    |
 LL |     fn hash(&self, state: &mut H);
-   |                ^^^^^^ required by this bound in `std::hash::Hash::hash`
+   |             ^ required by this bound in `std::hash::Hash::hash`
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
diff --git a/src/test/ui/derives/derives-span-Hash-struct.stderr b/src/test/ui/derives/derives-span-Hash-struct.stderr
index 405285f883810..c57cebe04ebcb 100644
--- a/src/test/ui/derives/derives-span-Hash-struct.stderr
+++ b/src/test/ui/derives/derives-span-Hash-struct.stderr
@@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash`
   --> $SRC_DIR/core/src/hash/mod.rs:LL:COL
    |
 LL |     fn hash(&self, state: &mut H);
-   |                ^^^^^^ required by this bound in `std::hash::Hash::hash`
+   |             ^ required by this bound in `std::hash::Hash::hash`
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr
index aa12314c05176..200937f0c9fc3 100644
--- a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr
+++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr
@@ -11,7 +11,7 @@ note: required by a bound in `std::hash::Hash::hash`
   --> $SRC_DIR/core/src/hash/mod.rs:LL:COL
    |
 LL |     fn hash(&self, state: &mut H);
-   |                ^^^^^^ required by this bound in `std::hash::Hash::hash`
+   |             ^ required by this bound in `std::hash::Hash::hash`
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
diff --git a/src/test/ui/generic-associated-types/issue-74816.stderr b/src/test/ui/generic-associated-types/issue-74816.stderr
index d5cc5cfbe912d..49ae87cbfe9dc 100644
--- a/src/test/ui/generic-associated-types/issue-74816.stderr
+++ b/src/test/ui/generic-associated-types/issue-74816.stderr
@@ -1,34 +1,34 @@
-error[E0277]: the size for values of type `Self` cannot be known at compilation time
+error[E0277]: the trait bound `Self: Trait1` is not satisfied
   --> $DIR/issue-74816.rs:9:5
    |
 LL |     type Associated: Trait1 = Self;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait1` is not implemented for `Self`
    |
 note: required by a bound in `Trait2::Associated`
-  --> $DIR/issue-74816.rs:9:5
+  --> $DIR/issue-74816.rs:9:22
    |
 LL |     type Associated: Trait1 = Self;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait2::Associated`
+   |                      ^^^^^^ required by this bound in `Trait2::Associated`
 help: consider further restricting `Self`
    |
-LL | trait Trait2: Sized {
-   |             +++++++
+LL | trait Trait2: Trait1 {
+   |             ++++++++
 
-error[E0277]: the trait bound `Self: Trait1` is not satisfied
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
   --> $DIR/issue-74816.rs:9:5
    |
 LL |     type Associated: Trait1 = Self;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait1` is not implemented for `Self`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
    |
 note: required by a bound in `Trait2::Associated`
-  --> $DIR/issue-74816.rs:9:22
+  --> $DIR/issue-74816.rs:9:5
    |
 LL |     type Associated: Trait1 = Self;
-   |                      ^^^^^^ required by this bound in `Trait2::Associated`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait2::Associated`
 help: consider further restricting `Self`
    |
-LL | trait Trait2: Trait1 {
-   |             ++++++++
+LL | trait Trait2: Sized {
+   |             +++++++
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/generic-associated-types/issue-86483.stderr b/src/test/ui/generic-associated-types/issue-86483.stderr
index 5d0fcbca552d6..d6978794e1e95 100644
--- a/src/test/ui/generic-associated-types/issue-86483.stderr
+++ b/src/test/ui/generic-associated-types/issue-86483.stderr
@@ -20,13 +20,13 @@ LL |     for<'a> T: 'a,
    |                ^^
 
 error[E0311]: the parameter type `T` may not live long enough
-  --> $DIR/issue-86483.rs:9:19
+  --> $DIR/issue-86483.rs:9:5
    |
 LL | pub trait IceIce
    |                  - help: consider adding an explicit lifetime bound...: `T: 'a`
 ...
 LL |     type Ice<'v>: IntoIterator;
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
    |
 note: ...that is required by this bound
   --> $DIR/issue-86483.rs:7:16
diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr
index 50f90618e4db7..2c397d80b013e 100644
--- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr
+++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr
@@ -6,10 +6,10 @@ LL | impl Tsized for () {}
    |
    = help: the trait `Sized` is not implemented for `[()]`
 note: required by a bound in `Tsized`
-  --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:17
+  --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14
    |
 LL | trait Tsized {}
-   |                 ^^^^^ required by this bound in `Tsized`
+   |              ^ required by this bound in `Tsized`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr
index 7597824e08f9d..09e20c0c77731 100644
--- a/src/test/ui/issues/issue-16966.stderr
+++ b/src/test/ui/issues/issue-16966.stderr
@@ -1,21 +1,11 @@
-error[E0283]: type annotations needed
+error[E0282]: type annotations needed
   --> $DIR/issue-16966.rs:2:5
    |
 LL |     panic!(std::default::Default::default());
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` declared on the function `begin_panic`
    |
-   = note: cannot satisfy `_: Any`
-note: required by a bound in `begin_panic`
-  --> $SRC_DIR/std/src/panicking.rs:LL:COL
-   |
-LL | pub fn begin_panic(msg: M) -> ! {
-   |                       ^^^ required by this bound in `begin_panic`
    = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
-help: consider specifying the type argument in the function call
-   |
-LL |         $crate::rt::begin_panic::($msg)
-   |                                +++++
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0283`.
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/issues/issue-21160.stderr b/src/test/ui/issues/issue-21160.stderr
index c2f6fc21acd7f..92742b50619e0 100644
--- a/src/test/ui/issues/issue-21160.stderr
+++ b/src/test/ui/issues/issue-21160.stderr
@@ -10,7 +10,7 @@ note: required by a bound in `std::hash::Hash::hash`
   --> $SRC_DIR/core/src/hash/mod.rs:LL:COL
    |
 LL |     fn hash(&self, state: &mut H);
-   |                ^^^^^^ required by this bound in `std::hash::Hash::hash`
+   |             ^ required by this bound in `std::hash::Hash::hash`
    = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-23122-2.stderr b/src/test/ui/issues/issue-23122-2.stderr
index e6cec722978dd..b345e90178742 100644
--- a/src/test/ui/issues/issue-23122-2.stderr
+++ b/src/test/ui/issues/issue-23122-2.stderr
@@ -1,4 +1,4 @@
-error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Next`
+error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized`
   --> $DIR/issue-23122-2.rs:9:17
    |
 LL |     type Next =  as Next>::Next;
diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr
index d88397fd7e15d..df76a985559d0 100644
--- a/src/test/ui/issues/issue-54954.stderr
+++ b/src/test/ui/issues/issue-54954.stderr
@@ -12,10 +12,10 @@ LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
    |
    = note: cannot satisfy `_: Tt`
 note: required by a bound in `Tt::const_val`
-  --> $DIR/issue-54954.rs:5:27
+  --> $DIR/issue-54954.rs:5:24
    |
 LL |     const fn const_val() -> usize {
-   |                           ^^^^^ required by this bound in `Tt::const_val`
+   |                        ^ required by this bound in `Tt::const_val`
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
index 4a4544c16c941..fffb91f98700b 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
@@ -20,11 +20,11 @@ error[E0277]: the trait bound `T: Bar` is not satisfied
 LL |     T::c::();
    |     ^^^^^^^^^ the trait `Bar` is not implemented for `T`
    |
-note: required by a bound in `Foo::c`
-  --> $DIR/trait-where-clause.rs:9:10
+note: required by `Foo::c`
+  --> $DIR/trait-where-clause.rs:9:5
    |
 LL |     fn c();
-   |          ^ required by this bound in `Foo::c`
+   |     ^^^^^^^^^^^^^^^^^^^^^^
 help: consider further restricting this bound
    |
 LL | const fn test1() {
@@ -52,11 +52,11 @@ error[E0277]: the trait bound `T: Bar` is not satisfied
 LL |     T::c::();
    |     ^^^^^^^^^ the trait `Bar` is not implemented for `T`
    |
-note: required by a bound in `Foo::c`
-  --> $DIR/trait-where-clause.rs:9:10
+note: required by `Foo::c`
+  --> $DIR/trait-where-clause.rs:9:5
    |
 LL |     fn c();
-   |          ^ required by this bound in `Foo::c`
+   |     ^^^^^^^^^^^^^^^^^^^^^^
 help: consider further restricting this bound
    |
 LL | fn test3() {
diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr
index 58075ed7caebc..ae55c96702ada 100644
--- a/src/test/ui/suggestions/issue-84973-blacklist.stderr
+++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr
@@ -49,10 +49,10 @@ LL |     f_sized(*ref_cl);
    |
    = help: the trait `Sized` is not implemented for `dyn Fn()`
 note: required by a bound in `f_sized`
-  --> $DIR/issue-84973-blacklist.rs:9:15
+  --> $DIR/issue-84973-blacklist.rs:9:12
    |
 LL | fn f_sized(t: T) {}
-   |               ^^^^^ required by this bound in `f_sized`
+   |            ^ required by this bound in `f_sized`
 
 error[E0277]: `Rc<{integer}>` cannot be sent between threads safely
   --> $DIR/issue-84973-blacklist.rs:27:12
diff --git a/src/test/ui/suggestions/slice-issue-87994.stderr b/src/test/ui/suggestions/slice-issue-87994.stderr
index 9e0d4ced01153..0275fd475d8c6 100644
--- a/src/test/ui/suggestions/slice-issue-87994.stderr
+++ b/src/test/ui/suggestions/slice-issue-87994.stderr
@@ -1,4 +1,4 @@
-error[E0277]: `[i32]` is not an iterator
+error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
   --> $DIR/slice-issue-87994.rs:3:12
    |
 LL |   for _ in v[1..] {
@@ -18,7 +18,7 @@ LL |   for _ in &v[1..] {
 LL |   for _ in &mut v[1..] {
    |            ++++
 
-error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
+error[E0277]: `[i32]` is not an iterator
   --> $DIR/slice-issue-87994.rs:3:12
    |
 LL |   for _ in v[1..] {
@@ -38,7 +38,7 @@ LL |   for _ in &v[1..] {
 LL |   for _ in &mut v[1..] {
    |            ++++
 
-error[E0277]: `[K]` is not an iterator
+error[E0277]: the size for values of type `[K]` cannot be known at compilation time
   --> $DIR/slice-issue-87994.rs:11:13
    |
 LL |   for i2 in v2[1..] {
@@ -58,7 +58,7 @@ LL |   for i2 in &v2[1..] {
 LL |   for i2 in &mut v2[1..] {
    |             ++++
 
-error[E0277]: the size for values of type `[K]` cannot be known at compilation time
+error[E0277]: `[K]` is not an iterator
   --> $DIR/slice-issue-87994.rs:11:13
    |
 LL |   for i2 in v2[1..] {
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs
index 4baf198b12fae..747081933172b 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs
@@ -5,7 +5,7 @@ use std::fmt::Debug;
 fn main() {}
 
 type Two = impl Debug;
-//~^ ERROR the trait bound `A: Foo` is not satisfied
+//~^ ERROR the trait bound `A: Foo` is not satisfied in `(A, B, ::Bar)`
 //~| ERROR `A` doesn't implement `Debug`
 //~| ERROR `B` doesn't implement `Debug`
 
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr
index f21e036edc2ca..a8eb53a50e38b 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr
@@ -10,6 +10,18 @@ note: previous use here
 LL | fn two(t: T, u: U) -> Two {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+error[E0277]: the trait bound `A: Foo` is not satisfied in `(A, B, ::Bar)`
+  --> $DIR/generic_duplicate_param_use9.rs:7:18
+   |
+LL | type Two = impl Debug;
+   |                  ^^^^^^^^^^ within `(A, B, ::Bar)`, the trait `Foo` is not implemented for `A`
+   |
+   = note: required because it appears within the type `(A, B, ::Bar)`
+help: consider restricting type parameter `A`
+   |
+LL | type Two = impl Debug;
+   |           +++++
+
 error[E0277]: `A` doesn't implement `Debug`
   --> $DIR/generic_duplicate_param_use9.rs:7:18
    |
@@ -34,18 +46,6 @@ help: consider restricting type parameter `B`
 LL | type Two = impl Debug;
    |              +++++++++++++++++
 
-error[E0277]: the trait bound `A: Foo` is not satisfied
-  --> $DIR/generic_duplicate_param_use9.rs:7:18
-   |
-LL | type Two = impl Debug;
-   |                  ^^^^^^^^^^ the trait `Foo` is not implemented for `A`
-   |
-   = note: required because of the requirements on the impl of `Debug` for `(A, B, ::Bar)`
-help: consider restricting type parameter `A`
-   |
-LL | type Two = impl Debug;
-   |           +++++
-
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/unique-object-noncopyable.stderr b/src/test/ui/unique-object-noncopyable.stderr
index 8626b726f47c4..5c40787febfb7 100644
--- a/src/test/ui/unique-object-noncopyable.stderr
+++ b/src/test/ui/unique-object-noncopyable.stderr
@@ -19,10 +19,10 @@ LL | | >(Unique, A);
    | |________________- doesn't satisfy `Box: Clone`
    |
    = note: the following trait bounds were not satisfied:
-           `dyn Foo: Clone`
-           which is required by `Box: Clone`
            `dyn Foo: Sized`
            which is required by `Box: Clone`
+           `dyn Foo: Clone`
+           which is required by `Box: Clone`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/unsized/unsized-bare-typaram.stderr b/src/test/ui/unsized/unsized-bare-typaram.stderr
index 0dd439e14e3cd..531e9b4c9c955 100644
--- a/src/test/ui/unsized/unsized-bare-typaram.stderr
+++ b/src/test/ui/unsized/unsized-bare-typaram.stderr
@@ -7,10 +7,10 @@ LL | fn foo() { bar::() }
    |        this type parameter needs to be `std::marker::Sized`
    |
 note: required by a bound in `bar`
-  --> $DIR/unsized-bare-typaram.rs:1:11
+  --> $DIR/unsized-bare-typaram.rs:1:8
    |
 LL | fn bar() { }
-   |           ^^^^^ required by this bound in `bar`
+   |        ^ required by this bound in `bar`
 help: consider removing the `?Sized` bound to make the type parameter `Sized`
    |
 LL - fn foo() { bar::() }
diff --git a/src/test/ui/unsized/unsized-struct.stderr b/src/test/ui/unsized/unsized-struct.stderr
index 88ba7567402db..1c70a840c77dc 100644
--- a/src/test/ui/unsized/unsized-struct.stderr
+++ b/src/test/ui/unsized/unsized-struct.stderr
@@ -38,10 +38,10 @@ note: required because it appears within the type `Bar`
 LL | struct Bar { data: T }
    |        ^^^
 note: required by a bound in `is_sized`
-  --> $DIR/unsized-struct.rs:1:15
+  --> $DIR/unsized-struct.rs:1:13
    |
 LL | fn is_sized() { }
-   |               ^^^^^ required by this bound in `is_sized`
+   |             ^ required by this bound in `is_sized`
 help: consider removing the `?Sized` bound to make the type parameter `Sized`
    |
 LL - fn bar2() { is_sized::>() }

From 101a81b807a20c2fb30508fd5a1103e1661e45ea Mon Sep 17 00:00:00 2001
From: Yuki Okushi 
Date: Tue, 19 Oct 2021 02:43:54 +0900
Subject: [PATCH 166/181] Add a regression test for #89935

---
 src/test/ui/typeck/issue-89935.rs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 src/test/ui/typeck/issue-89935.rs

diff --git a/src/test/ui/typeck/issue-89935.rs b/src/test/ui/typeck/issue-89935.rs
new file mode 100644
index 0000000000000..03f8f09a72201
--- /dev/null
+++ b/src/test/ui/typeck/issue-89935.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+trait Foo: Baz {}
+trait Bar {}
+trait Baz: Bar {
+    fn bar(&self);
+}
+
+impl Bar for T {}
+impl Baz for T {
+    fn bar(&self) {}
+}
+
+fn accept_foo(x: Box) {
+    x.bar();
+}
+
+fn main() {}

From 171cbc01efe103f255f83afa2a70768e1d373edb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= 
Date: Sun, 17 Oct 2021 00:00:00 +0000
Subject: [PATCH 167/181] Rename `needs_drop` to `needs_non_const_drop`

---
 .../src/transform/check_consts/check.rs       | 22 +++++++++----------
 .../check_consts/post_drop_elaboration.rs     |  2 +-
 .../src/transform/check_consts/qualifs.rs     |  4 ++--
 compiler/rustc_middle/src/mir/query.rs        |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
index d704c4335c754..8cd75dd8e2841 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
@@ -39,7 +39,7 @@ type QualifResults<'mir, 'tcx, Q> =
 #[derive(Default)]
 pub struct Qualifs<'mir, 'tcx> {
     has_mut_interior: Option>,
-    needs_drop: Option>,
+    needs_non_const_drop: Option>,
     indirectly_mutable: Option>,
 }
 
@@ -70,10 +70,10 @@ impl Qualifs<'mir, 'tcx> {
         indirectly_mutable.get().contains(local)
     }
 
-    /// Returns `true` if `local` is `NeedsDrop` at the given `Location`.
+    /// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`.
     ///
     /// Only updates the cursor if absolutely necessary
-    pub fn needs_drop(
+    pub fn needs_non_const_drop(
         &mut self,
         ccx: &'mir ConstCx<'mir, 'tcx>,
         local: Local,
@@ -84,7 +84,7 @@ impl Qualifs<'mir, 'tcx> {
             return false;
         }
 
-        let needs_drop = self.needs_drop.get_or_insert_with(|| {
+        let needs_non_const_drop = self.needs_non_const_drop.get_or_insert_with(|| {
             let ConstCx { tcx, body, .. } = *ccx;
 
             FlowSensitiveAnalysis::new(NeedsNonConstDrop, ccx)
@@ -93,8 +93,8 @@ impl Qualifs<'mir, 'tcx> {
                 .into_results_cursor(&body)
         });
 
-        needs_drop.seek_before_primary_effect(location);
-        needs_drop.get().contains(local) || self.indirectly_mutable(ccx, local, location)
+        needs_non_const_drop.seek_before_primary_effect(location);
+        needs_non_const_drop.get().contains(local) || self.indirectly_mutable(ccx, local, location)
     }
 
     /// Returns `true` if `local` is `HasMutInterior` at the given `Location`.
@@ -172,7 +172,7 @@ impl Qualifs<'mir, 'tcx> {
         };
 
         ConstQualifs {
-            needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
+            needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
             has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
             custom_eq,
             error_occured,
@@ -999,7 +999,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
             }
 
             // Forbid all `Drop` terminators unless the place being dropped is a local with no
-            // projections that cannot be `NeedsDrop`.
+            // projections that cannot be `NeedsNonConstDrop`.
             TerminatorKind::Drop { place: dropped_place, .. }
             | TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
                 // If we are checking live drops after drop-elaboration, don't emit duplicate
@@ -1019,15 +1019,15 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
                     return;
                 }
 
-                let needs_drop = if let Some(local) = dropped_place.as_local() {
+                let needs_non_const_drop = if let Some(local) = dropped_place.as_local() {
                     // Use the span where the local was declared as the span of the drop error.
                     err_span = self.body.local_decls[local].source_info.span;
-                    self.qualifs.needs_drop(self.ccx, local, location)
+                    self.qualifs.needs_non_const_drop(self.ccx, local, location)
                 } else {
                     true
                 };
 
-                if needs_drop {
+                if needs_non_const_drop {
                     self.check_op_spanned(
                         ops::LiveDrop { dropped_at: Some(terminator.source_info.span) },
                         err_span,
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs
index 1a8c8b1c78d08..7a2be3c3bad32 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs
@@ -97,7 +97,7 @@ impl Visitor<'tcx> for CheckLiveDrops<'mir, 'tcx> {
                 // `src/test/ui/consts/control-flow/drop-pass.rs`; e.g., when an `Option>` is
                 // initialized with `None` and never changed, it still emits drop glue.
                 // Hence we additionally check the qualifs here to allow more code to pass.
-                if self.qualifs.needs_drop(self.ccx, dropped_place.local, location) {
+                if self.qualifs.needs_non_const_drop(self.ccx, dropped_place.local, location) {
                     // Use the span where the dropped local was declared for the error.
                     let span = self.body.local_decls[dropped_place.local].source_info.span;
                     self.check_live_drop(span);
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
index 5eb7d7a91cc76..689aa0993711f 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
@@ -21,7 +21,7 @@ pub fn in_any_value_of_ty(
 ) -> ConstQualifs {
     ConstQualifs {
         has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
-        needs_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
+        needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
         custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
         error_occured,
     }
@@ -108,7 +108,7 @@ impl Qualif for NeedsNonConstDrop {
     const IS_CLEARED_ON_MOVE: bool = true;
 
     fn in_qualifs(qualifs: &ConstQualifs) -> bool {
-        qualifs.needs_drop
+        qualifs.needs_non_const_drop
     }
 
     fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, mut ty: Ty<'tcx>) -> bool {
diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs
index d5541d7890c77..98f116a16e2b2 100644
--- a/compiler/rustc_middle/src/mir/query.rs
+++ b/compiler/rustc_middle/src/mir/query.rs
@@ -224,7 +224,7 @@ pub struct BorrowCheckResult<'tcx> {
 #[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
 pub struct ConstQualifs {
     pub has_mut_interior: bool,
-    pub needs_drop: bool,
+    pub needs_non_const_drop: bool,
     pub custom_eq: bool,
     pub error_occured: Option,
 }

From 915a581bcb3d9b7e1e2ef0da4fbfbae6b1a7fa7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= 
Date: Sun, 17 Oct 2021 00:00:00 +0000
Subject: [PATCH 168/181] Do not promote values with const drop that need to be
 dropped

Changes from #88558 allowed using `~const Drop` in constants by
introducing a new `NeedsNonConstDrop` qualif.

The new qualif was also used for promotion purposes, and allowed
promotion to happen for values that needs to be dropped but which
do have a const drop impl.

Since for promoted the drop implementation is never executed,
this lead to observable change in behaviour. For example:

```rust

struct Panic();

impl const Drop for Panic {
    fn drop(&mut self) {
        panic!();
    }
}

fn main() {
    let _ = &Panic();
}
```

Restore the use of `NeedsDrop` qualif during promotion to avoid the issue.
---
 .../src/transform/check_consts/check.rs       | 31 ++++++++++++++++++-
 .../src/transform/check_consts/qualifs.rs     | 29 +++++++++++++++--
 .../src/transform/promote_consts.rs           |  2 +-
 compiler/rustc_middle/src/mir/query.rs        |  1 +
 src/test/ui/consts/promoted-const-drop.rs     | 15 +++++++++
 src/test/ui/consts/promoted-const-drop.stderr | 24 ++++++++++++++
 6 files changed, 97 insertions(+), 5 deletions(-)
 create mode 100644 src/test/ui/consts/promoted-const-drop.rs
 create mode 100644 src/test/ui/consts/promoted-const-drop.stderr

diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
index 8cd75dd8e2841..03e60deea2783 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs
@@ -22,7 +22,7 @@ use std::mem;
 use std::ops::Deref;
 
 use super::ops::{self, NonConstOp, Status};
-use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop};
+use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
 use super::resolver::FlowSensitiveAnalysis;
 use super::{is_lang_panic_fn, is_lang_special_const_fn, ConstCx, Qualif};
 use crate::const_eval::is_unstable_const_fn;
@@ -39,6 +39,7 @@ type QualifResults<'mir, 'tcx, Q> =
 #[derive(Default)]
 pub struct Qualifs<'mir, 'tcx> {
     has_mut_interior: Option>,
+    needs_drop: Option>,
     needs_non_const_drop: Option>,
     indirectly_mutable: Option>,
 }
@@ -70,6 +71,33 @@ impl Qualifs<'mir, 'tcx> {
         indirectly_mutable.get().contains(local)
     }
 
+    /// Returns `true` if `local` is `NeedsDrop` at the given `Location`.
+    ///
+    /// Only updates the cursor if absolutely necessary
+    pub fn needs_drop(
+        &mut self,
+        ccx: &'mir ConstCx<'mir, 'tcx>,
+        local: Local,
+        location: Location,
+    ) -> bool {
+        let ty = ccx.body.local_decls[local].ty;
+        if !NeedsDrop::in_any_value_of_ty(ccx, ty) {
+            return false;
+        }
+
+        let needs_drop = self.needs_drop.get_or_insert_with(|| {
+            let ConstCx { tcx, body, .. } = *ccx;
+
+            FlowSensitiveAnalysis::new(NeedsDrop, ccx)
+                .into_engine(tcx, &body)
+                .iterate_to_fixpoint()
+                .into_results_cursor(&body)
+        });
+
+        needs_drop.seek_before_primary_effect(location);
+        needs_drop.get().contains(local) || self.indirectly_mutable(ccx, local, location)
+    }
+
     /// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`.
     ///
     /// Only updates the cursor if absolutely necessary
@@ -172,6 +200,7 @@ impl Qualifs<'mir, 'tcx> {
         };
 
         ConstQualifs {
+            needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
             needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
             has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
             custom_eq,
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
index 689aa0993711f..dd2980d40ade7 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
@@ -21,6 +21,7 @@ pub fn in_any_value_of_ty(
 ) -> ConstQualifs {
     ConstQualifs {
         has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
+        needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
         needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
         custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
         error_occured,
@@ -98,9 +99,31 @@ impl Qualif for HasMutInterior {
 }
 
 /// Constant containing an ADT that implements `Drop`.
-/// This must be ruled out (a) because we cannot run `Drop` during compile-time
-/// as that might not be a `const fn`, and (b) because implicit promotion would
-/// remove side-effects that occur as part of dropping that value.
+/// This must be ruled out because implicit promotion would remove side-effects
+/// that occur as part of dropping that value. N.B., the implicit promotion has
+/// to reject const Drop implementations because even if side-effects are ruled
+/// out through other means, the execution of the drop could diverge.
+pub struct NeedsDrop;
+
+impl Qualif for NeedsDrop {
+    const ANALYSIS_NAME: &'static str = "flow_needs_drop";
+    const IS_CLEARED_ON_MOVE: bool = true;
+
+    fn in_qualifs(qualifs: &ConstQualifs) -> bool {
+        qualifs.needs_drop
+    }
+
+    fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
+        ty.needs_drop(cx.tcx, cx.param_env)
+    }
+
+    fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
+        adt.has_dtor(cx.tcx)
+    }
+}
+
+/// Constant containing an ADT that implements non-const `Drop`.
+/// This must be ruled out because we cannot run `Drop` during compile-time.
 pub struct NeedsNonConstDrop;
 
 impl Qualif for NeedsNonConstDrop {
diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs
index 7cfe3d7f809e9..ebcc8213c604b 100644
--- a/compiler/rustc_const_eval/src/transform/promote_consts.rs
+++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs
@@ -230,7 +230,7 @@ impl<'tcx> Validator<'_, 'tcx> {
 
                         // We cannot promote things that need dropping, since the promoted value
                         // would not get dropped.
-                        if self.qualif_local::(place.local) {
+                        if self.qualif_local::(place.local) {
                             return Err(Unpromotable);
                         }
 
diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs
index 98f116a16e2b2..cb3f3850958ec 100644
--- a/compiler/rustc_middle/src/mir/query.rs
+++ b/compiler/rustc_middle/src/mir/query.rs
@@ -224,6 +224,7 @@ pub struct BorrowCheckResult<'tcx> {
 #[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
 pub struct ConstQualifs {
     pub has_mut_interior: bool,
+    pub needs_drop: bool,
     pub needs_non_const_drop: bool,
     pub custom_eq: bool,
     pub error_occured: Option,
diff --git a/src/test/ui/consts/promoted-const-drop.rs b/src/test/ui/consts/promoted-const-drop.rs
new file mode 100644
index 0000000000000..c896c011ab66a
--- /dev/null
+++ b/src/test/ui/consts/promoted-const-drop.rs
@@ -0,0 +1,15 @@
+#![feature(const_trait_impl)]
+#![feature(const_mut_refs)]
+
+struct A();
+
+impl const Drop for A {
+    fn drop(&mut self) {}
+}
+
+const C: A = A();
+
+fn main() {
+    let _: &'static A = &A(); //~ ERROR temporary value dropped while borrowed
+    let _: &'static [A] = &[C]; //~ ERROR temporary value dropped while borrowed
+}
diff --git a/src/test/ui/consts/promoted-const-drop.stderr b/src/test/ui/consts/promoted-const-drop.stderr
new file mode 100644
index 0000000000000..184ba0ea3b377
--- /dev/null
+++ b/src/test/ui/consts/promoted-const-drop.stderr
@@ -0,0 +1,24 @@
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/promoted-const-drop.rs:13:26
+   |
+LL |     let _: &'static A = &A();
+   |            ----------    ^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
+LL |     let _: &'static [A] = &[C];
+LL | }
+   | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/promoted-const-drop.rs:14:28
+   |
+LL |     let _: &'static [A] = &[C];
+   |            ------------    ^^^ creates a temporary which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
+LL | }
+   | - temporary value is freed at the end of this statement
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0716`.

From 1519ca99d8020f4d2e4fb04a3eb425b97e457d18 Mon Sep 17 00:00:00 2001
From: moxian 
Date: Tue, 19 Oct 2021 00:03:51 +0000
Subject: [PATCH 169/181] Tiny tweak to Iterator::unzip() doc comment example.

It's easier to figure out what it's doing and which output
elements map to which input ones if the matrix we are dealing
with is rectangular 2x3 rather than square 2x2.
---
 library/core/src/iter/traits/iterator.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index f53d6cac7ed98..d957a7527cf58 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -2837,12 +2837,12 @@ pub trait Iterator {
     /// Basic usage:
     ///
     /// ```
-    /// let a = [(1, 2), (3, 4)];
+    /// let a = [(1, 2), (3, 4), (5, 6)];
     ///
     /// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
     ///
-    /// assert_eq!(left, [1, 3]);
-    /// assert_eq!(right, [2, 4]);
+    /// assert_eq!(left, [1, 3, 5]);
+    /// assert_eq!(right, [2, 4, 6]);
     ///
     /// // you can also unzip multiple nested tuples at once
     /// let a = [(1, (2, 3)), (4, (5, 6))];

From 9aec3a0e5a5adcdc83e45ed595ccb0b1265f5389 Mon Sep 17 00:00:00 2001
From: Jacob Hoffman-Andrews 
Date: Mon, 18 Oct 2021 20:24:41 -0700
Subject: [PATCH 170/181] Remove border-bottom from most docblocks.

Headings in the top-doc docblock still get a border-bottom due to a rule
that covers all h2, h3, and h4. Method docblocks are generally h5, and
so don't get a border-bottom anymore.

This fixes a problem where a sub-sub-heading within a method would have
a line that went all the way across the page, creating a division that
made that sub-sub-heading look much more important than it really is.
---
 src/librustdoc/html/static/css/rustdoc.css | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 11c54876dea30..98a9925655912 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -502,10 +502,6 @@ nav.sub {
 	white-space: pre-wrap;
 }
 
-.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
-	border-bottom: 1px solid;
-}
-
 .top-doc .docblock h2 { font-size: 1.3em; }
 .top-doc .docblock h3 { font-size: 1.15em; }
 .top-doc .docblock h4,

From e39934374a6e27fa446fc2dcb4ea45050059c5a8 Mon Sep 17 00:00:00 2001
From: Jacob Hoffman-Andrews 
Date: Mon, 18 Oct 2021 21:04:38 -0700
Subject: [PATCH 171/181] Reduce margin on h5 and h6

---
 src/librustdoc/html/static/css/rustdoc.css | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 98a9925655912..11a76846efc51 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -129,9 +129,14 @@ h3 {
 }
 h1, h2, h3, h4, h5, h6 {
 	font-weight: 500;
+}
+h1, h2, h3, h4 {
 	margin: 20px 0 15px 0;
 	padding-bottom: 6px;
 }
+h5, h6 {
+	margin: 15px 0 5px 0;
+}
 h1.fqn {
 	display: flex;
 	border-bottom: 1px dashed;
@@ -505,7 +510,9 @@ nav.sub {
 .top-doc .docblock h2 { font-size: 1.3em; }
 .top-doc .docblock h3 { font-size: 1.15em; }
 .top-doc .docblock h4,
-.top-doc .docblock h5,
+.top-doc .docblock h5 {
+	font-size: 1.1em;
+}
 .top-doc .docblock h6 {
 	font-size: 1em;
 }

From 2fcf911741f85626251c3557985ab7d201ceeb16 Mon Sep 17 00:00:00 2001
From: Eric Huss 
Date: Mon, 18 Oct 2021 21:22:09 -0700
Subject: [PATCH 172/181] Update cargo

---
 src/tools/cargo | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tools/cargo b/src/tools/cargo
index c7957a74bdcf3..7fbbf4e8f23e3 160000
--- a/src/tools/cargo
+++ b/src/tools/cargo
@@ -1 +1 @@
-Subproject commit c7957a74bdcf3b11e7154c1a9401735f23ebd484
+Subproject commit 7fbbf4e8f23e3c24b8afff541dcb17e53eb5ff88

From 7dbd5bb0bd655abe3f4de232f9ccb50db3843d42 Mon Sep 17 00:00:00 2001
From: Gary Guo 
Date: Tue, 19 Oct 2021 06:42:44 +0100
Subject: [PATCH 173/181] Fix issue 90038

---
 compiler/rustc_target/src/abi/mod.rs         |  2 +-
 src/test/ui/enum-discriminant/issue-90038.rs | 21 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 src/test/ui/enum-discriminant/issue-90038.rs

diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs
index 616071592087d..a57ad8f2bbd1b 100644
--- a/compiler/rustc_target/src/abi/mod.rs
+++ b/compiler/rustc_target/src/abi/mod.rs
@@ -1117,7 +1117,7 @@ impl Niche {
         // In practice this means that enums with `count > 1` are unlikely to claim niche zero, since they have to fit perfectly.
         // If niche zero is already reserved, the selection of bounds are of little interest.
         let move_start = |v: WrappingRange| {
-            let start = v.start.wrapping_sub(1) & max_value;
+            let start = v.start.wrapping_sub(count) & max_value;
             Some((start, Scalar { value, valid_range: v.with_start(start) }))
         };
         let move_end = |v: WrappingRange| {
diff --git a/src/test/ui/enum-discriminant/issue-90038.rs b/src/test/ui/enum-discriminant/issue-90038.rs
new file mode 100644
index 0000000000000..5e98eccd9b55c
--- /dev/null
+++ b/src/test/ui/enum-discriminant/issue-90038.rs
@@ -0,0 +1,21 @@
+// run-pass
+
+#[repr(u32)]
+pub enum Foo {
+    // Greater than or equal to 2
+    A = 2,
+}
+
+pub enum Bar {
+    A(Foo),
+    // More than two const variants
+    B,
+    C,
+}
+
+fn main() {
+    match Bar::A(Foo::A) {
+        Bar::A(_) => (),
+        _ => unreachable!(),
+    }
+}

From e0c5ed0c182918093002acd10caaa0cb8ec8044a Mon Sep 17 00:00:00 2001
From: Mara Bos 
Date: Wed, 4 Aug 2021 19:00:46 +0200
Subject: [PATCH 174/181] Sort and categorize #![feature]s in alloc.

---
 library/alloc/src/lib.rs | 94 ++++++++++++++++++++++------------------
 1 file changed, 52 insertions(+), 42 deletions(-)

diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 635708fd4cf6e..a143c4e8dde41 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -80,87 +80,97 @@
 )]
 #![no_std]
 #![needs_allocator]
+//
+// Lints:
+#![deny(unsafe_op_in_unsafe_fn)]
 #![warn(deprecated_in_future)]
-#![warn(missing_docs)]
 #![warn(missing_debug_implementations)]
+#![warn(missing_docs)]
 #![allow(explicit_outlives_requirements)]
-#![deny(unsafe_op_in_unsafe_fn)]
-#![feature(rustc_allow_const_fn_unstable)]
-#![cfg_attr(not(test), feature(generator_trait))]
-#![cfg_attr(test, feature(test))]
-#![cfg_attr(test, feature(new_uninit))]
+//
+// Library features:
+#![feature(alloc_layout_extra)]
 #![feature(allocator_api)]
 #![feature(array_chunks)]
 #![feature(array_methods)]
 #![feature(array_windows)]
-#![feature(allow_internal_unstable)]
-#![feature(arbitrary_self_types)]
 #![feature(async_stream)]
-#![feature(box_patterns)]
-#![feature(box_syntax)]
-#![feature(cfg_sanitize)]
-#![feature(cfg_target_has_atomic)]
 #![feature(coerce_unsized)]
 #![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
-#![feature(const_fn_trait_bound)]
-#![feature(cow_is_borrowed)]
 #![feature(const_cow_is_borrowed)]
-#![feature(const_trait_impl)]
-#![feature(destructuring_assignment)]
-#![feature(dispatch_from_dyn)]
 #![feature(core_intrinsics)]
-#![feature(dropck_eyepatch)]
+#![feature(cow_is_borrowed)]
+#![feature(dispatch_from_dyn)]
 #![feature(exact_size_is_empty)]
-#![feature(exclusive_range_pattern)]
 #![feature(extend_one)]
 #![feature(fmt_internals)]
 #![feature(fn_traits)]
-#![feature(fundamental)]
 #![feature(inplace_iteration)]
-// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
-// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
-// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
-// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
-#![feature(intra_doc_pointers)]
 #![feature(iter_advance_by)]
 #![feature(iter_zip)]
-#![feature(lang_items)]
 #![feature(layout_for_ptr)]
-#![feature(negative_impls)]
-#![feature(never_type)]
-#![feature(nll)]
+#![feature(maybe_uninit_extra)]
+#![feature(maybe_uninit_slice)]
+#![feature(maybe_uninit_uninit_array)]
+#![cfg_attr(test, feature(new_uninit))]
 #![feature(nonnull_slice_from_raw_parts)]
-#![feature(auto_traits)]
 #![feature(option_result_unwrap_unchecked)]
 #![feature(pattern)]
 #![feature(ptr_internals)]
-#![feature(rustc_attrs)]
 #![feature(receiver_trait)]
-#![feature(min_specialization)]
 #![feature(set_ptr_value)]
+#![feature(slice_group_by)]
+#![feature(slice_partition_dedup)]
 #![feature(slice_ptr_get)]
 #![feature(slice_ptr_len)]
 #![feature(slice_range)]
-#![feature(staged_api)]
 #![feature(str_internals)]
 #![feature(trusted_len)]
-#![feature(unboxed_closures)]
+#![feature(trusted_random_access)]
+#![feature(try_trait_v2)]
 #![feature(unicode_internals)]
 #![feature(unsize)]
-#![feature(unsized_fn_params)]
+//
+// Language features:
 #![feature(allocator_internals)]
-#![feature(slice_partition_dedup)]
-#![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)]
-#![feature(alloc_layout_extra)]
-#![feature(trusted_random_access)]
-#![feature(try_trait_v2)]
+#![feature(allow_internal_unstable)]
+#![feature(arbitrary_self_types)]
 #![feature(associated_type_bounds)]
-#![feature(slice_group_by)]
+#![feature(auto_traits)]
+#![feature(box_patterns)]
+#![feature(box_syntax)]
+#![feature(cfg_sanitize)]
+#![feature(cfg_target_has_atomic)]
+#![feature(const_fn_trait_bound)]
+#![feature(const_trait_impl)]
 #![feature(decl_macro)]
+#![feature(destructuring_assignment)]
+#![feature(dropck_eyepatch)]
+#![feature(exclusive_range_pattern)]
+#![feature(fundamental)]
+#![cfg_attr(not(test), feature(generator_trait))]
+#![feature(lang_items)]
+#![feature(min_specialization)]
+#![feature(negative_impls)]
+#![feature(never_type)]
+#![feature(nll)]
+#![feature(rustc_allow_const_fn_unstable)]
+#![feature(rustc_attrs)]
+#![feature(staged_api)]
+#![cfg_attr(test, feature(test))]
+#![feature(unboxed_closures)]
+#![feature(unsized_fn_params)]
+//
+// Rustdoc features:
 #![feature(doc_cfg)]
 #![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
-// Allow testing this library
+// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
+// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
+// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
+// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
+#![feature(intra_doc_pointers)]
 
+// Allow testing this library
 #[cfg(test)]
 #[macro_use]
 extern crate std;

From 4ddc1f2109232461c07e4b2e5f5a09f76a66e91f Mon Sep 17 00:00:00 2001
From: Mara Bos 
Date: Wed, 4 Aug 2021 19:17:35 +0200
Subject: [PATCH 175/181] Remove unused library #![feature]s from alloc.

---
 library/alloc/src/lib.rs | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index a143c4e8dde41..c8ae9d9a38b06 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -99,7 +99,6 @@
 #![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
 #![feature(const_cow_is_borrowed)]
 #![feature(core_intrinsics)]
-#![feature(cow_is_borrowed)]
 #![feature(dispatch_from_dyn)]
 #![feature(exact_size_is_empty)]
 #![feature(extend_one)]
@@ -111,7 +110,6 @@
 #![feature(layout_for_ptr)]
 #![feature(maybe_uninit_extra)]
 #![feature(maybe_uninit_slice)]
-#![feature(maybe_uninit_uninit_array)]
 #![cfg_attr(test, feature(new_uninit))]
 #![feature(nonnull_slice_from_raw_parts)]
 #![feature(option_result_unwrap_unchecked)]
@@ -120,7 +118,6 @@
 #![feature(receiver_trait)]
 #![feature(set_ptr_value)]
 #![feature(slice_group_by)]
-#![feature(slice_partition_dedup)]
 #![feature(slice_ptr_get)]
 #![feature(slice_ptr_len)]
 #![feature(slice_range)]

From 2104ac5706df99777d7bb7bebc264d3f439fba9f Mon Sep 17 00:00:00 2001
From: Mara Bos 
Date: Wed, 4 Aug 2021 19:17:35 +0200
Subject: [PATCH 176/181] Remove unused language #![feature]s from alloc.

---
 library/alloc/src/lib.rs | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index c8ae9d9a38b06..6f2c24422fda7 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -131,16 +131,12 @@
 // Language features:
 #![feature(allocator_internals)]
 #![feature(allow_internal_unstable)]
-#![feature(arbitrary_self_types)]
 #![feature(associated_type_bounds)]
-#![feature(auto_traits)]
-#![feature(box_patterns)]
 #![feature(box_syntax)]
 #![feature(cfg_sanitize)]
 #![feature(cfg_target_has_atomic)]
 #![feature(const_fn_trait_bound)]
 #![feature(const_trait_impl)]
-#![feature(decl_macro)]
 #![feature(destructuring_assignment)]
 #![feature(dropck_eyepatch)]
 #![feature(exclusive_range_pattern)]
@@ -150,7 +146,6 @@
 #![feature(min_specialization)]
 #![feature(negative_impls)]
 #![feature(never_type)]
-#![feature(nll)]
 #![feature(rustc_allow_const_fn_unstable)]
 #![feature(rustc_attrs)]
 #![feature(staged_api)]

From 6fdcedc9c8eff1f56c1568bb936638f1249cd2aa Mon Sep 17 00:00:00 2001
From: Mara Bos 
Date: Tue, 19 Oct 2021 14:54:35 +0200
Subject: [PATCH 177/181] Reenable feature(nll) in alloc.

---
 library/alloc/src/lib.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 6f2c24422fda7..285d7755c0689 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -146,6 +146,7 @@
 #![feature(min_specialization)]
 #![feature(negative_impls)]
 #![feature(never_type)]
+#![feature(nll)] // Not necessary, but here to test the `nll` feature.
 #![feature(rustc_allow_const_fn_unstable)]
 #![feature(rustc_attrs)]
 #![feature(staged_api)]

From 93701569573b367aaeaf659af154f5ae0d49af2b Mon Sep 17 00:00:00 2001
From: Gary Guo 
Date: Sat, 11 Sep 2021 03:44:02 +0100
Subject: [PATCH 178/181] Deduplicate panic_fmt

std's begin_panic_fmt and core's panic_fmt are duplicates.
Merge them to declutter code and remove a lang item.
---
 .../src/const_eval/machine.rs                 |  4 +--
 .../src/transform/check_consts/mod.rs         |  1 -
 compiler/rustc_hir/src/lang_items.rs          |  1 -
 compiler/rustc_span/src/symbol.rs             |  1 -
 library/core/src/panic/panic_info.rs          |  2 +-
 library/core/src/panicking.rs                 |  9 ++++++-
 library/std/src/panic.rs                      |  2 +-
 library/std/src/panicking.rs                  | 26 ++-----------------
 library/std/src/rt.rs                         |  4 +--
 9 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs
index ae20f6f97b212..adc574ce9c9df 100644
--- a/compiler/rustc_const_eval/src/const_eval/machine.rs
+++ b/compiler/rustc_const_eval/src/const_eval/machine.rs
@@ -51,9 +51,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
             let span = self.find_closest_untracked_caller_location();
             let (file, line, col) = self.location_triple_for_span(span);
             return Err(ConstEvalErrKind::Panic { msg, file, line, col }.into());
-        } else if Some(def_id) == self.tcx.lang_items().panic_fmt()
-            || Some(def_id) == self.tcx.lang_items().begin_panic_fmt()
-        {
+        } else if Some(def_id) == self.tcx.lang_items().panic_fmt() {
             // For panic_fmt, call const_panic_fmt instead.
             if let Some(const_panic_fmt) = self.tcx.lang_items().const_panic_fmt() {
                 return Ok(Some(
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
index d1fd3ceaa589a..8fb0d995ec6c2 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
@@ -82,7 +82,6 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
         || Some(def_id) == tcx.lang_items().panic_display()
         || Some(def_id) == tcx.lang_items().begin_panic_fn()
         || Some(def_id) == tcx.lang_items().panic_fmt()
-        || Some(def_id) == tcx.lang_items().begin_panic_fmt()
 }
 
 pub fn rustc_allow_const_fn_unstable(
diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs
index 814054c551878..790509b691d38 100644
--- a/compiler/rustc_hir/src/lang_items.rs
+++ b/compiler/rustc_hir/src/lang_items.rs
@@ -292,7 +292,6 @@ language_item_table! {
     PanicImpl,               sym::panic_impl,          panic_impl,                 Target::Fn,             GenericRequirement::None;
     /// libstd panic entry point. Necessary for const eval to be able to catch it
     BeginPanic,              sym::begin_panic,         begin_panic_fn,             Target::Fn,             GenericRequirement::None;
-    BeginPanicFmt,           sym::begin_panic_fmt,     begin_panic_fmt,            Target::Fn,             GenericRequirement::None;
 
     ExchangeMalloc,          sym::exchange_malloc,     exchange_malloc_fn,         Target::Fn,             GenericRequirement::None;
     BoxFree,                 sym::box_free,            box_free_fn,                Target::Fn,             GenericRequirement::Minimum(1);
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 9551120ca5522..21e6cdb47e195 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -355,7 +355,6 @@ symbols! {
         await_macro,
         bang,
         begin_panic,
-        begin_panic_fmt,
         bench,
         bin,
         bind_by_move_pattern_guards,
diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs
index a52a0022e5d2b..649bc3e44ad21 100644
--- a/library/core/src/panic/panic_info.rs
+++ b/library/core/src/panic/panic_info.rs
@@ -121,7 +121,7 @@ impl<'a> PanicInfo<'a> {
     #[stable(feature = "panic_hooks", since = "1.10.0")]
     pub fn location(&self) -> Option<&Location<'_>> {
         // NOTE: If this is changed to sometimes return None,
-        // deal with that case in std::panicking::default_hook and std::panicking::begin_panic_fmt.
+        // deal with that case in std::panicking::default_hook and core::panicking::panic_fmt.
         Some(&self.location)
     }
 }
diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs
index 6d3ec6ae8612a..a12447acf7ec3 100644
--- a/library/core/src/panicking.rs
+++ b/library/core/src/panicking.rs
@@ -76,8 +76,15 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
     panic!("index out of bounds: the len is {} but the index is {}", len, index)
 }
 
-/// The underlying implementation of libcore's `panic!` macro when formatting is used.
+/// The entry point for panicking with a formatted message.
+///
+/// This is designed to reduce the amount of code required at the call
+/// site as much as possible (so that `panic!()` has as low an impact
+/// on (e.g.) the inlining of other functions as possible), by moving
+/// the actual formatting into this shared place.
 #[cold]
+// If panic_immediate_abort, inline the abort call,
+// otherwise avoid inlining because of it is cold path.
 #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
 #[cfg_attr(feature = "panic_immediate_abort", inline)]
 #[track_caller]
diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs
index 21e9669c11079..c0605b2f4121c 100644
--- a/library/std/src/panic.rs
+++ b/library/std/src/panic.rs
@@ -25,7 +25,7 @@ pub macro panic_2015 {
         $crate::rt::panic_display(&$arg)
     }),
     ($fmt:expr, $($arg:tt)+) => ({
-        $crate::rt::begin_panic_fmt(&$crate::const_format_args!($fmt, $($arg)+))
+        $crate::rt::panic_fmt($crate::const_format_args!($fmt, $($arg)+))
     }),
 }
 
diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs
index 231c9fc19c08a..56646b72dd54f 100644
--- a/library/std/src/panicking.rs
+++ b/library/std/src/panicking.rs
@@ -437,31 +437,9 @@ pub fn panicking() -> bool {
     !panic_count::count_is_zero()
 }
 
-/// The entry point for panicking with a formatted message.
-///
-/// This is designed to reduce the amount of code required at the call
-/// site as much as possible (so that `panic!()` has as low an impact
-/// on (e.g.) the inlining of other functions as possible), by moving
-/// the actual formatting into this shared place.
-#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
-#[cold]
-// If panic_immediate_abort, inline the abort call,
-// otherwise avoid inlining because of it is cold path.
-#[cfg_attr(not(feature = "panic_immediate_abort"), track_caller)]
-#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
-#[cfg_attr(feature = "panic_immediate_abort", inline)]
-#[cfg_attr(not(test), lang = "begin_panic_fmt")]
-pub fn begin_panic_fmt(msg: &fmt::Arguments<'_>) -> ! {
-    if cfg!(feature = "panic_immediate_abort") {
-        intrinsics::abort()
-    }
-
-    let info = PanicInfo::internal_constructor(Some(msg), Location::caller());
-    begin_panic_handler(&info)
-}
-
 /// Entry point of panics from the libcore crate (`panic_impl` lang item).
-#[cfg_attr(not(test), panic_handler)]
+#[cfg(not(test))]
+#[panic_handler]
 pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
     struct PanicPayload<'a> {
         inner: &'a fmt::Arguments<'a>,
diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs
index 4d72aff011684..121c214780d2d 100644
--- a/library/std/src/rt.rs
+++ b/library/std/src/rt.rs
@@ -19,8 +19,8 @@
 use crate::ffi::CString;
 
 // Re-export some of our utilities which are expected by other crates.
-pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};
-pub use core::panicking::panic_display;
+pub use crate::panicking::{begin_panic, panic_count};
+pub use core::panicking::{panic_display, panic_fmt};
 
 use crate::sync::Once;
 use crate::sys;

From 7bd93dfeefac34a440ff011786d28e7b821add31 Mon Sep 17 00:00:00 2001
From: Gary Guo 
Date: Tue, 19 Oct 2021 13:58:58 +0100
Subject: [PATCH 179/181] Remove begin_panic_fmt from clippy

---
 src/tools/clippy/clippy_utils/src/higher.rs | 1 -
 src/tools/clippy/clippy_utils/src/lib.rs    | 1 -
 src/tools/clippy/clippy_utils/src/paths.rs  | 1 -
 3 files changed, 3 deletions(-)

diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs
index ba4d50bf74469..74cf323720cbb 100644
--- a/src/tools/clippy/clippy_utils/src/higher.rs
+++ b/src/tools/clippy/clippy_utils/src/higher.rs
@@ -619,7 +619,6 @@ impl PanicExpn<'tcx> {
             if let Some(init) = block.expr;
             if let ExprKind::Call(_, [format_args]) = init.kind;
             let expn_data = expr.span.ctxt().outer_expn_data();
-            if let ExprKind::AddrOf(_, _, format_args) = format_args.kind;
             if let Some(format_args) = FormatArgsExpn::parse(format_args);
             then {
                 Some(PanicExpn {
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index c47aa9170e547..8e94d16a33a0e 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -1646,7 +1646,6 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
         did,
         &[
             &paths::BEGIN_PANIC,
-            &paths::BEGIN_PANIC_FMT,
             &paths::PANIC_ANY,
             &paths::PANICKING_PANIC,
             &paths::PANICKING_PANIC_FMT,
diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs
index e43c575602145..81aff585ded1b 100644
--- a/src/tools/clippy/clippy_utils/src/paths.rs
+++ b/src/tools/clippy/clippy_utils/src/paths.rs
@@ -20,7 +20,6 @@ pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
 pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
 pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
 pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
-pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"];
 /// Preferably use the diagnostic item `sym::Borrow` where possible
 pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
 pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];

From 3b53c8ef3d7ace3bb2060a6b58b159a17e215c79 Mon Sep 17 00:00:00 2001
From: Vincent de Phily 
Date: Tue, 19 Oct 2021 15:50:27 +0100
Subject: [PATCH 180/181] Update RELEASES.md

Fix typo.
---
 RELEASES.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/RELEASES.md b/RELEASES.md
index 52d823d8acac4..f1584224656ae 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -77,7 +77,7 @@ Cargo
 - [Cargo supports specifying a minimum supported Rust version in Cargo.toml.][`rust-version`]
   This has no effect at present on dependency version selection.
   We encourage crates to specify their minimum supported Rust version, and we encourage CI systems
-  that support Rust code to include a crate's specified minimum version in the text matrix for that
+  that support Rust code to include a crate's specified minimum version in the test matrix for that
   crate by default.
 
 Compatibility notes

From 90eb42dcc167f2dd100d12ebbd8343d0bd758b07 Mon Sep 17 00:00:00 2001
From: AlexApps99 
Date: Thu, 14 Oct 2021 13:44:18 +1300
Subject: [PATCH 181/181] Added const versions of common numeric operations

---
 library/core/src/internal_macros.rs |  68 +++++++++++++++
 library/core/src/lib.rs             |   1 +
 library/core/src/num/nonzero.rs     |  21 +++--
 library/core/src/num/wrapping.rs    | 128 +++++++++++++++++-----------
 library/core/src/ops/arith.rs       |  65 ++++++++------
 library/core/src/ops/bit.rs         |  55 +++++++-----
 6 files changed, 232 insertions(+), 106 deletions(-)

diff --git a/library/core/src/internal_macros.rs b/library/core/src/internal_macros.rs
index be12f90464084..b5c1bf6897c18 100644
--- a/library/core/src/internal_macros.rs
+++ b/library/core/src/internal_macros.rs
@@ -5,6 +5,22 @@ macro_rules! forward_ref_unop {
         forward_ref_unop!(impl $imp, $method for $t,
                 #[stable(feature = "rust1", since = "1.0.0")]);
     };
+    (impl const $imp:ident, $method:ident for $t:ty) => {
+        forward_ref_unop!(impl const $imp, $method for $t,
+                #[stable(feature = "rust1", since = "1.0.0")]);
+    };
+    (impl const $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
+        #[$attr]
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const $imp for &$t {
+            type Output = <$t as $imp>::Output;
+
+            #[inline]
+            fn $method(self) -> <$t as $imp>::Output {
+                $imp::$method(*self)
+            }
+        }
+    };
     (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => {
         #[$attr]
         impl $imp for &$t {
@@ -25,6 +41,44 @@ macro_rules! forward_ref_binop {
         forward_ref_binop!(impl $imp, $method for $t, $u,
                 #[stable(feature = "rust1", since = "1.0.0")]);
     };
+    (impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
+        forward_ref_binop!(impl const $imp, $method for $t, $u,
+                #[stable(feature = "rust1", since = "1.0.0")]);
+    };
+    (impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
+        #[$attr]
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl<'a> const $imp<$u> for &'a $t {
+            type Output = <$t as $imp<$u>>::Output;
+
+            #[inline]
+            fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
+                $imp::$method(*self, other)
+            }
+        }
+
+        #[$attr]
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const $imp<&$u> for $t {
+            type Output = <$t as $imp<$u>>::Output;
+
+            #[inline]
+            fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
+                $imp::$method(self, *other)
+            }
+        }
+
+        #[$attr]
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const $imp<&$u> for &$t {
+            type Output = <$t as $imp<$u>>::Output;
+
+            #[inline]
+            fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
+                $imp::$method(*self, *other)
+            }
+        }
+    };
     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
         #[$attr]
         impl<'a> $imp<$u> for &'a $t {
@@ -65,6 +119,20 @@ macro_rules! forward_ref_op_assign {
         forward_ref_op_assign!(impl $imp, $method for $t, $u,
                 #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
     };
+    (impl const $imp:ident, $method:ident for $t:ty, $u:ty) => {
+        forward_ref_op_assign!(impl const $imp, $method for $t, $u,
+                #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]);
+    };
+    (impl const $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
+        #[$attr]
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const $imp<&$u> for $t {
+            #[inline]
+            fn $method(&mut self, other: &$u) {
+                $imp::$method(self, *other);
+            }
+        }
+    };
     (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => {
         #[$attr]
         impl $imp<&$u> for $t {
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 13b80c05dbb30..dde0a1a8226b7 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -115,6 +115,7 @@
 #![feature(const_likely)]
 #![feature(const_maybe_uninit_as_ptr)]
 #![feature(const_maybe_uninit_assume_init)]
+#![feature(const_ops)]
 #![feature(const_option)]
 #![feature(const_pin)]
 #![feature(const_replace)]
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs
index d28474c29232c..de056b3e2de0b 100644
--- a/library/core/src/num/nonzero.rs
+++ b/library/core/src/num/nonzero.rs
@@ -92,7 +92,8 @@ macro_rules! nonzero_integers {
             }
 
             #[stable(feature = "nonzero_bitor", since = "1.45.0")]
-            impl BitOr for $Ty {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const BitOr for $Ty {
                 type Output = Self;
                 #[inline]
                 fn bitor(self, rhs: Self) -> Self::Output {
@@ -103,7 +104,8 @@ macro_rules! nonzero_integers {
             }
 
             #[stable(feature = "nonzero_bitor", since = "1.45.0")]
-            impl BitOr<$Int> for $Ty {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const BitOr<$Int> for $Ty {
                 type Output = Self;
                 #[inline]
                 fn bitor(self, rhs: $Int) -> Self::Output {
@@ -115,7 +117,8 @@ macro_rules! nonzero_integers {
             }
 
             #[stable(feature = "nonzero_bitor", since = "1.45.0")]
-            impl BitOr<$Ty> for $Int {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const BitOr<$Ty> for $Int {
                 type Output = $Ty;
                 #[inline]
                 fn bitor(self, rhs: $Ty) -> Self::Output {
@@ -127,7 +130,8 @@ macro_rules! nonzero_integers {
             }
 
             #[stable(feature = "nonzero_bitor", since = "1.45.0")]
-            impl BitOrAssign for $Ty {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const BitOrAssign for $Ty {
                 #[inline]
                 fn bitor_assign(&mut self, rhs: Self) {
                     *self = *self | rhs;
@@ -135,7 +139,8 @@ macro_rules! nonzero_integers {
             }
 
             #[stable(feature = "nonzero_bitor", since = "1.45.0")]
-            impl BitOrAssign<$Int> for $Ty {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const BitOrAssign<$Int> for $Ty {
                 #[inline]
                 fn bitor_assign(&mut self, rhs: $Int) {
                     *self = *self | rhs;
@@ -257,7 +262,8 @@ macro_rules! nonzero_integers_div {
     ( $( $Ty: ident($Int: ty); )+ ) => {
         $(
             #[stable(feature = "nonzero_div", since = "1.51.0")]
-            impl Div<$Ty> for $Int {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const Div<$Ty> for $Int {
                 type Output = $Int;
                 /// This operation rounds towards zero,
                 /// truncating any fractional part of the exact result, and cannot panic.
@@ -270,7 +276,8 @@ macro_rules! nonzero_integers_div {
             }
 
             #[stable(feature = "nonzero_div", since = "1.51.0")]
-            impl Rem<$Ty> for $Int {
+            #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+            impl const Rem<$Ty> for $Int {
                 type Output = $Int;
                 /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
                 #[inline]
diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs
index f387bd5b41cc4..a0e42c51e4517 100644
--- a/library/core/src/num/wrapping.rs
+++ b/library/core/src/num/wrapping.rs
@@ -87,7 +87,8 @@ impl fmt::UpperHex for Wrapping {
 macro_rules! sh_impl_signed {
     ($t:ident, $f:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shl<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shl<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -99,20 +100,22 @@ macro_rules! sh_impl_signed {
                 }
             }
         }
-        forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
+        forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
         #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShlAssign<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShlAssign<$f> for Wrapping<$t> {
             #[inline]
             fn shl_assign(&mut self, other: $f) {
                 *self = *self << other;
             }
         }
-        forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
+        forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shr<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shr<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -124,24 +127,26 @@ macro_rules! sh_impl_signed {
                 }
             }
         }
-        forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
+        forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
         #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShrAssign<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShrAssign<$f> for Wrapping<$t> {
             #[inline]
             fn shr_assign(&mut self, other: $f) {
                 *self = *self >> other;
             }
         }
-        forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
+        forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
     };
 }
 
 macro_rules! sh_impl_unsigned {
     ($t:ident, $f:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shl<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shl<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -149,20 +154,22 @@ macro_rules! sh_impl_unsigned {
                 Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32))
             }
         }
-        forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
+        forward_ref_binop! { impl const Shl, shl for Wrapping<$t>, $f,
         #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShlAssign<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShlAssign<$f> for Wrapping<$t> {
             #[inline]
             fn shl_assign(&mut self, other: $f) {
                 *self = *self << other;
             }
         }
-        forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
+        forward_ref_op_assign! { impl const ShlAssign, shl_assign for Wrapping<$t>, $f }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shr<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shr<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -170,17 +177,18 @@ macro_rules! sh_impl_unsigned {
                 Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32))
             }
         }
-        forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
+        forward_ref_binop! { impl const Shr, shr for Wrapping<$t>, $f,
         #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShrAssign<$f> for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShrAssign<$f> for Wrapping<$t> {
             #[inline]
             fn shr_assign(&mut self, other: $f) {
                 *self = *self >> other;
             }
         }
-        forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
+        forward_ref_op_assign! { impl const ShrAssign, shr_assign for Wrapping<$t>, $f }
     };
 }
 
@@ -209,7 +217,8 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
 macro_rules! wrapping_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Add for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Add for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -217,20 +226,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0.wrapping_add(other.0))
             }
         }
-        forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const Add, add for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl AddAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const AddAssign for Wrapping<$t> {
             #[inline]
             fn add_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self + other;
             }
         }
-        forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Sub for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Sub for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -238,20 +249,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0.wrapping_sub(other.0))
             }
         }
-        forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const Sub, sub for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl SubAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const SubAssign for Wrapping<$t> {
             #[inline]
             fn sub_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self - other;
             }
         }
-        forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Mul for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Mul for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -263,16 +276,18 @@ macro_rules! wrapping_impl {
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl MulAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const MulAssign for Wrapping<$t> {
             #[inline]
             fn mul_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self * other;
             }
         }
-        forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "wrapping_div", since = "1.3.0")]
-        impl Div for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Div for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -280,20 +295,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0.wrapping_div(other.0))
             }
         }
-        forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const Div, div for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl DivAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const DivAssign for Wrapping<$t> {
             #[inline]
             fn div_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self / other;
             }
         }
-        forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "wrapping_impls", since = "1.7.0")]
-        impl Rem for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Rem for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -301,20 +318,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0.wrapping_rem(other.0))
             }
         }
-        forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const Rem, rem for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl RemAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const RemAssign for Wrapping<$t> {
             #[inline]
             fn rem_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self % other;
             }
         }
-        forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Not for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Not for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -322,11 +341,12 @@ macro_rules! wrapping_impl {
                 Wrapping(!self.0)
             }
         }
-        forward_ref_unop! { impl Not, not for Wrapping<$t>,
+        forward_ref_unop! { impl const Not, not for Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitXor for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitXor for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -334,20 +354,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0 ^ other.0)
             }
         }
-        forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitXorAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitXorAssign for Wrapping<$t> {
             #[inline]
             fn bitxor_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self ^ other;
             }
         }
-        forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitOr for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitOr for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -355,20 +377,22 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0 | other.0)
             }
         }
-        forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitOrAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitOrAssign for Wrapping<$t> {
             #[inline]
             fn bitor_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self | other;
             }
         }
-        forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitAnd for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitAnd for Wrapping<$t> {
             type Output = Wrapping<$t>;
 
             #[inline]
@@ -376,27 +400,29 @@ macro_rules! wrapping_impl {
                 Wrapping(self.0 & other.0)
             }
         }
-        forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
+        forward_ref_binop! { impl const BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitAndAssign for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitAndAssign for Wrapping<$t> {
             #[inline]
             fn bitand_assign(&mut self, other: Wrapping<$t>) {
                 *self = *self & other;
             }
         }
-        forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
+        forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
 
         #[stable(feature = "wrapping_neg", since = "1.10.0")]
-        impl Neg for Wrapping<$t> {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Neg for Wrapping<$t> {
             type Output = Self;
             #[inline]
             fn neg(self) -> Self {
                 Wrapping(0) - self
             }
         }
-        forward_ref_unop! { impl Neg, neg for Wrapping<$t>,
+        forward_ref_unop! { impl const Neg, neg for Wrapping<$t>,
                 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
 
     )*)
diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs
index a0577b287ce24..e954742938910 100644
--- a/library/core/src/ops/arith.rs
+++ b/library/core/src/ops/arith.rs
@@ -92,7 +92,8 @@ pub trait Add {
 macro_rules! add_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Add for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Add for $t {
             type Output = $t;
 
             #[inline]
@@ -100,7 +101,7 @@ macro_rules! add_impl {
             fn add(self, other: $t) -> $t { self + other }
         }
 
-        forward_ref_binop! { impl Add, add for $t, $t }
+        forward_ref_binop! { impl const Add, add for $t, $t }
     )*)
 }
 
@@ -198,7 +199,8 @@ pub trait Sub {
 macro_rules! sub_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Sub for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Sub for $t {
             type Output = $t;
 
             #[inline]
@@ -206,7 +208,7 @@ macro_rules! sub_impl {
             fn sub(self, other: $t) -> $t { self - other }
         }
 
-        forward_ref_binop! { impl Sub, sub for $t, $t }
+        forward_ref_binop! { impl const Sub, sub for $t, $t }
     )*)
 }
 
@@ -326,7 +328,8 @@ pub trait Mul {
 macro_rules! mul_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Mul for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Mul for $t {
             type Output = $t;
 
             #[inline]
@@ -334,7 +337,7 @@ macro_rules! mul_impl {
             fn mul(self, other: $t) -> $t { self * other }
         }
 
-        forward_ref_binop! { impl Mul, mul for $t, $t }
+        forward_ref_binop! { impl const Mul, mul for $t, $t }
     )*)
 }
 
@@ -464,14 +467,15 @@ macro_rules! div_impl_integer {
         ///
         #[doc = $panic]
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Div for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Div for $t {
             type Output = $t;
 
             #[inline]
             fn div(self, other: $t) -> $t { self / other }
         }
 
-        forward_ref_binop! { impl Div, div for $t, $t }
+        forward_ref_binop! { impl const Div, div for $t, $t }
     )*)*)
 }
 
@@ -483,14 +487,15 @@ div_impl_integer! {
 macro_rules! div_impl_float {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Div for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Div for $t {
             type Output = $t;
 
             #[inline]
             fn div(self, other: $t) -> $t { self / other }
         }
 
-        forward_ref_binop! { impl Div, div for $t, $t }
+        forward_ref_binop! { impl const Div, div for $t, $t }
     )*)
 }
 
@@ -564,14 +569,15 @@ macro_rules! rem_impl_integer {
         ///
         #[doc = $panic]
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Rem for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Rem for $t {
             type Output = $t;
 
             #[inline]
             fn rem(self, other: $t) -> $t { self % other }
         }
 
-        forward_ref_binop! { impl Rem, rem for $t, $t }
+        forward_ref_binop! { impl const Rem, rem for $t, $t }
     )*)*)
 }
 
@@ -598,14 +604,15 @@ macro_rules! rem_impl_float {
         /// assert_eq!(x % y, remainder);
         /// ```
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Rem for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Rem for $t {
             type Output = $t;
 
             #[inline]
             fn rem(self, other: $t) -> $t { self % other }
         }
 
-        forward_ref_binop! { impl Rem, rem for $t, $t }
+        forward_ref_binop! { impl const Rem, rem for $t, $t }
     )*)
 }
 
@@ -671,7 +678,8 @@ pub trait Neg {
 macro_rules! neg_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Neg for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Neg for $t {
             type Output = $t;
 
             #[inline]
@@ -679,7 +687,7 @@ macro_rules! neg_impl {
             fn neg(self) -> $t { -self }
         }
 
-        forward_ref_unop! { impl Neg, neg for $t }
+        forward_ref_unop! { impl const Neg, neg for $t }
     )*)
 }
 
@@ -739,13 +747,14 @@ pub trait AddAssign {
 macro_rules! add_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl AddAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const AddAssign for $t {
             #[inline]
             #[rustc_inherit_overflow_checks]
             fn add_assign(&mut self, other: $t) { *self += other }
         }
 
-        forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t }
+        forward_ref_op_assign! { impl const AddAssign, add_assign for $t, $t }
     )+)
 }
 
@@ -805,13 +814,14 @@ pub trait SubAssign {
 macro_rules! sub_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl SubAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const SubAssign for $t {
             #[inline]
             #[rustc_inherit_overflow_checks]
             fn sub_assign(&mut self, other: $t) { *self -= other }
         }
 
-        forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t }
+        forward_ref_op_assign! { impl const SubAssign, sub_assign for $t, $t }
     )+)
 }
 
@@ -862,13 +872,14 @@ pub trait MulAssign {
 macro_rules! mul_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl MulAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const MulAssign for $t {
             #[inline]
             #[rustc_inherit_overflow_checks]
             fn mul_assign(&mut self, other: $t) { *self *= other }
         }
 
-        forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t }
+        forward_ref_op_assign! { impl const MulAssign, mul_assign for $t, $t }
     )+)
 }
 
@@ -919,12 +930,13 @@ pub trait DivAssign {
 macro_rules! div_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl DivAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const DivAssign for $t {
             #[inline]
             fn div_assign(&mut self, other: $t) { *self /= other }
         }
 
-        forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t }
+        forward_ref_op_assign! { impl const DivAssign, div_assign for $t, $t }
     )+)
 }
 
@@ -979,12 +991,13 @@ pub trait RemAssign {
 macro_rules! rem_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl RemAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const RemAssign for $t {
             #[inline]
             fn rem_assign(&mut self, other: $t) { *self %= other }
         }
 
-        forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t }
+        forward_ref_op_assign! { impl const RemAssign, rem_assign for $t, $t }
     )+)
 }
 
diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs
index 92f45ac9e7ea9..255f6cb7933a2 100644
--- a/library/core/src/ops/bit.rs
+++ b/library/core/src/ops/bit.rs
@@ -54,14 +54,15 @@ pub trait Not {
 macro_rules! not_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Not for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Not for $t {
             type Output = $t;
 
             #[inline]
             fn not(self) -> $t { !self }
         }
 
-        forward_ref_unop! { impl Not, not for $t }
+        forward_ref_unop! { impl const Not, not for $t }
     )*)
 }
 
@@ -154,14 +155,15 @@ pub trait BitAnd {
 macro_rules! bitand_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitAnd for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitAnd for $t {
             type Output = $t;
 
             #[inline]
             fn bitand(self, rhs: $t) -> $t { self & rhs }
         }
 
-        forward_ref_binop! { impl BitAnd, bitand for $t, $t }
+        forward_ref_binop! { impl const BitAnd, bitand for $t, $t }
     )*)
 }
 
@@ -254,14 +256,15 @@ pub trait BitOr {
 macro_rules! bitor_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitOr for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitOr for $t {
             type Output = $t;
 
             #[inline]
             fn bitor(self, rhs: $t) -> $t { self | rhs }
         }
 
-        forward_ref_binop! { impl BitOr, bitor for $t, $t }
+        forward_ref_binop! { impl const BitOr, bitor for $t, $t }
     )*)
 }
 
@@ -354,14 +357,15 @@ pub trait BitXor {
 macro_rules! bitxor_impl {
     ($($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl BitXor for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitXor for $t {
             type Output = $t;
 
             #[inline]
             fn bitxor(self, other: $t) -> $t { self ^ other }
         }
 
-        forward_ref_binop! { impl BitXor, bitxor for $t, $t }
+        forward_ref_binop! { impl const BitXor, bitxor for $t, $t }
     )*)
 }
 
@@ -451,7 +455,8 @@ pub trait Shl {
 macro_rules! shl_impl {
     ($t:ty, $f:ty) => {
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shl<$f> for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shl<$f> for $t {
             type Output = $t;
 
             #[inline]
@@ -461,7 +466,7 @@ macro_rules! shl_impl {
             }
         }
 
-        forward_ref_binop! { impl Shl, shl for $t, $f }
+        forward_ref_binop! { impl const Shl, shl for $t, $f }
     };
 }
 
@@ -569,7 +574,8 @@ pub trait Shr {
 macro_rules! shr_impl {
     ($t:ty, $f:ty) => {
         #[stable(feature = "rust1", since = "1.0.0")]
-        impl Shr<$f> for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const Shr<$f> for $t {
             type Output = $t;
 
             #[inline]
@@ -579,7 +585,7 @@ macro_rules! shr_impl {
             }
         }
 
-        forward_ref_binop! { impl Shr, shr for $t, $f }
+        forward_ref_binop! { impl const Shr, shr for $t, $f }
     };
 }
 
@@ -704,12 +710,13 @@ pub trait BitAndAssign {
 macro_rules! bitand_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitAndAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitAndAssign for $t {
             #[inline]
             fn bitand_assign(&mut self, other: $t) { *self &= other }
         }
 
-        forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t }
+        forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for $t, $t }
     )+)
 }
 
@@ -775,12 +782,13 @@ pub trait BitOrAssign {
 macro_rules! bitor_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitOrAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitOrAssign for $t {
             #[inline]
             fn bitor_assign(&mut self, other: $t) { *self |= other }
         }
 
-        forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t }
+        forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for $t, $t }
     )+)
 }
 
@@ -846,12 +854,13 @@ pub trait BitXorAssign {
 macro_rules! bitxor_assign_impl {
     ($($t:ty)+) => ($(
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl BitXorAssign for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const BitXorAssign for $t {
             #[inline]
             fn bitxor_assign(&mut self, other: $t) { *self ^= other }
         }
 
-        forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t }
+        forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for $t, $t }
     )+)
 }
 
@@ -907,7 +916,8 @@ pub trait ShlAssign {
 macro_rules! shl_assign_impl {
     ($t:ty, $f:ty) => {
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShlAssign<$f> for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShlAssign<$f> for $t {
             #[inline]
             #[rustc_inherit_overflow_checks]
             fn shl_assign(&mut self, other: $f) {
@@ -915,7 +925,7 @@ macro_rules! shl_assign_impl {
             }
         }
 
-        forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f }
+        forward_ref_op_assign! { impl const ShlAssign, shl_assign for $t, $f }
     };
 }
 
@@ -989,7 +999,8 @@ pub trait ShrAssign {
 macro_rules! shr_assign_impl {
     ($t:ty, $f:ty) => {
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
-        impl ShrAssign<$f> for $t {
+        #[rustc_const_unstable(feature = "const_ops", issue = "90080")]
+        impl const ShrAssign<$f> for $t {
             #[inline]
             #[rustc_inherit_overflow_checks]
             fn shr_assign(&mut self, other: $f) {
@@ -997,7 +1008,7 @@ macro_rules! shr_assign_impl {
             }
         }
 
-        forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f }
+        forward_ref_op_assign! { impl const ShrAssign, shr_assign for $t, $f }
     };
 }