From c713caff6d952f12acfdf55d1a2fd9c6a0904f31 Mon Sep 17 00:00:00 2001 From: coekjan Date: Tue, 4 Jun 2024 16:09:23 +0800 Subject: [PATCH 01/54] update tracking issue for `const_binary_heap_new_in` --- library/alloc/src/collections/binary_heap/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 0b04fb4a2744..8d644ec8ee8c 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -487,7 +487,7 @@ impl BinaryHeap { /// heap.push(4); /// ``` #[unstable(feature = "allocator_api", issue = "32838")] - #[rustc_const_unstable(feature = "const_binary_heap_new_in", issue = "112353")] + #[rustc_const_unstable(feature = "const_binary_heap_new_in", issue = "125961")] #[must_use] pub const fn new_in(alloc: A) -> BinaryHeap { BinaryHeap { data: Vec::new_in(alloc) } From 46b84956f8391b90a4c140a85270571954309bbf Mon Sep 17 00:00:00 2001 From: ilikdoge Date: Sun, 23 Jun 2024 13:43:46 -0700 Subject: [PATCH 02/54] Implement `unsigned_signed_diff` --- library/core/src/num/uint_macros.rs | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 1491c27372bf..81062f916134 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -726,6 +726,67 @@ macro_rules! uint_impl { } } + #[doc = concat!( + "Checked integer subtraction. Computes `self - rhs` and checks if the result fits into an [`", + stringify!($SignedT), "`], returning `None` if overflow occurred." + )] + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// #![feature(unsigned_signed_diff)] + #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_signed_diff(2), Some(8));")] + #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_signed_diff(10), Some(-8));")] + #[doc = concat!( + "assert_eq!(", + stringify!($SelfT), + "::MAX.checked_signed_diff(", + stringify!($SignedT), + "::MAX as ", + stringify!($SelfT), + "), None);" + )] + #[doc = concat!( + "assert_eq!((", + stringify!($SignedT), + "::MAX as ", + stringify!($SelfT), + ").checked_signed_diff(", + stringify!($SelfT), + "::MAX), Some(", + stringify!($SignedT), + "::MIN));" + )] + #[doc = concat!( + "assert_eq!((", + stringify!($SignedT), + "::MAX as ", + stringify!($SelfT), + " + 1).checked_signed_diff(0), None);" + )] + #[doc = concat!( + "assert_eq!(", + stringify!($SelfT), + "::MAX.checked_signed_diff(", + stringify!($SelfT), + "::MAX), Some(0));" + )] + /// ``` + #[unstable(feature = "unsigned_signed_diff", issue = "126041")] + #[inline] + pub const fn checked_signed_diff(self, rhs: Self) -> Option<$SignedT> { + let res = self.wrapping_sub(rhs) as $SignedT; + let overflow = (self >= rhs) == (res < 0); + + if !overflow { + Some(res) + } else { + None + } + } + /// Checked integer multiplication. Computes `self * rhs`, returning /// `None` if overflow occurred. /// From 91af6b51223625ea5cd34d77861648ca19566deb Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 2 Jul 2024 15:00:09 -0700 Subject: [PATCH 03/54] Add edge-case examples to `{count,leading,trailing}_{ones,zeros}` methods Some architectures (i386) do not define a "count leading zeros" instruction, they define a "find first set bit" instruction (`bsf`) whose result is undefined when given zero (ie none of the bits are set). Of this family of bitwise operations, I always forget which of these things is potentially undefined for zero, and I'm also not 100% sure that Rust provides a hard guarantee for the results of these methods when given zero. So I figured there are others who have these same uncertainties, and it would be good to resolve them and answer the question via extending these doc examples/tests. See https://en.wikipedia.org/wiki/Find_first_set#Hardware_support for more info on i386 and `bsf` on zero. --- library/core/src/num/uint_macros.rs | 41 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ad72c29758bd..40bc58204e80 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -65,8 +65,13 @@ macro_rules! uint_impl { /// /// ``` #[doc = concat!("let n = 0b01001100", stringify!($SelfT), ";")] - /// /// assert_eq!(n.count_ones(), 3); + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + #[doc = concat!("assert_eq!(max.count_ones(), ", stringify!($BITS), ");")] + /// + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + /// assert_eq!(zero.count_ones(), 0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] @@ -86,7 +91,11 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 0);")] + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + #[doc = concat!("assert_eq!(zero.count_zeros(), ", stringify!($BITS), ");")] + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + /// assert_eq!(max.count_zeros(), 0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] @@ -108,8 +117,13 @@ macro_rules! uint_impl { /// /// ``` #[doc = concat!("let n = ", stringify!($SelfT), "::MAX >> 2;")] - /// /// assert_eq!(n.leading_zeros(), 2); + /// + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + #[doc = concat!("assert_eq!(zero.leading_zeros(), ", stringify!($BITS), ");")] + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + /// assert_eq!(max.leading_zeros(), 0); /// ``` #[doc = concat!("[`ilog2`]: ", stringify!($SelfT), "::ilog2")] #[stable(feature = "rust1", since = "1.0.0")] @@ -130,8 +144,13 @@ macro_rules! uint_impl { /// /// ``` #[doc = concat!("let n = 0b0101000", stringify!($SelfT), ";")] - /// /// assert_eq!(n.trailing_zeros(), 3); + /// + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + #[doc = concat!("assert_eq!(zero.trailing_zeros(), ", stringify!($BITS), ");")] + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + #[doc = concat!("assert_eq!(max.trailing_zeros(), 0);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_math", since = "1.32.0")] @@ -150,8 +169,13 @@ macro_rules! uint_impl { /// /// ``` #[doc = concat!("let n = !(", stringify!($SelfT), "::MAX >> 2);")] - /// /// assert_eq!(n.leading_ones(), 2); + /// + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + /// assert_eq!(zero.leading_ones(), 0); + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + #[doc = concat!("assert_eq!(max.leading_ones(), ", stringify!($BITS), ");")] /// ``` #[stable(feature = "leading_trailing_ones", since = "1.46.0")] #[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")] @@ -171,8 +195,13 @@ macro_rules! uint_impl { /// /// ``` #[doc = concat!("let n = 0b1010111", stringify!($SelfT), ";")] - /// /// assert_eq!(n.trailing_ones(), 3); + /// + #[doc = concat!("let zero = 0", stringify!($SelfT), ";")] + /// assert_eq!(zero.trailing_ones(), 0); + /// + #[doc = concat!("let max = ", stringify!($SelfT),"::MAX;")] + #[doc = concat!("assert_eq!(max.trailing_ones(), ", stringify!($BITS), ");")] /// ``` #[stable(feature = "leading_trailing_ones", since = "1.46.0")] #[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")] From 6519c143a7ae1494b38920cfb08a55793fbfe07d Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Mon, 8 Jul 2024 10:56:13 +0530 Subject: [PATCH 04/54] Reset sigpipe not supported for vxworks --- library/std/src/sys/pal/unix/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 16fc2011d708..d016e5e32d40 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -164,6 +164,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { target_os = "emscripten", target_os = "fuchsia", target_os = "horizon", + target_os = "vxworks", // Unikraft's `signal` implementation is currently broken: // https://github.com/unikraft/lib-musl/issues/57 target_vendor = "unikraft", From 287b66b0b5cc06b9c0acb01d8a7b0db9ddf764ee Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 8 Jun 2024 11:26:10 +0200 Subject: [PATCH 05/54] size_of_val_raw: for length 0 this is safe to call --- library/core/src/alloc/layout.rs | 2 ++ library/core/src/mem/mod.rs | 8 ++++++++ tests/ui/layout/size-of-val-raw-too-big.rs | 18 ++++++++++++++++++ tests/ui/layout/size-of-val-raw-too-big.stderr | 4 ++++ 4 files changed, 32 insertions(+) create mode 100644 tests/ui/layout/size-of-val-raw-too-big.rs create mode 100644 tests/ui/layout/size-of-val-raw-too-big.stderr diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 0b92767c9320..e96a41422a2a 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -183,6 +183,8 @@ impl Layout { /// - a [slice], then the length of the slice tail must be an initialized /// integer, and the size of the *entire value* /// (dynamic tail length + statically sized prefix) must fit in `isize`. + /// For the special case where the dynamic tail length is 0, this function + /// is safe to call. /// - a [trait object], then the vtable part of the pointer must point /// to a valid vtable for the type `T` acquired by an unsizing coercion, /// and the size of the *entire value* diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index dd4b6e823434..9bb4ba922cd4 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -359,6 +359,12 @@ pub const fn size_of_val(val: &T) -> usize { /// - a [slice], then the length of the slice tail must be an initialized /// integer, and the size of the *entire value* /// (dynamic tail length + statically sized prefix) must fit in `isize`. +/// For the special case where the dynamic tail length is 0, this function +/// is safe to call. +// NOTE: the reason this is safe is that if an overflow were to occur already with size 0, +// then we would stop compilation as even the "statically known" part of the type would +// already be too big (or the call may be in dead code and optimized away, but then it +// doesn't matter). /// - a [trait object], then the vtable part of the pointer must point /// to a valid vtable acquired by an unsizing coercion, and the size /// of the *entire value* (dynamic tail length + statically sized prefix) @@ -506,6 +512,8 @@ pub const fn align_of_val(val: &T) -> usize { /// - a [slice], then the length of the slice tail must be an initialized /// integer, and the size of the *entire value* /// (dynamic tail length + statically sized prefix) must fit in `isize`. +/// For the special case where the dynamic tail length is 0, this function +/// is safe to call. /// - a [trait object], then the vtable part of the pointer must point /// to a valid vtable acquired by an unsizing coercion, and the size /// of the *entire value* (dynamic tail length + statically sized prefix) diff --git a/tests/ui/layout/size-of-val-raw-too-big.rs b/tests/ui/layout/size-of-val-raw-too-big.rs new file mode 100644 index 000000000000..8d82c78d9539 --- /dev/null +++ b/tests/ui/layout/size-of-val-raw-too-big.rs @@ -0,0 +1,18 @@ +//@ build-fail +//@ compile-flags: --crate-type lib +//@ only-32bit Layout computation rejects this layout for different reasons on 64-bit. +//@ error-pattern: too big for the current architecture +#![feature(core_intrinsics)] +#![allow(internal_features)] + +// isize::MAX is fine, but with the padding for the unsized tail it is too big. +#[repr(C)] +pub struct Example([u8; isize::MAX as usize], [u16]); + +// We guarantee that with length 0, `size_of_val_raw` (which calls the `size_of_val` intrinsic) +// is safe to call. The compiler aborts compilation if a length of 0 would overflow. +// So let's construct a case where length 0 just barely overflows, and ensure that +// does abort compilation. +pub fn check(x: *const Example) -> usize { + unsafe { std::intrinsics::size_of_val(x) } +} diff --git a/tests/ui/layout/size-of-val-raw-too-big.stderr b/tests/ui/layout/size-of-val-raw-too-big.stderr new file mode 100644 index 000000000000..aa9abd644faa --- /dev/null +++ b/tests/ui/layout/size-of-val-raw-too-big.stderr @@ -0,0 +1,4 @@ +error: values of the type `Example` are too big for the current architecture + +error: aborting due to 1 previous error + From e13eb37eeb3ccb447f33496fe86d77498558d2d5 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sun, 14 Jul 2024 17:46:25 +0530 Subject: [PATCH 06/54] Fix malformed suggestion for repeated maybe unsized bounds --- compiler/rustc_hir/src/hir.rs | 24 ++- compiler/rustc_middle/src/ty/diagnostics.rs | 69 +++++-- ...tionf-for-repeated-unsized-bound-127441.rs | 39 ++++ ...f-for-repeated-unsized-bound-127441.stderr | 192 ++++++++++++++++++ 4 files changed, 295 insertions(+), 29 deletions(-) create mode 100644 tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs create mode 100644 tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d57fad6ba4c2..0f1b2bec6c64 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -723,7 +723,7 @@ impl<'hir> Generics<'hir> { ) } - fn span_for_predicate_removal(&self, pos: usize) -> Span { + pub fn span_for_predicate_removal(&self, pos: usize) -> Span { let predicate = &self.predicates[pos]; let span = predicate.span(); @@ -766,15 +766,21 @@ impl<'hir> Generics<'hir> { return self.span_for_predicate_removal(predicate_pos); } - let span = bounds[bound_pos].span(); - if bound_pos == 0 { - // where T: ?Sized + Bar, Foo: Bar, - // ^^^^^^^^^ - span.to(bounds[1].span().shrink_to_lo()) + let bound_span = bounds[bound_pos].span(); + if bound_pos < bounds.len() - 1 { + // If there's another bound after the current bound + // include the following '+' e.g.: + // + // `T: Foo + CurrentBound + Bar` + // ^^^^^^^^^^^^^^^ + bound_span.to(bounds[bound_pos + 1].span().shrink_to_lo()) } else { - // where T: Bar + ?Sized, Foo: Bar, - // ^^^^^^^^^ - bounds[bound_pos - 1].span().shrink_to_hi().to(span) + // If the current bound is the last bound + // include the preceding '+' E.g.: + // + // `T: Foo + Bar + CurrentBound` + // ^^^^^^^^^^^^^^^ + bound_span.with_lo(bounds[bound_pos - 1].span().hi()) } } } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 4bf223379913..3a5cb22be388 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -188,31 +188,60 @@ fn suggest_changing_unsized_bound( continue; }; - for (pos, bound) in predicate.bounds.iter().enumerate() { - let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else { - continue; - }; - if poly.trait_ref.trait_def_id() != def_id { - continue; - } - if predicate.origin == PredicateOrigin::ImplTrait && predicate.bounds.len() == 1 { - // For `impl ?Sized` with no other bounds, suggest `impl Sized` instead. - let bound_span = bound.span(); - if bound_span.can_be_used_for_suggestions() { - let question_span = bound_span.with_hi(bound_span.lo() + BytePos(1)); - suggestions.push(( + let unsized_bounds = predicate + .bounds + .iter() + .enumerate() + .filter(|(_, bound)| { + if let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound + && poly.trait_ref.trait_def_id() == def_id + { + true + } else { + false + } + }) + .collect::>(); + + if unsized_bounds.is_empty() { + continue; + } + + let mut push_suggestion = |sp, msg| suggestions.push((sp, String::new(), msg)); + + if predicate.bounds.len() == unsized_bounds.len() { + // All the bounds are unsized bounds, e.g. + // `T: ?Sized + ?Sized` or `_: impl ?Sized + ?Sized`, + // so in this case: + // - if it's an impl trait predicate suggest changing the + // the first bound to sized and removing the rest + // - Otherwise simply suggest removing the entire predicate + if predicate.origin == PredicateOrigin::ImplTrait { + let first_bound = unsized_bounds[0].1; + let first_bound_span = first_bound.span(); + if first_bound_span.can_be_used_for_suggestions() { + let question_span = + first_bound_span.with_hi(first_bound_span.lo() + BytePos(1)); + push_suggestion( question_span, - String::new(), SuggestChangingConstraintsMessage::ReplaceMaybeUnsizedWithSized, - )); + ); + + for (pos, _) in unsized_bounds.iter().skip(1) { + let sp = generics.span_for_bound_removal(where_pos, *pos); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); + } } } else { + let sp = generics.span_for_predicate_removal(where_pos); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); + } + } else { + // Some of the bounds are other than unsized. + // So push separate removal suggestion for each unsized bound + for (pos, _) in unsized_bounds { let sp = generics.span_for_bound_removal(where_pos, pos); - suggestions.push(( - sp, - String::new(), - SuggestChangingConstraintsMessage::RemoveMaybeUnsized, - )); + push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized); } } } diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs new file mode 100644 index 000000000000..e6d7f74880fb --- /dev/null +++ b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.rs @@ -0,0 +1,39 @@ +// Regression test for #127441 + +// Tests that we make the correct suggestion +// in case there are more than one `?Sized` +// bounds on a function parameter + +use std::fmt::Debug; + +fn foo1(a: T) {} +//~^ ERROR he size for values of type `T` cannot be known at compilation time + +fn foo2(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `T` cannot be known at compilation time + +fn foo3(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR he size for values of type `T` cannot be known at compilation time + +fn foo4(a: T) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `T` cannot be known at compilation time + +fn foo5(_: impl ?Sized) {} +//~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time + +fn foo6(_: impl ?Sized + ?Sized) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation tim + +fn foo7(_: impl ?Sized + ?Sized + Debug) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time + +fn foo8(_: impl ?Sized + Debug + ?Sized ) {} +//~^ ERROR type parameter has more than one relaxed default bound, only one is supported +//~| ERROR the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time + +fn main() {} diff --git a/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr new file mode 100644 index 000000000000..3e8f45ee9fc2 --- /dev/null +++ b/tests/ui/trait-bounds/bad-suggestionf-for-repeated-unsized-bound-127441.stderr @@ -0,0 +1,192 @@ +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:12 + | +LL | fn foo2(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:12 + | +LL | fn foo3(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:12 + | +LL | fn foo4(a: T) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:17 + | +LL | fn foo6(_: impl ?Sized + ?Sized) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:17 + | +LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {} + | ^^^^^^ ^^^^^^ + +error[E0203]: type parameter has more than one relaxed default bound, only one is supported + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:17 + | +LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {} + | ^^^^^^ ^^^^^^ + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:9:20 + | +LL | fn foo1(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn foo1(a: T) {} +LL + fn foo1(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo1(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:12:29 + | +LL | fn foo2(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn foo2(a: T) {} +LL + fn foo2(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo2(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:16:37 + | +LL | fn foo3(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo3(a: T) {} +LL + fn foo3(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo3(a: &T) {} + | + + +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:20:38 + | +LL | fn foo4(a: T) {} + | - ^ doesn't have a size known at compile-time + | | + | this type parameter needs to be `Sized` + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo4(a: T) {} +LL + fn foo4(a: T) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo4(a: &T) {} + | + + +error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:24:9 + | +LL | fn foo5(_: impl ?Sized) {} + | ^ ----------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider replacing `?Sized` with `Sized` + | +LL - fn foo5(_: impl ?Sized) {} +LL + fn foo5(_: impl Sized) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo5(_: &impl ?Sized) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:27:9 + | +LL | fn foo6(_: impl ?Sized + ?Sized) {} + | ^ -------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo6(_: impl ?Sized + ?Sized) {} +LL + fn foo6(_: impl Sized) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo6(_: &impl ?Sized + ?Sized) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + ?Sized + Debug` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:31:9 + | +LL | fn foo7(_: impl ?Sized + ?Sized + Debug) {} + | ^ ---------------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo7(_: impl ?Sized + ?Sized + Debug) {} +LL + fn foo7(_: impl Debug) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo7(_: &impl ?Sized + ?Sized + Debug) {} + | + + +error[E0277]: the size for values of type `impl ?Sized + Debug + ?Sized` cannot be known at compilation time + --> $DIR/bad-suggestionf-for-repeated-unsized-bound-127441.rs:35:9 + | +LL | fn foo8(_: impl ?Sized + Debug + ?Sized ) {} + | ^ ---------------------------- this type parameter needs to be `Sized` + | | + | doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider restricting type parameters + | +LL - fn foo8(_: impl ?Sized + Debug + ?Sized ) {} +LL + fn foo8(_: impl Debug ) {} + | +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn foo8(_: &impl ?Sized + Debug + ?Sized ) {} + | + + +error: aborting due to 14 previous errors + +Some errors have detailed explanations: E0203, E0277. +For more information about an error, try `rustc --explain E0203`. From 772315de7c1f68bb95de5a7eb85cb2f167834c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 8 Jul 2024 14:30:17 +0200 Subject: [PATCH 07/54] Remove generic lifetime parameter of trait `Pattern` Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway. --- library/alloc/src/str.rs | 4 +- library/alloc/src/string.rs | 27 ++-- library/alloc/tests/str.rs | 14 +- library/core/src/str/iter.rs | 90 ++++++------ library/core/src/str/mod.rs | 75 +++++----- library/core/src/str/pattern.rs | 132 +++++++++--------- tests/ui/suggestions/issue-104961.fixed | 4 +- tests/ui/suggestions/issue-104961.rs | 4 +- tests/ui/suggestions/issue-104961.stderr | 12 +- tests/ui/suggestions/issue-62843.stderr | 6 +- .../bound/assoc-fn-bound-root-obligation.rs | 12 +- .../assoc-fn-bound-root-obligation.stderr | 15 +- .../root-obligation.fixed | 2 +- .../suggest-dereferences/root-obligation.rs | 2 +- .../root-obligation.stderr | 6 +- 15 files changed, 207 insertions(+), 198 deletions(-) diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 3bb808a6c73a..94053ef83a0e 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -269,7 +269,7 @@ impl str { without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String { + pub fn replace(&self, from: P, to: &str) -> String { let mut result = String::new(); let mut last_end = 0; for (start, part) in self.match_indices(from) { @@ -309,7 +309,7 @@ impl str { #[must_use = "this returns the replaced string as a new allocation, \ without modifying the original"] #[stable(feature = "str_replacen", since = "1.16.0")] - pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String { + pub fn replacen(&self, pat: P, to: &str, count: usize) -> String { // Hope to reduce the times of re-allocation let mut result = String::with_capacity(32); let mut last_end = 0; diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 07ffd3e15191..0ff66167a46a 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1497,10 +1497,7 @@ impl String { /// ``` #[cfg(not(no_global_oom_handling))] #[unstable(feature = "string_remove_matches", reason = "new API", issue = "72826")] - pub fn remove_matches<'a, P>(&'a mut self, pat: P) - where - P: for<'x> Pattern<'x>, - { + pub fn remove_matches(&mut self, pat: P) { use core::str::pattern::Searcher; let rejections = { @@ -2288,35 +2285,41 @@ impl<'a> Extend> for String { reason = "API not fully fleshed out and ready to be stabilized", issue = "27721" )] -impl<'a, 'b> Pattern<'a> for &'b String { - type Searcher = <&'b str as Pattern<'a>>::Searcher; +impl<'b> Pattern for &'b String { + type Searcher<'a> = <&'b str as Pattern>::Searcher<'a>; - fn into_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher { + fn into_searcher(self, haystack: &str) -> <&'b str as Pattern>::Searcher<'_> { self[..].into_searcher(haystack) } #[inline] - fn is_contained_in(self, haystack: &'a str) -> bool { + fn is_contained_in(self, haystack: &str) -> bool { self[..].is_contained_in(haystack) } #[inline] - fn is_prefix_of(self, haystack: &'a str) -> bool { + fn is_prefix_of(self, haystack: &str) -> bool { self[..].is_prefix_of(haystack) } #[inline] - fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_prefix_of(self, haystack: &str) -> Option<&str> { self[..].strip_prefix_of(haystack) } #[inline] - fn is_suffix_of(self, haystack: &'a str) -> bool { + fn is_suffix_of<'a>(self, haystack: &'a str) -> bool + where + Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>, + { self[..].is_suffix_of(haystack) } #[inline] - fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&str> + where + Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>, + { self[..].strip_suffix_of(haystack) } } diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 0078f5eaa3d2..de5d3991c914 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -1927,12 +1927,10 @@ mod pattern { } } - fn cmp_search_to_vec<'a>( - rev: bool, - pat: impl Pattern<'a, Searcher: ReverseSearcher<'a>>, - haystack: &'a str, - right: Vec, - ) { + fn cmp_search_to_vec

(rev: bool, pat: P, haystack: &str, right: Vec) + where + P: for<'a> Pattern: ReverseSearcher<'a>>, + { let mut searcher = pat.into_searcher(haystack); let mut v = vec![]; loop { @@ -2191,9 +2189,9 @@ generate_iterator_test! { fn different_str_pattern_forwarding_lifetimes() { use std::str::pattern::Pattern; - fn foo<'a, P>(p: P) + fn foo

(p: P) where - for<'b> &'b P: Pattern<'a>, + for<'b> &'b P: Pattern, { for _ in 0..3 { "asdf".find(&p); diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 19627f28e64f..5845e3b5481a 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -411,7 +411,7 @@ macro_rules! derive_pattern_clone { (clone $t:ident with |$s:ident| $e:expr) => { impl<'a, P> Clone for $t<'a, P> where - P: Pattern<'a, Searcher: Clone>, + P: Pattern: Clone>, { fn clone(&self) -> Self { let $s = self; @@ -424,7 +424,7 @@ macro_rules! derive_pattern_clone { /// This macro generates two public iterator structs /// wrapping a private internal one that makes use of the `Pattern` API. /// -/// For all patterns `P: Pattern<'a>` the following items will be +/// For all patterns `P: Pattern` the following items will be /// generated (generics omitted): /// /// struct $forward_iterator($internal_iterator); @@ -484,12 +484,12 @@ macro_rules! generate_pattern_iterators { } => { $(#[$forward_iterator_attribute])* $(#[$common_stability_attribute])* - pub struct $forward_iterator<'a, P: Pattern<'a>>(pub(super) $internal_iterator<'a, P>); + pub struct $forward_iterator<'a, P: Pattern>(pub(super) $internal_iterator<'a, P>); $(#[$common_stability_attribute])* impl<'a, P> fmt::Debug for $forward_iterator<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple(stringify!($forward_iterator)) @@ -499,7 +499,7 @@ macro_rules! generate_pattern_iterators { } $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> Iterator for $forward_iterator<'a, P> { + impl<'a, P: Pattern> Iterator for $forward_iterator<'a, P> { type Item = $iterty; #[inline] @@ -511,7 +511,7 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* impl<'a, P> Clone for $forward_iterator<'a, P> where - P: Pattern<'a, Searcher: Clone>, + P: Pattern: Clone>, { fn clone(&self) -> Self { $forward_iterator(self.0.clone()) @@ -520,12 +520,12 @@ macro_rules! generate_pattern_iterators { $(#[$reverse_iterator_attribute])* $(#[$common_stability_attribute])* - pub struct $reverse_iterator<'a, P: Pattern<'a>>(pub(super) $internal_iterator<'a, P>); + pub struct $reverse_iterator<'a, P: Pattern>(pub(super) $internal_iterator<'a, P>); $(#[$common_stability_attribute])* impl<'a, P> fmt::Debug for $reverse_iterator<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple(stringify!($reverse_iterator)) @@ -537,7 +537,7 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* impl<'a, P> Iterator for $reverse_iterator<'a, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + P: Pattern: ReverseSearcher<'a>>, { type Item = $iterty; @@ -550,7 +550,7 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* impl<'a, P> Clone for $reverse_iterator<'a, P> where - P: Pattern<'a, Searcher: Clone>, + P: Pattern: Clone>, { fn clone(&self) -> Self { $reverse_iterator(self.0.clone()) @@ -558,12 +558,12 @@ macro_rules! generate_pattern_iterators { } #[stable(feature = "fused", since = "1.26.0")] - impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {} + impl<'a, P: Pattern> FusedIterator for $forward_iterator<'a, P> {} #[stable(feature = "fused", since = "1.26.0")] impl<'a, P> FusedIterator for $reverse_iterator<'a, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + P: Pattern: ReverseSearcher<'a>>, {} generate_pattern_iterators!($($t)* with $(#[$common_stability_attribute])*, @@ -578,7 +578,7 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* impl<'a, P> DoubleEndedIterator for $forward_iterator<'a, P> where - P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, + P: Pattern: DoubleEndedSearcher<'a>>, { #[inline] fn next_back(&mut self) -> Option<$iterty> { @@ -589,7 +589,7 @@ macro_rules! generate_pattern_iterators { $(#[$common_stability_attribute])* impl<'a, P> DoubleEndedIterator for $reverse_iterator<'a, P> where - P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, + P: Pattern: DoubleEndedSearcher<'a>>, { #[inline] fn next_back(&mut self) -> Option<$iterty> { @@ -609,17 +609,17 @@ derive_pattern_clone! { with |s| SplitInternal { matcher: s.matcher.clone(), ..*s } } -pub(super) struct SplitInternal<'a, P: Pattern<'a>> { +pub(super) struct SplitInternal<'a, P: Pattern> { pub(super) start: usize, pub(super) end: usize, - pub(super) matcher: P::Searcher, + pub(super) matcher: P::Searcher<'a>, pub(super) allow_trailing_empty: bool, pub(super) finished: bool, } impl<'a, P> fmt::Debug for SplitInternal<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SplitInternal") @@ -632,7 +632,7 @@ where } } -impl<'a, P: Pattern<'a>> SplitInternal<'a, P> { +impl<'a, P: Pattern> SplitInternal<'a, P> { #[inline] fn get_end(&mut self) -> Option<&'a str> { if !self.finished { @@ -689,7 +689,7 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> { #[inline] fn next_back(&mut self) -> Option<&'a str> where - P::Searcher: ReverseSearcher<'a>, + P::Searcher<'a>: ReverseSearcher<'a>, { if self.finished { return None; @@ -726,7 +726,7 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> { #[inline] fn next_back_inclusive(&mut self) -> Option<&'a str> where - P::Searcher: ReverseSearcher<'a>, + P::Searcher<'a>: ReverseSearcher<'a>, { if self.finished { return None; @@ -796,7 +796,7 @@ generate_pattern_iterators! { delegate double ended; } -impl<'a, P: Pattern<'a>> Split<'a, P> { +impl<'a, P: Pattern> Split<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -819,7 +819,7 @@ impl<'a, P: Pattern<'a>> Split<'a, P> { } } -impl<'a, P: Pattern<'a>> RSplit<'a, P> { +impl<'a, P: Pattern> RSplit<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -860,7 +860,7 @@ generate_pattern_iterators! { delegate double ended; } -impl<'a, P: Pattern<'a>> SplitTerminator<'a, P> { +impl<'a, P: Pattern> SplitTerminator<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -883,7 +883,7 @@ impl<'a, P: Pattern<'a>> SplitTerminator<'a, P> { } } -impl<'a, P: Pattern<'a>> RSplitTerminator<'a, P> { +impl<'a, P: Pattern> RSplitTerminator<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -911,7 +911,7 @@ derive_pattern_clone! { with |s| SplitNInternal { iter: s.iter.clone(), ..*s } } -pub(super) struct SplitNInternal<'a, P: Pattern<'a>> { +pub(super) struct SplitNInternal<'a, P: Pattern> { pub(super) iter: SplitInternal<'a, P>, /// The number of splits remaining pub(super) count: usize, @@ -919,7 +919,7 @@ pub(super) struct SplitNInternal<'a, P: Pattern<'a>> { impl<'a, P> fmt::Debug for SplitNInternal<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SplitNInternal") @@ -929,7 +929,7 @@ where } } -impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> { +impl<'a, P: Pattern> SplitNInternal<'a, P> { #[inline] fn next(&mut self) -> Option<&'a str> { match self.count { @@ -948,7 +948,7 @@ impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> { #[inline] fn next_back(&mut self) -> Option<&'a str> where - P::Searcher: ReverseSearcher<'a>, + P::Searcher<'a>: ReverseSearcher<'a>, { match self.count { 0 => None, @@ -987,7 +987,7 @@ generate_pattern_iterators! { delegate single ended; } -impl<'a, P: Pattern<'a>> SplitN<'a, P> { +impl<'a, P: Pattern> SplitN<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -1010,7 +1010,7 @@ impl<'a, P: Pattern<'a>> SplitN<'a, P> { } } -impl<'a, P: Pattern<'a>> RSplitN<'a, P> { +impl<'a, P: Pattern> RSplitN<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. @@ -1038,18 +1038,18 @@ derive_pattern_clone! { with |s| MatchIndicesInternal(s.0.clone()) } -pub(super) struct MatchIndicesInternal<'a, P: Pattern<'a>>(pub(super) P::Searcher); +pub(super) struct MatchIndicesInternal<'a, P: Pattern>(pub(super) P::Searcher<'a>); impl<'a, P> fmt::Debug for MatchIndicesInternal<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("MatchIndicesInternal").field(&self.0).finish() } } -impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> { +impl<'a, P: Pattern> MatchIndicesInternal<'a, P> { #[inline] fn next(&mut self) -> Option<(usize, &'a str)> { self.0 @@ -1061,7 +1061,7 @@ impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> { #[inline] fn next_back(&mut self) -> Option<(usize, &'a str)> where - P::Searcher: ReverseSearcher<'a>, + P::Searcher<'a>: ReverseSearcher<'a>, { self.0 .next_match_back() @@ -1093,18 +1093,18 @@ derive_pattern_clone! { with |s| MatchesInternal(s.0.clone()) } -pub(super) struct MatchesInternal<'a, P: Pattern<'a>>(pub(super) P::Searcher); +pub(super) struct MatchesInternal<'a, P: Pattern>(pub(super) P::Searcher<'a>); impl<'a, P> fmt::Debug for MatchesInternal<'a, P> where - P: Pattern<'a, Searcher: fmt::Debug>, + P: Pattern: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("MatchesInternal").field(&self.0).finish() } } -impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> { +impl<'a, P: Pattern> MatchesInternal<'a, P> { #[inline] fn next(&mut self) -> Option<&'a str> { // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries. @@ -1117,7 +1117,7 @@ impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> { #[inline] fn next_back(&mut self) -> Option<&'a str> where - P::Searcher: ReverseSearcher<'a>, + P::Searcher<'a>: ReverseSearcher<'a>, { // SAFETY: `Searcher` guarantees that `start` and `end` lie on unicode boundaries. self.0.next_match_back().map(|(a, b)| unsafe { @@ -1288,7 +1288,7 @@ pub struct SplitAsciiWhitespace<'a> { /// /// [`split_inclusive`]: str::split_inclusive #[stable(feature = "split_inclusive", since = "1.51.0")] -pub struct SplitInclusive<'a, P: Pattern<'a>>(pub(super) SplitInternal<'a, P>); +pub struct SplitInclusive<'a, P: Pattern>(pub(super) SplitInternal<'a, P>); #[stable(feature = "split_whitespace", since = "1.1.0")] impl<'a> Iterator for SplitWhitespace<'a> { @@ -1410,7 +1410,7 @@ impl<'a> SplitAsciiWhitespace<'a> { } #[stable(feature = "split_inclusive", since = "1.51.0")] -impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> { +impl<'a, P: Pattern> Iterator for SplitInclusive<'a, P> { type Item = &'a str; #[inline] @@ -1420,7 +1420,7 @@ impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> { } #[stable(feature = "split_inclusive", since = "1.51.0")] -impl<'a, P: Pattern<'a, Searcher: fmt::Debug>> fmt::Debug for SplitInclusive<'a, P> { +impl<'a, P: Pattern: fmt::Debug>> fmt::Debug for SplitInclusive<'a, P> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SplitInclusive").field("0", &self.0).finish() } @@ -1428,14 +1428,14 @@ impl<'a, P: Pattern<'a, Searcher: fmt::Debug>> fmt::Debug for SplitInclusive<'a, // FIXME(#26925) Remove in favor of `#[derive(Clone)]` #[stable(feature = "split_inclusive", since = "1.51.0")] -impl<'a, P: Pattern<'a, Searcher: Clone>> Clone for SplitInclusive<'a, P> { +impl<'a, P: Pattern: Clone>> Clone for SplitInclusive<'a, P> { fn clone(&self) -> Self { SplitInclusive(self.0.clone()) } } #[stable(feature = "split_inclusive", since = "1.51.0")] -impl<'a, P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>> DoubleEndedIterator +impl<'a, P: Pattern: DoubleEndedSearcher<'a>>> DoubleEndedIterator for SplitInclusive<'a, P> { #[inline] @@ -1445,9 +1445,9 @@ impl<'a, P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>> DoubleEndedIterator } #[stable(feature = "split_inclusive", since = "1.51.0")] -impl<'a, P: Pattern<'a>> FusedIterator for SplitInclusive<'a, P> {} +impl<'a, P: Pattern> FusedIterator for SplitInclusive<'a, P> {} -impl<'a, P: Pattern<'a>> SplitInclusive<'a, P> { +impl<'a, P: Pattern> SplitInclusive<'a, P> { /// Returns remainder of the split string. /// /// If the iterator is empty, returns `None`. diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 683109380439..0537b3d93c46 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -1137,7 +1137,7 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool { + pub fn contains(&self, pat: P) -> bool { pat.is_contained_in(self) } @@ -1174,7 +1174,7 @@ impl str { /// assert!(bananas.starts_with(&['a', 'b', 'c', 'd'])); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn starts_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool { + pub fn starts_with(&self, pat: P) -> bool { pat.is_prefix_of(self) } @@ -1198,9 +1198,9 @@ impl str { /// assert!(!bananas.ends_with("nana")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn ends_with<'a, P>(&'a self, pat: P) -> bool + pub fn ends_with(&self, pat: P) -> bool where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { pat.is_suffix_of(self) } @@ -1249,7 +1249,7 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option { + pub fn find(&self, pat: P) -> Option { pat.into_searcher(self).next_match().map(|(i, _)| i) } @@ -1295,9 +1295,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rfind<'a, P>(&'a self, pat: P) -> Option + pub fn rfind(&self, pat: P) -> Option where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { pat.into_searcher(self).next_match_back().map(|(i, _)| i) } @@ -1417,7 +1417,7 @@ impl str { /// [`split_whitespace`]: str::split_whitespace #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> { + pub fn split(&self, pat: P) -> Split<'_, P> { Split(SplitInternal { start: 0, end: self.len(), @@ -1457,7 +1457,7 @@ impl str { /// ``` #[stable(feature = "split_inclusive", since = "1.51.0")] #[inline] - pub fn split_inclusive<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitInclusive<'a, P> { + pub fn split_inclusive(&self, pat: P) -> SplitInclusive<'_, P> { SplitInclusive(SplitInternal { start: 0, end: self.len(), @@ -1512,9 +1512,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplit<'a, P>(&'a self, pat: P) -> RSplit<'a, P> + pub fn rsplit(&self, pat: P) -> RSplit<'_, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { RSplit(self.split(pat).0) } @@ -1561,7 +1561,7 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P> { + pub fn split_terminator(&self, pat: P) -> SplitTerminator<'_, P> { SplitTerminator(SplitInternal { allow_trailing_empty: false, ..self.split(pat).0 }) } @@ -1607,9 +1607,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplit_terminator<'a, P>(&'a self, pat: P) -> RSplitTerminator<'a, P> + pub fn rsplit_terminator(&self, pat: P) -> RSplitTerminator<'_, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { RSplitTerminator(self.split_terminator(pat).0) } @@ -1662,7 +1662,7 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn splitn<'a, P: Pattern<'a>>(&'a self, n: usize, pat: P) -> SplitN<'a, P> { + pub fn splitn(&self, n: usize, pat: P) -> SplitN<'_, P> { SplitN(SplitNInternal { iter: self.split(pat).0, count: n }) } @@ -1711,9 +1711,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplitn<'a, P>(&'a self, n: usize, pat: P) -> RSplitN<'a, P> + pub fn rsplitn(&self, n: usize, pat: P) -> RSplitN<'_, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { RSplitN(self.splitn(n, pat).0) } @@ -1731,7 +1731,7 @@ impl str { /// ``` #[stable(feature = "str_split_once", since = "1.52.0")] #[inline] - pub fn split_once<'a, P: Pattern<'a>>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)> { + pub fn split_once(&self, delimiter: P) -> Option<(&'_ str, &'_ str)> { let (start, end) = delimiter.into_searcher(self).next_match()?; // SAFETY: `Searcher` is known to return valid indices. unsafe { Some((self.get_unchecked(..start), self.get_unchecked(end..))) } @@ -1749,9 +1749,9 @@ impl str { /// ``` #[stable(feature = "str_split_once", since = "1.52.0")] #[inline] - pub fn rsplit_once<'a, P>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)> + pub fn rsplit_once(&self, delimiter: P) -> Option<(&'_ str, &'_ str)> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { let (start, end) = delimiter.into_searcher(self).next_match_back()?; // SAFETY: `Searcher` is known to return valid indices. @@ -1789,7 +1789,7 @@ impl str { /// ``` #[stable(feature = "str_matches", since = "1.2.0")] #[inline] - pub fn matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> Matches<'a, P> { + pub fn matches(&self, pat: P) -> Matches<'_, P> { Matches(MatchesInternal(pat.into_searcher(self))) } @@ -1823,9 +1823,9 @@ impl str { /// ``` #[stable(feature = "str_matches", since = "1.2.0")] #[inline] - pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> + pub fn rmatches(&self, pat: P) -> RMatches<'_, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { RMatches(self.matches(pat).0) } @@ -1867,7 +1867,7 @@ impl str { /// ``` #[stable(feature = "str_match_indices", since = "1.5.0")] #[inline] - pub fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P> { + pub fn match_indices(&self, pat: P) -> MatchIndices<'_, P> { MatchIndices(MatchIndicesInternal(pat.into_searcher(self))) } @@ -1907,9 +1907,9 @@ impl str { /// ``` #[stable(feature = "str_match_indices", since = "1.5.0")] #[inline] - pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> + pub fn rmatch_indices(&self, pat: P) -> RMatchIndices<'_, P> where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { RMatchIndices(self.match_indices(pat).0) } @@ -2122,9 +2122,9 @@ impl str { #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] - pub fn trim_matches<'a, P>(&'a self, pat: P) -> &'a str + pub fn trim_matches(&self, pat: P) -> &str where - P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, + for<'a> P::Searcher<'a>: DoubleEndedSearcher<'a>, { let mut i = 0; let mut j = 0; @@ -2169,7 +2169,7 @@ impl str { #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] - pub fn trim_start_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str { + pub fn trim_start_matches(&self, pat: P) -> &str { let mut i = self.len(); let mut matcher = pat.into_searcher(self); if let Some((a, _)) = matcher.next_reject() { @@ -2202,7 +2202,7 @@ impl str { #[must_use = "this returns the remaining substring as a new slice, \ without modifying the original"] #[stable(feature = "str_strip", since = "1.45.0")] - pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str> { + pub fn strip_prefix(&self, prefix: P) -> Option<&str> { prefix.strip_prefix_of(self) } @@ -2229,10 +2229,9 @@ impl str { #[must_use = "this returns the remaining substring as a new slice, \ without modifying the original"] #[stable(feature = "str_strip", since = "1.45.0")] - pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str> + pub fn strip_suffix(&self, suffix: P) -> Option<&str> where - P: Pattern<'a>, -

>::Searcher: ReverseSearcher<'a>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { suffix.strip_suffix_of(self) } @@ -2273,9 +2272,9 @@ impl str { #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] - pub fn trim_end_matches<'a, P>(&'a self, pat: P) -> &'a str + pub fn trim_end_matches(&self, pat: P) -> &str where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { let mut j = 0; let mut matcher = pat.into_searcher(self); @@ -2317,7 +2316,7 @@ impl str { note = "superseded by `trim_start_matches`", suggestion = "trim_start_matches" )] - pub fn trim_left_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str { + pub fn trim_left_matches(&self, pat: P) -> &str { self.trim_start_matches(pat) } @@ -2360,9 +2359,9 @@ impl str { note = "superseded by `trim_end_matches`", suggestion = "trim_end_matches" )] - pub fn trim_right_matches<'a, P>(&'a self, pat: P) -> &'a str + pub fn trim_right_matches(&self, pat: P) -> &str where - P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + for<'a> P::Searcher<'a>: ReverseSearcher<'a>, { self.trim_end_matches(pat) } diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index 8988229be2e5..33a5d45e445d 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -48,8 +48,8 @@ use crate::slice::memchr; /// A string pattern. /// -/// A `Pattern<'a>` expresses that the implementing type -/// can be used as a string pattern for searching in a [`&'a str`][str]. +/// A `Pattern` expresses that the implementing type +/// can be used as a string pattern for searching in a [`&str`][str]. /// /// For example, both `'a'` and `"aa"` are patterns that /// would match at index `1` in the string `"baaaab"`. @@ -97,38 +97,38 @@ use crate::slice::memchr; /// assert_eq!("abcdef_z".find(|ch| ch > 'd' && ch < 'y'), Some(4)); /// assert_eq!("abcddd_z".find(|ch| ch > 'd' && ch < 'y'), None); /// ``` -pub trait Pattern<'a>: Sized { +pub trait Pattern: Sized { /// Associated searcher for this pattern - type Searcher: Searcher<'a>; + type Searcher<'a>: Searcher<'a>; /// Constructs the associated searcher from /// `self` and the `haystack` to search in. - fn into_searcher(self, haystack: &'a str) -> Self::Searcher; + fn into_searcher(self, haystack: &str) -> Self::Searcher<'_>; /// Checks whether the pattern matches anywhere in the haystack #[inline] - fn is_contained_in(self, haystack: &'a str) -> bool { + fn is_contained_in(self, haystack: &str) -> bool { self.into_searcher(haystack).next_match().is_some() } /// Checks whether the pattern matches at the front of the haystack #[inline] - fn is_prefix_of(self, haystack: &'a str) -> bool { + fn is_prefix_of(self, haystack: &str) -> bool { matches!(self.into_searcher(haystack).next(), SearchStep::Match(0, _)) } /// Checks whether the pattern matches at the back of the haystack #[inline] - fn is_suffix_of(self, haystack: &'a str) -> bool + fn is_suffix_of<'a>(self, haystack: &'a str) -> bool where - Self::Searcher: ReverseSearcher<'a>, + Self::Searcher<'a>: ReverseSearcher<'a>, { matches!(self.into_searcher(haystack).next_back(), SearchStep::Match(_, j) if haystack.len() == j) } /// Removes the pattern from the front of haystack, if it matches. #[inline] - fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_prefix_of(self, haystack: &str) -> Option<&str> { if let SearchStep::Match(start, len) = self.into_searcher(haystack).next() { debug_assert_eq!( start, 0, @@ -144,9 +144,9 @@ pub trait Pattern<'a>: Sized { /// Removes the pattern from the back of haystack, if it matches. #[inline] - fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> + fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str> where - Self::Searcher: ReverseSearcher<'a>, + Self::Searcher<'a>: ReverseSearcher<'a>, { if let SearchStep::Match(start, end) = self.into_searcher(haystack).next_back() { debug_assert_eq!( @@ -349,7 +349,7 @@ pub trait DoubleEndedSearcher<'a>: ReverseSearcher<'a> {} // Impl for char ///////////////////////////////////////////////////////////////////////////// -/// Associated type for `>::Searcher`. +/// Associated type for `::Searcher<'a>`. #[derive(Clone, Debug)] pub struct CharSearcher<'a> { haystack: &'a str, @@ -543,11 +543,11 @@ impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {} /// ``` /// assert_eq!("Hello world".find('o'), Some(4)); /// ``` -impl<'a> Pattern<'a> for char { - type Searcher = CharSearcher<'a>; +impl Pattern for char { + type Searcher<'a> = CharSearcher<'a>; #[inline] - fn into_searcher(self, haystack: &'a str) -> Self::Searcher { + fn into_searcher(self, haystack: &str) -> Self::Searcher<'_> { let mut utf8_encoded = [0; 4]; let utf8_size = self .encode_utf8(&mut utf8_encoded) @@ -566,7 +566,7 @@ impl<'a> Pattern<'a> for char { } #[inline] - fn is_contained_in(self, haystack: &'a str) -> bool { + fn is_contained_in(self, haystack: &str) -> bool { if (self as u32) < 128 { haystack.as_bytes().contains(&(self as u8)) } else { @@ -576,27 +576,27 @@ impl<'a> Pattern<'a> for char { } #[inline] - fn is_prefix_of(self, haystack: &'a str) -> bool { + fn is_prefix_of(self, haystack: &str) -> bool { self.encode_utf8(&mut [0u8; 4]).is_prefix_of(haystack) } #[inline] - fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_prefix_of(self, haystack: &str) -> Option<&str> { self.encode_utf8(&mut [0u8; 4]).strip_prefix_of(haystack) } #[inline] - fn is_suffix_of(self, haystack: &'a str) -> bool + fn is_suffix_of<'a>(self, haystack: &'a str) -> bool where - Self::Searcher: ReverseSearcher<'a>, + Self::Searcher<'a>: ReverseSearcher<'a>, { self.encode_utf8(&mut [0u8; 4]).is_suffix_of(haystack) } #[inline] - fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> + fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str> where - Self::Searcher: ReverseSearcher<'a>, + Self::Searcher<'a>: ReverseSearcher<'a>, { self.encode_utf8(&mut [0u8; 4]).strip_suffix_of(haystack) } @@ -651,11 +651,11 @@ struct MultiCharEqSearcher<'a, C: MultiCharEq> { char_indices: super::CharIndices<'a>, } -impl<'a, C: MultiCharEq> Pattern<'a> for MultiCharEqPattern { - type Searcher = MultiCharEqSearcher<'a, C>; +impl Pattern for MultiCharEqPattern { + type Searcher<'a> = MultiCharEqSearcher<'a, C>; #[inline] - fn into_searcher(self, haystack: &'a str) -> MultiCharEqSearcher<'a, C> { + fn into_searcher(self, haystack: &str) -> MultiCharEqSearcher<'_, C> { MultiCharEqSearcher { haystack, char_eq: self.0, char_indices: haystack.char_indices() } } } @@ -710,41 +710,41 @@ impl<'a, C: MultiCharEq> DoubleEndedSearcher<'a> for MultiCharEqSearcher<'a, C> ///////////////////////////////////////////////////////////////////////////// macro_rules! pattern_methods { - ($t:ty, $pmap:expr, $smap:expr) => { - type Searcher = $t; + ($a:lifetime, $t:ty, $pmap:expr, $smap:expr) => { + type Searcher<$a> = $t; #[inline] - fn into_searcher(self, haystack: &'a str) -> $t { + fn into_searcher<$a>(self, haystack: &$a str) -> $t { ($smap)(($pmap)(self).into_searcher(haystack)) } #[inline] - fn is_contained_in(self, haystack: &'a str) -> bool { + fn is_contained_in<$a>(self, haystack: &$a str) -> bool { ($pmap)(self).is_contained_in(haystack) } #[inline] - fn is_prefix_of(self, haystack: &'a str) -> bool { + fn is_prefix_of<$a>(self, haystack: &$a str) -> bool { ($pmap)(self).is_prefix_of(haystack) } #[inline] - fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_prefix_of<$a>(self, haystack: &$a str) -> Option<&$a str> { ($pmap)(self).strip_prefix_of(haystack) } #[inline] - fn is_suffix_of(self, haystack: &'a str) -> bool + fn is_suffix_of<$a>(self, haystack: &$a str) -> bool where - $t: ReverseSearcher<'a>, + $t: ReverseSearcher<$a>, { ($pmap)(self).is_suffix_of(haystack) } #[inline] - fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> + fn strip_suffix_of<$a>(self, haystack: &$a str) -> Option<&$a str> where - $t: ReverseSearcher<'a>, + $t: ReverseSearcher<$a>, { ($pmap)(self).strip_suffix_of(haystack) } @@ -786,16 +786,16 @@ macro_rules! searcher_methods { }; } -/// Associated type for `<[char; N] as Pattern<'a>>::Searcher`. +/// Associated type for `<[char; N] as Pattern>::Searcher<'a>`. #[derive(Clone, Debug)] pub struct CharArraySearcher<'a, const N: usize>( - as Pattern<'a>>::Searcher, + as Pattern>::Searcher<'a>, ); -/// Associated type for `<&[char; N] as Pattern<'a>>::Searcher`. +/// Associated type for `<&[char; N] as Pattern>::Searcher<'a>`. #[derive(Clone, Debug)] pub struct CharArrayRefSearcher<'a, 'b, const N: usize>( - as Pattern<'a>>::Searcher, + as Pattern>::Searcher<'a>, ); /// Searches for chars that are equal to any of the [`char`]s in the array. @@ -806,8 +806,8 @@ pub struct CharArrayRefSearcher<'a, 'b, const N: usize>( /// assert_eq!("Hello world".find(['o', 'l']), Some(2)); /// assert_eq!("Hello world".find(['h', 'w']), Some(6)); /// ``` -impl<'a, const N: usize> Pattern<'a> for [char; N] { - pattern_methods!(CharArraySearcher<'a, N>, MultiCharEqPattern, CharArraySearcher); +impl Pattern for [char; N] { + pattern_methods!('a, CharArraySearcher<'a, N>, MultiCharEqPattern, CharArraySearcher); } unsafe impl<'a, const N: usize> Searcher<'a> for CharArraySearcher<'a, N> { @@ -828,8 +828,8 @@ impl<'a, const N: usize> DoubleEndedSearcher<'a> for CharArraySearcher<'a, N> {} /// assert_eq!("Hello world".find(&['o', 'l']), Some(2)); /// assert_eq!("Hello world".find(&['h', 'w']), Some(6)); /// ``` -impl<'a, 'b, const N: usize> Pattern<'a> for &'b [char; N] { - pattern_methods!(CharArrayRefSearcher<'a, 'b, N>, MultiCharEqPattern, CharArrayRefSearcher); +impl<'b, const N: usize> Pattern for &'b [char; N] { + pattern_methods!('a, CharArrayRefSearcher<'a, 'b, N>, MultiCharEqPattern, CharArrayRefSearcher); } unsafe impl<'a, 'b, const N: usize> Searcher<'a> for CharArrayRefSearcher<'a, 'b, N> { @@ -848,9 +848,9 @@ impl<'a, 'b, const N: usize> DoubleEndedSearcher<'a> for CharArrayRefSearcher<'a // Todo: Change / Remove due to ambiguity in meaning. -/// Associated type for `<&[char] as Pattern<'a>>::Searcher`. +/// Associated type for `<&[char] as Pattern>::Searcher<'a>`. #[derive(Clone, Debug)] -pub struct CharSliceSearcher<'a, 'b>( as Pattern<'a>>::Searcher); +pub struct CharSliceSearcher<'a, 'b>( as Pattern>::Searcher<'a>); unsafe impl<'a, 'b> Searcher<'a> for CharSliceSearcher<'a, 'b> { searcher_methods!(forward); @@ -870,17 +870,17 @@ impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {} /// assert_eq!("Hello world".find(&['l', 'l'] as &[_]), Some(2)); /// assert_eq!("Hello world".find(&['l', 'l'][..]), Some(2)); /// ``` -impl<'a, 'b> Pattern<'a> for &'b [char] { - pattern_methods!(CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher); +impl<'b> Pattern for &'b [char] { + pattern_methods!('a, CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher); } ///////////////////////////////////////////////////////////////////////////// // Impl for F: FnMut(char) -> bool ///////////////////////////////////////////////////////////////////////////// -/// Associated type for `>::Searcher`. +/// Associated type for `::Searcher<'a>`. #[derive(Clone)] -pub struct CharPredicateSearcher<'a, F>( as Pattern<'a>>::Searcher) +pub struct CharPredicateSearcher<'a, F>( as Pattern>::Searcher<'a>) where F: FnMut(char) -> bool; @@ -919,11 +919,11 @@ impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F> where F: Fn /// assert_eq!("Hello world".find(char::is_uppercase), Some(0)); /// assert_eq!("Hello world".find(|c| "aeiou".contains(c)), Some(1)); /// ``` -impl<'a, F> Pattern<'a> for F +impl Pattern for F where F: FnMut(char) -> bool, { - pattern_methods!(CharPredicateSearcher<'a, F>, MultiCharEqPattern, CharPredicateSearcher); + pattern_methods!('a, CharPredicateSearcher<'a, F>, MultiCharEqPattern, CharPredicateSearcher); } ///////////////////////////////////////////////////////////////////////////// @@ -931,8 +931,8 @@ where ///////////////////////////////////////////////////////////////////////////// /// Delegates to the `&str` impl. -impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str { - pattern_methods!(StrSearcher<'a, 'b>, |&s| s, |s| s); +impl<'b, 'c> Pattern for &'c &'b str { + pattern_methods!('a, StrSearcher<'a, 'b>, |&s| s, |s| s); } ///////////////////////////////////////////////////////////////////////////// @@ -949,23 +949,23 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str { /// ``` /// assert_eq!("Hello world".find("world"), Some(6)); /// ``` -impl<'a, 'b> Pattern<'a> for &'b str { - type Searcher = StrSearcher<'a, 'b>; +impl<'b> Pattern for &'b str { + type Searcher<'a> = StrSearcher<'a, 'b>; #[inline] - fn into_searcher(self, haystack: &'a str) -> StrSearcher<'a, 'b> { + fn into_searcher(self, haystack: &str) -> StrSearcher<'_, 'b> { StrSearcher::new(haystack, self) } /// Checks whether the pattern matches at the front of the haystack. #[inline] - fn is_prefix_of(self, haystack: &'a str) -> bool { + fn is_prefix_of(self, haystack: &str) -> bool { haystack.as_bytes().starts_with(self.as_bytes()) } /// Checks whether the pattern matches anywhere in the haystack #[inline] - fn is_contained_in(self, haystack: &'a str) -> bool { + fn is_contained_in(self, haystack: &str) -> bool { if self.len() == 0 { return true; } @@ -991,7 +991,7 @@ impl<'a, 'b> Pattern<'a> for &'b str { /// Removes the pattern from the front of haystack, if it matches. #[inline] - fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_prefix_of(self, haystack: &str) -> Option<&str> { if self.is_prefix_of(haystack) { // SAFETY: prefix was just verified to exist. unsafe { Some(haystack.get_unchecked(self.as_bytes().len()..)) } @@ -1002,13 +1002,19 @@ impl<'a, 'b> Pattern<'a> for &'b str { /// Checks whether the pattern matches at the back of the haystack. #[inline] - fn is_suffix_of(self, haystack: &'a str) -> bool { + fn is_suffix_of<'a>(self, haystack: &'a str) -> bool + where + Self::Searcher<'a>: ReverseSearcher<'a>, + { haystack.as_bytes().ends_with(self.as_bytes()) } /// Removes the pattern from the back of haystack, if it matches. #[inline] - fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> { + fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str> + where + Self::Searcher<'a>: ReverseSearcher<'a>, + { if self.is_suffix_of(haystack) { let i = haystack.len() - self.as_bytes().len(); // SAFETY: suffix was just verified to exist. @@ -1024,7 +1030,7 @@ impl<'a, 'b> Pattern<'a> for &'b str { ///////////////////////////////////////////////////////////////////////////// #[derive(Clone, Debug)] -/// Associated type for `<&str as Pattern<'a>>::Searcher`. +/// Associated type for `<&str as Pattern>::Searcher<'a>`. pub struct StrSearcher<'a, 'b> { haystack: &'a str, needle: &'b str, diff --git a/tests/ui/suggestions/issue-104961.fixed b/tests/ui/suggestions/issue-104961.fixed index 5def21b506e1..3019242880f8 100644 --- a/tests/ui/suggestions/issue-104961.fixed +++ b/tests/ui/suggestions/issue-104961.fixed @@ -2,12 +2,12 @@ fn foo(x: &str) -> bool { x.starts_with(&("hi".to_string() + " you")) - //~^ ERROR the trait bound `String: Pattern<'_>` is not satisfied [E0277] + //~^ ERROR the trait bound `String: Pattern` is not satisfied [E0277] } fn foo2(x: &str) -> bool { x.starts_with(&"hi".to_string()) - //~^ ERROR the trait bound `String: Pattern<'_>` is not satisfied [E0277] + //~^ ERROR the trait bound `String: Pattern` is not satisfied [E0277] } fn main() { diff --git a/tests/ui/suggestions/issue-104961.rs b/tests/ui/suggestions/issue-104961.rs index a09b8a887114..b315e9bab0d1 100644 --- a/tests/ui/suggestions/issue-104961.rs +++ b/tests/ui/suggestions/issue-104961.rs @@ -2,12 +2,12 @@ fn foo(x: &str) -> bool { x.starts_with("hi".to_string() + " you") - //~^ ERROR the trait bound `String: Pattern<'_>` is not satisfied [E0277] + //~^ ERROR the trait bound `String: Pattern` is not satisfied [E0277] } fn foo2(x: &str) -> bool { x.starts_with("hi".to_string()) - //~^ ERROR the trait bound `String: Pattern<'_>` is not satisfied [E0277] + //~^ ERROR the trait bound `String: Pattern` is not satisfied [E0277] } fn main() { diff --git a/tests/ui/suggestions/issue-104961.stderr b/tests/ui/suggestions/issue-104961.stderr index 3c5f86817f3a..0d229e6dada5 100644 --- a/tests/ui/suggestions/issue-104961.stderr +++ b/tests/ui/suggestions/issue-104961.stderr @@ -1,12 +1,12 @@ -error[E0277]: the trait bound `String: Pattern<'_>` is not satisfied +error[E0277]: the trait bound `String: Pattern` is not satisfied --> $DIR/issue-104961.rs:4:19 | LL | x.starts_with("hi".to_string() + " you") - | ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` + | ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Pattern` is not implemented for `String` | | | required by a bound introduced by this call | - = note: required for `String` to implement `Pattern<'_>` + = note: required for `String` to implement `Pattern` note: required by a bound in `core::str::::starts_with` --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider borrowing here @@ -14,15 +14,15 @@ help: consider borrowing here LL | x.starts_with(&("hi".to_string() + " you")) | ++ + -error[E0277]: the trait bound `String: Pattern<'_>` is not satisfied +error[E0277]: the trait bound `String: Pattern` is not satisfied --> $DIR/issue-104961.rs:9:19 | LL | x.starts_with("hi".to_string()) - | ----------- ^^^^^^^^^^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` + | ----------- ^^^^^^^^^^^^^^^^ the trait `Pattern` is not implemented for `String` | | | required by a bound introduced by this call | - = note: required for `String` to implement `Pattern<'_>` + = note: required for `String` to implement `Pattern` note: required by a bound in `core::str::::starts_with` --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider borrowing here diff --git a/tests/ui/suggestions/issue-62843.stderr b/tests/ui/suggestions/issue-62843.stderr index 84ab4a0edd39..c3c0360b3a9d 100644 --- a/tests/ui/suggestions/issue-62843.stderr +++ b/tests/ui/suggestions/issue-62843.stderr @@ -1,12 +1,12 @@ -error[E0277]: the trait bound `String: Pattern<'_>` is not satisfied +error[E0277]: the trait bound `String: Pattern` is not satisfied --> $DIR/issue-62843.rs:4:32 | LL | println!("{:?}", line.find(pattern)); - | ---- ^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` + | ---- ^^^^^^^ the trait `Pattern` is not implemented for `String` | | | required by a bound introduced by this call | - = note: required for `String` to implement `Pattern<'_>` + = note: required for `String` to implement `Pattern` note: required by a bound in `core::str::::find` --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider borrowing here diff --git a/tests/ui/traits/bound/assoc-fn-bound-root-obligation.rs b/tests/ui/traits/bound/assoc-fn-bound-root-obligation.rs index 98825bd536e0..dc2de5bb715b 100644 --- a/tests/ui/traits/bound/assoc-fn-bound-root-obligation.rs +++ b/tests/ui/traits/bound/assoc-fn-bound-root-obligation.rs @@ -1,11 +1,11 @@ fn strip_lf(s: &str) -> &str { s.strip_suffix(b'\n').unwrap_or(s) - //~^ ERROR expected a `FnMut(char)` closure, found `u8` - //~| NOTE expected an `FnMut(char)` closure, found `u8` - //~| HELP the trait `FnMut(char)` is not implemented for `u8` - //~| HELP the following other types implement trait `Pattern<'a>`: - //~| NOTE required for `u8` to implement `Pattern<'_>` - + //~^ ERROR the trait bound `u8: Pattern` is not satisfied + //~| NOTE required by a bound introduced by this call + //~| NOTE the trait `FnMut(char)` is not implemented for `u8`, which is required by `u8: Pattern` + //~| HELP the following other types implement trait `Pattern`: + //~| NOTE required for `u8` to implement `Pattern` + //~| NOTE required by a bound in `core::str::::strip_suffix` } fn main() {} diff --git a/tests/ui/traits/bound/assoc-fn-bound-root-obligation.stderr b/tests/ui/traits/bound/assoc-fn-bound-root-obligation.stderr index 49272e7d357b..8351d15fdf3b 100644 --- a/tests/ui/traits/bound/assoc-fn-bound-root-obligation.stderr +++ b/tests/ui/traits/bound/assoc-fn-bound-root-obligation.stderr @@ -1,11 +1,12 @@ -error[E0277]: expected a `FnMut(char)` closure, found `u8` - --> $DIR/assoc-fn-bound-root-obligation.rs:2:7 +error[E0277]: the trait bound `u8: Pattern` is not satisfied + --> $DIR/assoc-fn-bound-root-obligation.rs:2:20 | LL | s.strip_suffix(b'\n').unwrap_or(s) - | ^^^^^^^^^^^^ expected an `FnMut(char)` closure, found `u8` + | ------------ ^^^^^ the trait `FnMut(char)` is not implemented for `u8`, which is required by `u8: Pattern` + | | + | required by a bound introduced by this call | - = help: the trait `FnMut(char)` is not implemented for `u8`, which is required by `u8: Pattern<'_>` - = help: the following other types implement trait `Pattern<'a>`: + = help: the following other types implement trait `Pattern`: &'b String &'b [char; N] &'b [char] @@ -13,7 +14,9 @@ LL | s.strip_suffix(b'\n').unwrap_or(s) &'c &'b str [char; N] char - = note: required for `u8` to implement `Pattern<'_>` + = note: required for `u8` to implement `Pattern` +note: required by a bound in `core::str::::strip_suffix` + --> $SRC_DIR/core/src/str/mod.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/traits/suggest-dereferences/root-obligation.fixed b/tests/ui/traits/suggest-dereferences/root-obligation.fixed index 072296c6b154..ad0f184dc9a4 100644 --- a/tests/ui/traits/suggest-dereferences/root-obligation.fixed +++ b/tests/ui/traits/suggest-dereferences/root-obligation.fixed @@ -4,7 +4,7 @@ fn get_vowel_count(string: &str) -> usize { string .chars() .filter(|c| "aeiou".contains(*c)) - //~^ ERROR the trait bound `&char: Pattern<'_>` is not satisfied + //~^ ERROR the trait bound `&char: Pattern` is not satisfied .count() } diff --git a/tests/ui/traits/suggest-dereferences/root-obligation.rs b/tests/ui/traits/suggest-dereferences/root-obligation.rs index e7025fe08254..a31a9955d313 100644 --- a/tests/ui/traits/suggest-dereferences/root-obligation.rs +++ b/tests/ui/traits/suggest-dereferences/root-obligation.rs @@ -4,7 +4,7 @@ fn get_vowel_count(string: &str) -> usize { string .chars() .filter(|c| "aeiou".contains(c)) - //~^ ERROR the trait bound `&char: Pattern<'_>` is not satisfied + //~^ ERROR the trait bound `&char: Pattern` is not satisfied .count() } diff --git a/tests/ui/traits/suggest-dereferences/root-obligation.stderr b/tests/ui/traits/suggest-dereferences/root-obligation.stderr index bbfbb98fba77..2f5e1c5b5377 100644 --- a/tests/ui/traits/suggest-dereferences/root-obligation.stderr +++ b/tests/ui/traits/suggest-dereferences/root-obligation.stderr @@ -1,13 +1,13 @@ -error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied +error[E0277]: the trait bound `&char: Pattern` is not satisfied --> $DIR/root-obligation.rs:6:38 | LL | .filter(|c| "aeiou".contains(c)) - | -------- ^ the trait `Fn(char)` is not implemented for `char`, which is required by `&char: Pattern<'_>` + | -------- ^ the trait `Fn(char)` is not implemented for `char`, which is required by `&char: Pattern` | | | required by a bound introduced by this call | = note: required for `&char` to implement `FnOnce(char)` - = note: required for `&char` to implement `Pattern<'_>` + = note: required for `&char` to implement `Pattern` note: required by a bound in `core::str::::contains` --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider dereferencing here From f6fe7e49a2bc2ad14513aa609b67e188470309f6 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Sun, 14 Jul 2024 22:17:28 +0300 Subject: [PATCH 08/54] lib: replace some `mem::forget`'s with `ManuallyDrop` --- library/alloc/src/rc.rs | 45 +++++++++---------- library/alloc/src/sync.rs | 36 +++++++-------- library/core/src/task/wake.rs | 15 +++---- library/proc_macro/src/bridge/buffer.rs | 11 +++-- library/proc_macro/src/bridge/client.rs | 4 +- library/std/src/os/fd/owned.rs | 6 +-- library/std/src/os/solid/io.rs | 6 +-- library/std/src/os/windows/io/handle.rs | 6 +-- library/std/src/os/windows/io/socket.rs | 7 +-- library/std/src/sys/pal/hermit/thread.rs | 6 +-- library/std/src/sys/pal/sgx/abi/tls/mod.rs | 4 +- .../src/sys/pal/sgx/abi/usercalls/alloc.rs | 7 ++- library/std/src/sys/pal/sgx/fd.rs | 10 ++--- library/std/src/sys/pal/teeos/thread.rs | 16 +++---- library/std/src/sys/pal/unix/thread.rs | 14 +++--- library/std/src/sys/pal/wasi/thread.rs | 10 ++--- library/std/src/thread/mod.rs | 9 ++-- .../libc_pthread_mutex_deadlock.stderr | 2 +- ..._pthread_rwlock_write_read_deadlock.stderr | 2 +- ...pthread_rwlock_write_write_deadlock.stderr | 2 +- 20 files changed, 87 insertions(+), 131 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 9982c8ea6dcb..bfe3ea208001 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -259,7 +259,7 @@ use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; use core::marker::{PhantomData, Unsize}; -use core::mem::{self, align_of_val_raw, forget, ManuallyDrop}; +use core::mem::{self, align_of_val_raw, ManuallyDrop}; use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver}; use core::panic::{RefUnwindSafe, UnwindSafe}; #[cfg(not(no_global_oom_handling))] @@ -908,19 +908,18 @@ impl Rc { #[stable(feature = "rc_unique", since = "1.4.0")] pub fn try_unwrap(this: Self) -> Result { if Rc::strong_count(&this) == 1 { - unsafe { - let val = ptr::read(&*this); // copy the contained object - let alloc = ptr::read(&this.alloc); // copy the allocator + let this = ManuallyDrop::new(this); - // Indicate to Weaks that they can't be promoted by decrementing - // the strong count, and then remove the implicit "strong weak" - // pointer while also handling drop logic by just crafting a - // fake Weak. - this.inner().dec_strong(); - let _weak = Weak { ptr: this.ptr, alloc }; - forget(this); - Ok(val) - } + let val: T = unsafe { ptr::read(&**this) }; // copy the contained object + let alloc: A = unsafe { ptr::read(&this.alloc) }; // copy the allocator + + // Indicate to Weaks that they can't be promoted by decrementing + // the strong count, and then remove the implicit "strong weak" + // pointer while also handling drop logic by just crafting a + // fake Weak. + this.inner().dec_strong(); + let _weak = Weak { ptr: this.ptr, alloc }; + Ok(val) } else { Err(this) } @@ -1354,9 +1353,8 @@ impl Rc { #[stable(feature = "rc_raw", since = "1.17.0")] #[rustc_never_returns_null_ptr] pub fn into_raw(this: Self) -> *const T { - let ptr = Self::as_ptr(&this); - mem::forget(this); - ptr + let this = ManuallyDrop::new(this); + Self::as_ptr(&*this) } /// Consumes the `Rc`, returning the wrapped pointer and allocator. @@ -2127,7 +2125,7 @@ impl Rc<[T]> { } // All clear. Forget the guard so it doesn't free the new RcBox. - forget(guard); + mem::forget(guard); Self::from_ptr(ptr) } @@ -3080,9 +3078,7 @@ impl Weak { #[must_use = "losing the pointer will leak memory"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { - let result = self.as_ptr(); - mem::forget(self); - result + mem::ManuallyDrop::new(self).as_ptr() } /// Consumes the `Weak`, returning the wrapped pointer and allocator. @@ -3762,10 +3758,11 @@ impl UniqueRcUninit { /// # Safety /// /// The data must have been initialized (by writing to [`Self::data_ptr()`]). - unsafe fn into_rc(mut self) -> Rc { - let ptr = self.ptr; - let alloc = self.alloc.take().unwrap(); - mem::forget(self); + unsafe fn into_rc(self) -> Rc { + let mut this = ManuallyDrop::new(self); + let ptr = this.ptr; + let alloc = this.alloc.take().unwrap(); + // SAFETY: The pointer is valid as per `UniqueRcUninit::new`, and the caller is responsible // for having initialized the data. unsafe { Rc::from_ptr_in(ptr.as_ptr(), alloc) } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index a905a1e6b7e6..c36b8f6a1ac8 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -20,7 +20,7 @@ use core::intrinsics::abort; #[cfg(not(no_global_oom_handling))] use core::iter; use core::marker::{PhantomData, Unsize}; -use core::mem::{self, align_of_val_raw}; +use core::mem::{self, align_of_val_raw, ManuallyDrop}; use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver}; use core::panic::{RefUnwindSafe, UnwindSafe}; use core::pin::Pin; @@ -960,16 +960,14 @@ impl Arc { acquire!(this.inner().strong); - unsafe { - let elem = ptr::read(&this.ptr.as_ref().data); - let alloc = ptr::read(&this.alloc); // copy the allocator + let this = ManuallyDrop::new(this); + let elem: T = unsafe { ptr::read(&this.ptr.as_ref().data) }; + let alloc: A = unsafe { ptr::read(&this.alloc) }; // copy the allocator - // Make a weak pointer to clean up the implicit strong-weak reference - let _weak = Weak { ptr: this.ptr, alloc }; - mem::forget(this); + // Make a weak pointer to clean up the implicit strong-weak reference + let _weak = Weak { ptr: this.ptr, alloc }; - Ok(elem) - } + Ok(elem) } /// Returns the inner value, if the `Arc` has exactly one strong reference. @@ -1493,9 +1491,8 @@ impl Arc { #[stable(feature = "rc_raw", since = "1.17.0")] #[rustc_never_returns_null_ptr] pub fn into_raw(this: Self) -> *const T { - let ptr = Self::as_ptr(&this); - mem::forget(this); - ptr + let this = ManuallyDrop::new(this); + Self::as_ptr(&*this) } /// Consumes the `Arc`, returning the wrapped pointer and allocator. @@ -2801,9 +2798,7 @@ impl Weak { #[must_use = "losing the pointer will leak memory"] #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn into_raw(self) -> *const T { - let result = self.as_ptr(); - mem::forget(self); - result + ManuallyDrop::new(self).as_ptr() } /// Consumes the `Weak`, returning the wrapped pointer and allocator. @@ -3875,13 +3870,14 @@ impl UniqueArcUninit { /// # Safety /// /// The data must have been initialized (by writing to [`Self::data_ptr()`]). - unsafe fn into_arc(mut self) -> Arc { - let ptr = self.ptr; - let alloc = self.alloc.take().unwrap(); - mem::forget(self); + unsafe fn into_arc(self) -> Arc { + let mut this = ManuallyDrop::new(self); + let ptr = this.ptr.as_ptr(); + let alloc = this.alloc.take().unwrap(); + // SAFETY: The pointer is valid as per `UniqueArcUninit::new`, and the caller is responsible // for having initialized the data. - unsafe { Arc::from_ptr_in(ptr.as_ptr(), alloc) } + unsafe { Arc::from_ptr_in(ptr, alloc) } } } diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 86a965f68e08..e785d75a63d7 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -1,10 +1,9 @@ #![stable(feature = "futures_api", since = "1.36.0")] -use crate::mem::transmute; - use crate::any::Any; use crate::fmt; use crate::marker::PhantomData; +use crate::mem::{transmute, ManuallyDrop}; use crate::panic::AssertUnwindSafe; use crate::ptr; @@ -465,16 +464,14 @@ impl Waker { pub fn wake(self) { // The actual wakeup call is delegated through a virtual function call // to the implementation which is defined by the executor. - let wake = self.waker.vtable.wake; - let data = self.waker.data; // Don't call `drop` -- the waker will be consumed by `wake`. - crate::mem::forget(self); + let this = ManuallyDrop::new(self); // SAFETY: This is safe because `Waker::from_raw` is the only way // to initialize `wake` and `data` requiring the user to acknowledge // that the contract of `RawWaker` is upheld. - unsafe { (wake)(data) }; + unsafe { (this.waker.vtable.wake)(this.waker.data) }; } /// Wake up the task associated with this `Waker` without consuming the `Waker`. @@ -726,16 +723,14 @@ impl LocalWaker { pub fn wake(self) { // The actual wakeup call is delegated through a virtual function call // to the implementation which is defined by the executor. - let wake = self.waker.vtable.wake; - let data = self.waker.data; // Don't call `drop` -- the waker will be consumed by `wake`. - crate::mem::forget(self); + let this = ManuallyDrop::new(self); // SAFETY: This is safe because `Waker::from_raw` is the only way // to initialize `wake` and `data` requiring the user to acknowledge // that the contract of `RawWaker` is upheld. - unsafe { (wake)(data) }; + unsafe { (this.waker.vtable.wake)(this.waker.data) }; } /// Wake up the task associated with this `LocalWaker` without consuming the `LocalWaker`. diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 149767bf7052..78fcd1999b2f 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -1,7 +1,7 @@ //! Buffer management for same-process client<->server communication. use std::io::{self, Write}; -use std::mem; +use std::mem::{self, ManuallyDrop}; use std::ops::{Deref, DerefMut}; use std::slice; @@ -129,17 +129,16 @@ impl Drop for Buffer { } impl From> for Buffer { - fn from(mut v: Vec) -> Self { + fn from(v: Vec) -> Self { + let mut v = ManuallyDrop::new(v); let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity()); - mem::forget(v); // This utility function is nested in here because it can *only* // be safely called on `Buffer`s created by *this* `proc_macro`. fn to_vec(b: Buffer) -> Vec { unsafe { - let Buffer { data, len, capacity, .. } = b; - mem::forget(b); - Vec::from_raw_parts(data, len, capacity) + let b = ManuallyDrop::new(b); + Vec::from_raw_parts(b.data, b.len, b.capacity) } } diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs index faca745e56f7..9658fc4840f6 100644 --- a/library/proc_macro/src/bridge/client.rs +++ b/library/proc_macro/src/bridge/client.rs @@ -51,9 +51,7 @@ macro_rules! define_client_handles { impl Encode for $oty { fn encode(self, w: &mut Writer, s: &mut S) { - let handle = self.handle; - mem::forget(self); - handle.encode(w, s); + mem::ManuallyDrop::new(self).handle.encode(w, s); } } diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index a1f83029d272..800f3b0274fa 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -8,7 +8,7 @@ use crate::fmt; use crate::fs; use crate::io; use crate::marker::PhantomData; -use crate::mem::forget; +use crate::mem::ManuallyDrop; #[cfg(not(any(target_arch = "wasm32", target_env = "sgx", target_os = "hermit")))] use crate::sys::cvt; use crate::sys_common::{AsInner, FromInner, IntoInner}; @@ -141,9 +141,7 @@ impl AsRawFd for OwnedFd { impl IntoRawFd for OwnedFd { #[inline] fn into_raw_fd(self) -> RawFd { - let fd = self.fd; - forget(self); - fd + ManuallyDrop::new(self).fd } } diff --git a/library/std/src/os/solid/io.rs b/library/std/src/os/solid/io.rs index 19b4fe22093c..34fd745d4f9b 100644 --- a/library/std/src/os/solid/io.rs +++ b/library/std/src/os/solid/io.rs @@ -49,7 +49,7 @@ use crate::fmt; use crate::marker::PhantomData; -use crate::mem::forget; +use crate::mem::ManuallyDrop; use crate::net; use crate::sys; use crate::sys_common::{self, AsInner, FromInner, IntoInner}; @@ -149,9 +149,7 @@ impl AsRawFd for OwnedFd { impl IntoRawFd for OwnedFd { #[inline] fn into_raw_fd(self) -> RawFd { - let fd = self.fd; - forget(self); - fd + ManuallyDrop::new(self).fd } } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index a9d1983dce61..9865386e753d 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -7,7 +7,7 @@ use crate::fmt; use crate::fs; use crate::io; use crate::marker::PhantomData; -use crate::mem::{forget, ManuallyDrop}; +use crate::mem::ManuallyDrop; use crate::ptr; use crate::sys; use crate::sys::cvt; @@ -319,9 +319,7 @@ impl AsRawHandle for OwnedHandle { impl IntoRawHandle for OwnedHandle { #[inline] fn into_raw_handle(self) -> RawHandle { - let handle = self.handle; - forget(self); - handle + ManuallyDrop::new(self).handle } } diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 6ffdf907c8ed..a0a0cd2d2a3f 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -6,8 +6,7 @@ use super::raw::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; use crate::fmt; use crate::io; use crate::marker::PhantomData; -use crate::mem; -use crate::mem::forget; +use crate::mem::{self, ManuallyDrop}; use crate::sys; #[cfg(not(target_vendor = "uwp"))] use crate::sys::cvt; @@ -191,9 +190,7 @@ impl AsRawSocket for OwnedSocket { impl IntoRawSocket for OwnedSocket { #[inline] fn into_raw_socket(self) -> RawSocket { - let socket = self.socket; - forget(self); - socket + ManuallyDrop::new(self).socket } } diff --git a/library/std/src/sys/pal/hermit/thread.rs b/library/std/src/sys/pal/hermit/thread.rs index a244b953d2a4..3723f03081c1 100644 --- a/library/std/src/sys/pal/hermit/thread.rs +++ b/library/std/src/sys/pal/hermit/thread.rs @@ -3,7 +3,7 @@ use super::hermit_abi; use crate::ffi::CStr; use crate::io; -use crate::mem; +use crate::mem::ManuallyDrop; use crate::num::NonZero; use crate::ptr; use crate::time::Duration; @@ -90,9 +90,7 @@ impl Thread { #[inline] pub fn into_id(self) -> Tid { - let id = self.tid; - mem::forget(self); - id + ManuallyDrop::new(self).tid } } diff --git a/library/std/src/sys/pal/sgx/abi/tls/mod.rs b/library/std/src/sys/pal/sgx/abi/tls/mod.rs index 8a9ea4ac00df..bab59a3422d1 100644 --- a/library/std/src/sys/pal/sgx/abi/tls/mod.rs +++ b/library/std/src/sys/pal/sgx/abi/tls/mod.rs @@ -95,8 +95,8 @@ impl Tls { #[allow(unused)] pub unsafe fn activate_persistent(self: Box) { // FIXME: Needs safety information. See entry.S for `set_tls_ptr` definition. - unsafe { set_tls_ptr(core::ptr::addr_of!(*self) as _) }; - mem::forget(self); + let ptr = Box::into_raw(self).cast_const().cast::(); + unsafe { set_tls_ptr(ptr) }; } unsafe fn current<'a>() -> &'a Tls { diff --git a/library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs b/library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs index f99cea360f1f..b625636752cc 100644 --- a/library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs +++ b/library/std/src/sys/pal/sgx/abi/usercalls/alloc.rs @@ -5,7 +5,7 @@ use crate::cell::UnsafeCell; use crate::cmp; use crate::convert::TryInto; use crate::intrinsics; -use crate::mem; +use crate::mem::{self, ManuallyDrop}; use crate::ops::{CoerceUnsized, Deref, DerefMut, Index, IndexMut}; use crate::ptr::{self, NonNull}; use crate::slice; @@ -176,6 +176,7 @@ unsafe impl UserSafe for [T] { /// are used solely to indicate intent: a mutable reference is for writing to /// user memory, an immutable reference for reading from user memory. #[unstable(feature = "sgx_platform", issue = "56975")] +#[repr(transparent)] pub struct UserRef(UnsafeCell); /// An owned type in userspace memory. `User` is equivalent to `Box` in /// enclave memory. Access to the memory is only allowed by copying to avoid @@ -266,9 +267,7 @@ where /// Converts this value into a raw pointer. The value will no longer be /// automatically freed. pub fn into_raw(self) -> *mut T { - let ret = self.0; - mem::forget(self); - ret.as_ptr() as _ + ManuallyDrop::new(self).0.as_ptr() as _ } } diff --git a/library/std/src/sys/pal/sgx/fd.rs b/library/std/src/sys/pal/sgx/fd.rs index b3686d0e2832..c41b527cff79 100644 --- a/library/std/src/sys/pal/sgx/fd.rs +++ b/library/std/src/sys/pal/sgx/fd.rs @@ -2,7 +2,7 @@ use fortanix_sgx_abi::Fd; use super::abi::usercalls; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut}; -use crate::mem; +use crate::mem::ManuallyDrop; use crate::sys::{AsInner, FromInner, IntoInner}; #[derive(Debug)] @@ -21,9 +21,7 @@ impl FileDesc { /// Extracts the actual file descriptor without closing it. pub fn into_raw(self) -> Fd { - let fd = self.fd; - mem::forget(self); - fd + ManuallyDrop::new(self).fd } pub fn read(&self, buf: &mut [u8]) -> io::Result { @@ -70,9 +68,7 @@ impl AsInner for FileDesc { impl IntoInner for FileDesc { fn into_inner(self) -> Fd { - let fd = self.fd; - mem::forget(self); - fd + ManuallyDrop::new(self).fd } } diff --git a/library/std/src/sys/pal/teeos/thread.rs b/library/std/src/sys/pal/teeos/thread.rs index f4723b2ea46b..ef40eba4df2b 100644 --- a/library/std/src/sys/pal/teeos/thread.rs +++ b/library/std/src/sys/pal/teeos/thread.rs @@ -1,9 +1,7 @@ -use core::convert::TryInto; - use crate::cmp; use crate::ffi::CStr; use crate::io; -use crate::mem; +use crate::mem::{self, ManuallyDrop}; use crate::num::NonZero; use crate::ptr; use crate::sys::os; @@ -113,11 +111,9 @@ impl Thread { /// must join, because no pthread_detach supported pub fn join(self) { - unsafe { - let ret = libc::pthread_join(self.id, ptr::null_mut()); - mem::forget(self); - assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret)); - } + let id = self.into_id(); + let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; + assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret)); } pub fn id(&self) -> libc::pthread_t { @@ -125,9 +121,7 @@ impl Thread { } pub fn into_id(self) -> libc::pthread_t { - let id = self.id; - mem::forget(self); - id + ManuallyDrop::new(self).id } } diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 619f4e4121e7..483697b8597f 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -1,7 +1,7 @@ use crate::cmp; use crate::ffi::CStr; use crate::io; -use crate::mem; +use crate::mem::{self, ManuallyDrop}; use crate::num::NonZero; use crate::ptr; use crate::sys::{os, stack_overflow}; @@ -268,11 +268,9 @@ impl Thread { } pub fn join(self) { - unsafe { - let ret = libc::pthread_join(self.id, ptr::null_mut()); - mem::forget(self); - assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret)); - } + let id = self.into_id(); + let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; + assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret)); } pub fn id(&self) -> libc::pthread_t { @@ -280,9 +278,7 @@ impl Thread { } pub fn into_id(self) -> libc::pthread_t { - let id = self.id; - mem::forget(self); - id + ManuallyDrop::new(self).id } } diff --git a/library/std/src/sys/pal/wasi/thread.rs b/library/std/src/sys/pal/wasi/thread.rs index 975eef2451f4..2a3a39aafa70 100644 --- a/library/std/src/sys/pal/wasi/thread.rs +++ b/library/std/src/sys/pal/wasi/thread.rs @@ -172,12 +172,10 @@ impl Thread { pub fn join(self) { cfg_if::cfg_if! { if #[cfg(target_feature = "atomics")] { - unsafe { - let ret = libc::pthread_join(self.id, ptr::null_mut()); - mem::forget(self); - if ret != 0 { - rtabort!("failed to join thread: {}", io::Error::from_raw_os_error(ret)); - } + let id = mem::ManuallyDrop::new(self).id; + let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; + if ret != 0 { + rtabort!("failed to join thread: {}", io::Error::from_raw_os_error(ret)); } } else { self.0 diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index c8ee365392f8..73bf56237082 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -165,7 +165,7 @@ use crate::ffi::{CStr, CString}; use crate::fmt; use crate::io; use crate::marker::PhantomData; -use crate::mem::{self, forget}; +use crate::mem::{self, forget, ManuallyDrop}; use crate::num::NonZero; use crate::panic; use crate::panicking; @@ -514,11 +514,10 @@ impl Builder { MaybeDangling(mem::MaybeUninit::new(x)) } fn into_inner(self) -> T { - // SAFETY: we are always initialized. - let ret = unsafe { self.0.assume_init_read() }; // Make sure we don't drop. - mem::forget(self); - ret + let this = ManuallyDrop::new(self); + // SAFETY: we are always initialized. + unsafe { this.0.assume_init_read() } } } impl Drop for MaybeDangling { diff --git a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr index 987d0fc4c2d0..079c1729b600 100644 --- a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr +++ b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_deadlock.stderr @@ -10,7 +10,7 @@ LL | assert_eq!(libc::pthread_mutex_lock(lock_copy.0.get() as *mut _ error: deadlock: the evaluated program deadlocked --> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC | -LL | let ret = libc::pthread_join(self.id, ptr::null_mut()); +LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; | ^ the evaluated program deadlocked | = note: BACKTRACE: diff --git a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.stderr b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.stderr index bc9b15f293ef..d03c6402d64f 100644 --- a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.stderr +++ b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_read_deadlock.stderr @@ -10,7 +10,7 @@ LL | assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mu error: deadlock: the evaluated program deadlocked --> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC | -LL | let ret = libc::pthread_join(self.id, ptr::null_mut()); +LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; | ^ the evaluated program deadlocked | = note: BACKTRACE: diff --git a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.stderr b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.stderr index 66c142bbc5c8..73c5e77a1bce 100644 --- a/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.stderr +++ b/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_write_write_deadlock.stderr @@ -10,7 +10,7 @@ LL | assert_eq!(libc::pthread_rwlock_wrlock(lock_copy.0.get() as *mu error: deadlock: the evaluated program deadlocked --> RUSTLIB/std/src/sys/pal/PLATFORM/thread.rs:LL:CC | -LL | let ret = libc::pthread_join(self.id, ptr::null_mut()); +LL | let ret = unsafe { libc::pthread_join(id, ptr::null_mut()) }; | ^ the evaluated program deadlocked | = note: BACKTRACE: From b74f426e074bbaafdd9d15d60c3f57ff4e3f91b9 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Mon, 22 Jul 2024 00:59:58 +0300 Subject: [PATCH 09/54] Fix some `#[cfg_attr(not(doc), repr(..))]` Now that #90435 seems to have been resolved. --- library/core/src/error.rs | 2 +- library/core/src/ffi/c_str.rs | 2 +- library/core/src/ffi/mod.rs | 2 +- library/core/src/ffi/va_list.rs | 4 ++-- library/core/src/task/wake.rs | 4 ++-- library/std/src/ffi/os_str.rs | 6 ++---- library/std/src/path.rs | 6 ++---- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/library/core/src/error.rs b/library/core/src/error.rs index ca8983d4cbcf..19b7bb44f855 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -506,7 +506,7 @@ where /// ``` /// #[unstable(feature = "error_generic_member_access", issue = "99301")] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] pub struct Request<'a>(Tagged + 'a>); impl<'a> Request<'a> { diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 563f0a324e3f..c9111254082d 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -103,7 +103,7 @@ use crate::str; // However, `CStr` layout is considered an implementation detail and must not be relied upon. We // want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under // `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +#[repr(transparent)] #[allow(clippy::derived_hash_with_manual_eq)] pub struct CStr { // FIXME: this should not be represented with a DST slice but rather with diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 88adc378477f..93426b90c706 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -191,7 +191,7 @@ mod c_long_definition { // be UB. #[doc = include_str!("c_void.md")] #[lang = "c_void"] -#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435 +#[cfg_attr(not(doc), repr(u8))] // An implementation detail we don't want to show up in rustdoc #[stable(feature = "core_c_void", since = "1.30.0")] pub enum c_void { #[unstable( diff --git a/library/core/src/ffi/va_list.rs b/library/core/src/ffi/va_list.rs index 6a2e8b67d0c2..f4c746225dc0 100644 --- a/library/core/src/ffi/va_list.rs +++ b/library/core/src/ffi/va_list.rs @@ -23,7 +23,7 @@ use crate::ops::{Deref, DerefMut}; target_os = "uefi", windows, ))] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] #[lang = "va_list"] pub struct VaListImpl<'f> { ptr: *mut c_void, @@ -115,7 +115,7 @@ pub struct VaListImpl<'f> { } /// A wrapper for a `va_list` -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435 +#[repr(transparent)] #[derive(Debug)] pub struct VaList<'a, 'f: 'a> { #[cfg(any( diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 86a965f68e08..9d74e64ed637 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -429,7 +429,7 @@ impl<'a> ContextBuilder<'a> { /// [`Future::poll()`]: core::future::Future::poll /// [`Poll::Pending`]: core::task::Poll::Pending /// [`Wake`]: ../../alloc/task/trait.Wake.html -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401 +#[repr(transparent)] #[stable(feature = "futures_api", since = "1.36.0")] pub struct Waker { waker: RawWaker, @@ -695,7 +695,7 @@ impl fmt::Debug for Waker { /// [`Poll::Pending`]: core::task::Poll::Pending /// [`local_waker`]: core::task::Context::local_waker #[unstable(feature = "local_waker", issue = "118959")] -#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401 +#[repr(transparent)] pub struct LocalWaker { waker: RawWaker, } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index f9dba08da4c3..0fb3964c9a9b 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -115,10 +115,8 @@ impl crate::sealed::Sealed for OsString {} #[stable(feature = "rust1", since = "1.0.0")] // `OsStr::from_inner` current implementation relies // on `OsStr` being layout-compatible with `Slice`. -// However, `OsStr` layout is considered an implementation detail and must not be relied upon. We -// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under -// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +// However, `OsStr` layout is considered an implementation detail and must not be relied upon. +#[repr(transparent)] pub struct OsStr { inner: Slice, } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index d5121a554bf6..0cef862549c8 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2079,10 +2079,8 @@ impl AsRef for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] // `Path::new` current implementation relies // on `Path` being layout-compatible with `OsStr`. -// However, `Path` layout is considered an implementation detail and must not be relied upon. We -// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under -// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy. -#[cfg_attr(not(doc), repr(transparent))] +// However, `Path` layout is considered an implementation detail and must not be relied upon. +#[repr(transparent)] pub struct Path { inner: OsStr, } From 5241d8bb19c54a084a6dbe2c7ae582f579f85d6a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Jul 2024 10:40:37 +0000 Subject: [PATCH 10/54] Merge impl and trait item mut visitor methods to mirror immut visitor --- compiler/rustc_ast/src/mut_visit.rs | 15 ++++---- compiler/rustc_builtin_macros/src/cfg_eval.rs | 32 ++++++++--------- compiler/rustc_builtin_macros/src/util.rs | 3 +- compiler/rustc_expand/src/base.rs | 20 ++++------- compiler/rustc_expand/src/expand.rs | 34 ++++++++++--------- compiler/rustc_expand/src/placeholders.rs | 23 +++++++------ 6 files changed, 62 insertions(+), 65 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 39d0f2c7305f..4b7f303a02d9 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,6 +11,7 @@ use crate::ast::*; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::*; +use crate::visit::AssocCtxt; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -109,11 +110,11 @@ pub trait MutVisitor: Sized { noop_flat_map_field_def(fd, self) } - fn flat_map_trait_item(&mut self, i: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, self) - } - - fn flat_map_impl_item(&mut self, i: P) -> SmallVec<[P; 1]> { + fn flat_map_assoc_item( + &mut self, + i: P, + _ctxt: AssocCtxt, + ) -> SmallVec<[P; 1]> { noop_flat_map_item(i, self) } @@ -1127,13 +1128,13 @@ impl NoopVisitItemKind for ItemKind { visit_polarity(polarity, vis); visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref)); vis.visit_ty(self_ty); - items.flat_map_in_place(|item| vis.flat_map_impl_item(item)); + items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Impl)); } ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => { visit_safety(safety, vis); vis.visit_generics(generics); visit_bounds(bounds, vis); - items.flat_map_in_place(|item| vis.flat_map_trait_item(item)); + items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Trait)); } ItemKind::TraitAlias(generics, bounds) => { vis.visit_generics(generics); diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index b09975c0ba79..f421ae8f6a62 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -4,7 +4,7 @@ use core::ops::ControlFlow; use rustc_ast as ast; use rustc_ast::mut_visit::MutVisitor; use rustc_ast::ptr::P; -use rustc_ast::visit::Visitor; +use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_ast::NodeId; use rustc_ast::{mut_visit, visit}; use rustc_ast::{Attribute, HasAttrs, HasTokens}; @@ -53,11 +53,8 @@ fn flat_map_annotatable( ) -> Option { match annotatable { Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item), - Annotatable::TraitItem(item) => { - vis.flat_map_trait_item(item).pop().map(Annotatable::TraitItem) - } - Annotatable::ImplItem(item) => { - vis.flat_map_impl_item(item).pop().map(Annotatable::ImplItem) + Annotatable::AssocItem(item, ctxt) => { + Some(Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop()?, ctxt)) } Annotatable::ForeignItem(item) => { vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem) @@ -106,8 +103,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool { let res = match annotatable { Annotatable::Item(item) => CfgFinder.visit_item(item), - Annotatable::TraitItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Trait), - Annotatable::ImplItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Impl), + Annotatable::AssocItem(item, ctxt) => CfgFinder.visit_assoc_item(item, *ctxt), Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item), Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt), Annotatable::Expr(expr) => CfgFinder.visit_expr(expr), @@ -150,14 +146,16 @@ impl CfgEval<'_> { Annotatable::Item(_) => { |parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap())) } - Annotatable::TraitItem(_) => |parser| { - Ok(Annotatable::TraitItem( + Annotatable::AssocItem(_, AssocCtxt::Trait) => |parser| { + Ok(Annotatable::AssocItem( parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(), + AssocCtxt::Trait, )) }, - Annotatable::ImplItem(_) => |parser| { - Ok(Annotatable::ImplItem( + Annotatable::AssocItem(_, AssocCtxt::Impl) => |parser| { + Ok(Annotatable::AssocItem( parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(), + AssocCtxt::Impl, )) }, Annotatable::ForeignItem(_) => |parser| { @@ -244,11 +242,11 @@ impl MutVisitor for CfgEval<'_> { mut_visit::noop_flat_map_item(configure!(self, item), self) } - fn flat_map_impl_item(&mut self, item: P) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), self) - } - - fn flat_map_trait_item(&mut self, item: P) -> SmallVec<[P; 1]> { + fn flat_map_assoc_item( + &mut self, + item: P, + _ctxt: AssocCtxt, + ) -> SmallVec<[P; 1]> { mut_visit::noop_flat_map_item(configure!(self, item), self) } diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs index 652e34268ea9..fabcb6a4b706 100644 --- a/compiler/rustc_builtin_macros/src/util.rs +++ b/compiler/rustc_builtin_macros/src/util.rs @@ -27,8 +27,7 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) { let attrs: Option<&[Attribute]> = match item { Annotatable::Item(item) => Some(&item.attrs), - Annotatable::TraitItem(item) => Some(&item.attrs), - Annotatable::ImplItem(item) => Some(&item.attrs), + Annotatable::AssocItem(item, _) => Some(&item.attrs), Annotatable::ForeignItem(item) => Some(&item.attrs), Annotatable::Expr(expr) => Some(&expr.attrs), Annotatable::Arm(arm) => Some(&arm.attrs), diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index d8e6d3525da8..b439ec74ffae 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -37,8 +37,7 @@ use thin_vec::ThinVec; #[derive(Debug, Clone)] pub enum Annotatable { Item(P), - TraitItem(P), - ImplItem(P), + AssocItem(P, AssocCtxt), ForeignItem(P), Stmt(P), Expr(P), @@ -56,8 +55,7 @@ impl Annotatable { pub fn span(&self) -> Span { match self { Annotatable::Item(item) => item.span, - Annotatable::TraitItem(trait_item) => trait_item.span, - Annotatable::ImplItem(impl_item) => impl_item.span, + Annotatable::AssocItem(assoc_item, _) => assoc_item.span, Annotatable::ForeignItem(foreign_item) => foreign_item.span, Annotatable::Stmt(stmt) => stmt.span, Annotatable::Expr(expr) => expr.span, @@ -75,8 +73,7 @@ impl Annotatable { pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) { match self { Annotatable::Item(item) => item.visit_attrs(f), - Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f), - Annotatable::ImplItem(impl_item) => impl_item.visit_attrs(f), + Annotatable::AssocItem(assoc_item, _) => assoc_item.visit_attrs(f), Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f), Annotatable::Stmt(stmt) => stmt.visit_attrs(f), Annotatable::Expr(expr) => expr.visit_attrs(f), @@ -94,8 +91,7 @@ impl Annotatable { pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result { match self { Annotatable::Item(item) => visitor.visit_item(item), - Annotatable::TraitItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Trait), - Annotatable::ImplItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Impl), + Annotatable::AssocItem(item, ctxt) => visitor.visit_assoc_item(item, *ctxt), Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item), Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt), Annotatable::Expr(expr) => visitor.visit_expr(expr), @@ -113,9 +109,7 @@ impl Annotatable { pub fn to_tokens(&self) -> TokenStream { match self { Annotatable::Item(node) => TokenStream::from_ast(node), - Annotatable::TraitItem(node) | Annotatable::ImplItem(node) => { - TokenStream::from_ast(node) - } + Annotatable::AssocItem(node, _) => TokenStream::from_ast(node), Annotatable::ForeignItem(node) => TokenStream::from_ast(node), Annotatable::Stmt(node) => { assert!(!matches!(node.kind, ast::StmtKind::Empty)); @@ -142,14 +136,14 @@ impl Annotatable { pub fn expect_trait_item(self) -> P { match self { - Annotatable::TraitItem(i) => i, + Annotatable::AssocItem(i, AssocCtxt::Trait) => i, _ => panic!("expected Item"), } } pub fn expect_impl_item(self) -> P { match self { - Annotatable::ImplItem(i) => i, + Annotatable::AssocItem(i, AssocCtxt::Impl) => i, _ => panic!("expected Item"), } } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 26fc77c7f33d..00dda62f3df4 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -140,7 +140,7 @@ macro_rules! ast_fragments { AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr), $($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)* $($(AstFragment::$Kind(ast) => - ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)* + ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast, $($args)*)),)?)* } } @@ -177,13 +177,13 @@ ast_fragments! { } TraitItems(SmallVec<[P; 1]>) { "trait item"; - many fn flat_map_trait_item; + many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Trait); fn make_trait_items; } ImplItems(SmallVec<[P; 1]>) { "impl item"; - many fn flat_map_impl_item; + many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Impl); fn make_impl_items; } @@ -833,7 +833,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { self.cx, deleg, &item, &suffixes, item.span, true, ); fragment_kind.expect_from_annotatables( - single_delegations.map(|item| Annotatable::ImplItem(P(item))), + single_delegations.map(|item| Annotatable::AssocItem(P(item), AssocCtxt::Impl)), ) } }) @@ -843,8 +843,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) { let kind = match item { Annotatable::Item(_) - | Annotatable::TraitItem(_) - | Annotatable::ImplItem(_) + | Annotatable::AssocItem(..) | Annotatable::ForeignItem(_) | Annotatable::Crate(..) => return, Annotatable::Stmt(stmt) => { @@ -1288,7 +1287,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::TraitItems; fn to_annotatable(self) -> Annotatable { - Annotatable::TraitItem(self.wrapped) + Annotatable::AssocItem(self.wrapped, AssocCtxt::Trait) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_trait_items() @@ -1329,7 +1328,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::ImplItems; fn to_annotatable(self) -> Annotatable { - Annotatable::ImplItem(self.wrapped) + Annotatable::AssocItem(self.wrapped, AssocCtxt::Impl) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_impl_items() @@ -1993,9 +1992,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { let traitless_qself = matches!(&deleg.qself, Some(qself) if qself.position == 0); let item = match node.to_annotatable() { - Annotatable::ImplItem(item) => item, + Annotatable::AssocItem(item, AssocCtxt::Impl) => item, ann @ (Annotatable::Item(_) - | Annotatable::TraitItem(_) + | Annotatable::AssocItem(..) | Annotatable::Stmt(_)) => { let span = ann.span(); self.cx.dcx().emit_err(GlobDelegationOutsideImpls { span }); @@ -2081,12 +2080,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.flat_map_node(node) } - fn flat_map_trait_item(&mut self, node: P) -> SmallVec<[P; 1]> { - self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)) - } - - fn flat_map_impl_item(&mut self, node: P) -> SmallVec<[P; 1]> { - self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag)) + fn flat_map_assoc_item( + &mut self, + node: P, + ctxt: AssocCtxt, + ) -> SmallVec<[P; 1]> { + match ctxt { + AssocCtxt::Trait => self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)), + AssocCtxt::Impl => self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag)), + } } fn flat_map_foreign_item( diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index e21f041d69af..0817c2876445 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -1,8 +1,8 @@ use crate::expand::{AstFragment, AstFragmentKind}; -use rustc_ast as ast; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; +use rustc_ast::{self as ast, visit::AssocCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_span::symbol::Ident; use rustc_span::DUMMY_SP; @@ -271,16 +271,19 @@ impl MutVisitor for PlaceholderExpander { } } - fn flat_map_trait_item(&mut self, item: P) -> SmallVec<[P; 1]> { + fn flat_map_assoc_item( + &mut self, + item: P, + ctxt: AssocCtxt, + ) -> SmallVec<[P; 1]> { match item.kind { - ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_trait_items(), - _ => noop_flat_map_item(item, self), - } - } - - fn flat_map_impl_item(&mut self, item: P) -> SmallVec<[P; 1]> { - match item.kind { - ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_impl_items(), + ast::AssocItemKind::MacCall(_) => { + let it = self.remove(item.id); + match ctxt { + AssocCtxt::Trait => it.make_trait_items(), + AssocCtxt::Impl => it.make_impl_items(), + } + } _ => noop_flat_map_item(item, self), } } From c064b363b912857303f081de537514bf5190e5d2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 8 Jul 2024 11:02:16 +0000 Subject: [PATCH 11/54] Track visit_param_bound in mut visit just like in the immutable visitor --- compiler/rustc_ast/src/mut_visit.rs | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 4b7f303a02d9..11a928196e7c 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,7 +11,7 @@ use crate::ast::*; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::*; -use crate::visit::AssocCtxt; +use crate::visit::{AssocCtxt, BoundKind}; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -256,7 +256,7 @@ pub trait MutVisitor: Sized { noop_flat_map_generic_param(param, self) } - fn visit_param_bound(&mut self, tpb: &mut GenericBound) { + fn visit_param_bound(&mut self, tpb: &mut GenericBound, _ctxt: BoundKind) { noop_visit_param_bound(tpb, self); } @@ -375,8 +375,8 @@ fn visit_thin_exprs(exprs: &mut ThinVec>, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_bounds(bounds: &mut GenericBounds, vis: &mut T) { - visit_vec(bounds, |bound| vis.visit_param_bound(bound)); +fn visit_bounds(bounds: &mut GenericBounds, ctxt: BoundKind, vis: &mut T) { + visit_vec(bounds, |bound| vis.visit_param_bound(bound, ctxt)); } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. @@ -468,7 +468,7 @@ fn noop_visit_assoc_item_constraint( Term::Ty(ty) => vis.visit_ty(ty), Term::Const(c) => vis.visit_anon_const(c), }, - AssocItemConstraintKind::Bound { bounds } => visit_bounds(bounds, vis), + AssocItemConstraintKind::Bound { bounds } => visit_bounds(bounds, BoundKind::Bound, vis), } vis.visit_span(span); } @@ -509,11 +509,11 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { } TyKind::Typeof(expr) => vis.visit_anon_const(expr), TyKind::TraitObject(bounds, _syntax) => { - visit_vec(bounds, |bound| vis.visit_param_bound(bound)) + visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::TraitObject)) } TyKind::ImplTrait(id, bounds) => { vis.visit_id(id); - visit_vec(bounds, |bound| vis.visit_param_bound(bound)); + visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Impl)); } TyKind::MacCall(mac) => vis.visit_mac_call(mac), TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => { @@ -926,7 +926,7 @@ pub fn noop_flat_map_generic_param( vis.visit_id(id); visit_attrs(attrs, vis); vis.visit_ident(ident); - visit_vec(bounds, |bound| vis.visit_param_bound(bound)); + visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound)); match kind { GenericParamKind::Lifetime => {} GenericParamKind::Type { default } => { @@ -979,13 +979,13 @@ fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mu let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp; bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_ty(bounded_ty); - visit_vec(bounds, |bound| vis.visit_param_bound(bound)); + visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound)); vis.visit_span(span); } WherePredicate::RegionPredicate(rp) => { let WhereRegionPredicate { span, lifetime, bounds } = rp; vis.visit_lifetime(lifetime); - visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis)); + visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound)); vis.visit_span(span); } WherePredicate::EqPredicate(ep) => { @@ -1099,7 +1099,7 @@ impl NoopVisitItemKind for ItemKind { ItemKind::TyAlias(box TyAlias { defaultness, generics, where_clauses, bounds, ty }) => { visit_defaultness(defaultness, vis); vis.visit_generics(generics); - visit_bounds(bounds, vis); + visit_bounds(bounds, BoundKind::Bound, vis); visit_opt(ty, |ty| vis.visit_ty(ty)); noop_visit_ty_alias_where_clauses(where_clauses, vis); } @@ -1133,12 +1133,12 @@ impl NoopVisitItemKind for ItemKind { ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => { visit_safety(safety, vis); vis.visit_generics(generics); - visit_bounds(bounds, vis); + visit_bounds(bounds, BoundKind::Bound, vis); items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Trait)); } ItemKind::TraitAlias(generics, bounds) => { vis.visit_generics(generics); - visit_bounds(bounds, vis); + visit_bounds(bounds, BoundKind::Bound, vis); } ItemKind::MacCall(m) => vis.visit_mac_call(m), ItemKind::MacroDef(def) => vis.visit_macro_def(def), @@ -1200,7 +1200,7 @@ impl NoopVisitItemKind for AssocItemKind { }) => { visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); - visit_bounds(bounds, visitor); + visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); noop_visit_ty_alias_where_clauses(where_clauses, visitor); } @@ -1307,7 +1307,7 @@ impl NoopVisitItemKind for ForeignItemKind { }) => { visit_defaultness(defaultness, visitor); visitor.visit_generics(generics); - visit_bounds(bounds, visitor); + visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); noop_visit_ty_alias_where_clauses(where_clauses, visitor); } From 1b9ac0011f8c871edf9515503e9e38fb7d1c777b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Jul 2024 05:02:00 +0000 Subject: [PATCH 12/54] Make function items in mut visitors all go through the same visit_fn function, just like with immutable visitors --- compiler/rustc_ast/src/mut_visit.rs | 82 ++++++++++++------- compiler/rustc_builtin_macros/src/cfg_eval.rs | 8 +- .../rustc_builtin_macros/src/test_harness.rs | 2 +- compiler/rustc_expand/src/expand.rs | 8 +- compiler/rustc_expand/src/placeholders.rs | 6 +- 5 files changed, 64 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 11a928196e7c..143651765a93 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,7 +11,7 @@ use crate::ast::*; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::*; -use crate::visit::{AssocCtxt, BoundKind}; +use crate::visit::{AssocCtxt, BoundKind, FnCtxt}; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -36,7 +36,7 @@ impl ExpectOne for SmallVec { } pub trait NoopVisitItemKind { - fn noop_visit(&mut self, visitor: &mut impl MutVisitor); + fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor); } pub trait MutVisitor: Sized { @@ -95,11 +95,11 @@ pub trait MutVisitor: Sized { } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(ni, self) + noop_flat_map_item(ni, None, self) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, self) + noop_flat_map_item(i, None, self) } fn visit_fn_header(&mut self, header: &mut FnHeader) { @@ -113,15 +113,19 @@ pub trait MutVisitor: Sized { fn flat_map_assoc_item( &mut self, i: P, - _ctxt: AssocCtxt, + ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, self) + noop_flat_map_item(i, Some(ctxt), self) } fn visit_fn_decl(&mut self, d: &mut P) { noop_visit_fn_decl(d, self); } + fn visit_fn(&mut self, fk: FnKind<'_>) { + noop_visit_fn(fk, self) + } + fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) { noop_visit_coroutine_kind(a, self); } @@ -379,13 +383,6 @@ fn visit_bounds(bounds: &mut GenericBounds, ctxt: BoundKind, vis: visit_vec(bounds, |bound| vis.visit_param_bound(bound, ctxt)); } -// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_fn_sig(FnSig { header, decl, span }: &mut FnSig, vis: &mut T) { - vis.visit_fn_header(header); - vis.visit_fn_decl(decl); - vis.visit_span(span); -} - // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { match args { @@ -880,6 +877,26 @@ fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, } } +fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { + match kind { + FnKind::Fn(_ctxt, FnSig { header, decl, span }, generics, body) => { + // Identifier and visibility are visited as a part of the item. + vis.visit_fn_header(header); + vis.visit_generics(generics); + vis.visit_fn_decl(decl); + if let Some(body) = body { + vis.visit_block(body); + } + vis.visit_span(span); + } + FnKind::Closure(binder, decl, body) => { + vis.visit_closure_binder(binder); + vis.visit_fn_decl(decl); + vis.visit_expr(body); + } + } +} + fn noop_visit_fn_decl(decl: &mut P, vis: &mut T) { let FnDecl { inputs, output } = decl.deref_mut(); inputs.flat_map_in_place(|param| vis.flat_map_param(param)); @@ -1062,11 +1079,12 @@ pub fn noop_visit_block(block: &mut P, vis: &mut T) { } pub fn noop_visit_item_kind(kind: &mut impl NoopVisitItemKind, vis: &mut impl MutVisitor) { - kind.noop_visit(vis) + kind.noop_visit(None, vis) } impl NoopVisitItemKind for ItemKind { - fn noop_visit(&mut self, vis: &mut impl MutVisitor) { + fn noop_visit(&mut self, ctxt: Option, vis: &mut impl MutVisitor) { + assert_eq!(ctxt, None); match self { ItemKind::ExternCrate(_orig_name) => {} ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), @@ -1079,9 +1097,7 @@ impl NoopVisitItemKind for ItemKind { } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, vis); - vis.visit_generics(generics); - visit_fn_sig(sig, vis); - visit_opt(body, |body| vis.visit_block(body)); + vis.visit_fn(FnKind::Fn(FnCtxt::Free, sig, generics, body)); } ItemKind::Mod(safety, mod_kind) => { visit_safety(safety, vis); @@ -1180,16 +1196,15 @@ impl NoopVisitItemKind for ItemKind { } impl NoopVisitItemKind for AssocItemKind { - fn noop_visit(&mut self, visitor: &mut impl MutVisitor) { + fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor) { + let ctxt = ctxt.unwrap(); match self { AssocItemKind::Const(item) => { visit_const_item(item, visitor); } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_generics(generics); - visit_fn_sig(sig, visitor); - visit_opt(body, |body| visitor.visit_block(body)); + visitor.visit_fn(FnKind::Fn(FnCtxt::Assoc(ctxt), sig, generics, body)); } AssocItemKind::Type(box TyAlias { defaultness, @@ -1272,6 +1287,7 @@ pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { // Mutates one item into possibly many items. pub fn noop_flat_map_item( mut item: P>, + ctxt: Option, visitor: &mut impl MutVisitor, ) -> SmallVec<[P>; 1]> { let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut(); @@ -1279,14 +1295,15 @@ pub fn noop_flat_map_item( visit_attrs(attrs, visitor); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.noop_visit(visitor); + kind.noop_visit(ctxt, visitor); visit_lazy_tts(tokens, visitor); visitor.visit_span(span); smallvec![item] } impl NoopVisitItemKind for ForeignItemKind { - fn noop_visit(&mut self, visitor: &mut impl MutVisitor) { + fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor) { + assert_eq!(ctxt, None); match self { ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => { visitor.visit_ty(ty); @@ -1294,9 +1311,7 @@ impl NoopVisitItemKind for ForeignItemKind { } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_generics(generics); - visit_fn_sig(sig, visitor); - visit_opt(body, |body| visitor.visit_block(body)); + visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, sig, generics, body)); } ForeignItemKind::TyAlias(box TyAlias { defaultness, @@ -1506,12 +1521,10 @@ pub fn noop_visit_expr( fn_decl_span, fn_arg_span, }) => { - vis.visit_closure_binder(binder); visit_constness(constness, vis); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); vis.visit_capture_by(capture_clause); - vis.visit_fn_decl(fn_decl); - vis.visit_expr(body); + vis.visit_fn(FnKind::Closure(binder, fn_decl, body)); vis.visit_span(fn_decl_span); vis.visit_span(fn_arg_span); } @@ -1768,3 +1781,12 @@ impl DummyAstNode for crate::ast_traits::AstNo crate::ast_traits::AstNodeWrapper::new(N::dummy(), T::dummy()) } } + +#[derive(Debug)] +pub enum FnKind<'a> { + /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. + Fn(FnCtxt, &'a mut FnSig, &'a mut Generics, &'a mut Option>), + + /// E.g., `|x, y| body`. + Closure(&'a mut ClosureBinder, &'a mut P, &'a mut P), +} diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index f421ae8f6a62..1cfbaf9d669a 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -239,22 +239,22 @@ impl MutVisitor for CfgEval<'_> { } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), self) + mut_visit::noop_flat_map_item(configure!(self, item), None, self) } fn flat_map_assoc_item( &mut self, item: P, - _ctxt: AssocCtxt, + ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), self) + mut_visit::noop_flat_map_item(configure!(self, item), Some(ctxt), self) } fn flat_map_foreign_item( &mut self, foreign_item: P, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, foreign_item), self) + mut_visit::noop_flat_map_item(configure!(self, foreign_item), None, self) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 9d032eb190a0..4fd1f1ac2dc4 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = noop_flat_map_item(i, self).expect_one("noop did something"); + let item = noop_flat_map_item(i, None, self).expect_one("noop did something"); self.depth -= 1; // Remove any #[rustc_main] or #[start] from the AST so it doesn't diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 00dda62f3df4..6f4df7bb1685 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1149,7 +1149,7 @@ impl InvocationCollectorNode for P { fragment.make_items() } fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, visitor) + noop_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1293,7 +1293,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fragment.make_trait_items() } fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, visitor) + noop_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1334,7 +1334,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fragment.make_impl_items() } fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, visitor) + noop_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1372,7 +1372,7 @@ impl InvocationCollectorNode for P { fragment.make_foreign_items() } fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, visitor) + noop_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 0817c2876445..2ed968f57bce 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -267,7 +267,7 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => noop_flat_map_item(item, self), + _ => noop_flat_map_item(item, None, self), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => noop_flat_map_item(item, self), + _ => noop_flat_map_item(item, Some(ctxt), self), } } @@ -294,7 +294,7 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => noop_flat_map_item(item, self), + _ => noop_flat_map_item(item, None, self), } } From 545553ca4ffde01272dbeaba8ac12e90600bcf46 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Jul 2024 09:43:38 +0000 Subject: [PATCH 13/54] Pass id and span to `visit_fn`, just like for the immutable visitor --- compiler/rustc_ast/src/mut_visit.rs | 56 ++++++++++++++----- .../rustc_builtin_macros/src/test_harness.rs | 8 +-- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 143651765a93..999ef3a01cde 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -36,7 +36,13 @@ impl ExpectOne for SmallVec { } pub trait NoopVisitItemKind { - fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor); + fn noop_visit( + &mut self, + ctxt: Option, + span: Span, + id: NodeId, + visitor: &mut impl MutVisitor, + ); } pub trait MutVisitor: Sized { @@ -122,7 +128,8 @@ pub trait MutVisitor: Sized { noop_visit_fn_decl(d, self); } - fn visit_fn(&mut self, fk: FnKind<'_>) { + /// `Span` and `NodeId` are mutated at the caller site. + fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) { noop_visit_fn(fk, self) } @@ -1078,12 +1085,23 @@ pub fn noop_visit_block(block: &mut P, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_item_kind(kind: &mut impl NoopVisitItemKind, vis: &mut impl MutVisitor) { - kind.noop_visit(None, vis) +pub fn noop_visit_item_kind( + kind: &mut impl NoopVisitItemKind, + span: Span, + id: NodeId, + vis: &mut impl MutVisitor, +) { + kind.noop_visit(None, span, id, vis) } impl NoopVisitItemKind for ItemKind { - fn noop_visit(&mut self, ctxt: Option, vis: &mut impl MutVisitor) { + fn noop_visit( + &mut self, + ctxt: Option, + span: Span, + id: NodeId, + vis: &mut impl MutVisitor, + ) { assert_eq!(ctxt, None); match self { ItemKind::ExternCrate(_orig_name) => {} @@ -1097,7 +1115,7 @@ impl NoopVisitItemKind for ItemKind { } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, vis); - vis.visit_fn(FnKind::Fn(FnCtxt::Free, sig, generics, body)); + vis.visit_fn(FnKind::Fn(FnCtxt::Free, sig, generics, body), span, id); } ItemKind::Mod(safety, mod_kind) => { visit_safety(safety, vis); @@ -1196,7 +1214,13 @@ impl NoopVisitItemKind for ItemKind { } impl NoopVisitItemKind for AssocItemKind { - fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor) { + fn noop_visit( + &mut self, + ctxt: Option, + span: Span, + id: NodeId, + visitor: &mut impl MutVisitor, + ) { let ctxt = ctxt.unwrap(); match self { AssocItemKind::Const(item) => { @@ -1204,7 +1228,7 @@ impl NoopVisitItemKind for AssocItemKind { } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_fn(FnKind::Fn(FnCtxt::Assoc(ctxt), sig, generics, body)); + visitor.visit_fn(FnKind::Fn(FnCtxt::Assoc(ctxt), sig, generics, body), span, id); } AssocItemKind::Type(box TyAlias { defaultness, @@ -1284,7 +1308,7 @@ pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { vis.visit_span(inject_use_span); } -// Mutates one item into possibly many items. +/// Mutates one item, returning the item again. pub fn noop_flat_map_item( mut item: P>, ctxt: Option, @@ -1295,14 +1319,20 @@ pub fn noop_flat_map_item( visit_attrs(attrs, visitor); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.noop_visit(ctxt, visitor); + kind.noop_visit(ctxt, *span, *id, visitor); visit_lazy_tts(tokens, visitor); visitor.visit_span(span); smallvec![item] } impl NoopVisitItemKind for ForeignItemKind { - fn noop_visit(&mut self, ctxt: Option, visitor: &mut impl MutVisitor) { + fn noop_visit( + &mut self, + ctxt: Option, + span: Span, + id: NodeId, + visitor: &mut impl MutVisitor, + ) { assert_eq!(ctxt, None); match self { ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => { @@ -1311,7 +1341,7 @@ impl NoopVisitItemKind for ForeignItemKind { } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, sig, generics, body)); + visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, sig, generics, body), span, id); } ForeignItemKind::TyAlias(box TyAlias { defaultness, @@ -1524,7 +1554,7 @@ pub fn noop_visit_expr( visit_constness(constness, vis); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); vis.visit_capture_by(capture_clause); - vis.visit_fn(FnKind::Closure(binder, fn_decl, body)); + vis.visit_fn(FnKind::Closure(binder, fn_decl, body), *span, *id); vis.visit_span(fn_decl_span); vis.visit_span(fn_arg_span); } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 4fd1f1ac2dc4..5b1aedda9044 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -129,8 +129,8 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { c.items.push(mk_main(&mut self.cx)); } - fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - let mut item = i.into_inner(); + fn flat_map_item(&mut self, mut i: P) -> SmallVec<[P; 1]> { + let item = &mut *i; if let Some(name) = get_test_name(&item) { debug!("this is a test item"); @@ -144,13 +144,13 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - noop_visit_item_kind(&mut item.kind, self); + noop_visit_item_kind(&mut item.kind, item.span, item.id, self); self.add_test_cases(item.id, span, prev_tests); } else { // But in those cases, we emit a lint to warn the user of these missing tests. walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item); } - smallvec![P(item)] + smallvec![i] } } From e426f262fd8ed1f1ea1d09834d365b41548e21d1 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Jul 2024 10:28:09 +0000 Subject: [PATCH 14/54] Split up `visit_path` so `MutVisitor` has a `path_segment` method just like the immutable visitor --- compiler/rustc_ast/src/mut_visit.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 999ef3a01cde..f84929f52999 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -207,6 +207,10 @@ pub trait MutVisitor: Sized { noop_visit_path(p, self); } + fn visit_path_segment(&mut self, p: &mut PathSegment) { + noop_visit_path_segment(p, self) + } + fn visit_qself(&mut self, qs: &mut Option>) { noop_visit_qself(qs, self); } @@ -554,11 +558,16 @@ fn noop_visit_ident(Ident { name: _, span }: &mut Ident, vis: &mu vis.visit_span(span); } +fn noop_visit_path_segment(segment: &mut PathSegment, vis: &mut T) { + let PathSegment { ident, id, args } = segment; + vis.visit_id(id); + vis.visit_ident(ident); + visit_opt(args, |args| vis.visit_generic_args(args)); +} + fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vis: &mut T) { - for PathSegment { ident, id, args } in segments { - vis.visit_id(id); - vis.visit_ident(ident); - visit_opt(args, |args| vis.visit_generic_args(args)); + for segment in segments { + vis.visit_path_segment(segment); } visit_lazy_tts(tokens, vis); vis.visit_span(span); From 6f85f20520f6cbdbadae7695959e7b893c673693 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Jul 2024 11:13:55 +0000 Subject: [PATCH 15/54] Add `Ident` to `FnKind::Fn`, just like with the immutable visitor --- compiler/rustc_ast/src/mut_visit.rs | 23 +++++++++++++------ .../rustc_builtin_macros/src/test_harness.rs | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index f84929f52999..2d749bd8fd4e 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -39,6 +39,7 @@ pub trait NoopVisitItemKind { fn noop_visit( &mut self, ctxt: Option, + ident: Ident, span: Span, id: NodeId, visitor: &mut impl MutVisitor, @@ -895,7 +896,7 @@ fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { match kind { - FnKind::Fn(_ctxt, FnSig { header, decl, span }, generics, body) => { + FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. vis.visit_fn_header(header); vis.visit_generics(generics); @@ -1096,17 +1097,19 @@ pub fn noop_visit_block(block: &mut P, vis: &mut T) { pub fn noop_visit_item_kind( kind: &mut impl NoopVisitItemKind, + ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, ) { - kind.noop_visit(None, span, id, vis) + kind.noop_visit(None, ident, span, id, vis) } impl NoopVisitItemKind for ItemKind { fn noop_visit( &mut self, ctxt: Option, + ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, @@ -1124,7 +1127,7 @@ impl NoopVisitItemKind for ItemKind { } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, vis); - vis.visit_fn(FnKind::Fn(FnCtxt::Free, sig, generics, body), span, id); + vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, sig, generics, body), span, id); } ItemKind::Mod(safety, mod_kind) => { visit_safety(safety, vis); @@ -1226,6 +1229,7 @@ impl NoopVisitItemKind for AssocItemKind { fn noop_visit( &mut self, ctxt: Option, + ident: Ident, span: Span, id: NodeId, visitor: &mut impl MutVisitor, @@ -1237,7 +1241,11 @@ impl NoopVisitItemKind for AssocItemKind { } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_fn(FnKind::Fn(FnCtxt::Assoc(ctxt), sig, generics, body), span, id); + visitor.visit_fn( + FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, generics, body), + span, + id, + ); } AssocItemKind::Type(box TyAlias { defaultness, @@ -1328,7 +1336,7 @@ pub fn noop_flat_map_item( visit_attrs(attrs, visitor); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.noop_visit(ctxt, *span, *id, visitor); + kind.noop_visit(ctxt, *ident, *span, *id, visitor); visit_lazy_tts(tokens, visitor); visitor.visit_span(span); smallvec![item] @@ -1338,6 +1346,7 @@ impl NoopVisitItemKind for ForeignItemKind { fn noop_visit( &mut self, ctxt: Option, + ident: Ident, span: Span, id: NodeId, visitor: &mut impl MutVisitor, @@ -1350,7 +1359,7 @@ impl NoopVisitItemKind for ForeignItemKind { } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(defaultness, visitor); - visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, sig, generics, body), span, id); + visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, ident, sig, generics, body), span, id); } ForeignItemKind::TyAlias(box TyAlias { defaultness, @@ -1824,7 +1833,7 @@ impl DummyAstNode for crate::ast_traits::AstNo #[derive(Debug)] pub enum FnKind<'a> { /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. - Fn(FnCtxt, &'a mut FnSig, &'a mut Generics, &'a mut Option>), + Fn(FnCtxt, Ident, &'a mut FnSig, &'a mut Generics, &'a mut Option>), /// E.g., `|x, y| body`. Closure(&'a mut ClosureBinder, &'a mut P, &'a mut P), diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 5b1aedda9044..88712ad569b0 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -144,7 +144,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - noop_visit_item_kind(&mut item.kind, item.span, item.id, self); + noop_visit_item_kind(&mut item.kind, item.ident, item.span, item.id, self); self.add_test_cases(item.id, span, prev_tests); } else { // But in those cases, we emit a lint to warn the user of these missing tests. From 754bdef79345db368c7af43df3fae1c5cbed6c91 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jul 2024 08:17:13 +0000 Subject: [PATCH 16/54] Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/) --- compiler/rustc_ast/src/mut_visit.rs | 259 +++++++++--------- compiler/rustc_builtin_macros/src/cfg_eval.rs | 28 +- .../rustc_builtin_macros/src/test_harness.rs | 6 +- compiler/rustc_expand/src/expand.rs | 108 ++++---- compiler/rustc_expand/src/placeholders.rs | 32 +-- compiler/rustc_parse/src/parser/expr.rs | 12 +- compiler/rustc_parse/src/parser/pat.rs | 4 +- .../clippy_lints/src/unnested_or_patterns.rs | 8 +- tests/ui-fulldeps/pprust-expr-roundtrip.rs | 4 +- 9 files changed, 226 insertions(+), 235 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 2d749bd8fd4e..56dd6663bb69 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -36,7 +36,7 @@ impl ExpectOne for SmallVec { } pub trait NoopVisitItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -86,35 +86,35 @@ pub trait MutVisitor: Sized { // forget to add handling for it. fn visit_crate(&mut self, c: &mut Crate) { - noop_visit_crate(c, self) + walk_crate(c, self) } fn visit_meta_list_item(&mut self, list_item: &mut NestedMetaItem) { - noop_visit_meta_list_item(list_item, self); + walk_meta_list_item(list_item, self); } fn visit_meta_item(&mut self, meta_item: &mut MetaItem) { - noop_visit_meta_item(meta_item, self); + walk_meta_item(meta_item, self); } fn visit_use_tree(&mut self, use_tree: &mut UseTree) { - noop_visit_use_tree(use_tree, self); + walk_use_tree(use_tree, self); } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(ni, None, self) + walk_flat_map_item(ni, None, self) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, None, self) + walk_flat_map_item(i, None, self) } fn visit_fn_header(&mut self, header: &mut FnHeader) { - noop_visit_fn_header(header, self); + walk_fn_header(header, self); } fn flat_map_field_def(&mut self, fd: FieldDef) -> SmallVec<[FieldDef; 1]> { - noop_flat_map_field_def(fd, self) + walk_flat_map_field_def(fd, self) } fn flat_map_assoc_item( @@ -122,48 +122,48 @@ pub trait MutVisitor: Sized { i: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - noop_flat_map_item(i, Some(ctxt), self) + walk_flat_map_item(i, Some(ctxt), self) } fn visit_fn_decl(&mut self, d: &mut P) { - noop_visit_fn_decl(d, self); + walk_fn_decl(d, self); } /// `Span` and `NodeId` are mutated at the caller site. fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) { - noop_visit_fn(fk, self) + walk_fn(fk, self) } fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) { - noop_visit_coroutine_kind(a, self); + walk_coroutine_kind(a, self); } fn visit_closure_binder(&mut self, b: &mut ClosureBinder) { - noop_visit_closure_binder(b, self); + walk_closure_binder(b, self); } fn visit_block(&mut self, b: &mut P) { - noop_visit_block(b, self); + walk_block(b, self); } fn flat_map_stmt(&mut self, s: Stmt) -> SmallVec<[Stmt; 1]> { - noop_flat_map_stmt(s, self) + walk_flat_map_stmt(s, self) } fn flat_map_arm(&mut self, arm: Arm) -> SmallVec<[Arm; 1]> { - noop_flat_map_arm(arm, self) + walk_flat_map_arm(arm, self) } fn visit_pat(&mut self, p: &mut P) { - noop_visit_pat(p, self); + walk_pat(p, self); } fn visit_anon_const(&mut self, c: &mut AnonConst) { - noop_visit_anon_const(c, self); + walk_anon_const(c, self); } fn visit_expr(&mut self, e: &mut P) { - noop_visit_expr(e, self); + walk_expr(e, self); } /// This method is a hack to workaround unstable of `stmt_expr_attributes`. @@ -177,127 +177,127 @@ pub trait MutVisitor: Sized { } fn visit_generic_arg(&mut self, arg: &mut GenericArg) { - noop_visit_generic_arg(arg, self); + walk_generic_arg(arg, self); } fn visit_ty(&mut self, t: &mut P) { - noop_visit_ty(t, self); + walk_ty(t, self); } fn visit_lifetime(&mut self, l: &mut Lifetime) { - noop_visit_lifetime(l, self); + walk_lifetime(l, self); } fn visit_assoc_item_constraint(&mut self, c: &mut AssocItemConstraint) { - noop_visit_assoc_item_constraint(c, self); + walk_assoc_item_constraint(c, self); } fn visit_foreign_mod(&mut self, nm: &mut ForeignMod) { - noop_visit_foreign_mod(nm, self); + walk_foreign_mod(nm, self); } fn flat_map_variant(&mut self, v: Variant) -> SmallVec<[Variant; 1]> { - noop_flat_map_variant(v, self) + walk_flat_map_variant(v, self) } fn visit_ident(&mut self, i: &mut Ident) { - noop_visit_ident(i, self); + walk_ident(i, self); } fn visit_path(&mut self, p: &mut Path) { - noop_visit_path(p, self); + walk_path(self, p); } fn visit_path_segment(&mut self, p: &mut PathSegment) { - noop_visit_path_segment(p, self) + walk_path_segment(self, p) } fn visit_qself(&mut self, qs: &mut Option>) { - noop_visit_qself(qs, self); + walk_qself(qs, self); } fn visit_generic_args(&mut self, p: &mut GenericArgs) { - noop_visit_generic_args(p, self); + walk_generic_args(p, self); } fn visit_angle_bracketed_parameter_data(&mut self, p: &mut AngleBracketedArgs) { - noop_visit_angle_bracketed_parameter_data(p, self); + walk_angle_bracketed_parameter_data(p, self); } fn visit_parenthesized_parameter_data(&mut self, p: &mut ParenthesizedArgs) { - noop_visit_parenthesized_parameter_data(p, self); + walk_parenthesized_parameter_data(p, self); } fn visit_local(&mut self, l: &mut P) { - noop_visit_local(l, self); + walk_local(l, self); } fn visit_mac_call(&mut self, mac: &mut MacCall) { - noop_visit_mac(mac, self); + walk_mac(mac, self); } fn visit_macro_def(&mut self, def: &mut MacroDef) { - noop_visit_macro_def(def, self); + walk_macro_def(def, self); } fn visit_label(&mut self, label: &mut Label) { - noop_visit_label(label, self); + walk_label(label, self); } fn visit_attribute(&mut self, at: &mut Attribute) { - noop_visit_attribute(at, self); + walk_attribute(at, self); } fn flat_map_param(&mut self, param: Param) -> SmallVec<[Param; 1]> { - noop_flat_map_param(param, self) + walk_flat_map_param(param, self) } fn visit_generics(&mut self, generics: &mut Generics) { - noop_visit_generics(generics, self); + walk_generics(generics, self); } fn visit_trait_ref(&mut self, tr: &mut TraitRef) { - noop_visit_trait_ref(tr, self); + walk_trait_ref(tr, self); } fn visit_poly_trait_ref(&mut self, p: &mut PolyTraitRef) { - noop_visit_poly_trait_ref(p, self); + walk_poly_trait_ref(p, self); } fn visit_variant_data(&mut self, vdata: &mut VariantData) { - noop_visit_variant_data(vdata, self); + walk_variant_data(vdata, self); } fn flat_map_generic_param(&mut self, param: GenericParam) -> SmallVec<[GenericParam; 1]> { - noop_flat_map_generic_param(param, self) + walk_flat_map_generic_param(param, self) } fn visit_param_bound(&mut self, tpb: &mut GenericBound, _ctxt: BoundKind) { - noop_visit_param_bound(tpb, self); + walk_param_bound(tpb, self); } fn visit_precise_capturing_arg(&mut self, arg: &mut PreciseCapturingArg) { - noop_visit_precise_capturing_arg(arg, self); + walk_precise_capturing_arg(arg, self); } fn visit_mt(&mut self, mt: &mut MutTy) { - noop_visit_mt(mt, self); + walk_mt(mt, self); } fn flat_map_expr_field(&mut self, f: ExprField) -> SmallVec<[ExprField; 1]> { - noop_flat_map_expr_field(f, self) + walk_flat_map_expr_field(f, self) } fn visit_where_clause(&mut self, where_clause: &mut WhereClause) { - noop_visit_where_clause(where_clause, self); + walk_where_clause(where_clause, self); } fn visit_where_predicate(&mut self, where_predicate: &mut WherePredicate) { - noop_visit_where_predicate(where_predicate, self); + walk_where_predicate(where_predicate, self); } fn visit_vis(&mut self, vis: &mut Visibility) { - noop_visit_vis(vis, self); + walk_vis(vis, self); } fn visit_id(&mut self, _id: &mut NodeId) { @@ -309,23 +309,23 @@ pub trait MutVisitor: Sized { } fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> { - noop_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(fp, self) } fn visit_inline_asm(&mut self, asm: &mut InlineAsm) { - noop_visit_inline_asm(asm, self) + walk_inline_asm(asm, self) } fn visit_inline_asm_sym(&mut self, sym: &mut InlineAsmSym) { - noop_visit_inline_asm_sym(sym, self) + walk_inline_asm_sym(sym, self) } fn visit_format_args(&mut self, fmt: &mut FormatArgs) { - noop_visit_format_args(fmt, self) + walk_format_args(fmt, self) } fn visit_capture_by(&mut self, capture_by: &mut CaptureBy) { - noop_visit_capture_by(capture_by, self) + walk_capture_by(capture_by, self) } } @@ -422,7 +422,7 @@ pub fn visit_delim_span(DelimSpan { open, close }: &mut DelimSpan vis.visit_span(close); } -pub fn noop_flat_map_pat_field( +pub fn walk_flat_map_pat_field( mut fp: PatField, vis: &mut T, ) -> SmallVec<[PatField; 1]> { @@ -435,7 +435,7 @@ pub fn noop_flat_map_pat_field( smallvec![fp] } -fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { +fn walk_use_tree(use_tree: &mut UseTree, vis: &mut T) { let UseTree { prefix, kind, span } = use_tree; vis.visit_path(prefix); match kind { @@ -452,7 +452,7 @@ fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { vis.visit_span(span); } -pub fn noop_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> { +pub fn walk_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> { let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm; vis.visit_id(id); visit_attrs(attrs, vis); @@ -463,7 +463,7 @@ pub fn noop_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[ smallvec![arm] } -fn noop_visit_assoc_item_constraint( +fn walk_assoc_item_constraint( AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint, vis: &mut T, ) { @@ -482,7 +482,7 @@ fn noop_visit_assoc_item_constraint( vis.visit_span(span); } -pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { +pub fn walk_ty(ty: &mut P, vis: &mut T) { let Ty { id, kind, span, tokens } = ty.deref_mut(); vis.visit_id(id); match kind { @@ -534,13 +534,13 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { +fn walk_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { let ForeignMod { safety, abi: _, items } = foreign_mod; visit_safety(safety, vis); items.flat_map_in_place(|item| vis.flat_map_foreign_item(item)); } -pub fn noop_flat_map_variant( +pub fn walk_flat_map_variant( mut variant: Variant, visitor: &mut T, ) -> SmallVec<[Variant; 1]> { @@ -555,18 +555,18 @@ pub fn noop_flat_map_variant( smallvec![variant] } -fn noop_visit_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { +fn walk_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_path_segment(segment: &mut PathSegment, vis: &mut T) { +fn walk_path_segment(vis: &mut T, segment: &mut PathSegment) { let PathSegment { ident, id, args } = segment; vis.visit_id(id); vis.visit_ident(ident); visit_opt(args, |args| vis.visit_generic_args(args)); } -fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vis: &mut T) { +fn walk_path(vis: &mut T, Path { segments, span, tokens }: &mut Path) { for segment in segments { vis.visit_path_segment(segment); } @@ -574,7 +574,7 @@ fn noop_visit_path(Path { segments, span, tokens }: &mut Path, vi vis.visit_span(span); } -fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { +fn walk_qself(qself: &mut Option>, vis: &mut T) { visit_opt(qself, |qself| { let QSelf { ty, path_span, position: _ } = &mut **qself; vis.visit_ty(ty); @@ -582,7 +582,7 @@ fn noop_visit_qself(qself: &mut Option>, vis: &mut T) { }) } -fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { +fn walk_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { match generic_args { GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data), GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data), @@ -590,7 +590,7 @@ fn noop_visit_generic_args(generic_args: &mut GenericArgs, vis: & } } -fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { +fn walk_generic_arg(arg: &mut GenericArg, vis: &mut T) { match arg { GenericArg::Lifetime(lt) => vis.visit_lifetime(lt), GenericArg::Type(ty) => vis.visit_ty(ty), @@ -598,10 +598,7 @@ fn noop_visit_generic_arg(arg: &mut GenericArg, vis: &mut T) { } } -fn noop_visit_angle_bracketed_parameter_data( - data: &mut AngleBracketedArgs, - vis: &mut T, -) { +fn walk_angle_bracketed_parameter_data(data: &mut AngleBracketedArgs, vis: &mut T) { let AngleBracketedArgs { args, span } = data; visit_thin_vec(args, |arg| match arg { AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg), @@ -610,18 +607,15 @@ fn noop_visit_angle_bracketed_parameter_data( vis.visit_span(span); } -fn noop_visit_parenthesized_parameter_data( - args: &mut ParenthesizedArgs, - vis: &mut T, -) { +fn walk_parenthesized_parameter_data(args: &mut ParenthesizedArgs, vis: &mut T) { let ParenthesizedArgs { inputs, output, span, inputs_span } = args; visit_thin_vec(inputs, |input| vis.visit_ty(input)); - noop_visit_fn_ret_ty(output, vis); + walk_fn_ret_ty(output, vis); vis.visit_span(span); vis.visit_span(inputs_span); } -fn noop_visit_local(local: &mut P, vis: &mut T) { +fn walk_local(local: &mut P, vis: &mut T) { let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut(); vis.visit_id(id); visit_attrs(attrs, vis); @@ -642,7 +636,7 @@ fn noop_visit_local(local: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { +fn walk_attribute(attr: &mut Attribute, vis: &mut T) { let Attribute { kind, id: _, style: _, span } = attr; match kind { AttrKind::Normal(normal) => { @@ -660,25 +654,25 @@ fn noop_visit_attribute(attr: &mut Attribute, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_mac(mac: &mut MacCall, vis: &mut T) { +fn walk_mac(mac: &mut MacCall, vis: &mut T) { let MacCall { path, args } = mac; vis.visit_path(path); visit_delim_args(args, vis); } -fn noop_visit_macro_def(macro_def: &mut MacroDef, vis: &mut T) { +fn walk_macro_def(macro_def: &mut MacroDef, vis: &mut T) { let MacroDef { body, macro_rules: _ } = macro_def; visit_delim_args(body, vis); } -fn noop_visit_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { +fn walk_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { match li { NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi), NestedMetaItem::Lit(_lit) => {} } } -fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { +fn walk_meta_item(mi: &mut MetaItem, vis: &mut T) { let MetaItem { unsafety: _, path: _, kind, span } = mi; match kind { MetaItemKind::Word => {} @@ -688,7 +682,7 @@ fn noop_visit_meta_item(mi: &mut MetaItem, vis: &mut T) { vis.visit_span(span); } -pub fn noop_flat_map_param(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> { +pub fn walk_flat_map_param(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> { let Param { attrs, id, pat, span, ty, is_placeholder: _ } = &mut param; vis.visit_id(id); visit_attrs(attrs, vis); @@ -873,7 +867,7 @@ fn visit_constness(constness: &mut Const, vis: &mut T) { } } -fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { +fn walk_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { match binder { ClosureBinder::NotPresent => {} ClosureBinder::For { span: _, generic_params } => { @@ -882,7 +876,7 @@ fn noop_visit_closure_binder(binder: &mut ClosureBinder, vis: &mu } } -fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { +fn walk_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { match coroutine_kind { CoroutineKind::Async { span, closure_id, return_impl_trait_id } | CoroutineKind::Gen { span, closure_id, return_impl_trait_id } @@ -894,7 +888,7 @@ fn noop_visit_coroutine_kind(coroutine_kind: &mut CoroutineKind, } } -fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { +fn walk_fn(kind: FnKind<'_>, vis: &mut T) { match kind { FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. @@ -914,23 +908,23 @@ fn noop_visit_fn(kind: FnKind<'_>, vis: &mut T) { } } -fn noop_visit_fn_decl(decl: &mut P, vis: &mut T) { +fn walk_fn_decl(decl: &mut P, vis: &mut T) { let FnDecl { inputs, output } = decl.deref_mut(); inputs.flat_map_in_place(|param| vis.flat_map_param(param)); - noop_visit_fn_ret_ty(output, vis); + walk_fn_ret_ty(output, vis); } -fn noop_visit_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { +fn walk_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { match fn_ret_ty { FnRetTy::Default(span) => vis.visit_span(span), FnRetTy::Ty(ty) => vis.visit_ty(ty), } } -fn noop_visit_param_bound(pb: &mut GenericBound, vis: &mut T) { +fn walk_param_bound(pb: &mut GenericBound, vis: &mut T) { match pb { GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty), - GenericBound::Outlives(lifetime) => noop_visit_lifetime(lifetime, vis), + GenericBound::Outlives(lifetime) => walk_lifetime(lifetime, vis), GenericBound::Use(args, span) => { for arg in args { vis.visit_precise_capturing_arg(arg); @@ -940,7 +934,7 @@ fn noop_visit_param_bound(pb: &mut GenericBound, vis: &mut T) { } } -fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { +fn walk_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { match arg { PreciseCapturingArg::Lifetime(lt) => { vis.visit_lifetime(lt); @@ -952,7 +946,7 @@ fn noop_visit_precise_capturing_arg(arg: &mut PreciseCapturingArg } } -pub fn noop_flat_map_generic_param( +pub fn walk_flat_map_generic_param( mut param: GenericParam, vis: &mut T, ) -> SmallVec<[GenericParam; 1]> { @@ -977,23 +971,23 @@ pub fn noop_flat_map_generic_param( smallvec![param] } -fn noop_visit_label(Label { ident }: &mut Label, vis: &mut T) { +fn walk_label(Label { ident }: &mut Label, vis: &mut T) { vis.visit_ident(ident); } -fn noop_visit_lifetime(Lifetime { id, ident }: &mut Lifetime, vis: &mut T) { +fn walk_lifetime(Lifetime { id, ident }: &mut Lifetime, vis: &mut T) { vis.visit_id(id); vis.visit_ident(ident); } -fn noop_visit_generics(generics: &mut Generics, vis: &mut T) { +fn walk_generics(generics: &mut Generics, vis: &mut T) { let Generics { params, where_clause, span } = generics; params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_where_clause(where_clause); vis.visit_span(span); } -fn noop_visit_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, vis: &mut T) { +fn walk_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, vis: &mut T) { let TyAliasWhereClauses { before, after, split: _ } = tawcs; let TyAliasWhereClause { has_where_token: _, span: span_before } = before; let TyAliasWhereClause { has_where_token: _, span: span_after } = after; @@ -1001,13 +995,13 @@ fn noop_visit_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClau vis.visit_span(span_after); } -fn noop_visit_where_clause(wc: &mut WhereClause, vis: &mut T) { +fn walk_where_clause(wc: &mut WhereClause, vis: &mut T) { let WhereClause { has_where_token: _, predicates, span } = wc; visit_thin_vec(predicates, |predicate| vis.visit_where_predicate(predicate)); vis.visit_span(span); } -fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mut T) { +fn walk_where_predicate(pred: &mut WherePredicate, vis: &mut T) { match pred { WherePredicate::BoundPredicate(bp) => { let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp; @@ -1031,7 +1025,7 @@ fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: &mu } } -fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) { +fn walk_variant_data(vdata: &mut VariantData, vis: &mut T) { match vdata { VariantData::Struct { fields, recovered: _ } => { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); @@ -1044,19 +1038,19 @@ fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) } } -fn noop_visit_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { +fn walk_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { vis.visit_id(ref_id); vis.visit_path(path); } -fn noop_visit_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { +fn walk_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { let PolyTraitRef { bound_generic_params, trait_ref, span } = p; bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_trait_ref(trait_ref); vis.visit_span(span); } -pub fn noop_flat_map_field_def( +pub fn walk_flat_map_field_def( mut fd: FieldDef, visitor: &mut T, ) -> SmallVec<[FieldDef; 1]> { @@ -1070,7 +1064,7 @@ pub fn noop_flat_map_field_def( smallvec![fd] } -pub fn noop_flat_map_expr_field( +pub fn walk_flat_map_expr_field( mut f: ExprField, vis: &mut T, ) -> SmallVec<[ExprField; 1]> { @@ -1083,11 +1077,11 @@ pub fn noop_flat_map_expr_field( smallvec![f] } -fn noop_visit_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { +fn walk_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { vis.visit_ty(ty); } -pub fn noop_visit_block(block: &mut P, vis: &mut T) { +pub fn walk_block(block: &mut P, vis: &mut T) { let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut(); vis.visit_id(id); stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt)); @@ -1095,18 +1089,18 @@ pub fn noop_visit_block(block: &mut P, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_item_kind( +pub fn walk_item_kind( kind: &mut impl NoopVisitItemKind, ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, ) { - kind.noop_visit(None, ident, span, id, vis) + kind.walk(None, ident, span, id, vis) } impl NoopVisitItemKind for ItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1147,7 +1141,7 @@ impl NoopVisitItemKind for ItemKind { vis.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, vis); visit_opt(ty, |ty| vis.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, vis); + walk_ty_alias_where_clauses(where_clauses, vis); } ItemKind::Enum(EnumDef { variants }, generics) => { vis.visit_generics(generics); @@ -1226,7 +1220,7 @@ impl NoopVisitItemKind for ItemKind { } impl NoopVisitItemKind for AssocItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1258,7 +1252,7 @@ impl NoopVisitItemKind for AssocItemKind { visitor.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(where_clauses, visitor); } AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac), AssocItemKind::Delegation(box Delegation { @@ -1308,14 +1302,14 @@ fn visit_const_item( visit_opt(expr, |expr| visitor.visit_expr(expr)); } -fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { +fn walk_fn_header(header: &mut FnHeader, vis: &mut T) { let FnHeader { safety, coroutine_kind, constness, ext: _ } = header; visit_constness(constness, vis); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); visit_safety(safety, vis); } -pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { +pub fn walk_crate(krate: &mut Crate, vis: &mut T) { let Crate { attrs, items, spans, id, is_placeholder: _ } = krate; vis.visit_id(id); visit_attrs(attrs, vis); @@ -1326,7 +1320,7 @@ pub fn noop_visit_crate(krate: &mut Crate, vis: &mut T) { } /// Mutates one item, returning the item again. -pub fn noop_flat_map_item( +pub fn walk_flat_map_item( mut item: P>, ctxt: Option, visitor: &mut impl MutVisitor, @@ -1336,14 +1330,14 @@ pub fn noop_flat_map_item( visit_attrs(attrs, visitor); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.noop_visit(ctxt, *ident, *span, *id, visitor); + kind.walk(ctxt, *ident, *span, *id, visitor); visit_lazy_tts(tokens, visitor); visitor.visit_span(span); smallvec![item] } impl NoopVisitItemKind for ForeignItemKind { - fn noop_visit( + fn walk( &mut self, ctxt: Option, ident: Ident, @@ -1372,14 +1366,14 @@ impl NoopVisitItemKind for ForeignItemKind { visitor.visit_generics(generics); visit_bounds(bounds, BoundKind::Bound, visitor); visit_opt(ty, |ty| visitor.visit_ty(ty)); - noop_visit_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(where_clauses, visitor); } ForeignItemKind::MacCall(mac) => visitor.visit_mac_call(mac), } } } -pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { +pub fn walk_pat(pat: &mut P, vis: &mut T) { let Pat { id, kind, span, tokens } = pat.deref_mut(); vis.visit_id(id); match kind { @@ -1422,12 +1416,12 @@ pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { +fn walk_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { vis.visit_id(id); vis.visit_expr(value); } -fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { +fn walk_inline_asm(asm: &mut InlineAsm, vis: &mut T) { // FIXME: Visit spans inside all this currently ignored stuff. let InlineAsm { template: _, @@ -1457,7 +1451,7 @@ fn noop_visit_inline_asm(asm: &mut InlineAsm, vis: &mut T) { } } -fn noop_visit_inline_asm_sym( +fn walk_inline_asm_sym( InlineAsmSym { id, qself, path }: &mut InlineAsmSym, vis: &mut T, ) { @@ -1466,7 +1460,7 @@ fn noop_visit_inline_asm_sym( vis.visit_path(path); } -fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { +fn walk_format_args(fmt: &mut FormatArgs, vis: &mut T) { // FIXME: visit the template exhaustively. let FormatArgs { span, template: _, arguments } = fmt; for FormatArgument { kind, expr } in arguments.all_args_mut() { @@ -1481,10 +1475,7 @@ fn noop_visit_format_args(fmt: &mut FormatArgs, vis: &mut T) { vis.visit_span(span); } -pub fn noop_visit_expr( - Expr { kind, id, span, attrs, tokens }: &mut Expr, - vis: &mut T, -) { +pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Expr, vis: &mut T) { vis.visit_id(id); visit_attrs(attrs, vis); match kind { @@ -1673,12 +1664,12 @@ pub fn noop_filter_map_expr(mut e: P, vis: &mut T) -> Optio }) } -pub fn noop_flat_map_stmt( +pub fn walk_flat_map_stmt( Stmt { kind, mut span, mut id }: Stmt, vis: &mut T, ) -> SmallVec<[Stmt; 1]> { vis.visit_id(&mut id); - let stmts: SmallVec<_> = noop_flat_map_stmt_kind(kind, vis) + let stmts: SmallVec<_> = walk_flat_map_stmt_kind(kind, vis) .into_iter() .map(|kind| Stmt { id, kind, span }) .collect(); @@ -1692,7 +1683,7 @@ pub fn noop_flat_map_stmt( stmts } -fn noop_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallVec<[StmtKind; 1]> { +fn walk_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallVec<[StmtKind; 1]> { match kind { StmtKind::Let(mut local) => smallvec![StmtKind::Let({ vis.visit_local(&mut local); @@ -1712,7 +1703,7 @@ fn noop_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallV } } -fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { +fn walk_vis(visibility: &mut Visibility, vis: &mut T) { let Visibility { kind, span, tokens } = visibility; match kind { VisibilityKind::Public | VisibilityKind::Inherited => {} @@ -1725,7 +1716,7 @@ fn noop_visit_vis(visibility: &mut Visibility, vis: &mut T) { vis.visit_span(span); } -fn noop_visit_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { +fn walk_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { match capture_by { CaptureBy::Ref => {} CaptureBy::Value { move_kw } => { diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index 1cfbaf9d669a..39d66b5a6de0 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -212,18 +212,18 @@ impl MutVisitor for CfgEval<'_> { #[instrument(level = "trace", skip(self))] fn visit_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, false); - mut_visit::noop_visit_expr(expr, self); + mut_visit::walk_expr(expr, self); } #[instrument(level = "trace", skip(self))] fn visit_method_receiver_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, true); - mut_visit::noop_visit_expr(expr, self); + mut_visit::walk_expr(expr, self); } fn filter_map_expr(&mut self, expr: P) -> Option> { let mut expr = configure!(self, expr); - mut_visit::noop_visit_expr(&mut expr, self); + mut_visit::walk_expr(&mut expr, self); Some(expr) } @@ -231,15 +231,15 @@ impl MutVisitor for CfgEval<'_> { &mut self, param: ast::GenericParam, ) -> SmallVec<[ast::GenericParam; 1]> { - mut_visit::noop_flat_map_generic_param(configure!(self, param), self) + mut_visit::walk_flat_map_generic_param(configure!(self, param), self) } fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { - mut_visit::noop_flat_map_stmt(configure!(self, stmt), self) + mut_visit::walk_flat_map_stmt(configure!(self, stmt), self) } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), None, self) + mut_visit::walk_flat_map_item(configure!(self, item), None, self) } fn flat_map_assoc_item( @@ -247,37 +247,37 @@ impl MutVisitor for CfgEval<'_> { item: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, item), Some(ctxt), self) + mut_visit::walk_flat_map_item(configure!(self, item), Some(ctxt), self) } fn flat_map_foreign_item( &mut self, foreign_item: P, ) -> SmallVec<[P; 1]> { - mut_visit::noop_flat_map_item(configure!(self, foreign_item), None, self) + mut_visit::walk_flat_map_item(configure!(self, foreign_item), None, self) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { - mut_visit::noop_flat_map_arm(configure!(self, arm), self) + mut_visit::walk_flat_map_arm(configure!(self, arm), self) } fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> { - mut_visit::noop_flat_map_expr_field(configure!(self, field), self) + mut_visit::walk_flat_map_expr_field(configure!(self, field), self) } fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> { - mut_visit::noop_flat_map_pat_field(configure!(self, fp), self) + mut_visit::walk_flat_map_pat_field(configure!(self, fp), self) } fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> { - mut_visit::noop_flat_map_param(configure!(self, p), self) + mut_visit::walk_flat_map_param(configure!(self, p), self) } fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> { - mut_visit::noop_flat_map_field_def(configure!(self, sf), self) + mut_visit::walk_flat_map_field_def(configure!(self, sf), self) } fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> { - mut_visit::noop_flat_map_variant(configure!(self, variant), self) + mut_visit::walk_flat_map_variant(configure!(self, variant), self) } } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 88712ad569b0..2e4d60a08177 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -122,7 +122,7 @@ impl TestHarnessGenerator<'_> { impl<'a> MutVisitor for TestHarnessGenerator<'a> { fn visit_crate(&mut self, c: &mut ast::Crate) { let prev_tests = mem::take(&mut self.tests); - noop_visit_crate(c, self); + walk_crate(c, self); self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests); // Create a main function to run our tests @@ -144,7 +144,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - noop_visit_item_kind(&mut item.kind, item.ident, item.span, item.id, self); + walk_item_kind(&mut item.kind, item.ident, item.span, item.id, self); self.add_test_cases(item.id, span, prev_tests); } else { // But in those cases, we emit a lint to warn the user of these missing tests. @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = noop_flat_map_item(i, None, self).expect_one("noop did something"); + let item = walk_flat_map_item(i, None, self).expect_one("noop did something"); self.depth -= 1; // Remove any #[rustc_main] or #[start] from the AST so it doesn't diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 6f4df7bb1685..c10b71141236 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1036,7 +1036,7 @@ pub(crate) fn ensure_complete_parse<'a>( } } -/// Wraps a call to `noop_visit_*` / `noop_flat_map_*` +/// Wraps a call to `walk_*` / `walk_flat_map_*` /// for an AST node that supports attributes /// (see the `Annotatable` enum) /// This method assigns a `NodeId`, and sets that `NodeId` @@ -1056,7 +1056,7 @@ pub(crate) fn ensure_complete_parse<'a>( /// * `id` is a mutable reference to the `NodeId` field /// of the current AST node. /// * `closure` is a closure that executes the -/// `noop_visit_*` / `noop_flat_map_*` method +/// `walk_*` / `walk_flat_map_*` method /// for the current AST node. macro_rules! assign_id { ($self:ident, $id:expr, $closure:expr) => {{ @@ -1090,10 +1090,10 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn descr() -> &'static str { unreachable!() } - fn noop_flat_map(self, _visitor: &mut V) -> Self::OutputTy { + fn walk_flat_map(self, _visitor: &mut V) -> Self::OutputTy { unreachable!() } - fn noop_visit(&mut self, _visitor: &mut V) { + fn walk(&mut self, _visitor: &mut V) { unreachable!() } fn is_mac_call(&self) -> bool { @@ -1117,12 +1117,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn pre_flat_map_node_collect_attr(_cfg: &StripUnconfigured<'_>, _attr: &ast::Attribute) {} fn post_flat_map_node_collect_bang(_output: &mut Self::OutputTy, _add_semicolon: AddSemicolon) { } - fn wrap_flat_map_node_noop_flat_map( + fn wrap_flat_map_node_walk_flat_map( node: Self, collector: &mut InvocationCollector<'_, '_>, - noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, + walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, ) -> Result { - Ok(noop_flat_map(node, collector)) + Ok(walk_flat_map(node, collector)) } fn expand_cfg_false( &mut self, @@ -1148,8 +1148,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, None, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1176,13 +1176,13 @@ impl InvocationCollectorNode for P { fn flatten_outputs(items: impl Iterator) -> Self::OutputTy { items.flatten().collect() } - fn wrap_flat_map_node_noop_flat_map( + fn wrap_flat_map_node_walk_flat_map( mut node: Self, collector: &mut InvocationCollector<'_, '_>, - noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, + walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy, ) -> Result { if !matches!(node.kind, ItemKind::Mod(..)) { - return Ok(noop_flat_map(node, collector)); + return Ok(walk_flat_map(node, collector)); } // Work around borrow checker not seeing through `P`'s deref. @@ -1252,7 +1252,7 @@ impl InvocationCollectorNode for P { let orig_dir_ownership = mem::replace(&mut ecx.current_expansion.dir_ownership, dir_ownership); - let res = Ok(noop_flat_map(node, collector)); + let res = Ok(walk_flat_map(node, collector)); collector.cx.current_expansion.dir_ownership = orig_dir_ownership; collector.cx.current_expansion.module = orig_module; @@ -1292,8 +1292,8 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_trait_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1333,8 +1333,8 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_impl_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1371,8 +1371,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_foreign_items() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_item(self, None, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_item(self, None, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) @@ -1394,8 +1394,8 @@ impl InvocationCollectorNode for ast::Variant { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_variants() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_variant(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_variant(self, visitor) } } @@ -1407,8 +1407,8 @@ impl InvocationCollectorNode for ast::FieldDef { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_field_defs() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_field_def(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_field_def(self, visitor) } } @@ -1420,8 +1420,8 @@ impl InvocationCollectorNode for ast::PatField { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_pat_fields() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_pat_field(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_pat_field(self, visitor) } } @@ -1433,8 +1433,8 @@ impl InvocationCollectorNode for ast::ExprField { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_expr_fields() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_expr_field(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_expr_field(self, visitor) } } @@ -1446,8 +1446,8 @@ impl InvocationCollectorNode for ast::Param { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_params() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_param(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_param(self, visitor) } } @@ -1459,8 +1459,8 @@ impl InvocationCollectorNode for ast::GenericParam { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_generic_params() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_generic_param(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_generic_param(self, visitor) } } @@ -1472,8 +1472,8 @@ impl InvocationCollectorNode for ast::Arm { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_arms() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_arm(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_arm(self, visitor) } } @@ -1486,8 +1486,8 @@ impl InvocationCollectorNode for ast::Stmt { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_stmts() } - fn noop_flat_map(self, visitor: &mut V) -> Self::OutputTy { - noop_flat_map_stmt(self, visitor) + fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { + walk_flat_map_stmt(self, visitor) } fn is_mac_call(&self) -> bool { match &self.kind { @@ -1560,8 +1560,8 @@ impl InvocationCollectorNode for ast::Crate { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_crate() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_crate(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_crate(self, visitor) } fn expand_cfg_false( &mut self, @@ -1586,8 +1586,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_ty() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_ty(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_ty(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ast::TyKind::MacCall(..)) @@ -1610,8 +1610,8 @@ impl InvocationCollectorNode for P { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_pat() } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_pat(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_pat(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, PatKind::MacCall(..)) @@ -1638,8 +1638,8 @@ impl InvocationCollectorNode for P { fn descr() -> &'static str { "an expression" } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_expr(self, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_expr(self, visitor) } fn is_mac_call(&self) -> bool { matches!(self.kind, ExprKind::MacCall(..)) @@ -1664,8 +1664,8 @@ impl InvocationCollectorNode for AstNodeWrapper, OptExprTag> { fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_opt_expr() } - fn noop_flat_map(mut self, visitor: &mut V) -> Self::OutputTy { - noop_visit_expr(&mut self.wrapped, visitor); + fn walk_flat_map(mut self, visitor: &mut V) -> Self::OutputTy { + walk_expr(&mut self.wrapped, visitor); Some(self.wrapped) } fn is_mac_call(&self) -> bool { @@ -1704,8 +1704,8 @@ impl InvocationCollectorNode for AstNodeWrapper, MethodReceiverTag> fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) } - fn noop_visit(&mut self, visitor: &mut V) { - noop_visit_expr(&mut self.wrapped, visitor) + fn walk(&mut self, visitor: &mut V) { + walk_expr(&mut self.wrapped, visitor) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) @@ -2015,12 +2015,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { ); Node::flatten_outputs(single_delegations.map(|item| { let mut item = Node::from_item(item); - assign_id!(self, item.node_id_mut(), || item.noop_flat_map(self)) + assign_id!(self, item.node_id_mut(), || item.walk_flat_map(self)) })) } None => { - match Node::wrap_flat_map_node_noop_flat_map(node, self, |mut node, this| { - assign_id!(this, node.node_id_mut(), || node.noop_flat_map(this)) + match Node::wrap_flat_map_node_walk_flat_map(node, self, |mut node, this| { + assign_id!(this, node.node_id_mut(), || node.walk_flat_map(this)) }) { Ok(output) => output, Err(returned_node) => { @@ -2068,7 +2068,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } None if node.delegation().is_some() => unreachable!(), None => { - assign_id!(self, node.node_id_mut(), || node.noop_visit(self)) + assign_id!(self, node.node_id_mut(), || node.walk(self)) } }; } @@ -2147,11 +2147,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.cx.current_expansion.is_trailing_mac = true; // Don't use `assign_id` for this statement - it may get removed // entirely due to a `#[cfg]` on the contained expression - let res = noop_flat_map_stmt(node, self); + let res = walk_flat_map_stmt(node, self); self.cx.current_expansion.is_trailing_mac = false; res } - _ => noop_flat_map_stmt(node, self), + _ => walk_flat_map_stmt(node, self), }; } @@ -2195,7 +2195,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { &mut self.cx.current_expansion.dir_ownership, DirOwnership::UnownedViaBlock, ); - noop_visit_block(node, self); + walk_block(node, self); self.cx.current_expansion.dir_ownership = orig_dir_ownership; } diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 2ed968f57bce..a9884b344c76 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -209,7 +209,7 @@ impl MutVisitor for PlaceholderExpander { if arm.is_placeholder { self.remove(arm.id).make_arms() } else { - noop_flat_map_arm(arm, self) + walk_flat_map_arm(arm, self) } } @@ -217,7 +217,7 @@ impl MutVisitor for PlaceholderExpander { if field.is_placeholder { self.remove(field.id).make_expr_fields() } else { - noop_flat_map_expr_field(field, self) + walk_flat_map_expr_field(field, self) } } @@ -225,7 +225,7 @@ impl MutVisitor for PlaceholderExpander { if fp.is_placeholder { self.remove(fp.id).make_pat_fields() } else { - noop_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(fp, self) } } @@ -236,7 +236,7 @@ impl MutVisitor for PlaceholderExpander { if param.is_placeholder { self.remove(param.id).make_generic_params() } else { - noop_flat_map_generic_param(param, self) + walk_flat_map_generic_param(param, self) } } @@ -244,7 +244,7 @@ impl MutVisitor for PlaceholderExpander { if p.is_placeholder { self.remove(p.id).make_params() } else { - noop_flat_map_param(p, self) + walk_flat_map_param(p, self) } } @@ -252,7 +252,7 @@ impl MutVisitor for PlaceholderExpander { if sf.is_placeholder { self.remove(sf.id).make_field_defs() } else { - noop_flat_map_field_def(sf, self) + walk_flat_map_field_def(sf, self) } } @@ -260,14 +260,14 @@ impl MutVisitor for PlaceholderExpander { if variant.is_placeholder { self.remove(variant.id).make_variants() } else { - noop_flat_map_variant(variant, self) + walk_flat_map_variant(variant, self) } } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => noop_flat_map_item(item, None, self), + _ => walk_flat_map_item(item, None, self), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => noop_flat_map_item(item, Some(ctxt), self), + _ => walk_flat_map_item(item, Some(ctxt), self), } } @@ -294,21 +294,21 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => noop_flat_map_item(item, None, self), + _ => walk_flat_map_item(item, None, self), } } fn visit_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(), - _ => noop_visit_expr(expr, self), + _ => walk_expr(expr, self), } } fn visit_method_receiver_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(), - _ => noop_visit_expr(expr, self), + _ => walk_expr(expr, self), } } @@ -322,7 +322,7 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { let (style, mut stmts) = match stmt.kind { ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()), - _ => return noop_flat_map_stmt(stmt, self), + _ => return walk_flat_map_stmt(stmt, self), }; if style == ast::MacStmtStyle::Semicolon { @@ -368,14 +368,14 @@ impl MutVisitor for PlaceholderExpander { fn visit_pat(&mut self, pat: &mut P) { match pat.kind { ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(), - _ => noop_visit_pat(pat, self), + _ => walk_pat(pat, self), } } fn visit_ty(&mut self, ty: &mut P) { match ty.kind { ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(), - _ => noop_visit_ty(ty, self), + _ => walk_ty(ty, self), } } @@ -383,7 +383,7 @@ impl MutVisitor for PlaceholderExpander { if krate.is_placeholder { *krate = self.remove(krate.id).make_crate(); } else { - noop_visit_crate(krate, self) + walk_crate(krate, self) } } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2542108728f7..e1b34c2564b9 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -10,7 +10,7 @@ use super::{ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; -use ast::mut_visit::{noop_visit_expr, MutVisitor}; +use ast::mut_visit::{self, MutVisitor}; use ast::token::IdentIsRaw; use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered}; use core::mem; @@ -3939,14 +3939,14 @@ impl MutVisitor for CondChecker<'_> { } } ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); } ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _) if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedOr(or_span)); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Paren(ref inner) @@ -3954,7 +3954,7 @@ impl MutVisitor for CondChecker<'_> { { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedParentheses(inner.span)); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Assign(ref lhs, _, span) => { @@ -3972,7 +3972,7 @@ impl MutVisitor for CondChecker<'_> { } let comparison = self.comparison; self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() }); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; self.missing_let = missing_let; self.comparison = comparison; @@ -3992,7 +3992,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::Paren(_) => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(OtherForbidden); - noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); self.forbid_let_reason = forbid_let_reason; } ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 18d531faeaa1..487072e2f515 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -12,7 +12,7 @@ use crate::errors::{ }; use crate::parser::expr::{could_be_unclosed_char_literal, LhsExpr}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; -use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor}; +use rustc_ast::mut_visit::{walk_pat, MutVisitor}; use rustc_ast::ptr::P; use rustc_ast::token::{self, BinOpToken, Delimiter, Token}; use rustc_ast::{ @@ -810,7 +810,7 @@ impl<'a> Parser<'a> { self.0 = true; *m = Mutability::Mut; } - noop_visit_pat(pat, self); + walk_pat(pat, self); } } diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index fcc41b51542f..1e6b5c1c7f1e 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { - noop_visit_pat(pat, self); + walk_pat(pat, self); let inner = match &mut pat.kind { Paren(i) => mem::replace(&mut i.kind, Wild), _ => return, @@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P) { impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { use ast::BindingMode; - noop_visit_pat(pat, self); + walk_pat(pat, self); let target = match &mut pat.kind { // `i @ a | b`, `box a | b`, and `& mut? a | b`. Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, @@ -160,7 +160,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool { impl MutVisitor for Visitor { fn visit_pat(&mut self, p: &mut P) { // This is a bottom up transformation, so recurse first. - noop_visit_pat(p, self); + walk_pat(p, self); // Don't have an or-pattern? Just quit early on. let Or(alternatives) = &mut p.kind else { return }; @@ -189,7 +189,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool { // Deal with `Some(Some(0)) | Some(Some(1))`. if this_level_changed { - noop_visit_pat(p, self); + walk_pat(p, self); } } } diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 762ad0b79ecc..8cb55d420b98 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -202,7 +202,7 @@ impl MutVisitor for RemoveParens { ExprKind::Paren(inner) => *e = inner, _ => {} }; - mut_visit::noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); } } @@ -211,7 +211,7 @@ struct AddParens; impl MutVisitor for AddParens { fn visit_expr(&mut self, e: &mut P) { - mut_visit::noop_visit_expr(e, self); + mut_visit::walk_expr(e, self); visit_clobber(e, |e| { P(Expr { id: DUMMY_NODE_ID, From 8d290058c93a434411e077996b98d197b628759e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 17 Jul 2024 11:23:35 +0000 Subject: [PATCH 17/54] Always pass the visitor as the first argument to walk* functions --- compiler/rustc_ast/src/mut_visit.rs | 414 +++++++++--------- compiler/rustc_builtin_macros/src/cfg_eval.rs | 39 +- .../rustc_builtin_macros/src/test_harness.rs | 4 +- compiler/rustc_expand/src/expand.rs | 42 +- compiler/rustc_expand/src/mbe/transcribe.rs | 4 +- compiler/rustc_expand/src/placeholders.rs | 34 +- compiler/rustc_parse/src/parser/expr.rs | 10 +- compiler/rustc_parse/src/parser/pat.rs | 2 +- .../clippy_lints/src/unnested_or_patterns.rs | 8 +- tests/ui-fulldeps/pprust-expr-roundtrip.rs | 19 +- 10 files changed, 294 insertions(+), 282 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 56dd6663bb69..043e3f1190eb 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -86,35 +86,35 @@ pub trait MutVisitor: Sized { // forget to add handling for it. fn visit_crate(&mut self, c: &mut Crate) { - walk_crate(c, self) + walk_crate(self, c) } fn visit_meta_list_item(&mut self, list_item: &mut NestedMetaItem) { - walk_meta_list_item(list_item, self); + walk_meta_list_item(self, list_item); } fn visit_meta_item(&mut self, meta_item: &mut MetaItem) { - walk_meta_item(meta_item, self); + walk_meta_item(self, meta_item); } fn visit_use_tree(&mut self, use_tree: &mut UseTree) { - walk_use_tree(use_tree, self); + walk_use_tree(self, use_tree); } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(ni, None, self) + walk_flat_map_item(self, ni, None) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(i, None, self) + walk_flat_map_item(self, i, None) } fn visit_fn_header(&mut self, header: &mut FnHeader) { - walk_fn_header(header, self); + walk_fn_header(self, header); } fn flat_map_field_def(&mut self, fd: FieldDef) -> SmallVec<[FieldDef; 1]> { - walk_flat_map_field_def(fd, self) + walk_flat_map_field_def(self, fd) } fn flat_map_assoc_item( @@ -122,48 +122,48 @@ pub trait MutVisitor: Sized { i: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - walk_flat_map_item(i, Some(ctxt), self) + walk_flat_map_item(self, i, Some(ctxt)) } fn visit_fn_decl(&mut self, d: &mut P) { - walk_fn_decl(d, self); + walk_fn_decl(self, d); } /// `Span` and `NodeId` are mutated at the caller site. fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) { - walk_fn(fk, self) + walk_fn(self, fk) } fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) { - walk_coroutine_kind(a, self); + walk_coroutine_kind(self, a); } fn visit_closure_binder(&mut self, b: &mut ClosureBinder) { - walk_closure_binder(b, self); + walk_closure_binder(self, b); } fn visit_block(&mut self, b: &mut P) { - walk_block(b, self); + walk_block(self, b); } fn flat_map_stmt(&mut self, s: Stmt) -> SmallVec<[Stmt; 1]> { - walk_flat_map_stmt(s, self) + walk_flat_map_stmt(self, s) } fn flat_map_arm(&mut self, arm: Arm) -> SmallVec<[Arm; 1]> { - walk_flat_map_arm(arm, self) + walk_flat_map_arm(self, arm) } fn visit_pat(&mut self, p: &mut P) { - walk_pat(p, self); + walk_pat(self, p); } fn visit_anon_const(&mut self, c: &mut AnonConst) { - walk_anon_const(c, self); + walk_anon_const(self, c); } fn visit_expr(&mut self, e: &mut P) { - walk_expr(e, self); + walk_expr(self, e); } /// This method is a hack to workaround unstable of `stmt_expr_attributes`. @@ -173,35 +173,35 @@ pub trait MutVisitor: Sized { } fn filter_map_expr(&mut self, e: P) -> Option> { - noop_filter_map_expr(e, self) + noop_filter_map_expr(self, e) } fn visit_generic_arg(&mut self, arg: &mut GenericArg) { - walk_generic_arg(arg, self); + walk_generic_arg(self, arg); } fn visit_ty(&mut self, t: &mut P) { - walk_ty(t, self); + walk_ty(self, t); } fn visit_lifetime(&mut self, l: &mut Lifetime) { - walk_lifetime(l, self); + walk_lifetime(self, l); } fn visit_assoc_item_constraint(&mut self, c: &mut AssocItemConstraint) { - walk_assoc_item_constraint(c, self); + walk_assoc_item_constraint(self, c); } fn visit_foreign_mod(&mut self, nm: &mut ForeignMod) { - walk_foreign_mod(nm, self); + walk_foreign_mod(self, nm); } fn flat_map_variant(&mut self, v: Variant) -> SmallVec<[Variant; 1]> { - walk_flat_map_variant(v, self) + walk_flat_map_variant(self, v) } fn visit_ident(&mut self, i: &mut Ident) { - walk_ident(i, self); + walk_ident(self, i); } fn visit_path(&mut self, p: &mut Path) { @@ -213,91 +213,91 @@ pub trait MutVisitor: Sized { } fn visit_qself(&mut self, qs: &mut Option>) { - walk_qself(qs, self); + walk_qself(self, qs); } fn visit_generic_args(&mut self, p: &mut GenericArgs) { - walk_generic_args(p, self); + walk_generic_args(self, p); } fn visit_angle_bracketed_parameter_data(&mut self, p: &mut AngleBracketedArgs) { - walk_angle_bracketed_parameter_data(p, self); + walk_angle_bracketed_parameter_data(self, p); } fn visit_parenthesized_parameter_data(&mut self, p: &mut ParenthesizedArgs) { - walk_parenthesized_parameter_data(p, self); + walk_parenthesized_parameter_data(self, p); } fn visit_local(&mut self, l: &mut P) { - walk_local(l, self); + walk_local(self, l); } fn visit_mac_call(&mut self, mac: &mut MacCall) { - walk_mac(mac, self); + walk_mac(self, mac); } fn visit_macro_def(&mut self, def: &mut MacroDef) { - walk_macro_def(def, self); + walk_macro_def(self, def); } fn visit_label(&mut self, label: &mut Label) { - walk_label(label, self); + walk_label(self, label); } fn visit_attribute(&mut self, at: &mut Attribute) { - walk_attribute(at, self); + walk_attribute(self, at); } fn flat_map_param(&mut self, param: Param) -> SmallVec<[Param; 1]> { - walk_flat_map_param(param, self) + walk_flat_map_param(self, param) } fn visit_generics(&mut self, generics: &mut Generics) { - walk_generics(generics, self); + walk_generics(self, generics); } fn visit_trait_ref(&mut self, tr: &mut TraitRef) { - walk_trait_ref(tr, self); + walk_trait_ref(self, tr); } fn visit_poly_trait_ref(&mut self, p: &mut PolyTraitRef) { - walk_poly_trait_ref(p, self); + walk_poly_trait_ref(self, p); } fn visit_variant_data(&mut self, vdata: &mut VariantData) { - walk_variant_data(vdata, self); + walk_variant_data(self, vdata); } fn flat_map_generic_param(&mut self, param: GenericParam) -> SmallVec<[GenericParam; 1]> { - walk_flat_map_generic_param(param, self) + walk_flat_map_generic_param(self, param) } fn visit_param_bound(&mut self, tpb: &mut GenericBound, _ctxt: BoundKind) { - walk_param_bound(tpb, self); + walk_param_bound(self, tpb); } fn visit_precise_capturing_arg(&mut self, arg: &mut PreciseCapturingArg) { - walk_precise_capturing_arg(arg, self); + walk_precise_capturing_arg(self, arg); } fn visit_mt(&mut self, mt: &mut MutTy) { - walk_mt(mt, self); + walk_mt(self, mt); } fn flat_map_expr_field(&mut self, f: ExprField) -> SmallVec<[ExprField; 1]> { - walk_flat_map_expr_field(f, self) + walk_flat_map_expr_field(self, f) } fn visit_where_clause(&mut self, where_clause: &mut WhereClause) { - walk_where_clause(where_clause, self); + walk_where_clause(self, where_clause); } fn visit_where_predicate(&mut self, where_predicate: &mut WherePredicate) { - walk_where_predicate(where_predicate, self); + walk_where_predicate(self, where_predicate); } fn visit_vis(&mut self, vis: &mut Visibility) { - walk_vis(vis, self); + walk_vis(self, vis); } fn visit_id(&mut self, _id: &mut NodeId) { @@ -309,23 +309,23 @@ pub trait MutVisitor: Sized { } fn flat_map_pat_field(&mut self, fp: PatField) -> SmallVec<[PatField; 1]> { - walk_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(self, fp) } fn visit_inline_asm(&mut self, asm: &mut InlineAsm) { - walk_inline_asm(asm, self) + walk_inline_asm(self, asm) } fn visit_inline_asm_sym(&mut self, sym: &mut InlineAsmSym) { - walk_inline_asm_sym(sym, self) + walk_inline_asm_sym(self, sym) } fn visit_format_args(&mut self, fmt: &mut FormatArgs) { - walk_format_args(fmt, self) + walk_format_args(self, fmt) } fn visit_capture_by(&mut self, capture_by: &mut CaptureBy) { - walk_capture_by(capture_by, self) + walk_capture_by(self, capture_by) } } @@ -373,7 +373,7 @@ where } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_attrs(attrs: &mut AttrVec, vis: &mut T) { +fn visit_attrs(vis: &mut T, attrs: &mut AttrVec) { for attr in attrs.iter_mut() { vis.visit_attribute(attr); } @@ -381,25 +381,25 @@ fn visit_attrs(attrs: &mut AttrVec, vis: &mut T) { // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. #[allow(unused)] -fn visit_exprs(exprs: &mut Vec>, vis: &mut T) { +fn visit_exprs(vis: &mut T, exprs: &mut Vec>) { exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr)) } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_thin_exprs(exprs: &mut ThinVec>, vis: &mut T) { +fn visit_thin_exprs(vis: &mut T, exprs: &mut ThinVec>) { exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr)) } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_bounds(bounds: &mut GenericBounds, ctxt: BoundKind, vis: &mut T) { +fn visit_bounds(vis: &mut T, bounds: &mut GenericBounds, ctxt: BoundKind) { visit_vec(bounds, |bound| vis.visit_param_bound(bound, ctxt)); } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { +fn visit_attr_args(vis: &mut T, args: &mut AttrArgs) { match args { AttrArgs::Empty => {} - AttrArgs::Delimited(args) => visit_delim_args(args, vis), + AttrArgs::Delimited(args) => visit_delim_args(vis, args), AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => { vis.visit_expr(expr); vis.visit_span(eq_span); @@ -411,31 +411,31 @@ fn visit_attr_args(args: &mut AttrArgs, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_delim_args(args: &mut DelimArgs, vis: &mut T) { +fn visit_delim_args(vis: &mut T, args: &mut DelimArgs) { let DelimArgs { dspan, delim: _, tokens } = args; - visit_tts(tokens, vis); - visit_delim_span(dspan, vis); + visit_tts(vis, tokens); + visit_delim_span(vis, dspan); } -pub fn visit_delim_span(DelimSpan { open, close }: &mut DelimSpan, vis: &mut T) { +pub fn visit_delim_span(vis: &mut T, DelimSpan { open, close }: &mut DelimSpan) { vis.visit_span(open); vis.visit_span(close); } pub fn walk_flat_map_pat_field( - mut fp: PatField, vis: &mut T, + mut fp: PatField, ) -> SmallVec<[PatField; 1]> { let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_ident(ident); vis.visit_pat(pat); vis.visit_span(span); smallvec![fp] } -fn walk_use_tree(use_tree: &mut UseTree, vis: &mut T) { +fn walk_use_tree(vis: &mut T, use_tree: &mut UseTree) { let UseTree { prefix, kind, span } = use_tree; vis.visit_path(prefix); match kind { @@ -452,10 +452,10 @@ fn walk_use_tree(use_tree: &mut UseTree, vis: &mut T) { vis.visit_span(span); } -pub fn walk_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> { +pub fn walk_flat_map_arm(vis: &mut T, mut arm: Arm) -> SmallVec<[Arm; 1]> { let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_pat(pat); visit_opt(guard, |guard| vis.visit_expr(guard)); visit_opt(body, |body| vis.visit_expr(body)); @@ -464,8 +464,8 @@ pub fn walk_flat_map_arm(mut arm: Arm, vis: &mut T) -> SmallVec<[ } fn walk_assoc_item_constraint( - AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint, vis: &mut T, + AssocItemConstraint { id, ident, gen_args, kind, span }: &mut AssocItemConstraint, ) { vis.visit_id(id); vis.visit_ident(ident); @@ -477,12 +477,12 @@ fn walk_assoc_item_constraint( Term::Ty(ty) => vis.visit_ty(ty), Term::Const(c) => vis.visit_anon_const(c), }, - AssocItemConstraintKind::Bound { bounds } => visit_bounds(bounds, BoundKind::Bound, vis), + AssocItemConstraintKind::Bound { bounds } => visit_bounds(vis, bounds, BoundKind::Bound), } vis.visit_span(span); } -pub fn walk_ty(ty: &mut P, vis: &mut T) { +pub fn walk_ty(vis: &mut T, ty: &mut P) { let Ty { id, kind, span, tokens } = ty.deref_mut(); vis.visit_id(id); match kind { @@ -497,7 +497,7 @@ pub fn walk_ty(ty: &mut P, vis: &mut T) { } TyKind::BareFn(bft) => { let BareFnTy { safety, ext: _, generic_params, decl, decl_span } = bft.deref_mut(); - visit_safety(safety, vis); + visit_safety(vis, safety); generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_fn_decl(decl); vis.visit_span(decl_span); @@ -530,23 +530,23 @@ pub fn walk_ty(ty: &mut P, vis: &mut T) { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); } } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } -fn walk_foreign_mod(foreign_mod: &mut ForeignMod, vis: &mut T) { +fn walk_foreign_mod(vis: &mut T, foreign_mod: &mut ForeignMod) { let ForeignMod { safety, abi: _, items } = foreign_mod; - visit_safety(safety, vis); + visit_safety(vis, safety); items.flat_map_in_place(|item| vis.flat_map_foreign_item(item)); } pub fn walk_flat_map_variant( - mut variant: Variant, visitor: &mut T, + mut variant: Variant, ) -> SmallVec<[Variant; 1]> { let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = &mut variant; visitor.visit_id(id); - visit_attrs(attrs, visitor); + visit_attrs(visitor, attrs); visitor.visit_vis(vis); visitor.visit_ident(ident); visitor.visit_variant_data(data); @@ -555,7 +555,7 @@ pub fn walk_flat_map_variant( smallvec![variant] } -fn walk_ident(Ident { name: _, span }: &mut Ident, vis: &mut T) { +fn walk_ident(vis: &mut T, Ident { name: _, span }: &mut Ident) { vis.visit_span(span); } @@ -570,11 +570,11 @@ fn walk_path(vis: &mut T, Path { segments, span, tokens }: &mut P for segment in segments { vis.visit_path_segment(segment); } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } -fn walk_qself(qself: &mut Option>, vis: &mut T) { +fn walk_qself(vis: &mut T, qself: &mut Option>) { visit_opt(qself, |qself| { let QSelf { ty, path_span, position: _ } = &mut **qself; vis.visit_ty(ty); @@ -582,7 +582,7 @@ fn walk_qself(qself: &mut Option>, vis: &mut T) { }) } -fn walk_generic_args(generic_args: &mut GenericArgs, vis: &mut T) { +fn walk_generic_args(vis: &mut T, generic_args: &mut GenericArgs) { match generic_args { GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data), GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data), @@ -590,7 +590,7 @@ fn walk_generic_args(generic_args: &mut GenericArgs, vis: &mut T) } } -fn walk_generic_arg(arg: &mut GenericArg, vis: &mut T) { +fn walk_generic_arg(vis: &mut T, arg: &mut GenericArg) { match arg { GenericArg::Lifetime(lt) => vis.visit_lifetime(lt), GenericArg::Type(ty) => vis.visit_ty(ty), @@ -598,7 +598,7 @@ fn walk_generic_arg(arg: &mut GenericArg, vis: &mut T) { } } -fn walk_angle_bracketed_parameter_data(data: &mut AngleBracketedArgs, vis: &mut T) { +fn walk_angle_bracketed_parameter_data(vis: &mut T, data: &mut AngleBracketedArgs) { let AngleBracketedArgs { args, span } = data; visit_thin_vec(args, |arg| match arg { AngleBracketedArg::Arg(arg) => vis.visit_generic_arg(arg), @@ -607,18 +607,18 @@ fn walk_angle_bracketed_parameter_data(data: &mut AngleBracketedA vis.visit_span(span); } -fn walk_parenthesized_parameter_data(args: &mut ParenthesizedArgs, vis: &mut T) { +fn walk_parenthesized_parameter_data(vis: &mut T, args: &mut ParenthesizedArgs) { let ParenthesizedArgs { inputs, output, span, inputs_span } = args; visit_thin_vec(inputs, |input| vis.visit_ty(input)); - walk_fn_ret_ty(output, vis); + walk_fn_ret_ty(vis, output); vis.visit_span(span); vis.visit_span(inputs_span); } -fn walk_local(local: &mut P, vis: &mut T) { +fn walk_local(vis: &mut T, local: &mut P) { let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut(); vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_pat(pat); visit_opt(ty, |ty| vis.visit_ty(ty)); match kind { @@ -631,12 +631,12 @@ fn walk_local(local: &mut P, vis: &mut T) { vis.visit_block(els); } } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); visit_opt(colon_sp, |sp| vis.visit_span(sp)); vis.visit_span(span); } -fn walk_attribute(attr: &mut Attribute, vis: &mut T) { +fn walk_attribute(vis: &mut T, attr: &mut Attribute) { let Attribute { kind, id: _, style: _, span } = attr; match kind { AttrKind::Normal(normal) => { @@ -645,34 +645,34 @@ fn walk_attribute(attr: &mut Attribute, vis: &mut T) { tokens: attr_tokens, } = &mut **normal; vis.visit_path(path); - visit_attr_args(args, vis); - visit_lazy_tts(tokens, vis); - visit_lazy_tts(attr_tokens, vis); + visit_attr_args(vis, args); + visit_lazy_tts(vis, tokens); + visit_lazy_tts(vis, attr_tokens); } AttrKind::DocComment(_kind, _sym) => {} } vis.visit_span(span); } -fn walk_mac(mac: &mut MacCall, vis: &mut T) { +fn walk_mac(vis: &mut T, mac: &mut MacCall) { let MacCall { path, args } = mac; vis.visit_path(path); - visit_delim_args(args, vis); + visit_delim_args(vis, args); } -fn walk_macro_def(macro_def: &mut MacroDef, vis: &mut T) { +fn walk_macro_def(vis: &mut T, macro_def: &mut MacroDef) { let MacroDef { body, macro_rules: _ } = macro_def; - visit_delim_args(body, vis); + visit_delim_args(vis, body); } -fn walk_meta_list_item(li: &mut NestedMetaItem, vis: &mut T) { +fn walk_meta_list_item(vis: &mut T, li: &mut NestedMetaItem) { match li { NestedMetaItem::MetaItem(mi) => vis.visit_meta_item(mi), NestedMetaItem::Lit(_lit) => {} } } -fn walk_meta_item(mi: &mut MetaItem, vis: &mut T) { +fn walk_meta_item(vis: &mut T, mi: &mut MetaItem) { let MetaItem { unsafety: _, path: _, kind, span } = mi; match kind { MetaItemKind::Word => {} @@ -682,10 +682,10 @@ fn walk_meta_item(mi: &mut MetaItem, vis: &mut T) { vis.visit_span(span); } -pub fn walk_flat_map_param(mut param: Param, vis: &mut T) -> SmallVec<[Param; 1]> { +pub fn walk_flat_map_param(vis: &mut T, mut param: Param) -> SmallVec<[Param; 1]> { let Param { attrs, id, pat, span, ty, is_placeholder: _ } = &mut param; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_pat(pat); vis.visit_ty(ty); vis.visit_span(span); @@ -693,69 +693,69 @@ pub fn walk_flat_map_param(mut param: Param, vis: &mut T) -> Smal } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_attr_tt(tt: &mut AttrTokenTree, vis: &mut T) { +fn visit_attr_tt(vis: &mut T, tt: &mut AttrTokenTree) { match tt { AttrTokenTree::Token(token, _spacing) => { - visit_token(token, vis); + visit_token(vis, token); } AttrTokenTree::Delimited(dspan, _spacing, _delim, tts) => { - visit_attr_tts(tts, vis); - visit_delim_span(dspan, vis); + visit_attr_tts(vis, tts); + visit_delim_span(vis, dspan); } AttrTokenTree::AttrsTarget(AttrsTarget { attrs, tokens }) => { - visit_attrs(attrs, vis); - visit_lazy_tts_opt_mut(Some(tokens), vis); + visit_attrs(vis, attrs); + visit_lazy_tts_opt_mut(vis, Some(tokens)); } } } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_tt(tt: &mut TokenTree, vis: &mut T) { +fn visit_tt(vis: &mut T, tt: &mut TokenTree) { match tt { TokenTree::Token(token, _spacing) => { - visit_token(token, vis); + visit_token(vis, token); } TokenTree::Delimited(dspan, _spacing, _delim, tts) => { - visit_tts(tts, vis); - visit_delim_span(dspan, vis); + visit_tts(vis, tts); + visit_delim_span(vis, dspan); } } } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_tts(TokenStream(tts): &mut TokenStream, vis: &mut T) { +fn visit_tts(vis: &mut T, TokenStream(tts): &mut TokenStream) { if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); - visit_vec(tts, |tree| visit_tt(tree, vis)); + visit_vec(tts, |tree| visit_tt(vis, tree)); } } -fn visit_attr_tts(AttrTokenStream(tts): &mut AttrTokenStream, vis: &mut T) { +fn visit_attr_tts(vis: &mut T, AttrTokenStream(tts): &mut AttrTokenStream) { if T::VISIT_TOKENS && !tts.is_empty() { let tts = Lrc::make_mut(tts); - visit_vec(tts, |tree| visit_attr_tt(tree, vis)); + visit_vec(tts, |tree| visit_attr_tt(vis, tree)); } } -fn visit_lazy_tts_opt_mut(lazy_tts: Option<&mut LazyAttrTokenStream>, vis: &mut T) { +fn visit_lazy_tts_opt_mut(vis: &mut T, lazy_tts: Option<&mut LazyAttrTokenStream>) { if T::VISIT_TOKENS { if let Some(lazy_tts) = lazy_tts { let mut tts = lazy_tts.to_attr_token_stream(); - visit_attr_tts(&mut tts, vis); + visit_attr_tts(vis, &mut tts); *lazy_tts = LazyAttrTokenStream::new(tts); } } } -fn visit_lazy_tts(lazy_tts: &mut Option, vis: &mut T) { - visit_lazy_tts_opt_mut(lazy_tts.as_mut(), vis); +fn visit_lazy_tts(vis: &mut T, lazy_tts: &mut Option) { + visit_lazy_tts_opt_mut(vis, lazy_tts.as_mut()); } /// Applies ident visitor if it's an ident; applies other visits to interpolated nodes. /// In practice the ident part is not actually used by specific visitors right now, /// but there's a test below checking that it works. // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -pub fn visit_token(t: &mut Token, vis: &mut T) { +pub fn visit_token(vis: &mut T, t: &mut Token) { let Token { kind, span } = t; match kind { token::Ident(name, _ /*raw*/) | token::Lifetime(name) => { @@ -773,7 +773,7 @@ pub fn visit_token(t: &mut Token, vis: &mut T) { } token::Interpolated(nt) => { let nt = Lrc::make_mut(nt); - visit_nonterminal(nt, vis); + visit_nonterminal(vis, nt); } _ => {} } @@ -804,7 +804,7 @@ pub fn visit_token(t: &mut Token, vis: &mut T) { // contain multiple items, but decided against it when I looked at // `parse_item_or_view_item` and tried to figure out what I would do with // multiple items there.... -fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T) { +fn visit_nonterminal(vis: &mut T, nt: &mut token::Nonterminal) { match nt { token::NtItem(item) => visit_clobber(item, |item| { // This is probably okay, because the only visitors likely to @@ -826,8 +826,8 @@ fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T) { token::NtMeta(item) => { let AttrItem { unsafety: _, path, args, tokens } = item.deref_mut(); vis.visit_path(path); - visit_attr_args(args, vis); - visit_lazy_tts(tokens, vis); + visit_attr_args(vis, args); + visit_lazy_tts(vis, tokens); } token::NtPath(path) => vis.visit_path(path), token::NtVis(visib) => vis.visit_vis(visib), @@ -835,7 +835,7 @@ fn visit_nonterminal(nt: &mut token::Nonterminal, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut T) { +fn visit_defaultness(vis: &mut T, defaultness: &mut Defaultness) { match defaultness { Defaultness::Default(span) => vis.visit_span(span), Defaultness::Final => {} @@ -843,7 +843,7 @@ fn visit_defaultness(defaultness: &mut Defaultness, vis: &mut T) } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_safety(safety: &mut Safety, vis: &mut T) { +fn visit_safety(vis: &mut T, safety: &mut Safety) { match safety { Safety::Unsafe(span) => vis.visit_span(span), Safety::Safe(span) => vis.visit_span(span), @@ -852,7 +852,7 @@ fn visit_safety(safety: &mut Safety, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { +fn visit_polarity(vis: &mut T, polarity: &mut ImplPolarity) { match polarity { ImplPolarity::Positive => {} ImplPolarity::Negative(span) => vis.visit_span(span), @@ -860,14 +860,14 @@ fn visit_polarity(polarity: &mut ImplPolarity, vis: &mut T) { } // No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. -fn visit_constness(constness: &mut Const, vis: &mut T) { +fn visit_constness(vis: &mut T, constness: &mut Const) { match constness { Const::Yes(span) => vis.visit_span(span), Const::No => {} } } -fn walk_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { +fn walk_closure_binder(vis: &mut T, binder: &mut ClosureBinder) { match binder { ClosureBinder::NotPresent => {} ClosureBinder::For { span: _, generic_params } => { @@ -876,7 +876,7 @@ fn walk_closure_binder(binder: &mut ClosureBinder, vis: &mut T) { } } -fn walk_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: &mut T) { +fn walk_coroutine_kind(vis: &mut T, coroutine_kind: &mut CoroutineKind) { match coroutine_kind { CoroutineKind::Async { span, closure_id, return_impl_trait_id } | CoroutineKind::Gen { span, closure_id, return_impl_trait_id } @@ -888,7 +888,7 @@ fn walk_coroutine_kind(coroutine_kind: &mut CoroutineKind, vis: & } } -fn walk_fn(kind: FnKind<'_>, vis: &mut T) { +fn walk_fn(vis: &mut T, kind: FnKind<'_>) { match kind { FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. @@ -908,23 +908,23 @@ fn walk_fn(kind: FnKind<'_>, vis: &mut T) { } } -fn walk_fn_decl(decl: &mut P, vis: &mut T) { +fn walk_fn_decl(vis: &mut T, decl: &mut P) { let FnDecl { inputs, output } = decl.deref_mut(); inputs.flat_map_in_place(|param| vis.flat_map_param(param)); - walk_fn_ret_ty(output, vis); + walk_fn_ret_ty(vis, output); } -fn walk_fn_ret_ty(fn_ret_ty: &mut FnRetTy, vis: &mut T) { +fn walk_fn_ret_ty(vis: &mut T, fn_ret_ty: &mut FnRetTy) { match fn_ret_ty { FnRetTy::Default(span) => vis.visit_span(span), FnRetTy::Ty(ty) => vis.visit_ty(ty), } } -fn walk_param_bound(pb: &mut GenericBound, vis: &mut T) { +fn walk_param_bound(vis: &mut T, pb: &mut GenericBound) { match pb { GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty), - GenericBound::Outlives(lifetime) => walk_lifetime(lifetime, vis), + GenericBound::Outlives(lifetime) => walk_lifetime(vis, lifetime), GenericBound::Use(args, span) => { for arg in args { vis.visit_precise_capturing_arg(arg); @@ -934,7 +934,7 @@ fn walk_param_bound(pb: &mut GenericBound, vis: &mut T) { } } -fn walk_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: &mut T) { +fn walk_precise_capturing_arg(vis: &mut T, arg: &mut PreciseCapturingArg) { match arg { PreciseCapturingArg::Lifetime(lt) => { vis.visit_lifetime(lt); @@ -947,12 +947,12 @@ fn walk_precise_capturing_arg(arg: &mut PreciseCapturingArg, vis: } pub fn walk_flat_map_generic_param( - mut param: GenericParam, vis: &mut T, + mut param: GenericParam, ) -> SmallVec<[GenericParam; 1]> { let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_ident(ident); visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound)); match kind { @@ -971,23 +971,23 @@ pub fn walk_flat_map_generic_param( smallvec![param] } -fn walk_label(Label { ident }: &mut Label, vis: &mut T) { +fn walk_label(vis: &mut T, Label { ident }: &mut Label) { vis.visit_ident(ident); } -fn walk_lifetime(Lifetime { id, ident }: &mut Lifetime, vis: &mut T) { +fn walk_lifetime(vis: &mut T, Lifetime { id, ident }: &mut Lifetime) { vis.visit_id(id); vis.visit_ident(ident); } -fn walk_generics(generics: &mut Generics, vis: &mut T) { +fn walk_generics(vis: &mut T, generics: &mut Generics) { let Generics { params, where_clause, span } = generics; params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_where_clause(where_clause); vis.visit_span(span); } -fn walk_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, vis: &mut T) { +fn walk_ty_alias_where_clauses(vis: &mut T, tawcs: &mut TyAliasWhereClauses) { let TyAliasWhereClauses { before, after, split: _ } = tawcs; let TyAliasWhereClause { has_where_token: _, span: span_before } = before; let TyAliasWhereClause { has_where_token: _, span: span_after } = after; @@ -995,13 +995,13 @@ fn walk_ty_alias_where_clauses(tawcs: &mut TyAliasWhereClauses, v vis.visit_span(span_after); } -fn walk_where_clause(wc: &mut WhereClause, vis: &mut T) { +fn walk_where_clause(vis: &mut T, wc: &mut WhereClause) { let WhereClause { has_where_token: _, predicates, span } = wc; visit_thin_vec(predicates, |predicate| vis.visit_where_predicate(predicate)); vis.visit_span(span); } -fn walk_where_predicate(pred: &mut WherePredicate, vis: &mut T) { +fn walk_where_predicate(vis: &mut T, pred: &mut WherePredicate) { match pred { WherePredicate::BoundPredicate(bp) => { let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp; @@ -1025,7 +1025,7 @@ fn walk_where_predicate(pred: &mut WherePredicate, vis: &mut T) { } } -fn walk_variant_data(vdata: &mut VariantData, vis: &mut T) { +fn walk_variant_data(vis: &mut T, vdata: &mut VariantData) { match vdata { VariantData::Struct { fields, recovered: _ } => { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); @@ -1038,12 +1038,12 @@ fn walk_variant_data(vdata: &mut VariantData, vis: &mut T) { } } -fn walk_trait_ref(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) { +fn walk_trait_ref(vis: &mut T, TraitRef { path, ref_id }: &mut TraitRef) { vis.visit_id(ref_id); vis.visit_path(path); } -fn walk_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { +fn walk_poly_trait_ref(vis: &mut T, p: &mut PolyTraitRef) { let PolyTraitRef { bound_generic_params, trait_ref, span } = p; bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_trait_ref(trait_ref); @@ -1051,12 +1051,12 @@ fn walk_poly_trait_ref(p: &mut PolyTraitRef, vis: &mut T) { } pub fn walk_flat_map_field_def( - mut fd: FieldDef, visitor: &mut T, + mut fd: FieldDef, ) -> SmallVec<[FieldDef; 1]> { let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd; visitor.visit_id(id); - visit_attrs(attrs, visitor); + visit_attrs(visitor, attrs); visitor.visit_vis(vis); visit_opt(ident, |ident| visitor.visit_ident(ident)); visitor.visit_ty(ty); @@ -1065,27 +1065,27 @@ pub fn walk_flat_map_field_def( } pub fn walk_flat_map_expr_field( - mut f: ExprField, vis: &mut T, + mut f: ExprField, ) -> SmallVec<[ExprField; 1]> { let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_ident(ident); vis.visit_expr(expr); vis.visit_span(span); smallvec![f] } -fn walk_mt(MutTy { ty, mutbl: _ }: &mut MutTy, vis: &mut T) { +fn walk_mt(vis: &mut T, MutTy { ty, mutbl: _ }: &mut MutTy) { vis.visit_ty(ty); } -pub fn walk_block(block: &mut P, vis: &mut T) { +pub fn walk_block(vis: &mut T, block: &mut P) { let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut(); vis.visit_id(id); stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt)); - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } @@ -1120,11 +1120,11 @@ impl NoopVisitItemKind for ItemKind { visit_const_item(item, vis); } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { - visit_defaultness(defaultness, vis); + visit_defaultness(vis, defaultness); vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, sig, generics, body), span, id); } ItemKind::Mod(safety, mod_kind) => { - visit_safety(safety, vis); + visit_safety(vis, safety); match mod_kind { ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => { items.flat_map_in_place(|item| vis.flat_map_item(item)); @@ -1137,11 +1137,11 @@ impl NoopVisitItemKind for ItemKind { ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm), ItemKind::GlobalAsm(asm) => vis.visit_inline_asm(asm), ItemKind::TyAlias(box TyAlias { defaultness, generics, where_clauses, bounds, ty }) => { - visit_defaultness(defaultness, vis); + visit_defaultness(vis, defaultness); vis.visit_generics(generics); - visit_bounds(bounds, BoundKind::Bound, vis); + visit_bounds(vis, bounds, BoundKind::Bound); visit_opt(ty, |ty| vis.visit_ty(ty)); - walk_ty_alias_where_clauses(where_clauses, vis); + walk_ty_alias_where_clauses(vis, where_clauses); } ItemKind::Enum(EnumDef { variants }, generics) => { vis.visit_generics(generics); @@ -1161,24 +1161,24 @@ impl NoopVisitItemKind for ItemKind { self_ty, items, }) => { - visit_defaultness(defaultness, vis); - visit_safety(safety, vis); + visit_defaultness(vis, defaultness); + visit_safety(vis, safety); vis.visit_generics(generics); - visit_constness(constness, vis); - visit_polarity(polarity, vis); + visit_constness(vis, constness); + visit_polarity(vis, polarity); visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref)); vis.visit_ty(self_ty); items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Impl)); } ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => { - visit_safety(safety, vis); + visit_safety(vis, safety); vis.visit_generics(generics); - visit_bounds(bounds, BoundKind::Bound, vis); + visit_bounds(vis, bounds, BoundKind::Bound); items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Trait)); } ItemKind::TraitAlias(generics, bounds) => { vis.visit_generics(generics); - visit_bounds(bounds, BoundKind::Bound, vis); + visit_bounds(vis, bounds, BoundKind::Bound); } ItemKind::MacCall(m) => vis.visit_mac_call(m), ItemKind::MacroDef(def) => vis.visit_macro_def(def), @@ -1234,7 +1234,7 @@ impl NoopVisitItemKind for AssocItemKind { visit_const_item(item, visitor); } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { - visit_defaultness(defaultness, visitor); + visit_defaultness(visitor, defaultness); visitor.visit_fn( FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, generics, body), span, @@ -1248,11 +1248,11 @@ impl NoopVisitItemKind for AssocItemKind { bounds, ty, }) => { - visit_defaultness(defaultness, visitor); + visit_defaultness(visitor, defaultness); visitor.visit_generics(generics); - visit_bounds(bounds, BoundKind::Bound, visitor); + visit_bounds(visitor, bounds, BoundKind::Bound); visit_opt(ty, |ty| visitor.visit_ty(ty)); - walk_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(visitor, where_clauses); } AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac), AssocItemKind::Delegation(box Delegation { @@ -1296,23 +1296,23 @@ fn visit_const_item( ConstItem { defaultness, generics, ty, expr }: &mut ConstItem, visitor: &mut T, ) { - visit_defaultness(defaultness, visitor); + visit_defaultness(visitor, defaultness); visitor.visit_generics(generics); visitor.visit_ty(ty); visit_opt(expr, |expr| visitor.visit_expr(expr)); } -fn walk_fn_header(header: &mut FnHeader, vis: &mut T) { +fn walk_fn_header(vis: &mut T, header: &mut FnHeader) { let FnHeader { safety, coroutine_kind, constness, ext: _ } = header; - visit_constness(constness, vis); + visit_constness(vis, constness); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); - visit_safety(safety, vis); + visit_safety(vis, safety); } -pub fn walk_crate(krate: &mut Crate, vis: &mut T) { +pub fn walk_crate(vis: &mut T, krate: &mut Crate) { let Crate { attrs, items, spans, id, is_placeholder: _ } = krate; vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); items.flat_map_in_place(|item| vis.flat_map_item(item)); let ModSpans { inner_span, inject_use_span } = spans; vis.visit_span(inner_span); @@ -1321,17 +1321,17 @@ pub fn walk_crate(krate: &mut Crate, vis: &mut T) { /// Mutates one item, returning the item again. pub fn walk_flat_map_item( + visitor: &mut impl MutVisitor, mut item: P>, ctxt: Option, - visitor: &mut impl MutVisitor, ) -> SmallVec<[P>; 1]> { let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut(); visitor.visit_id(id); - visit_attrs(attrs, visitor); + visit_attrs(visitor, attrs); visitor.visit_vis(vis); visitor.visit_ident(ident); kind.walk(ctxt, *ident, *span, *id, visitor); - visit_lazy_tts(tokens, visitor); + visit_lazy_tts(visitor, tokens); visitor.visit_span(span); smallvec![item] } @@ -1352,7 +1352,7 @@ impl NoopVisitItemKind for ForeignItemKind { visit_opt(expr, |expr| visitor.visit_expr(expr)); } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { - visit_defaultness(defaultness, visitor); + visit_defaultness(visitor, defaultness); visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, ident, sig, generics, body), span, id); } ForeignItemKind::TyAlias(box TyAlias { @@ -1362,18 +1362,18 @@ impl NoopVisitItemKind for ForeignItemKind { bounds, ty, }) => { - visit_defaultness(defaultness, visitor); + visit_defaultness(visitor, defaultness); visitor.visit_generics(generics); - visit_bounds(bounds, BoundKind::Bound, visitor); + visit_bounds(visitor, bounds, BoundKind::Bound); visit_opt(ty, |ty| visitor.visit_ty(ty)); - walk_ty_alias_where_clauses(where_clauses, visitor); + walk_ty_alias_where_clauses(visitor, where_clauses); } ForeignItemKind::MacCall(mac) => visitor.visit_mac_call(mac), } } } -pub fn walk_pat(pat: &mut P, vis: &mut T) { +pub fn walk_pat(vis: &mut T, pat: &mut P) { let Pat { id, kind, span, tokens } = pat.deref_mut(); vis.visit_id(id); match kind { @@ -1412,16 +1412,16 @@ pub fn walk_pat(pat: &mut P, vis: &mut T) { PatKind::Paren(inner) => vis.visit_pat(inner), PatKind::MacCall(mac) => vis.visit_mac_call(mac), } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } -fn walk_anon_const(AnonConst { id, value }: &mut AnonConst, vis: &mut T) { +fn walk_anon_const(vis: &mut T, AnonConst { id, value }: &mut AnonConst) { vis.visit_id(id); vis.visit_expr(value); } -fn walk_inline_asm(asm: &mut InlineAsm, vis: &mut T) { +fn walk_inline_asm(vis: &mut T, asm: &mut InlineAsm) { // FIXME: Visit spans inside all this currently ignored stuff. let InlineAsm { template: _, @@ -1452,15 +1452,15 @@ fn walk_inline_asm(asm: &mut InlineAsm, vis: &mut T) { } fn walk_inline_asm_sym( - InlineAsmSym { id, qself, path }: &mut InlineAsmSym, vis: &mut T, + InlineAsmSym { id, qself, path }: &mut InlineAsmSym, ) { vis.visit_id(id); vis.visit_qself(qself); vis.visit_path(path); } -fn walk_format_args(fmt: &mut FormatArgs, vis: &mut T) { +fn walk_format_args(vis: &mut T, fmt: &mut FormatArgs) { // FIXME: visit the template exhaustively. let FormatArgs { span, template: _, arguments } = fmt; for FormatArgument { kind, expr } in arguments.all_args_mut() { @@ -1475,11 +1475,11 @@ fn walk_format_args(fmt: &mut FormatArgs, vis: &mut T) { vis.visit_span(span); } -pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Expr, vis: &mut T) { +pub fn walk_expr(vis: &mut T, Expr { kind, id, span, attrs, tokens }: &mut Expr) { vis.visit_id(id); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); match kind { - ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis), + ExprKind::Array(exprs) => visit_thin_exprs(vis, exprs), ExprKind::ConstBlock(anon_const) => { vis.visit_anon_const(anon_const); } @@ -1487,10 +1487,10 @@ pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Exp vis.visit_expr(expr); vis.visit_anon_const(count); } - ExprKind::Tup(exprs) => visit_thin_exprs(exprs, vis), + ExprKind::Tup(exprs) => visit_thin_exprs(vis, exprs), ExprKind::Call(f, args) => { vis.visit_expr(f); - visit_thin_exprs(args, vis); + visit_thin_exprs(vis, args); } ExprKind::MethodCall(box MethodCall { seg: PathSegment { ident, id, args: seg_args }, @@ -1502,7 +1502,7 @@ pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Exp vis.visit_id(id); vis.visit_ident(ident); visit_opt(seg_args, |args| vis.visit_generic_args(args)); - visit_thin_exprs(call_args, vis); + visit_thin_exprs(vis, call_args); vis.visit_span(span); } ExprKind::Binary(_binop, lhs, rhs) => { @@ -1560,7 +1560,7 @@ pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Exp fn_decl_span, fn_arg_span, }) => { - visit_constness(constness, vis); + visit_constness(vis, constness); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); vis.visit_capture_by(capture_clause); vis.visit_fn(FnKind::Closure(binder, fn_decl, body), *span, *id); @@ -1653,11 +1653,11 @@ pub fn walk_expr(Expr { kind, id, span, attrs, tokens }: &mut Exp ExprKind::Err(_guar) => {} ExprKind::Dummy => {} } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } -pub fn noop_filter_map_expr(mut e: P, vis: &mut T) -> Option> { +pub fn noop_filter_map_expr(vis: &mut T, mut e: P) -> Option> { Some({ vis.visit_expr(&mut e); e @@ -1665,11 +1665,11 @@ pub fn noop_filter_map_expr(mut e: P, vis: &mut T) -> Optio } pub fn walk_flat_map_stmt( - Stmt { kind, mut span, mut id }: Stmt, vis: &mut T, + Stmt { kind, mut span, mut id }: Stmt, ) -> SmallVec<[Stmt; 1]> { vis.visit_id(&mut id); - let stmts: SmallVec<_> = walk_flat_map_stmt_kind(kind, vis) + let stmts: SmallVec<_> = walk_flat_map_stmt_kind(vis, kind) .into_iter() .map(|kind| Stmt { id, kind, span }) .collect(); @@ -1683,7 +1683,7 @@ pub fn walk_flat_map_stmt( stmts } -fn walk_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallVec<[StmtKind; 1]> { +fn walk_flat_map_stmt_kind(vis: &mut T, kind: StmtKind) -> SmallVec<[StmtKind; 1]> { match kind { StmtKind::Let(mut local) => smallvec![StmtKind::Let({ vis.visit_local(&mut local); @@ -1695,15 +1695,15 @@ fn walk_flat_map_stmt_kind(kind: StmtKind, vis: &mut T) -> SmallV StmtKind::Empty => smallvec![StmtKind::Empty], StmtKind::MacCall(mut mac) => { let MacCallStmt { mac: mac_, style: _, attrs, tokens } = mac.deref_mut(); - visit_attrs(attrs, vis); + visit_attrs(vis, attrs); vis.visit_mac_call(mac_); - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); smallvec![StmtKind::MacCall(mac)] } } } -fn walk_vis(visibility: &mut Visibility, vis: &mut T) { +fn walk_vis(vis: &mut T, visibility: &mut Visibility) { let Visibility { kind, span, tokens } = visibility; match kind { VisibilityKind::Public | VisibilityKind::Inherited => {} @@ -1712,11 +1712,11 @@ fn walk_vis(visibility: &mut Visibility, vis: &mut T) { vis.visit_path(path); } } - visit_lazy_tts(tokens, vis); + visit_lazy_tts(vis, tokens); vis.visit_span(span); } -fn walk_capture_by(capture_by: &mut CaptureBy, vis: &mut T) { +fn walk_capture_by(vis: &mut T, capture_by: &mut CaptureBy) { match capture_by { CaptureBy::Ref => {} CaptureBy::Value { move_kw } => { diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index 39d66b5a6de0..b45f5e83220c 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -212,18 +212,18 @@ impl MutVisitor for CfgEval<'_> { #[instrument(level = "trace", skip(self))] fn visit_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, false); - mut_visit::walk_expr(expr, self); + mut_visit::walk_expr(self, expr); } #[instrument(level = "trace", skip(self))] fn visit_method_receiver_expr(&mut self, expr: &mut P) { self.0.configure_expr(expr, true); - mut_visit::walk_expr(expr, self); + mut_visit::walk_expr(self, expr); } fn filter_map_expr(&mut self, expr: P) -> Option> { let mut expr = configure!(self, expr); - mut_visit::walk_expr(&mut expr, self); + mut_visit::walk_expr(self, &mut expr); Some(expr) } @@ -231,15 +231,18 @@ impl MutVisitor for CfgEval<'_> { &mut self, param: ast::GenericParam, ) -> SmallVec<[ast::GenericParam; 1]> { - mut_visit::walk_flat_map_generic_param(configure!(self, param), self) + let param = configure!(self, param); + mut_visit::walk_flat_map_generic_param(self, param) } fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { - mut_visit::walk_flat_map_stmt(configure!(self, stmt), self) + let stmt = configure!(self, stmt); + mut_visit::walk_flat_map_stmt(self, stmt) } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { - mut_visit::walk_flat_map_item(configure!(self, item), None, self) + let item = configure!(self, item); + mut_visit::walk_flat_map_item(self, item, None) } fn flat_map_assoc_item( @@ -247,37 +250,45 @@ impl MutVisitor for CfgEval<'_> { item: P, ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - mut_visit::walk_flat_map_item(configure!(self, item), Some(ctxt), self) + let item = configure!(self, item); + mut_visit::walk_flat_map_item(self, item, Some(ctxt)) } fn flat_map_foreign_item( &mut self, foreign_item: P, ) -> SmallVec<[P; 1]> { - mut_visit::walk_flat_map_item(configure!(self, foreign_item), None, self) + let foreign_item = configure!(self, foreign_item); + mut_visit::walk_flat_map_item(self, foreign_item, None) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { - mut_visit::walk_flat_map_arm(configure!(self, arm), self) + let arm = configure!(self, arm); + mut_visit::walk_flat_map_arm(self, arm) } fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> { - mut_visit::walk_flat_map_expr_field(configure!(self, field), self) + let field = configure!(self, field); + mut_visit::walk_flat_map_expr_field(self, field) } fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> { - mut_visit::walk_flat_map_pat_field(configure!(self, fp), self) + let fp = configure!(self, fp); + mut_visit::walk_flat_map_pat_field(self, fp) } fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> { - mut_visit::walk_flat_map_param(configure!(self, p), self) + let p = configure!(self, p); + mut_visit::walk_flat_map_param(self, p) } fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> { - mut_visit::walk_flat_map_field_def(configure!(self, sf), self) + let sf = configure!(self, sf); + mut_visit::walk_flat_map_field_def(self, sf) } fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> { - mut_visit::walk_flat_map_variant(configure!(self, variant), self) + let variant = configure!(self, variant); + mut_visit::walk_flat_map_variant(self, variant) } } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 2e4d60a08177..f6b23c52b427 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -122,7 +122,7 @@ impl TestHarnessGenerator<'_> { impl<'a> MutVisitor for TestHarnessGenerator<'a> { fn visit_crate(&mut self, c: &mut ast::Crate) { let prev_tests = mem::take(&mut self.tests); - walk_crate(c, self); + walk_crate(self, c); self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests); // Create a main function to run our tests @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = walk_flat_map_item(i, None, self).expect_one("noop did something"); + let item = walk_flat_map_item(self, i, None).expect_one("noop did something"); self.depth -= 1; // Remove any #[rustc_main] or #[start] from the AST so it doesn't diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index c10b71141236..b7c5a52eb4ab 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1149,7 +1149,7 @@ impl InvocationCollectorNode for P { fragment.make_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(self, None, visitor) + walk_flat_map_item(visitor, self, None) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1293,7 +1293,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fragment.make_trait_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(self.wrapped, Some(AssocCtxt::Trait), visitor) + walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Trait)) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1334,7 +1334,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fragment.make_impl_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(self.wrapped, Some(AssocCtxt::Impl), visitor) + walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Impl)) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1372,7 +1372,7 @@ impl InvocationCollectorNode for P { fragment.make_foreign_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(self, None, visitor) + walk_flat_map_item(visitor, self, None) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) @@ -1395,7 +1395,7 @@ impl InvocationCollectorNode for ast::Variant { fragment.make_variants() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_variant(self, visitor) + walk_flat_map_variant(visitor, self) } } @@ -1408,7 +1408,7 @@ impl InvocationCollectorNode for ast::FieldDef { fragment.make_field_defs() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_field_def(self, visitor) + walk_flat_map_field_def(visitor, self) } } @@ -1421,7 +1421,7 @@ impl InvocationCollectorNode for ast::PatField { fragment.make_pat_fields() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_pat_field(self, visitor) + walk_flat_map_pat_field(visitor, self) } } @@ -1434,7 +1434,7 @@ impl InvocationCollectorNode for ast::ExprField { fragment.make_expr_fields() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_expr_field(self, visitor) + walk_flat_map_expr_field(visitor, self) } } @@ -1447,7 +1447,7 @@ impl InvocationCollectorNode for ast::Param { fragment.make_params() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_param(self, visitor) + walk_flat_map_param(visitor, self) } } @@ -1460,7 +1460,7 @@ impl InvocationCollectorNode for ast::GenericParam { fragment.make_generic_params() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_generic_param(self, visitor) + walk_flat_map_generic_param(visitor, self) } } @@ -1473,7 +1473,7 @@ impl InvocationCollectorNode for ast::Arm { fragment.make_arms() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_arm(self, visitor) + walk_flat_map_arm(visitor, self) } } @@ -1487,7 +1487,7 @@ impl InvocationCollectorNode for ast::Stmt { fragment.make_stmts() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_stmt(self, visitor) + walk_flat_map_stmt(visitor, self) } fn is_mac_call(&self) -> bool { match &self.kind { @@ -1561,7 +1561,7 @@ impl InvocationCollectorNode for ast::Crate { fragment.make_crate() } fn walk(&mut self, visitor: &mut V) { - walk_crate(self, visitor) + walk_crate(visitor, self) } fn expand_cfg_false( &mut self, @@ -1587,7 +1587,7 @@ impl InvocationCollectorNode for P { fragment.make_ty() } fn walk(&mut self, visitor: &mut V) { - walk_ty(self, visitor) + walk_ty(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ast::TyKind::MacCall(..)) @@ -1611,7 +1611,7 @@ impl InvocationCollectorNode for P { fragment.make_pat() } fn walk(&mut self, visitor: &mut V) { - walk_pat(self, visitor) + walk_pat(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, PatKind::MacCall(..)) @@ -1639,7 +1639,7 @@ impl InvocationCollectorNode for P { "an expression" } fn walk(&mut self, visitor: &mut V) { - walk_expr(self, visitor) + walk_expr(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ExprKind::MacCall(..)) @@ -1665,7 +1665,7 @@ impl InvocationCollectorNode for AstNodeWrapper, OptExprTag> { fragment.make_opt_expr() } fn walk_flat_map(mut self, visitor: &mut V) -> Self::OutputTy { - walk_expr(&mut self.wrapped, visitor); + walk_expr(visitor, &mut self.wrapped); Some(self.wrapped) } fn is_mac_call(&self) -> bool { @@ -1705,7 +1705,7 @@ impl InvocationCollectorNode for AstNodeWrapper, MethodReceiverTag> AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) } fn walk(&mut self, visitor: &mut V) { - walk_expr(&mut self.wrapped, visitor) + walk_expr(visitor, &mut self.wrapped) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) @@ -2147,11 +2147,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.cx.current_expansion.is_trailing_mac = true; // Don't use `assign_id` for this statement - it may get removed // entirely due to a `#[cfg]` on the contained expression - let res = walk_flat_map_stmt(node, self); + let res = walk_flat_map_stmt(self, node); self.cx.current_expansion.is_trailing_mac = false; res } - _ => walk_flat_map_stmt(node, self), + _ => walk_flat_map_stmt(self, node), }; } @@ -2195,7 +2195,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { &mut self.cx.current_expansion.dir_ownership, DirOwnership::UnownedViaBlock, ); - walk_block(node, self); + walk_block(self, node); self.cx.current_expansion.dir_ownership = orig_dir_ownership; } diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 62337756cd88..0da542d379d2 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -333,7 +333,7 @@ pub(super) fn transcribe<'a>( // jump back out of the Delimited, pop the result_stack and add the new results back to // the previous results (from outside the Delimited). mbe::TokenTree::Delimited(mut span, spacing, delimited) => { - mut_visit::visit_delim_span(&mut span, &mut marker); + mut_visit::visit_delim_span(&mut marker, &mut span); stack.push(Frame::new_delimited(delimited, span, *spacing)); result_stack.push(mem::take(&mut result)); } @@ -342,7 +342,7 @@ pub(super) fn transcribe<'a>( // preserve syntax context. mbe::TokenTree::Token(token) => { let mut token = token.clone(); - mut_visit::visit_token(&mut token, &mut marker); + mut_visit::visit_token(&mut marker, &mut token); let tt = TokenTree::Token(token, Spacing::Alone); result.push(tt); } diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index a9884b344c76..dd19405d453b 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -209,7 +209,7 @@ impl MutVisitor for PlaceholderExpander { if arm.is_placeholder { self.remove(arm.id).make_arms() } else { - walk_flat_map_arm(arm, self) + walk_flat_map_arm(self, arm) } } @@ -217,7 +217,7 @@ impl MutVisitor for PlaceholderExpander { if field.is_placeholder { self.remove(field.id).make_expr_fields() } else { - walk_flat_map_expr_field(field, self) + walk_flat_map_expr_field(self, field) } } @@ -225,7 +225,7 @@ impl MutVisitor for PlaceholderExpander { if fp.is_placeholder { self.remove(fp.id).make_pat_fields() } else { - walk_flat_map_pat_field(fp, self) + walk_flat_map_pat_field(self, fp) } } @@ -236,7 +236,7 @@ impl MutVisitor for PlaceholderExpander { if param.is_placeholder { self.remove(param.id).make_generic_params() } else { - walk_flat_map_generic_param(param, self) + walk_flat_map_generic_param(self, param) } } @@ -244,7 +244,7 @@ impl MutVisitor for PlaceholderExpander { if p.is_placeholder { self.remove(p.id).make_params() } else { - walk_flat_map_param(p, self) + walk_flat_map_param(self, p) } } @@ -252,7 +252,7 @@ impl MutVisitor for PlaceholderExpander { if sf.is_placeholder { self.remove(sf.id).make_field_defs() } else { - walk_flat_map_field_def(sf, self) + walk_flat_map_field_def(self, sf) } } @@ -260,14 +260,14 @@ impl MutVisitor for PlaceholderExpander { if variant.is_placeholder { self.remove(variant.id).make_variants() } else { - walk_flat_map_variant(variant, self) + walk_flat_map_variant(self, variant) } } fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => walk_flat_map_item(item, None, self), + _ => walk_flat_map_item(self, item, None), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => walk_flat_map_item(item, Some(ctxt), self), + _ => walk_flat_map_item(self, item, Some(ctxt)), } } @@ -294,35 +294,35 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => walk_flat_map_item(item, None, self), + _ => walk_flat_map_item(self, item, None), } } fn visit_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(), - _ => walk_expr(expr, self), + _ => walk_expr(self, expr), } } fn visit_method_receiver_expr(&mut self, expr: &mut P) { match expr.kind { ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(), - _ => walk_expr(expr, self), + _ => walk_expr(self, expr), } } fn filter_map_expr(&mut self, expr: P) -> Option> { match expr.kind { ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(), - _ => noop_filter_map_expr(expr, self), + _ => noop_filter_map_expr(self, expr), } } fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> { let (style, mut stmts) = match stmt.kind { ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()), - _ => return walk_flat_map_stmt(stmt, self), + _ => return walk_flat_map_stmt(self, stmt), }; if style == ast::MacStmtStyle::Semicolon { @@ -368,14 +368,14 @@ impl MutVisitor for PlaceholderExpander { fn visit_pat(&mut self, pat: &mut P) { match pat.kind { ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(), - _ => walk_pat(pat, self), + _ => walk_pat(self, pat), } } fn visit_ty(&mut self, ty: &mut P) { match ty.kind { ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(), - _ => walk_ty(ty, self), + _ => walk_ty(self, ty), } } @@ -383,7 +383,7 @@ impl MutVisitor for PlaceholderExpander { if krate.is_placeholder { *krate = self.remove(krate.id).make_crate(); } else { - walk_crate(krate, self) + walk_crate(self, krate) } } } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e1b34c2564b9..389a6d11e19e 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3939,14 +3939,14 @@ impl MutVisitor for CondChecker<'_> { } } ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => { - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); } ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _) if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedOr(or_span)); - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); self.forbid_let_reason = forbid_let_reason; } ExprKind::Paren(ref inner) @@ -3954,7 +3954,7 @@ impl MutVisitor for CondChecker<'_> { { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(NotSupportedParentheses(inner.span)); - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); self.forbid_let_reason = forbid_let_reason; } ExprKind::Assign(ref lhs, _, span) => { @@ -3972,7 +3972,7 @@ impl MutVisitor for CondChecker<'_> { } let comparison = self.comparison; self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() }); - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); self.forbid_let_reason = forbid_let_reason; self.missing_let = missing_let; self.comparison = comparison; @@ -3992,7 +3992,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::Paren(_) => { let forbid_let_reason = self.forbid_let_reason; self.forbid_let_reason = Some(OtherForbidden); - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); self.forbid_let_reason = forbid_let_reason; } ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 487072e2f515..aa818878cd81 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -810,7 +810,7 @@ impl<'a> Parser<'a> { self.0 = true; *m = Mutability::Mut; } - walk_pat(pat, self); + walk_pat(self, pat); } } diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 1e6b5c1c7f1e..842046c941d4 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { - walk_pat(pat, self); + walk_pat(self, pat); let inner = match &mut pat.kind { Paren(i) => mem::replace(&mut i.kind, Wild), _ => return, @@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P) { impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut P) { use ast::BindingMode; - walk_pat(pat, self); + walk_pat(self, pat); let target = match &mut pat.kind { // `i @ a | b`, `box a | b`, and `& mut? a | b`. Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p, @@ -160,7 +160,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool { impl MutVisitor for Visitor { fn visit_pat(&mut self, p: &mut P) { // This is a bottom up transformation, so recurse first. - walk_pat(p, self); + walk_pat(self, p); // Don't have an or-pattern? Just quit early on. let Or(alternatives) = &mut p.kind else { return }; @@ -189,7 +189,7 @@ fn unnest_or_patterns(pat: &mut P) -> bool { // Deal with `Some(Some(0)) | Some(Some(1))`. if this_level_changed { - walk_pat(p, self); + walk_pat(self, p); } } } diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 8cb55d420b98..8379ca86494c 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -46,9 +46,11 @@ use thin_vec::{thin_vec, ThinVec}; fn parse_expr(psess: &ParseSess, src: &str) -> Option> { let src_as_string = src.to_string(); - let mut p = unwrap_or_emit_fatal( - new_parser_from_source_str(psess, FileName::Custom(src_as_string.clone()), src_as_string) - ); + let mut p = unwrap_or_emit_fatal(new_parser_from_source_str( + psess, + FileName::Custom(src_as_string.clone()), + src_as_string, + )); p.parse_expr().map_err(|e| e.cancel()).ok() } @@ -181,10 +183,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P)) { 18 => { let pat = P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None }); - iter_exprs( - depth - 1, - &mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No)) - ) + iter_exprs(depth - 1, &mut |e| { + g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No)) + }) } _ => panic!("bad counter value in iter_exprs"), } @@ -202,7 +203,7 @@ impl MutVisitor for RemoveParens { ExprKind::Paren(inner) => *e = inner, _ => {} }; - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); } } @@ -211,7 +212,7 @@ struct AddParens; impl MutVisitor for AddParens { fn visit_expr(&mut self, e: &mut P) { - mut_visit::walk_expr(e, self); + mut_visit::walk_expr(self, e); visit_clobber(e, |e| { P(Expr { id: DUMMY_NODE_ID, From 91b26fcb893c28150775323e2885155ea14cd36b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 22 Jul 2024 14:02:16 +0000 Subject: [PATCH 18/54] Update trait name from Noop -> Walk --- compiler/rustc_ast/src/mut_visit.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 043e3f1190eb..3c08e6d6ca63 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -35,7 +35,7 @@ impl ExpectOne for SmallVec { } } -pub trait NoopVisitItemKind { +pub trait WalkItemKind { fn walk( &mut self, ctxt: Option, @@ -1090,7 +1090,7 @@ pub fn walk_block(vis: &mut T, block: &mut P) { } pub fn walk_item_kind( - kind: &mut impl NoopVisitItemKind, + kind: &mut impl WalkItemKind, ident: Ident, span: Span, id: NodeId, @@ -1099,7 +1099,7 @@ pub fn walk_item_kind( kind.walk(None, ident, span, id, vis) } -impl NoopVisitItemKind for ItemKind { +impl WalkItemKind for ItemKind { fn walk( &mut self, ctxt: Option, @@ -1219,7 +1219,7 @@ impl NoopVisitItemKind for ItemKind { } } -impl NoopVisitItemKind for AssocItemKind { +impl WalkItemKind for AssocItemKind { fn walk( &mut self, ctxt: Option, @@ -1320,7 +1320,7 @@ pub fn walk_crate(vis: &mut T, krate: &mut Crate) { } /// Mutates one item, returning the item again. -pub fn walk_flat_map_item( +pub fn walk_flat_map_item( visitor: &mut impl MutVisitor, mut item: P>, ctxt: Option, @@ -1336,7 +1336,7 @@ pub fn walk_flat_map_item( smallvec![item] } -impl NoopVisitItemKind for ForeignItemKind { +impl WalkItemKind for ForeignItemKind { fn walk( &mut self, ctxt: Option, From e9f32d0ca6f5ffdb3714e9817b4a93a59b247112 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 22 Jul 2024 14:34:45 +0000 Subject: [PATCH 19/54] Avoid passing state that will not be visited --- compiler/rustc_ast/src/mut_visit.rs | 69 +++++-------------- compiler/rustc_builtin_macros/src/cfg_eval.rs | 8 +-- .../rustc_builtin_macros/src/test_harness.rs | 4 +- compiler/rustc_expand/src/expand.rs | 8 +-- compiler/rustc_expand/src/placeholders.rs | 6 +- 5 files changed, 29 insertions(+), 66 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 3c08e6d6ca63..8387e4499ae3 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,7 +11,7 @@ use crate::ast::*; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::*; -use crate::visit::{AssocCtxt, BoundKind, FnCtxt}; +use crate::visit::{AssocCtxt, BoundKind}; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -36,14 +36,7 @@ impl ExpectOne for SmallVec { } pub trait WalkItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor); } pub trait MutVisitor: Sized { @@ -102,11 +95,11 @@ pub trait MutVisitor: Sized { } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, ni, None) + walk_flat_map_item(self, ni) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, i, None) + walk_flat_map_item(self, i) } fn visit_fn_header(&mut self, header: &mut FnHeader) { @@ -120,9 +113,9 @@ pub trait MutVisitor: Sized { fn flat_map_assoc_item( &mut self, i: P, - ctxt: AssocCtxt, + _ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, i, Some(ctxt)) + walk_flat_map_item(self, i) } fn visit_fn_decl(&mut self, d: &mut P) { @@ -890,7 +883,7 @@ fn walk_coroutine_kind(vis: &mut T, coroutine_kind: &mut Coroutin fn walk_fn(vis: &mut T, kind: FnKind<'_>) { match kind { - FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { + FnKind::Fn(FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. vis.visit_fn_header(header); vis.visit_generics(generics); @@ -1091,24 +1084,15 @@ pub fn walk_block(vis: &mut T, block: &mut P) { pub fn walk_item_kind( kind: &mut impl WalkItemKind, - ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, ) { - kind.walk(None, ident, span, id, vis) + kind.walk(span, id, vis) } impl WalkItemKind for ItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - vis: &mut impl MutVisitor, - ) { - assert_eq!(ctxt, None); + fn walk(&mut self, span: Span, id: NodeId, vis: &mut impl MutVisitor) { match self { ItemKind::ExternCrate(_orig_name) => {} ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), @@ -1121,7 +1105,7 @@ impl WalkItemKind for ItemKind { } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(vis, defaultness); - vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, sig, generics, body), span, id); + vis.visit_fn(FnKind::Fn(sig, generics, body), span, id); } ItemKind::Mod(safety, mod_kind) => { visit_safety(vis, safety); @@ -1220,26 +1204,14 @@ impl WalkItemKind for ItemKind { } impl WalkItemKind for AssocItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ) { - let ctxt = ctxt.unwrap(); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor) { match self { AssocItemKind::Const(item) => { visit_const_item(item, visitor); } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(visitor, defaultness); - visitor.visit_fn( - FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, generics, body), - span, - id, - ); + visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id); } AssocItemKind::Type(box TyAlias { defaultness, @@ -1323,29 +1295,20 @@ pub fn walk_crate(vis: &mut T, krate: &mut Crate) { pub fn walk_flat_map_item( visitor: &mut impl MutVisitor, mut item: P>, - ctxt: Option, ) -> SmallVec<[P>; 1]> { let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut(); visitor.visit_id(id); visit_attrs(visitor, attrs); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.walk(ctxt, *ident, *span, *id, visitor); + kind.walk(*span, *id, visitor); visit_lazy_tts(visitor, tokens); visitor.visit_span(span); smallvec![item] } impl WalkItemKind for ForeignItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ) { - assert_eq!(ctxt, None); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor) { match self { ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => { visitor.visit_ty(ty); @@ -1353,7 +1316,7 @@ impl WalkItemKind for ForeignItemKind { } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(visitor, defaultness); - visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, ident, sig, generics, body), span, id); + visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id); } ForeignItemKind::TyAlias(box TyAlias { defaultness, @@ -1824,7 +1787,7 @@ impl DummyAstNode for crate::ast_traits::AstNo #[derive(Debug)] pub enum FnKind<'a> { /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. - Fn(FnCtxt, Ident, &'a mut FnSig, &'a mut Generics, &'a mut Option>), + Fn(&'a mut FnSig, &'a mut Generics, &'a mut Option>), /// E.g., `|x, y| body`. Closure(&'a mut ClosureBinder, &'a mut P, &'a mut P), diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index b45f5e83220c..b3d252e06a58 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -242,16 +242,16 @@ impl MutVisitor for CfgEval<'_> { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { let item = configure!(self, item); - mut_visit::walk_flat_map_item(self, item, None) + mut_visit::walk_flat_map_item(self, item) } fn flat_map_assoc_item( &mut self, item: P, - ctxt: AssocCtxt, + _ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { let item = configure!(self, item); - mut_visit::walk_flat_map_item(self, item, Some(ctxt)) + mut_visit::walk_flat_map_item(self, item) } fn flat_map_foreign_item( @@ -259,7 +259,7 @@ impl MutVisitor for CfgEval<'_> { foreign_item: P, ) -> SmallVec<[P; 1]> { let foreign_item = configure!(self, foreign_item); - mut_visit::walk_flat_map_item(self, foreign_item, None) + mut_visit::walk_flat_map_item(self, foreign_item) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index f6b23c52b427..bbafb0ac299c 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -144,7 +144,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - walk_item_kind(&mut item.kind, item.ident, item.span, item.id, self); + walk_item_kind(&mut item.kind, item.span, item.id, self); self.add_test_cases(item.id, span, prev_tests); } else { // But in those cases, we emit a lint to warn the user of these missing tests. @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = walk_flat_map_item(self, i, None).expect_one("noop did something"); + let item = walk_flat_map_item(self, i).expect_one("noop did something"); self.depth -= 1; // Remove any #[rustc_main] or #[start] from the AST so it doesn't diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index b7c5a52eb4ab..3c43d47292fb 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1149,7 +1149,7 @@ impl InvocationCollectorNode for P { fragment.make_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self, None) + walk_flat_map_item(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1293,7 +1293,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fragment.make_trait_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Trait)) + walk_flat_map_item(visitor, self.wrapped) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1334,7 +1334,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fragment.make_impl_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Impl)) + walk_flat_map_item(visitor, self.wrapped) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1372,7 +1372,7 @@ impl InvocationCollectorNode for P { fragment.make_foreign_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self, None) + walk_flat_map_item(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index dd19405d453b..3fa909877cc7 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -267,7 +267,7 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => walk_flat_map_item(self, item, None), + _ => walk_flat_map_item(self, item), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => walk_flat_map_item(self, item, Some(ctxt)), + _ => walk_flat_map_item(self, item), } } @@ -294,7 +294,7 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => walk_flat_map_item(self, item, None), + _ => walk_flat_map_item(self, item), } } From c807ac034089e31364baa24e19d5d61cbb657989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 5 Jul 2024 01:08:44 +0000 Subject: [PATCH 20/54] Use verbose suggestion for "wrong # of generics" --- .../errors/wrong_number_of_generic_args.rs | 8 +- .../invalid_const_in_lifetime_position.stderr | 27 +- tests/rustdoc-ui/mismatched_arg_count.stderr | 9 +- .../argument-suggestions/issue-100154.stderr | 9 +- ...ssue-82126-mismatched-subst-and-hir.stderr | 18 +- .../transmutable-ice-110969.stderr | 10 +- .../generic_arg_infer/infer-arg-test.stderr | 9 +- .../const_kind_expr/issue_114151.stderr | 9 +- .../generic_const_exprs/issue-102768.stderr | 27 +- .../incorrect-number-of-const-args.stderr | 9 +- .../invalid-const-arg-for-type-param.stderr | 9 +- .../invalid-constant-in-args.stderr | 10 +- tests/ui/constructor-lifetime-args.stderr | 18 +- tests/ui/consts/effect_param.stderr | 40 ++- tests/ui/error-codes/E0107.stderr | 72 +++-- .../gat-trait-path-parenthesised-args.stderr | 27 +- .../parameter_number_and_kind.stderr | 18 +- ...it-path-type-error-once-implemented.stderr | 27 +- .../generics/bad-mid-path-type-params.stderr | 45 ++- .../generics/foreign-generic-mismatch.stderr | 9 +- .../generic-arg-mismatch-recover.stderr | 27 +- ...eric-impl-more-params-with-defaults.stderr | 9 +- ...eric-type-more-params-with-defaults.stderr | 9 +- tests/ui/generics/wrong-number-of-args.stderr | 256 ++++++++++++------ .../explicit-generic-args-for-impl.stderr | 9 +- .../opaque-and-lifetime-mismatch.stderr | 27 +- tests/ui/issues/issue-18423.stderr | 10 +- tests/ui/issues/issue-53251.stderr | 18 +- tests/ui/issues/issue-60622.stderr | 9 +- .../mismatched_arg_count.stderr | 9 +- .../ui/lifetimes/noisy-follow-up-erro.stderr | 9 +- .../method-call-lifetime-args-fail.stderr | 18 +- tests/ui/resolve/issue-3214.stderr | 9 +- ...o-explicit-const-params-cross-crate.stderr | 18 +- .../effects/no-explicit-const-params.stderr | 18 +- tests/ui/seq-args.stderr | 18 +- .../struct-path-associated-type.stderr | 18 +- ...structure-constructor-type-mismatch.stderr | 18 +- tests/ui/suggestions/issue-101421.stderr | 9 +- tests/ui/suggestions/issue-104287.stderr | 9 +- tests/ui/suggestions/issue-89064.stderr | 9 +- ...assoc-type-suggestion-in-trait-impl.stderr | 9 +- tests/ui/traits/object/vs-lifetime.stderr | 9 +- tests/ui/traits/test-2.stderr | 18 +- .../ui/transmutability/issue-101739-2.stderr | 17 +- .../enum-variant-generic-args.stderr | 54 ++-- ...ypeck-builtin-bound-type-parameters.stderr | 78 ++++-- .../typeck_type_placeholder_lifetime_1.stderr | 9 +- .../typeck_type_placeholder_lifetime_2.stderr | 9 +- .../ui/ufcs/ufcs-qpath-missing-params.stderr | 9 +- ...wrong-number-number-type-parameters.stderr | 45 ++- .../unboxed-closure-sugar-wrong-trait.stderr | 9 +- 52 files changed, 811 insertions(+), 401 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 10be69a9fbb8..c2d5627f2b04 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -888,7 +888,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let comma = if args.len() > 0 { ", " } else { "" }; let trait_path = self.tcx.def_path_str(trait_def_id); let method_name = self.tcx.item_name(self.def_id); - err.span_suggestion( + err.span_suggestion_verbose( expr.span, msg, format!("{trait_path}::{generics}::{method_name}({rcvr}{comma}{rest})"), @@ -952,7 +952,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { s = pluralize!(num_redundant_lt_args), ); - err.span_suggestion( + err.span_suggestion_verbose( span_redundant_lt_args, msg_lifetimes, "", @@ -994,7 +994,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { s = pluralize!(num_redundant_gen_args), ); - err.span_suggestion( + err.span_suggestion_verbose( span_redundant_type_or_const_args, msg_types_or_consts, "", @@ -1044,7 +1044,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { }, ); - err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect); + err.span_suggestion_verbose(span, msg, "", Applicability::MaybeIncorrect); } else if redundant_lifetime_args && redundant_type_or_const_args { remove_lifetime_args(err); remove_type_or_const_args(err); diff --git a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr index 50d55284754e..ff73d3d5ddd6 100644 --- a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr +++ b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr @@ -18,15 +18,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 | LL | type Y<'a>; | ^ +help: remove these generics + | +LL - fn f<'a>(arg : Box = &'a ()>>) {} +LL + fn f<'a>(arg : Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/invalid_const_in_lifetime_position.rs:4:26 @@ -49,9 +52,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 @@ -59,6 +60,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f<'a>(arg : Box = &'a ()>>) {} +LL + fn f<'a>(arg : Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/invalid_const_in_lifetime_position.rs:4:26 @@ -81,9 +87,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 @@ -91,6 +95,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f<'a>(arg : Box = &'a ()>>) {} +LL + fn f<'a>(arg : Box>) {} + | error[E0038]: the trait `X` cannot be made into an object --> $DIR/invalid_const_in_lifetime_position.rs:4:20 diff --git a/tests/rustdoc-ui/mismatched_arg_count.stderr b/tests/rustdoc-ui/mismatched_arg_count.stderr index 857bbda2ef47..c58ff7a14df4 100644 --- a/tests/rustdoc-ui/mismatched_arg_count.stderr +++ b/tests/rustdoc-ui/mismatched_arg_count.stderr @@ -2,15 +2,18 @@ error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were --> $DIR/mismatched_arg_count.rs:7:29 | LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} - | ^^^^^ -- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^ expected 1 lifetime argument | note: type alias defined here, with 1 lifetime parameter: `'a` --> $DIR/mismatched_arg_count.rs:5:6 | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- +help: remove this lifetime argument + | +LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} +LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} + | error: aborting due to 1 previous error diff --git a/tests/ui/argument-suggestions/issue-100154.stderr b/tests/ui/argument-suggestions/issue-100154.stderr index 966f56e2a156..1496d994ef35 100644 --- a/tests/ui/argument-suggestions/issue-100154.stderr +++ b/tests/ui/argument-suggestions/issue-100154.stderr @@ -2,9 +2,7 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/issue-100154.rs:4:5 | LL | foo::<()>(()); - | ^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/issue-100154.rs:1:4 @@ -12,6 +10,11 @@ note: function defined here, with 0 generic parameters LL | fn foo(i: impl std::fmt::Display) {} | ^^^ = note: `impl Trait` cannot be explicitly specified as a generic argument +help: remove these generics + | +LL - foo::<()>(()); +LL + foo(()); + | error[E0277]: `()` doesn't implement `std::fmt::Display` --> $DIR/issue-100154.rs:4:11 diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index c0b6dcd1512f..c50e3fb64059 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { - | ^^^^^^^^^^^^---- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^^^^^^^^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 | LL | struct LockedMarket(T); | ^^^^^^^^^^^^ +help: remove these generics + | +LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { +LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { + | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 @@ -32,9 +35,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { - | ^^^^^^^^^^^^---- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^^^^^^^^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 @@ -42,6 +43,11 @@ note: struct defined here, with 0 lifetime parameters LL | struct LockedMarket(T); | ^^^^^^^^^^^^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { +LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { + | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr index a8fc742e89f5..91a1053bb6d1 100644 --- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr +++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr @@ -2,9 +2,13 @@ error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments we --> $DIR/transmutable-ice-110969.rs:11:14 | LL | Dst: BikeshedIntrinsicFrom, - | ^^^^^^^^^^^^^^^^^^^^^ ------ help: remove this generic argument - | | - | expected at most 2 generic arguments + | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments + | +help: remove this generic argument + | +LL - Dst: BikeshedIntrinsicFrom, +LL + Dst: BikeshedIntrinsicFrom, + | error[E0308]: mismatched types --> $DIR/transmutable-ice-110969.rs:25:74 diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr index 6d8dd017734c..f891bbea21ef 100644 --- a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr +++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr @@ -23,15 +23,18 @@ error[E0107]: struct takes 2 generic arguments but 3 generic arguments were supp --> $DIR/infer-arg-test.rs:18:10 | LL | let a: All<_, _, _>; - | ^^^ - help: remove this generic argument - | | - | expected 2 generic arguments + | ^^^ expected 2 generic arguments | note: struct defined here, with 2 generic parameters: `T`, `N` --> $DIR/infer-arg-test.rs:3:8 | LL | struct All<'a, T, const N: usize> { | ^^^ - -------------- +help: remove this generic argument + | +LL - let a: All<_, _, _>; +LL + let a: All<_, _, >; + | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr index 0c29d94ed5b4..78d32b57f87f 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr @@ -2,15 +2,18 @@ error[E0107]: function takes 1 generic argument but 2 generic arguments were sup --> $DIR/issue_114151.rs:17:5 | LL | foo::<_, L>([(); L + 1 + L]); - | ^^^ - help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: function defined here, with 1 generic parameter: `N` --> $DIR/issue_114151.rs:4:4 | LL | fn foo( | ^^^ -------------- +help: remove this generic argument + | +LL - foo::<_, L>([(); L + 1 + L]); +LL + foo::<_, >([(); L + 1 + L]); + | error[E0308]: mismatched types --> $DIR/issue_114151.rs:17:18 diff --git a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr index a470c36134cf..6bd6eb4e00e6 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr @@ -18,15 +18,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 | LL | type Y<'a>; | ^ +help: remove these generics + | +LL - fn f2<'a>(arg: Box = &'a ()>>) {} +LL + fn f2<'a>(arg: Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-102768.rs:9:30 @@ -49,9 +52,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 @@ -59,6 +60,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f2<'a>(arg: Box = &'a ()>>) {} +LL + fn f2<'a>(arg: Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-102768.rs:9:30 @@ -81,9 +87,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 @@ -91,6 +95,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f2<'a>(arg: Box = &'a ()>>) {} +LL + fn f2<'a>(arg: Box>) {} + | error[E0038]: the trait `X` cannot be made into an object --> $DIR/issue-102768.rs:9:24 diff --git a/tests/ui/const-generics/incorrect-number-of-const-args.stderr b/tests/ui/const-generics/incorrect-number-of-const-args.stderr index 01ac4e69a057..97eb47275c2b 100644 --- a/tests/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/tests/ui/const-generics/incorrect-number-of-const-args.stderr @@ -20,15 +20,18 @@ error[E0107]: function takes 2 generic arguments but 3 generic arguments were su --> $DIR/incorrect-number-of-const-args.rs:9:5 | LL | foo::<0, 0, 0>(); - | ^^^ - help: remove this generic argument - | | - | expected 2 generic arguments + | ^^^ expected 2 generic arguments | note: function defined here, with 2 generic parameters: `X`, `Y` --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { | ^^^ -------------- -------------- +help: remove this generic argument + | +LL - foo::<0, 0, 0>(); +LL + foo::<0, 0, >(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr index 4a649d8a7e88..d4f899f83773 100644 --- a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr +++ b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr @@ -27,15 +27,18 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/invalid-const-arg-for-type-param.rs:12:5 | LL | S::<0>; - | ^----- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/invalid-const-arg-for-type-param.rs:3:8 | LL | struct S; | ^ +help: remove these generics + | +LL - S::<0>; +LL + S; + | error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/invalid-constant-in-args.stderr b/tests/ui/const-generics/invalid-constant-in-args.stderr index 158b9722ee61..ed715257ac1c 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.stderr +++ b/tests/ui/const-generics/invalid-constant-in-args.stderr @@ -2,9 +2,13 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/invalid-constant-in-args.rs:4:12 | LL | let _: Cell<&str, "a"> = Cell::new(""); - | ^^^^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^ expected 1 generic argument + | +help: remove this generic argument + | +LL - let _: Cell<&str, "a"> = Cell::new(""); +LL + let _: Cell<&str, > = Cell::new(""); + | error: aborting due to 1 previous error diff --git a/tests/ui/constructor-lifetime-args.stderr b/tests/ui/constructor-lifetime-args.stderr index a18123fe19cb..9e0bc3c6c1a6 100644 --- a/tests/ui/constructor-lifetime-args.stderr +++ b/tests/ui/constructor-lifetime-args.stderr @@ -20,15 +20,18 @@ error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/constructor-lifetime-args.rs:19:5 | LL | S::<'static, 'static, 'static>(&0, &0); - | ^ ------- help: remove this lifetime argument - | | - | expected 2 lifetime arguments + | ^ expected 2 lifetime arguments | note: struct defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/constructor-lifetime-args.rs:9:8 | LL | struct S<'a, 'b>(&'a u8, &'b u8); | ^ -- -- +help: remove this lifetime argument + | +LL - S::<'static, 'static, 'static>(&0, &0); +LL + S::<'static, 'static, >(&0, &0); + | error[E0107]: enum takes 2 lifetime arguments but 1 lifetime argument was supplied --> $DIR/constructor-lifetime-args.rs:22:8 @@ -52,15 +55,18 @@ error[E0107]: enum takes 2 lifetime arguments but 3 lifetime arguments were supp --> $DIR/constructor-lifetime-args.rs:24:8 | LL | E::V::<'static, 'static, 'static>(&0); - | ^ ------- help: remove this lifetime argument - | | - | expected 2 lifetime arguments + | ^ expected 2 lifetime arguments | note: enum defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/constructor-lifetime-args.rs:10:6 | LL | enum E<'a, 'b> { | ^ -- -- +help: remove this lifetime argument + | +LL - E::V::<'static, 'static, 'static>(&0); +LL + E::V::<'static, 'static, >(&0); + | error: aborting due to 4 previous errors diff --git a/tests/ui/consts/effect_param.stderr b/tests/ui/consts/effect_param.stderr index dba5d49b7921..3777e20e4c0a 100644 --- a/tests/ui/consts/effect_param.stderr +++ b/tests/ui/consts/effect_param.stderr @@ -2,33 +2,49 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/effect_param.rs:11:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^--------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - i8::checked_sub::(42, 43); +LL + i8::checked_sub(42, 43); + | error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:13:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^-------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - i8::checked_sub::(42, 43); +LL + i8::checked_sub(42, 43); + | error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:4:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^-------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - i8::checked_sub::(42, 43); +LL + i8::checked_sub(42, 43); + | error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:6:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^--------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - i8::checked_sub::(42, 43); +LL + i8::checked_sub(42, 43); + | error: aborting due to 4 previous errors diff --git a/tests/ui/error-codes/E0107.stderr b/tests/ui/error-codes/E0107.stderr index 3f540eb08bc7..c6317270f9b1 100644 --- a/tests/ui/error-codes/E0107.stderr +++ b/tests/ui/error-codes/E0107.stderr @@ -20,113 +20,137 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli --> $DIR/E0107.rs:17:10 | LL | bar: Bar<'a>, - | ^^^---- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^ expected 0 lifetime arguments | note: enum defined here, with 0 lifetime parameters --> $DIR/E0107.rs:6:6 | LL | enum Bar { | ^^^ +help: remove these generics + | +LL - bar: Bar<'a>, +LL + bar: Bar, + | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:21:11 | LL | foo2: Foo<'a, 'b, 'c>, - | ^^^ ------ help: remove these lifetime arguments - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:1:8 | LL | struct Foo<'a>(&'a str); | ^^^ -- +help: remove these lifetime arguments + | +LL - foo2: Foo<'a, 'b, 'c>, +LL + foo2: Foo<'a, >, + | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/E0107.rs:25:11 | LL | qux1: Qux<'a, 'b, i32>, - | ^^^ -- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- +help: remove this lifetime argument + | +LL - qux1: Qux<'a, 'b, i32>, +LL + qux1: Qux<'a, , i32>, + | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/E0107.rs:29:11 | LL | qux2: Qux<'a, i32, 'b>, - | ^^^ -- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- +help: remove this lifetime argument + | +LL - qux2: Qux<'a, i32, 'b>, +LL + qux2: Qux<'a, i32, >, + | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:33:11 | LL | qux3: Qux<'a, 'b, 'c, i32>, - | ^^^ ------ help: remove these lifetime arguments - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- +help: remove these lifetime arguments + | +LL - qux3: Qux<'a, 'b, 'c, i32>, +LL + qux3: Qux<'a, , i32>, + | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:37:11 | LL | qux4: Qux<'a, i32, 'b, 'c>, - | ^^^ ------ help: remove these lifetime arguments - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- +help: remove these lifetime arguments + | +LL - qux4: Qux<'a, i32, 'b, 'c>, +LL + qux4: Qux<'a, i32, >, + | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:41:11 | LL | qux5: Qux<'a, 'b, i32, 'c>, - | ^^^ -- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- +help: remove this lifetime argument + | +LL - qux5: Qux<'a, 'b, i32, 'c>, +LL + qux5: Qux<'a, , i32, 'c>, + | error[E0107]: struct takes 0 lifetime arguments but 2 lifetime arguments were supplied --> $DIR/E0107.rs:45:11 | LL | quux: Quux<'a, i32, 'b>, - | ^^^^ -- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/E0107.rs:4:8 | LL | struct Quux(T); | ^^^^ +help: remove this lifetime argument + | +LL - quux: Quux<'a, i32, 'b>, +LL + quux: Quux<, i32, 'b>, + | error[E0107]: trait takes 0 generic arguments but 2 generic arguments were supplied --> $DIR/E0107.rs:55:27 diff --git a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr index fcd3e7d9aace..18f37207ee55 100644 --- a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr +++ b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr @@ -43,15 +43,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^---- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 | LL | type Y<'a>; | ^ +help: remove these generics + | +LL - fn foo<'a>(arg: Box>) {} +LL + fn foo<'a>(arg: Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 @@ -74,9 +77,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^---- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 @@ -84,6 +85,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn foo<'a>(arg: Box>) {} +LL + fn foo<'a>(arg: Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 @@ -106,9 +112,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^---- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 @@ -116,6 +120,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn foo<'a>(arg: Box>) {} +LL + fn foo<'a>(arg: Box>) {} + | error[E0224]: at least one trait is required for an object type --> $DIR/gat-trait-path-parenthesised-args.rs:5:29 diff --git a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr index 4523044b5886..9eb0b8ca641c 100644 --- a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr +++ b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr @@ -2,15 +2,18 @@ error[E0107]: associated type takes 1 lifetime argument but 2 lifetime arguments --> $DIR/parameter_number_and_kind.rs:11:24 | LL | type FErr1 = Self::E<'static, 'static>; - | ^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` --> $DIR/parameter_number_and_kind.rs:8:10 | LL | type E<'a, T>; | ^ -- +help: remove this lifetime argument + | +LL - type FErr1 = Self::E<'static, 'static>; +LL + type FErr1 = Self::E<'static, >; + | error[E0107]: associated type takes 1 generic argument but 0 generic arguments were supplied --> $DIR/parameter_number_and_kind.rs:11:24 @@ -32,15 +35,18 @@ error[E0107]: associated type takes 1 generic argument but 2 generic arguments w --> $DIR/parameter_number_and_kind.rs:14:27 | LL | type FErr2 = Self::E<'static, T, u32>; - | ^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^ expected 1 generic argument | note: associated type defined here, with 1 generic parameter: `T` --> $DIR/parameter_number_and_kind.rs:8:10 | LL | type E<'a, T>; | ^ - +help: remove this generic argument + | +LL - type FErr2 = Self::E<'static, T, u32>; +LL + type FErr2 = Self::E<'static, T, >; + | error: aborting due to 3 previous errors diff --git a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr index 2090f75aed32..f73022922a5b 100644 --- a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr +++ b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr @@ -18,15 +18,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 | LL | type Y<'a>; | ^ +help: remove these generics + | +LL - fn f2<'a>(arg : Box = &'a ()>>) {} +LL + fn f2<'a>(arg : Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/trait-path-type-error-once-implemented.rs:6:29 @@ -49,9 +52,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 @@ -59,6 +60,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f2<'a>(arg : Box = &'a ()>>) {} +LL + fn f2<'a>(arg : Box>) {} + | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/trait-path-type-error-once-implemented.rs:6:29 @@ -81,9 +87,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^--- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 @@ -91,6 +95,11 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - fn f2<'a>(arg : Box = &'a ()>>) {} +LL + fn f2<'a>(arg : Box>) {} + | error[E0038]: the trait `X` cannot be made into an object --> $DIR/trait-path-type-error-once-implemented.rs:6:23 diff --git a/tests/ui/generics/bad-mid-path-type-params.stderr b/tests/ui/generics/bad-mid-path-type-params.stderr index 71e15dd4c926..7f4ba781e6ab 100644 --- a/tests/ui/generics/bad-mid-path-type-params.stderr +++ b/tests/ui/generics/bad-mid-path-type-params.stderr @@ -2,71 +2,86 @@ error[E0107]: associated function takes 1 generic argument but 2 generic argumen --> $DIR/bad-mid-path-type-params.rs:30:16 | LL | let _ = S::new::(1, 1.0); - | ^^^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:6:8 | LL | fn new(x: T, _: U) -> S { | ^^^ - +help: remove this generic argument + | +LL - let _ = S::new::(1, 1.0); +LL + let _ = S::new::(1, 1.0); + | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/bad-mid-path-type-params.rs:33:13 | LL | let _ = S::<'a,isize>::new::(1, 1.0); - | ^ -- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/bad-mid-path-type-params.rs:1:8 | LL | struct S { | ^ +help: remove this lifetime argument + | +LL - let _ = S::<'a,isize>::new::(1, 1.0); +LL + let _ = S::<,isize>::new::(1, 1.0); + | error[E0107]: associated function takes 1 generic argument but 2 generic arguments were supplied --> $DIR/bad-mid-path-type-params.rs:36:24 | LL | let _: S2 = Trait::new::(1, 1.0); - | ^^^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:14:8 | LL | fn new(x: T, y: U) -> Self; | ^^^ - +help: remove this generic argument + | +LL - let _: S2 = Trait::new::(1, 1.0); +LL + let _: S2 = Trait::new::(1, 1.0); + | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/bad-mid-path-type-params.rs:39:17 | LL | let _: S2 = Trait::<'a,isize>::new::(1, 1.0); - | ^^^^^ -- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^^^^ expected 0 lifetime arguments | note: trait defined here, with 0 lifetime parameters --> $DIR/bad-mid-path-type-params.rs:13:7 | LL | trait Trait { | ^^^^^ +help: remove this lifetime argument + | +LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); +LL + let _: S2 = Trait::<,isize>::new::(1, 1.0); + | error[E0107]: associated function takes 1 generic argument but 2 generic arguments were supplied --> $DIR/bad-mid-path-type-params.rs:39:36 | LL | let _: S2 = Trait::<'a,isize>::new::(1, 1.0); - | ^^^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:14:8 | LL | fn new(x: T, y: U) -> Self; | ^^^ - +help: remove this generic argument + | +LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); +LL + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); + | error: aborting due to 5 previous errors diff --git a/tests/ui/generics/foreign-generic-mismatch.stderr b/tests/ui/generics/foreign-generic-mismatch.stderr index 5322b3f919d2..7e8e854d6424 100644 --- a/tests/ui/generics/foreign-generic-mismatch.stderr +++ b/tests/ui/generics/foreign-generic-mismatch.stderr @@ -20,15 +20,18 @@ error[E0107]: function takes 1 lifetime argument but 2 lifetime arguments were s --> $DIR/foreign-generic-mismatch.rs:8:31 | LL | foreign_generic_mismatch::lt_arg::<'static, 'static>(); - | ^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^ expected 1 lifetime argument | note: function defined here, with 1 lifetime parameter: `'a` --> $DIR/auxiliary/foreign-generic-mismatch.rs:3:8 | LL | pub fn lt_arg<'a: 'a>() {} | ^^^^^^ -- +help: remove this lifetime argument + | +LL - foreign_generic_mismatch::lt_arg::<'static, 'static>(); +LL + foreign_generic_mismatch::lt_arg::<'static, >(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/generics/generic-arg-mismatch-recover.stderr b/tests/ui/generics/generic-arg-mismatch-recover.stderr index f549a7180fc6..cb25fa7af40a 100644 --- a/tests/ui/generics/generic-arg-mismatch-recover.stderr +++ b/tests/ui/generics/generic-arg-mismatch-recover.stderr @@ -2,43 +2,52 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/generic-arg-mismatch-recover.rs:6:5 | LL | Foo::<'static, 'static, ()>(&0); - | ^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/generic-arg-mismatch-recover.rs:1:8 | LL | struct Foo<'a, T: 'a>(&'a T); | ^^^ -- +help: remove this lifetime argument + | +LL - Foo::<'static, 'static, ()>(&0); +LL + Foo::<'static, , ()>(&0); + | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/generic-arg-mismatch-recover.rs:9:5 | LL | Bar::<'static, 'static, ()>(&()); - | ^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/generic-arg-mismatch-recover.rs:3:8 | LL | struct Bar<'a>(&'a ()); | ^^^ -- +help: remove this lifetime argument + | +LL - Bar::<'static, 'static, ()>(&()); +LL + Bar::<'static, , ()>(&()); + | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/generic-arg-mismatch-recover.rs:9:5 | LL | Bar::<'static, 'static, ()>(&()); - | ^^^ -- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/generic-arg-mismatch-recover.rs:3:8 | LL | struct Bar<'a>(&'a ()); | ^^^ +help: remove this generic argument + | +LL - Bar::<'static, 'static, ()>(&()); +LL + Bar::<'static, 'static, >(&()); + | error: aborting due to 3 previous errors diff --git a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr index c5812abfd3df..edbe7a5e139c 100644 --- a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes at most 2 generic arguments but 3 generic arguments w --> $DIR/generic-impl-more-params-with-defaults.rs:13:5 | LL | Vec::::new(); - | ^^^ ---- help: remove this generic argument - | | - | expected at most 2 generic arguments + | ^^^ expected at most 2 generic arguments | note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-impl-more-params-with-defaults.rs:5:8 | LL | struct Vec( | ^^^ - -------- +help: remove this generic argument + | +LL - Vec::::new(); +LL + Vec::::new(); + | error: aborting due to 1 previous error diff --git a/tests/ui/generics/generic-type-more-params-with-defaults.stderr b/tests/ui/generics/generic-type-more-params-with-defaults.stderr index c44f6b7ddc02..27752af1ad6c 100644 --- a/tests/ui/generics/generic-type-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-type-more-params-with-defaults.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes at most 2 generic arguments but 3 generic arguments w --> $DIR/generic-type-more-params-with-defaults.rs:9:12 | LL | let _: Vec; - | ^^^ ---- help: remove this generic argument - | | - | expected at most 2 generic arguments + | ^^^ expected at most 2 generic arguments | note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-type-more-params-with-defaults.rs:5:8 | LL | struct Vec( | ^^^ - -------- +help: remove this generic argument + | +LL - let _: Vec; +LL + let _: Vec; + | error: aborting due to 1 previous error diff --git a/tests/ui/generics/wrong-number-of-args.stderr b/tests/ui/generics/wrong-number-of-args.stderr index e04408a0fdf3..9df759bf29b1 100644 --- a/tests/ui/generics/wrong-number-of-args.stderr +++ b/tests/ui/generics/wrong-number-of-args.stderr @@ -171,71 +171,86 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/wrong-number-of-args.rs:6:14 | LL | type B = Ty<'static>; - | ^^--------- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ +help: remove these generics + | +LL - type B = Ty<'static>; +LL + type B = Ty; + | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:10:14 | LL | type C = Ty<'static, usize>; - | ^^ ------- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ +help: remove this lifetime argument + | +LL - type C = Ty<'static, usize>; +LL + type C = Ty<, usize>; + | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/wrong-number-of-args.rs:10:14 | LL | type C = Ty<'static, usize>; - | ^^ ----- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ +help: remove this generic argument + | +LL - type C = Ty<'static, usize>; +LL + type C = Ty<'static, >; + | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:16:14 | LL | type D = Ty<'static, usize, { 0 }>; - | ^^ ------- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^ expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ +help: remove this lifetime argument + | +LL - type D = Ty<'static, usize, { 0 }>; +LL + type D = Ty<, usize, { 0 }>; + | error[E0107]: struct takes 0 generic arguments but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:16:14 | LL | type D = Ty<'static, usize, { 0 }>; - | ^^ ------------ help: remove these generic arguments - | | - | expected 0 generic arguments + | ^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ +help: remove these generic arguments + | +LL - type D = Ty<'static, usize, { 0 }>; +LL + type D = Ty<'static, >; + | error[E0107]: missing generics for struct `type_and_type::Ty` --> $DIR/wrong-number-of-args.rs:26:14 @@ -275,15 +290,18 @@ error[E0107]: struct takes 2 generic arguments but 3 generic arguments were supp --> $DIR/wrong-number-of-args.rs:36:14 | LL | type D = Ty; - | ^^ ---- help: remove this generic argument - | | - | expected 2 generic arguments + | ^^ expected 2 generic arguments | note: struct defined here, with 2 generic parameters: `A`, `B` --> $DIR/wrong-number-of-args.rs:24:12 | LL | struct Ty(A, B); | ^^ - - +help: remove this generic argument + | +LL - type D = Ty; +LL + type D = Ty; + | error[E0107]: struct takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:40:14 @@ -353,29 +371,35 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/wrong-number-of-args.rs:70:14 | LL | type F = Ty<'static, usize, 'static, usize>; - | ^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>(&'a T); | ^^ -- +help: remove this lifetime argument + | +LL - type F = Ty<'static, usize, 'static, usize>; +LL + type F = Ty<'static, usize, , usize>; + | error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:70:14 | LL | type F = Ty<'static, usize, 'static, usize>; - | ^^ ----- help: remove this generic argument - | | - | expected 1 generic argument + | ^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>(&'a T); | ^^ - +help: remove this generic argument + | +LL - type F = Ty<'static, usize, 'static, usize>; +LL + type F = Ty<'static, usize, 'static, >; + | error[E0107]: missing generics for struct `type_and_type_and_type::Ty` --> $DIR/wrong-number-of-args.rs:80:14 @@ -415,15 +439,18 @@ error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments w --> $DIR/wrong-number-of-args.rs:92:14 | LL | type E = Ty; - | ^^ --- help: remove this generic argument - | | - | expected at most 3 generic arguments + | ^^ expected at most 3 generic arguments | note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C` --> $DIR/wrong-number-of-args.rs:78:12 | LL | struct Ty(A, B, C); | ^^ - - ---------------- +help: remove this generic argument + | +LL - type E = Ty; +LL + type E = Ty; + | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:96:14 @@ -445,29 +472,35 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/wrong-number-of-args.rs:116:22 | LL | type A = Box>; - | ^^^^^^^^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:104:11 | LL | trait NonGeneric { | ^^^^^^^^^^ +help: remove these generics + | +LL - type A = Box>; +LL + type A = Box; + | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:125:22 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^^^^^^^^^^ expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:108:11 | LL | trait GenericLifetime<'a> { | ^^^^^^^^^^^^^^^ -- +help: remove this lifetime argument + | +LL - type C = Box>; +LL + type C = Box>; + | error[E0107]: missing generics for trait `GenericType` --> $DIR/wrong-number-of-args.rs:129:22 @@ -489,15 +522,18 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:133:22 | LL | type E = Box>; - | ^^^^^^^^^^^ ----- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:112:11 | LL | trait GenericType { | ^^^^^^^^^^^ - +help: remove this generic argument + | +LL - type E = Box>; +LL + type E = Box>; + | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:142:22 @@ -519,43 +555,52 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/wrong-number-of-args.rs:153:26 | LL | type A = Box>; - | ^^^^^^^^^^^^------------------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:149:15 | LL | trait NonGenericAT { | ^^^^^^^^^^^^ +help: remove these generics + | +LL - type A = Box>; +LL + type A = Box; + | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:168:26 | LL | type B = Box>; - | ^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^ expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:159:15 | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ -- +help: remove this lifetime argument + | +LL - type B = Box>; +LL + type B = Box>; + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/wrong-number-of-args.rs:172:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^^^^^^^^^^^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:159:15 | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ +help: remove this generic argument + | +LL - type C = Box>; +LL + type C = Box>; + | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:185:26 @@ -577,29 +622,35 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:189:26 | LL | type B = Box>; - | ^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:181:15 | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ - +help: remove this generic argument + | +LL - type B = Box>; +LL + type B = Box>; + | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:193:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^--------------------- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^^^^^^^^^^ expected 0 lifetime arguments | note: trait defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:181:15 | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ +help: remove these generics + | +LL - type C = Box>; +LL + type C = Box; + | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:193:26 @@ -653,15 +704,18 @@ error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supp --> $DIR/wrong-number-of-args.rs:216:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- +help: remove this lifetime argument + | +LL - type C = Box>; +LL + type C = Box>; + | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:216:26 @@ -683,71 +737,86 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:227:26 | LL | type E = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - +help: remove this generic argument + | +LL - type E = Box>; +LL + type E = Box>; + | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:234:26 | LL | type F = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- +help: remove this lifetime argument + | +LL - type F = Box>; +LL + type F = Box>; + | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:238:26 | LL | type G = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - +help: remove this generic argument + | +LL - type G = Box>; +LL + type G = Box>; + | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:242:26 | LL | type H = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- +help: remove this lifetime argument + | +LL - type H = Box>; +LL + type H = Box>; + | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:242:26 | LL | type H = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - +help: remove this generic argument + | +LL - type H = Box>; +LL + type H = Box>; + | error[E0107]: trait takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:254:26 @@ -787,15 +856,18 @@ error[E0107]: trait takes 2 generic arguments but 3 generic arguments were suppl --> $DIR/wrong-number-of-args.rs:262:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^ -- help: remove this generic argument - | | - | expected 2 generic arguments + | ^^^^^^^^^^^^^^^^^ expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `A`, `B` --> $DIR/wrong-number-of-args.rs:250:15 | LL | trait GenericTypeTypeAT { | ^^^^^^^^^^^^^^^^^ - - +help: remove this generic argument + | +LL - type C = Box>; +LL + type C = Box>; + | error[E0107]: trait takes 2 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:277:26 @@ -911,9 +983,13 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/wrong-number-of-args.rs:318:18 | LL | type C = HashMap<'static>; - | ^^^^^^^--------- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^^^^ expected 0 lifetime arguments + | +help: remove these generics + | +LL - type C = HashMap<'static>; +LL + type C = HashMap; + | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:318:18 @@ -930,9 +1006,13 @@ error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments w --> $DIR/wrong-number-of-args.rs:324:18 | LL | type D = HashMap; - | ^^^^^^^ --- help: remove this generic argument - | | - | expected at most 3 generic arguments + | ^^^^^^^ expected at most 3 generic arguments + | +help: remove this generic argument + | +LL - type D = HashMap; +LL + type D = HashMap; + | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:328:18 @@ -973,9 +1053,13 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli --> $DIR/wrong-number-of-args.rs:342:18 | LL | type C = Result<'static>; - | ^^^^^^--------- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^^^ expected 0 lifetime arguments + | +help: remove these generics + | +LL - type C = Result<'static>; +LL + type C = Result; + | error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:342:18 @@ -992,9 +1076,13 @@ error[E0107]: enum takes 2 generic arguments but 3 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:348:18 | LL | type D = Result; - | ^^^^^^ ---- help: remove this generic argument - | | - | expected 2 generic arguments + | ^^^^^^ expected 2 generic arguments + | +help: remove this generic argument + | +LL - type D = Result; +LL + type D = Result; + | error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:352:18 diff --git a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index e8cd16bc3016..d184110c4534 100644 --- a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -2,9 +2,7 @@ error[E0107]: function takes 1 generic argument but 2 generic arguments were sup --> $DIR/explicit-generic-args-for-impl.rs:4:5 | LL | foo::("".to_string()); - | ^^^ ------ help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: function defined here, with 1 generic parameter: `T` --> $DIR/explicit-generic-args-for-impl.rs:1:4 @@ -12,6 +10,11 @@ note: function defined here, with 1 generic parameter: `T` LL | fn foo(_f: impl AsRef) {} | ^^^ - = note: `impl Trait` cannot be explicitly specified as a generic argument +help: remove this generic argument + | +LL - foo::("".to_string()); +LL + foo::("".to_string()); + | error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr index 1f8a0d5edd78..aba82084f225 100644 --- a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr @@ -38,29 +38,35 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/opaque-and-lifetime-mismatch.rs:4:17 | LL | fn bar() -> Wrapper; - | ^^^^^^^ ---------- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^^^^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ +help: remove this generic argument + | +LL - fn bar() -> Wrapper; +LL + fn bar() -> Wrapper<>; + | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/opaque-and-lifetime-mismatch.rs:18:17 | LL | fn foo() -> Wrapper; - | ^^^^^^^ ---------- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^^^^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ +help: remove this generic argument + | +LL - fn foo() -> Wrapper; +LL + fn foo() -> Wrapper<>; + | error[E0053]: method `bar` has an incompatible return type for trait --> $DIR/opaque-and-lifetime-mismatch.rs:10:17 @@ -93,15 +99,18 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/opaque-and-lifetime-mismatch.rs:24:17 | LL | fn foo() -> Wrapper { - | ^^^^^^^ ---------- help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^^^^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ +help: remove this generic argument + | +LL - fn foo() -> Wrapper { +LL + fn foo() -> Wrapper<> { + | error: aborting due to 8 previous errors diff --git a/tests/ui/issues/issue-18423.stderr b/tests/ui/issues/issue-18423.stderr index 2c6015eaa9d4..a73688205ac8 100644 --- a/tests/ui/issues/issue-18423.stderr +++ b/tests/ui/issues/issue-18423.stderr @@ -2,9 +2,13 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-18423.rs:4:8 | LL | x: Box<'a, isize> - | ^^^ -- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^^ expected 0 lifetime arguments + | +help: remove this lifetime argument + | +LL - x: Box<'a, isize> +LL + x: Box<, isize> + | error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-53251.stderr b/tests/ui/issues/issue-53251.stderr index 05ea63115896..db9df7d911c4 100644 --- a/tests/ui/issues/issue-53251.stderr +++ b/tests/ui/issues/issue-53251.stderr @@ -2,9 +2,7 @@ error[E0107]: associated function takes 0 generic arguments but 1 generic argume --> $DIR/issue-53251.rs:11:20 | LL | S::f::(); - | ^------- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments ... LL | impl_add!(a b); | -------------- in this macro invocation @@ -15,14 +13,17 @@ note: associated function defined here, with 0 generic parameters LL | fn f() {} | ^ = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove these generics + | +LL - S::f::(); +LL + S::f(); + | error[E0107]: associated function takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-53251.rs:11:20 | LL | S::f::(); - | ^------- help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments ... LL | impl_add!(a b); | -------------- in this macro invocation @@ -34,6 +35,11 @@ LL | fn f() {} | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove these generics + | +LL - S::f::(); +LL + S::f(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-60622.stderr b/tests/ui/issues/issue-60622.stderr index 43da2773940e..e694a92213c8 100644 --- a/tests/ui/issues/issue-60622.stderr +++ b/tests/ui/issues/issue-60622.stderr @@ -20,15 +20,18 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-60622.rs:10:7 | LL | b.a::<'_, T>(); - | ^ - help: remove this generic argument - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-60622.rs:6:8 | LL | fn a(&self) {} | ^ +help: remove this generic argument + | +LL - b.a::<'_, T>(); +LL + b.a::<'_, >(); + | error: aborting due to 2 previous errors diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr index 1b8f1c3fd6fa..de0a0631bf88 100644 --- a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr @@ -2,15 +2,18 @@ error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were --> $DIR/mismatched_arg_count.rs:9:29 | LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} - | ^^^^^ -- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^^^^^ expected 1 lifetime argument | note: type alias defined here, with 1 lifetime parameter: `'a` --> $DIR/mismatched_arg_count.rs:7:6 | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- +help: remove this lifetime argument + | +LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} +LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} + | error: aborting due to 1 previous error diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.stderr b/tests/ui/lifetimes/noisy-follow-up-erro.stderr index f549009a87c1..38465c7ac963 100644 --- a/tests/ui/lifetimes/noisy-follow-up-erro.stderr +++ b/tests/ui/lifetimes/noisy-follow-up-erro.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/noisy-follow-up-erro.rs:12:30 | LL | fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { - | ^^^ -- help: remove this lifetime argument - | | - | expected 2 lifetime arguments + | ^^^ expected 2 lifetime arguments | note: struct defined here, with 2 lifetime parameters: `'c`, `'d` --> $DIR/noisy-follow-up-erro.rs:1:8 | LL | struct Foo<'c, 'd>(&'c (), &'d ()); | ^^^ -- -- +help: remove this lifetime argument + | +LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { +LL + fn boom(&self, foo: &mut Foo<'_, '_, >) -> Result<(), &'a ()> { + | error[E0621]: explicit lifetime required in the type of `foo` --> $DIR/noisy-follow-up-erro.rs:14:9 diff --git a/tests/ui/methods/method-call-lifetime-args-fail.stderr b/tests/ui/methods/method-call-lifetime-args-fail.stderr index 645d8b8d14ad..d431e0721ccb 100644 --- a/tests/ui/methods/method-call-lifetime-args-fail.stderr +++ b/tests/ui/methods/method-call-lifetime-args-fail.stderr @@ -20,15 +20,18 @@ error[E0107]: method takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/method-call-lifetime-args-fail.rs:18:7 | LL | S.early::<'static, 'static, 'static>(); - | ^^^^^ ------- help: remove this lifetime argument - | | - | expected 2 lifetime arguments + | ^^^^^ expected 2 lifetime arguments | note: method defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/method-call-lifetime-args-fail.rs:6:8 | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- +help: remove this lifetime argument + | +LL - S.early::<'static, 'static, 'static>(); +LL + S.early::<'static, 'static, >(); + | error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/method-call-lifetime-args-fail.rs:27:15 @@ -220,15 +223,18 @@ error[E0107]: method takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/method-call-lifetime-args-fail.rs:65:8 | LL | S::early::<'static, 'static, 'static>(S); - | ^^^^^ ------- help: remove this lifetime argument - | | - | expected 2 lifetime arguments + | ^^^^^ expected 2 lifetime arguments | note: method defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/method-call-lifetime-args-fail.rs:6:8 | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- +help: remove this lifetime argument + | +LL - S::early::<'static, 'static, 'static>(S); +LL + S::early::<'static, 'static, >(S); + | error: aborting due to 18 previous errors diff --git a/tests/ui/resolve/issue-3214.stderr b/tests/ui/resolve/issue-3214.stderr index 5b57c1baf90b..614d3b21ff2c 100644 --- a/tests/ui/resolve/issue-3214.stderr +++ b/tests/ui/resolve/issue-3214.stderr @@ -12,15 +12,18 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-3214.rs:6:22 | LL | impl Drop for Foo { - | ^^^--- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/issue-3214.rs:2:12 | LL | struct Foo { | ^^^ +help: remove these generics + | +LL - impl Drop for Foo { +LL + impl Drop for Foo { + | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr index fa2e3da368bd..3d9df78b196e 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr @@ -2,15 +2,18 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params-cross-crate.rs:14:5 | LL | foo::(); - | ^^^--------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/auxiliary/cross-crate.rs:5:14 | LL | pub const fn foo() {} | ^^^ +help: remove these generics + | +LL - foo::(); +LL + foo(); + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params-cross-crate.rs:16:12 @@ -32,15 +35,18 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params-cross-crate.rs:7:5 | LL | foo::(); - | ^^^-------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/auxiliary/cross-crate.rs:5:14 | LL | pub const fn foo() {} | ^^^ +help: remove these generics + | +LL - foo::(); +LL + foo(); + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params-cross-crate.rs:9:12 diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr index fbb96dfd85e1..8412a3d0a8a0 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr @@ -16,15 +16,18 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params.rs:22:5 | LL | foo::(); - | ^^^--------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/no-explicit-const-params.rs:3:10 | LL | const fn foo() {} | ^^^ +help: remove these generics + | +LL - foo::(); +LL + foo(); + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params.rs:24:12 @@ -55,15 +58,18 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params.rs:15:5 | LL | foo::(); - | ^^^-------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/no-explicit-const-params.rs:3:10 | LL | const fn foo() {} | ^^^ +help: remove these generics + | +LL - foo::(); +LL + foo(); + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params.rs:17:12 diff --git a/tests/ui/seq-args.stderr b/tests/ui/seq-args.stderr index a5b0f8e98dca..bb46a11d9026 100644 --- a/tests/ui/seq-args.stderr +++ b/tests/ui/seq-args.stderr @@ -2,29 +2,35 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/seq-args.rs:4:13 | LL | impl Seq for Vec { - | ^^^--- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/seq-args.rs:2:11 | LL | trait Seq { } | ^^^ +help: remove these generics + | +LL - impl Seq for Vec { +LL + impl Seq for Vec { + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/seq-args.rs:9:10 | LL | impl Seq for u32 { - | ^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/seq-args.rs:2:11 | LL | trait Seq { } | ^^^ +help: remove these generics + | +LL - impl Seq for u32 { +LL + impl Seq for u32 { + | error: aborting due to 2 previous errors diff --git a/tests/ui/structs/struct-path-associated-type.stderr b/tests/ui/structs/struct-path-associated-type.stderr index 0c9d2aad5d82..edcb0bcc8332 100644 --- a/tests/ui/structs/struct-path-associated-type.stderr +++ b/tests/ui/structs/struct-path-associated-type.stderr @@ -8,15 +8,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/struct-path-associated-type.rs:14:16 | LL | let z = T::A:: {}; - | ^------ help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/struct-path-associated-type.rs:4:10 | LL | type A; | ^ +help: remove these generics + | +LL - let z = T::A:: {}; +LL + let z = T::A {}; + | error[E0071]: expected struct, variant or union type, found associated type --> $DIR/struct-path-associated-type.rs:14:13 @@ -34,15 +37,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/struct-path-associated-type.rs:25:16 | LL | let z = T::A:: {}; - | ^------ help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/struct-path-associated-type.rs:4:10 | LL | type A; | ^ +help: remove these generics + | +LL - let z = T::A:: {}; +LL + let z = T::A {}; + | error[E0223]: ambiguous associated type --> $DIR/struct-path-associated-type.rs:32:13 diff --git a/tests/ui/structs/structure-constructor-type-mismatch.stderr b/tests/ui/structs/structure-constructor-type-mismatch.stderr index cb9574873473..50ebd86a2166 100644 --- a/tests/ui/structs/structure-constructor-type-mismatch.stderr +++ b/tests/ui/structs/structure-constructor-type-mismatch.stderr @@ -68,15 +68,18 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/structure-constructor-type-mismatch.rs:48:15 | LL | let pt3 = PointF:: { - | ^^^^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/structure-constructor-type-mismatch.rs:6:6 | LL | type PointF = Point; | ^^^^^^ +help: remove these generics + | +LL - let pt3 = PointF:: { +LL + let pt3 = PointF { + | error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:49:12 @@ -104,15 +107,18 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/structure-constructor-type-mismatch.rs:54:9 | LL | PointF:: { .. } => {} - | ^^^^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/structure-constructor-type-mismatch.rs:6:6 | LL | type PointF = Point; | ^^^^^^ +help: remove these generics + | +LL - PointF:: { .. } => {} +LL + PointF { .. } => {} + | error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:54:9 diff --git a/tests/ui/suggestions/issue-101421.stderr b/tests/ui/suggestions/issue-101421.stderr index ececba5fb1ba..1a64f5313cf5 100644 --- a/tests/ui/suggestions/issue-101421.stderr +++ b/tests/ui/suggestions/issue-101421.stderr @@ -2,15 +2,18 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-101421.rs:10:8 | LL | ().f::<()>(()); - | ^------ help: remove these generics - | | - | expected 0 generic arguments + | ^ expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-101421.rs:2:8 | LL | fn f(&self, _: ()); | ^ +help: remove these generics + | +LL - ().f::<()>(()); +LL + ().f(()); + | error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/issue-104287.stderr b/tests/ui/suggestions/issue-104287.stderr index ed59b2e7a2d3..b65d3ad4d318 100644 --- a/tests/ui/suggestions/issue-104287.stderr +++ b/tests/ui/suggestions/issue-104287.stderr @@ -2,15 +2,18 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-104287.rs:10:5 | LL | foo::<()>(x); - | ^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-104287.rs:6:8 | LL | fn foo(&self) {} | ^^^ +help: remove these generics + | +LL - foo::<()>(x); +LL + foo(x); + | error[E0425]: cannot find function `foo` in this scope --> $DIR/issue-104287.rs:10:5 diff --git a/tests/ui/suggestions/issue-89064.stderr b/tests/ui/suggestions/issue-89064.stderr index be09dd895120..f1bb3c2adc74 100644 --- a/tests/ui/suggestions/issue-89064.stderr +++ b/tests/ui/suggestions/issue-89064.stderr @@ -46,15 +46,18 @@ error[E0107]: associated function takes 0 generic arguments but 1 generic argume --> $DIR/issue-89064.rs:27:21 | LL | let _ = A::::foo::(); - | ^^^----- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: associated function defined here, with 0 generic parameters --> $DIR/issue-89064.rs:4:8 | LL | fn foo() {} | ^^^ +help: remove these generics + | +LL - let _ = A::::foo::(); +LL + let _ = A::::foo(); + | error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-89064.rs:31:16 diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index 06e2fa5d4d1f..9193faeb1aa9 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -117,15 +117,18 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:40:58 | LL | impl, U> YetAnotherTrait for Struct {} - | ^^^^^^ - help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:8 | LL | struct Struct> { | ^^^^^^ - +help: remove this generic argument + | +LL - impl, U> YetAnotherTrait for Struct {} +LL + impl, U> YetAnotherTrait for Struct {} + | error: aborting due to 9 previous errors diff --git a/tests/ui/traits/object/vs-lifetime.stderr b/tests/ui/traits/object/vs-lifetime.stderr index a69cd140807f..aab4845a2742 100644 --- a/tests/ui/traits/object/vs-lifetime.stderr +++ b/tests/ui/traits/object/vs-lifetime.stderr @@ -8,15 +8,18 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/vs-lifetime.rs:11:12 | LL | let _: S<'static, 'static>; - | ^ ------- help: remove this lifetime argument - | | - | expected 1 lifetime argument + | ^ expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/vs-lifetime.rs:4:8 | LL | struct S<'a, T>(&'a u8, T); | ^ -- +help: remove this lifetime argument + | +LL - let _: S<'static, 'static>; +LL + let _: S<'static, >; + | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/vs-lifetime.rs:11:12 diff --git a/tests/ui/traits/test-2.stderr b/tests/ui/traits/test-2.stderr index 3972e539776c..9916cf97fca9 100644 --- a/tests/ui/traits/test-2.stderr +++ b/tests/ui/traits/test-2.stderr @@ -2,29 +2,35 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/test-2.rs:9:8 | LL | 10.dup::(); - | ^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^ expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/test-2.rs:4:16 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^ +help: remove these generics + | +LL - 10.dup::(); +LL + 10.dup(); + | error[E0107]: method takes 1 generic argument but 2 generic arguments were supplied --> $DIR/test-2.rs:11:8 | LL | 10.blah::(); - | ^^^^ --- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^^ expected 1 generic argument | note: method defined here, with 1 generic parameter: `X` --> $DIR/test-2.rs:4:39 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^^ - +help: remove this generic argument + | +LL - 10.blah::(); +LL + 10.blah::(); + | error[E0038]: the trait `bar` cannot be made into an object --> $DIR/test-2.rs:13:22 diff --git a/tests/ui/transmutability/issue-101739-2.stderr b/tests/ui/transmutability/issue-101739-2.stderr index 519a374dc229..93323049760a 100644 --- a/tests/ui/transmutability/issue-101739-2.stderr +++ b/tests/ui/transmutability/issue-101739-2.stderr @@ -1,13 +1,16 @@ error[E0107]: trait takes at most 2 generic arguments but 5 generic arguments were supplied --> $DIR/issue-101739-2.rs:17:14 | -LL | Dst: BikeshedIntrinsicFrom< - | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments -... -LL | / ASSUME_LIFETIMES, -LL | | ASSUME_VALIDITY, -LL | | ASSUME_VISIBILITY, - | |_____________________________- help: remove these generic arguments +LL | Dst: BikeshedIntrinsicFrom< + | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments + | +help: remove these generic arguments + | +LL - ASSUME_LIFETIMES, +LL - ASSUME_VALIDITY, +LL - ASSUME_VISIBILITY, +LL + , + | error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index 96a5c1327633..a2dd6805f3d5 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -308,29 +308,35 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:64:5 | LL | AliasFixed::<()>::TSVariant(()); - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::TSVariant(()); +LL + AliasFixed::TSVariant(()); + | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:66:5 | LL | AliasFixed::<()>::TSVariant::<()>(()); - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::TSVariant::<()>(()); +LL + AliasFixed::TSVariant::<()>(()); + | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:66:35 @@ -399,29 +405,35 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:82:5 | LL | AliasFixed::<()>::SVariant { v: () }; - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::SVariant { v: () }; +LL + AliasFixed::SVariant { v: () }; + | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:84:5 | LL | AliasFixed::<()>::SVariant::<()> { v: () }; - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::SVariant::<()> { v: () }; +LL + AliasFixed::SVariant::<()> { v: () }; + | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:84:34 @@ -474,29 +486,35 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:100:5 | LL | AliasFixed::<()>::UVariant; - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::UVariant; +LL + AliasFixed::UVariant; + | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:102:5 | LL | AliasFixed::<()>::UVariant::<()>; - | ^^^^^^^^^^------ help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^^^ expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ +help: remove these generics + | +LL - AliasFixed::<()>::UVariant::<()>; +LL + AliasFixed::UVariant::<()>; + | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:102:34 diff --git a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr index 9a9b2a68dbed..3be83682ec9a 100644 --- a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr +++ b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr @@ -2,69 +2,99 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/typeck-builtin-bound-type-parameters.rs:1:11 | LL | fn foo1, U>(x: T) {} - | ^^^^--- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - fn foo1, U>(x: T) {} +LL + fn foo1(x: T) {} + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^---------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - trait Trait: Copy {} +LL + trait Trait: Copy {} + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^---------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - trait Trait: Copy {} +LL + trait Trait: Copy {} + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^---------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: remove these generics + | +LL - trait Trait: Copy {} +LL + trait Trait: Copy {} + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:9:21 | LL | struct MyStruct1>(T); - | ^^^^--- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments + | +help: remove these generics + | +LL - struct MyStruct1>(T); +LL + struct MyStruct1(T); + | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:12:25 | LL | struct MyStruct2<'a, T: Copy<'a>>(&'a T); - | ^^^^---- help: remove these generics - | | - | expected 0 lifetime arguments + | ^^^^ expected 0 lifetime arguments + | +help: remove these generics + | +LL - struct MyStruct2<'a, T: Copy<'a>>(&'a T); +LL + struct MyStruct2<'a, T: Copy>(&'a T); + | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:15:15 | LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} - | ^^^^ -- help: remove this lifetime argument - | | - | expected 0 lifetime arguments + | ^^^^ expected 0 lifetime arguments + | +help: remove this lifetime argument + | +LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} +LL + fn foo2<'a, T:Copy<, U>, U>(x: T) {} + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:15:15 | LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} - | ^^^^ - help: remove this generic argument - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments + | +help: remove this generic argument + | +LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} +LL + fn foo2<'a, T:Copy<'a, >, U>(x: T) {} + | error: aborting due to 8 previous errors diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr index e4b1c02c2014..65f07bb08320 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/typeck_type_placeholder_lifetime_1.rs:9:12 | LL | let c: Foo<_, _> = Foo { r: &5 }; - | ^^^ - help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/typeck_type_placeholder_lifetime_1.rs:4:8 | LL | struct Foo<'a, T:'a> { | ^^^ - +help: remove this generic argument + | +LL - let c: Foo<_, _> = Foo { r: &5 }; +LL + let c: Foo<_, > = Foo { r: &5 }; + | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr index fcb5ecc4042b..b07cc225ba87 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr @@ -2,15 +2,18 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/typeck_type_placeholder_lifetime_2.rs:9:12 | LL | let c: Foo<_, usize> = Foo { r: &5 }; - | ^^^ ----- help: remove this generic argument - | | - | expected 1 generic argument + | ^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/typeck_type_placeholder_lifetime_2.rs:4:8 | LL | struct Foo<'a, T:'a> { | ^^^ - +help: remove this generic argument + | +LL - let c: Foo<_, usize> = Foo { r: &5 }; +LL + let c: Foo<_, > = Foo { r: &5 }; + | error: aborting due to 1 previous error diff --git a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr index 2338871218b1..0ae92d204b6f 100644 --- a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr +++ b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr @@ -34,15 +34,18 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/ufcs-qpath-missing-params.rs:17:26 | LL | ::into_cow::("foo".to_string()); - | ^^^^^^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^^^^^ expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/ufcs-qpath-missing-params.rs:4:8 | LL | fn into_cow(self) -> Cow<'a, B>; | ^^^^^^^^ +help: remove these generics + | +LL - ::into_cow::("foo".to_string()); +LL + ::into_cow("foo".to_string()); + | error: aborting due to 3 previous errors diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr index 5a2de132d70e..ac56d1d05fae 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr @@ -2,15 +2,18 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:17 | LL | fn foo1(_: &dyn Zero()) { - | ^^^^-- help: remove these parenthetical generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ +help: remove these parenthetical generics + | +LL - fn foo1(_: &dyn Zero()) { +LL + fn foo1(_: &dyn Zero) { + | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:17 @@ -22,43 +25,52 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:10:17 | LL | fn foo2(_: &dyn Zero) { - | ^^^^------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ +help: remove these generics + | +LL - fn foo2(_: &dyn Zero) { +LL + fn foo2(_: &dyn Zero) { + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:14:17 | LL | fn foo3(_: &dyn Zero < usize >) { - | ^^^^-------------- help: remove these generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ +help: remove these generics + | +LL - fn foo3(_: &dyn Zero < usize >) { +LL + fn foo3(_: &dyn Zero) { + | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:18:17 | LL | fn foo4(_: &dyn Zero(usize)) { - | ^^^^------- help: remove these parenthetical generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ +help: remove these parenthetical generics + | +LL - fn foo4(_: &dyn Zero(usize)) { +LL + fn foo4(_: &dyn Zero) { + | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:18:17 @@ -70,15 +82,18 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:23:17 | LL | fn foo5(_: &dyn Zero ( usize )) { - | ^^^^-------------- help: remove these parenthetical generics - | | - | expected 0 generic arguments + | ^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ +help: remove these parenthetical generics + | +LL - fn foo5(_: &dyn Zero ( usize )) { +LL + fn foo5(_: &dyn Zero) { + | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:23:17 diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr index 130b193d69c9..3736f25a51ff 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr @@ -2,15 +2,18 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:8 | LL | fn f isize>(x: F) {} - | ^^^^^------- help: remove these parenthetical generics - | | - | expected 0 generic arguments + | ^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-trait.rs:3:7 | LL | trait Trait {} | ^^^^^ +help: remove these parenthetical generics + | +LL - fn f isize>(x: F) {} +LL + fn f isize>(x: F) {} + | error[E0220]: associated type `Output` not found for `Trait` --> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:24 From 5c2b36a21cabafb1f08e278f4c6ed61753a654cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 5 Jul 2024 01:28:24 +0000 Subject: [PATCH 21/54] Change suggestion message wording --- .../errors/wrong_number_of_generic_args.rs | 8 +-- .../invalid_const_in_lifetime_position.stderr | 6 +- tests/rustdoc-ui/mismatched_arg_count.stderr | 2 +- .../argument-suggestions/issue-100154.stderr | 2 +- ...ssue-82126-mismatched-subst-and-hir.stderr | 4 +- .../transmutable-ice-110969.stderr | 2 +- .../generic_arg_infer/infer-arg-test.stderr | 2 +- .../const_kind_expr/issue_114151.stderr | 2 +- .../generic_const_exprs/issue-102768.stderr | 6 +- .../incorrect-number-of-const-args.stderr | 2 +- .../invalid-const-arg-for-type-param.stderr | 4 +- .../invalid-constant-in-args.stderr | 2 +- tests/ui/constructor-lifetime-args.stderr | 4 +- tests/ui/consts/effect_param.stderr | 8 +-- tests/ui/error-codes/E0107.rs | 16 +++--- tests/ui/error-codes/E0107.stderr | 16 +++--- .../gat-trait-path-parenthesised-args.stderr | 6 +- .../parameter_number_and_kind.stderr | 4 +- ...it-path-type-error-once-implemented.stderr | 6 +- .../generics/bad-mid-path-type-params.stderr | 10 ++-- .../generics/foreign-generic-mismatch.stderr | 2 +- .../generic-arg-mismatch-recover.stderr | 6 +- ...eric-impl-more-params-with-defaults.stderr | 2 +- ...eric-type-more-params-with-defaults.stderr | 2 +- tests/ui/generics/wrong-number-of-args.rs | 22 ++++---- tests/ui/generics/wrong-number-of-args.stderr | 56 +++++++++---------- .../explicit-generic-args-for-impl.stderr | 2 +- .../opaque-and-lifetime-mismatch.stderr | 6 +- tests/ui/issues/issue-18423.stderr | 2 +- tests/ui/issues/issue-53251.stderr | 4 +- tests/ui/issues/issue-60622.stderr | 2 +- .../mismatched_arg_count.stderr | 2 +- .../ui/lifetimes/noisy-follow-up-erro.stderr | 2 +- .../method-call-lifetime-args-fail.stderr | 4 +- tests/ui/resolve/issue-3214.stderr | 2 +- ...o-explicit-const-params-cross-crate.stderr | 4 +- .../effects/no-explicit-const-params.stderr | 4 +- tests/ui/seq-args.stderr | 4 +- .../struct-path-associated-type.stderr | 4 +- ...structure-constructor-type-mismatch.stderr | 4 +- tests/ui/suggestions/issue-101421.stderr | 2 +- tests/ui/suggestions/issue-104287.stderr | 2 +- tests/ui/suggestions/issue-89064.rs | 8 +-- tests/ui/suggestions/issue-89064.stderr | 8 +-- ...-generic-to-trait-in-method-with-params.rs | 2 +- ...eric-to-trait-in-method-with-params.stderr | 2 +- ...assoc-type-suggestion-in-trait-impl.stderr | 2 +- tests/ui/traits/object/vs-lifetime.stderr | 2 +- tests/ui/traits/test-2.stderr | 4 +- .../ui/transmutability/issue-101739-2.stderr | 2 +- .../enum-variant-generic-args.stderr | 12 ++-- ...ypeck-builtin-bound-type-parameters.stderr | 16 +++--- .../typeck_type_placeholder_lifetime_1.stderr | 2 +- .../typeck_type_placeholder_lifetime_2.stderr | 2 +- .../ui/ufcs/ufcs-qpath-missing-params.stderr | 2 +- ...wrong-number-number-type-parameters.stderr | 10 ++-- .../unboxed-closure-sugar-wrong-trait.stderr | 2 +- 57 files changed, 163 insertions(+), 165 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index c2d5627f2b04..6c2ec1acdf96 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -947,8 +947,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args(); let msg_lifetimes = format!( - "remove {these} lifetime argument{s}", - these = pluralize!("this", num_redundant_lt_args), + "remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args), ); @@ -989,8 +988,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let num_redundant_gen_args = gen_arg_spans.len() - self.num_expected_type_or_const_args(); let msg_types_or_consts = format!( - "remove {these} generic argument{s}", - these = pluralize!("this", num_redundant_gen_args), + "remove the unnecessary generic argument{s}", s = pluralize!(num_redundant_gen_args), ); @@ -1036,7 +1034,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { .with_lo(self.path_segment.ident.span.hi()); let msg = format!( - "remove these {}generics", + "remove the unnecessary {}generics", if self.gen_args.parenthesized == hir::GenericArgsParentheses::ParenSugar { "parenthetical " } else { diff --git a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr index ff73d3d5ddd6..755a0bba508f 100644 --- a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr +++ b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr @@ -25,7 +25,7 @@ note: associated type defined here, with 0 generic parameters | LL | type Y<'a>; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - fn f<'a>(arg : Box = &'a ()>>) {} LL + fn f<'a>(arg : Box>) {} @@ -60,7 +60,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f<'a>(arg : Box = &'a ()>>) {} LL + fn f<'a>(arg : Box>) {} @@ -95,7 +95,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f<'a>(arg : Box = &'a ()>>) {} LL + fn f<'a>(arg : Box>) {} diff --git a/tests/rustdoc-ui/mismatched_arg_count.stderr b/tests/rustdoc-ui/mismatched_arg_count.stderr index c58ff7a14df4..8e7def04f527 100644 --- a/tests/rustdoc-ui/mismatched_arg_count.stderr +++ b/tests/rustdoc-ui/mismatched_arg_count.stderr @@ -9,7 +9,7 @@ note: type alias defined here, with 1 lifetime parameter: `'a` | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} diff --git a/tests/ui/argument-suggestions/issue-100154.stderr b/tests/ui/argument-suggestions/issue-100154.stderr index 1496d994ef35..8a650099b818 100644 --- a/tests/ui/argument-suggestions/issue-100154.stderr +++ b/tests/ui/argument-suggestions/issue-100154.stderr @@ -10,7 +10,7 @@ note: function defined here, with 0 generic parameters LL | fn foo(i: impl std::fmt::Display) {} | ^^^ = note: `impl Trait` cannot be explicitly specified as a generic argument -help: remove these generics +help: remove the unnecessary generics | LL - foo::<()>(()); LL + foo(()); diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index c50e3fb64059..aaca4dc91c93 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -9,7 +9,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct LockedMarket(T); | ^^^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { @@ -43,7 +43,7 @@ note: struct defined here, with 0 lifetime parameters LL | struct LockedMarket(T); | ^^^^^^^^^^^^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr index 91a1053bb6d1..3f32b0eb6746 100644 --- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr +++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr @@ -4,7 +4,7 @@ error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments we LL | Dst: BikeshedIntrinsicFrom, | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments | -help: remove this generic argument +help: remove the unnecessary generic argument | LL - Dst: BikeshedIntrinsicFrom, LL + Dst: BikeshedIntrinsicFrom, diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr index f891bbea21ef..d8e794a7a652 100644 --- a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr +++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr @@ -30,7 +30,7 @@ note: struct defined here, with 2 generic parameters: `T`, `N` | LL | struct All<'a, T, const N: usize> { | ^^^ - -------------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let a: All<_, _, _>; LL + let a: All<_, _, >; diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr index 78d32b57f87f..a7232ef780e3 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr @@ -9,7 +9,7 @@ note: function defined here, with 1 generic parameter: `N` | LL | fn foo( | ^^^ -------------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - foo::<_, L>([(); L + 1 + L]); LL + foo::<_, >([(); L + 1 + L]); diff --git a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr index 6bd6eb4e00e6..416219117522 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr @@ -25,7 +25,7 @@ note: associated type defined here, with 0 generic parameters | LL | type Y<'a>; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg: Box = &'a ()>>) {} LL + fn f2<'a>(arg: Box>) {} @@ -60,7 +60,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg: Box = &'a ()>>) {} LL + fn f2<'a>(arg: Box>) {} @@ -95,7 +95,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg: Box = &'a ()>>) {} LL + fn f2<'a>(arg: Box>) {} diff --git a/tests/ui/const-generics/incorrect-number-of-const-args.stderr b/tests/ui/const-generics/incorrect-number-of-const-args.stderr index 97eb47275c2b..05c4a0a1a727 100644 --- a/tests/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/tests/ui/const-generics/incorrect-number-of-const-args.stderr @@ -27,7 +27,7 @@ note: function defined here, with 2 generic parameters: `X`, `Y` | LL | fn foo() -> usize { | ^^^ -------------- -------------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - foo::<0, 0, 0>(); LL + foo::<0, 0, >(); diff --git a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr index d4f899f83773..dadb67343312 100644 --- a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr +++ b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr @@ -8,7 +8,7 @@ help: consider moving this generic argument to the `TryInto` trait, which takes | LL | let _: u32 = TryInto::<32>::try_into(5i32).unwrap(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: remove these generics +help: remove the unnecessary generics | LL - let _: u32 = 5i32.try_into::<32>().unwrap(); LL + let _: u32 = 5i32.try_into().unwrap(); @@ -34,7 +34,7 @@ note: struct defined here, with 0 generic parameters | LL | struct S; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - S::<0>; LL + S; diff --git a/tests/ui/const-generics/invalid-constant-in-args.stderr b/tests/ui/const-generics/invalid-constant-in-args.stderr index ed715257ac1c..10334e0d896c 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.stderr +++ b/tests/ui/const-generics/invalid-constant-in-args.stderr @@ -4,7 +4,7 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl LL | let _: Cell<&str, "a"> = Cell::new(""); | ^^^^ expected 1 generic argument | -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let _: Cell<&str, "a"> = Cell::new(""); LL + let _: Cell<&str, > = Cell::new(""); diff --git a/tests/ui/constructor-lifetime-args.stderr b/tests/ui/constructor-lifetime-args.stderr index 9e0bc3c6c1a6..37b13cd048fe 100644 --- a/tests/ui/constructor-lifetime-args.stderr +++ b/tests/ui/constructor-lifetime-args.stderr @@ -27,7 +27,7 @@ note: struct defined here, with 2 lifetime parameters: `'a`, `'b` | LL | struct S<'a, 'b>(&'a u8, &'b u8); | ^ -- -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - S::<'static, 'static, 'static>(&0, &0); LL + S::<'static, 'static, >(&0, &0); @@ -62,7 +62,7 @@ note: enum defined here, with 2 lifetime parameters: `'a`, `'b` | LL | enum E<'a, 'b> { | ^ -- -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - E::V::<'static, 'static, 'static>(&0); LL + E::V::<'static, 'static, >(&0); diff --git a/tests/ui/consts/effect_param.stderr b/tests/ui/consts/effect_param.stderr index 3777e20e4c0a..fafc20b41924 100644 --- a/tests/ui/consts/effect_param.stderr +++ b/tests/ui/consts/effect_param.stderr @@ -4,7 +4,7 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli LL | i8::checked_sub::(42, 43); | ^^^^^^^^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - i8::checked_sub::(42, 43); LL + i8::checked_sub(42, 43); @@ -16,7 +16,7 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli LL | i8::checked_sub::(42, 43); | ^^^^^^^^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - i8::checked_sub::(42, 43); LL + i8::checked_sub(42, 43); @@ -28,7 +28,7 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli LL | i8::checked_sub::(42, 43); | ^^^^^^^^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - i8::checked_sub::(42, 43); LL + i8::checked_sub(42, 43); @@ -40,7 +40,7 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli LL | i8::checked_sub::(42, 43); | ^^^^^^^^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - i8::checked_sub::(42, 43); LL + i8::checked_sub(42, 43); diff --git a/tests/ui/error-codes/E0107.rs b/tests/ui/error-codes/E0107.rs index fd23e7c00f2b..161360a50128 100644 --- a/tests/ui/error-codes/E0107.rs +++ b/tests/ui/error-codes/E0107.rs @@ -16,35 +16,35 @@ struct Baz<'a, 'b, 'c> { bar: Bar<'a>, //~^ ERROR enum takes 0 lifetime arguments - //~| HELP remove these generics + //~| HELP remove the unnecessary generics foo2: Foo<'a, 'b, 'c>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove these lifetime arguments + //~| HELP remove the lifetime arguments qux1: Qux<'a, 'b, i32>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove this lifetime argument + //~| HELP remove the lifetime argument qux2: Qux<'a, i32, 'b>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove this lifetime argument + //~| HELP remove the lifetime argument qux3: Qux<'a, 'b, 'c, i32>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove these lifetime arguments + //~| HELP remove the lifetime arguments qux4: Qux<'a, i32, 'b, 'c>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove these lifetime arguments + //~| HELP remove the lifetime arguments qux5: Qux<'a, 'b, i32, 'c>, //~^ ERROR struct takes 1 lifetime argument - //~| HELP remove this lifetime argument + //~| HELP remove the lifetime argument quux: Quux<'a, i32, 'b>, //~^ ERROR struct takes 0 lifetime arguments - //~| HELP remove this lifetime argument + //~| HELP remove the lifetime argument } pub trait T { diff --git a/tests/ui/error-codes/E0107.stderr b/tests/ui/error-codes/E0107.stderr index c6317270f9b1..d8bd96e0ad46 100644 --- a/tests/ui/error-codes/E0107.stderr +++ b/tests/ui/error-codes/E0107.stderr @@ -27,7 +27,7 @@ note: enum defined here, with 0 lifetime parameters | LL | enum Bar { | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - bar: Bar<'a>, LL + bar: Bar, @@ -44,7 +44,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Foo<'a>(&'a str); | ^^^ -- -help: remove these lifetime arguments +help: remove the lifetime arguments | LL - foo2: Foo<'a, 'b, 'c>, LL + foo2: Foo<'a, >, @@ -61,7 +61,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - qux1: Qux<'a, 'b, i32>, LL + qux1: Qux<'a, , i32>, @@ -78,7 +78,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - qux2: Qux<'a, i32, 'b>, LL + qux2: Qux<'a, i32, >, @@ -95,7 +95,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove these lifetime arguments +help: remove the lifetime arguments | LL - qux3: Qux<'a, 'b, 'c, i32>, LL + qux3: Qux<'a, , i32>, @@ -112,7 +112,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove these lifetime arguments +help: remove the lifetime arguments | LL - qux4: Qux<'a, i32, 'b, 'c>, LL + qux4: Qux<'a, i32, >, @@ -129,7 +129,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - qux5: Qux<'a, 'b, i32, 'c>, LL + qux5: Qux<'a, , i32, 'c>, @@ -146,7 +146,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct Quux(T); | ^^^^ -help: remove this lifetime argument +help: remove the lifetime argument | LL - quux: Quux<'a, i32, 'b>, LL + quux: Quux<, i32, 'b>, diff --git a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr index 18f37207ee55..252d81fa6f35 100644 --- a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr +++ b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr @@ -50,7 +50,7 @@ note: associated type defined here, with 0 generic parameters | LL | type Y<'a>; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - fn foo<'a>(arg: Box>) {} LL + fn foo<'a>(arg: Box>) {} @@ -85,7 +85,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn foo<'a>(arg: Box>) {} LL + fn foo<'a>(arg: Box>) {} @@ -120,7 +120,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn foo<'a>(arg: Box>) {} LL + fn foo<'a>(arg: Box>) {} diff --git a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr index 9eb0b8ca641c..7b7f21b00c5a 100644 --- a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr +++ b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr @@ -9,7 +9,7 @@ note: associated type defined here, with 1 lifetime parameter: `'a` | LL | type E<'a, T>; | ^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type FErr1 = Self::E<'static, 'static>; LL + type FErr1 = Self::E<'static, >; @@ -42,7 +42,7 @@ note: associated type defined here, with 1 generic parameter: `T` | LL | type E<'a, T>; | ^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type FErr2 = Self::E<'static, T, u32>; LL + type FErr2 = Self::E<'static, T, >; diff --git a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr index f73022922a5b..6ea96b6228ef 100644 --- a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr +++ b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr @@ -25,7 +25,7 @@ note: associated type defined here, with 0 generic parameters | LL | type Y<'a>; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg : Box = &'a ()>>) {} LL + fn f2<'a>(arg : Box>) {} @@ -60,7 +60,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg : Box = &'a ()>>) {} LL + fn f2<'a>(arg : Box>) {} @@ -95,7 +95,7 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - fn f2<'a>(arg : Box = &'a ()>>) {} LL + fn f2<'a>(arg : Box>) {} diff --git a/tests/ui/generics/bad-mid-path-type-params.stderr b/tests/ui/generics/bad-mid-path-type-params.stderr index 7f4ba781e6ab..ba1d48f1210b 100644 --- a/tests/ui/generics/bad-mid-path-type-params.stderr +++ b/tests/ui/generics/bad-mid-path-type-params.stderr @@ -9,7 +9,7 @@ note: associated function defined here, with 1 generic parameter: `U` | LL | fn new(x: T, _: U) -> S { | ^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let _ = S::new::(1, 1.0); LL + let _ = S::new::(1, 1.0); @@ -26,7 +26,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct S { | ^ -help: remove this lifetime argument +help: remove the lifetime argument | LL - let _ = S::<'a,isize>::new::(1, 1.0); LL + let _ = S::<,isize>::new::(1, 1.0); @@ -43,7 +43,7 @@ note: associated function defined here, with 1 generic parameter: `U` | LL | fn new(x: T, y: U) -> Self; | ^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let _: S2 = Trait::new::(1, 1.0); LL + let _: S2 = Trait::new::(1, 1.0); @@ -60,7 +60,7 @@ note: trait defined here, with 0 lifetime parameters | LL | trait Trait { | ^^^^^ -help: remove this lifetime argument +help: remove the lifetime argument | LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); LL + let _: S2 = Trait::<,isize>::new::(1, 1.0); @@ -77,7 +77,7 @@ note: associated function defined here, with 1 generic parameter: `U` | LL | fn new(x: T, y: U) -> Self; | ^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); LL + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); diff --git a/tests/ui/generics/foreign-generic-mismatch.stderr b/tests/ui/generics/foreign-generic-mismatch.stderr index 7e8e854d6424..740963aeec54 100644 --- a/tests/ui/generics/foreign-generic-mismatch.stderr +++ b/tests/ui/generics/foreign-generic-mismatch.stderr @@ -27,7 +27,7 @@ note: function defined here, with 1 lifetime parameter: `'a` | LL | pub fn lt_arg<'a: 'a>() {} | ^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - foreign_generic_mismatch::lt_arg::<'static, 'static>(); LL + foreign_generic_mismatch::lt_arg::<'static, >(); diff --git a/tests/ui/generics/generic-arg-mismatch-recover.stderr b/tests/ui/generics/generic-arg-mismatch-recover.stderr index cb25fa7af40a..e8c2a4665f3d 100644 --- a/tests/ui/generics/generic-arg-mismatch-recover.stderr +++ b/tests/ui/generics/generic-arg-mismatch-recover.stderr @@ -9,7 +9,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Foo<'a, T: 'a>(&'a T); | ^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - Foo::<'static, 'static, ()>(&0); LL + Foo::<'static, , ()>(&0); @@ -26,7 +26,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Bar<'a>(&'a ()); | ^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - Bar::<'static, 'static, ()>(&()); LL + Bar::<'static, , ()>(&()); @@ -43,7 +43,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Bar<'a>(&'a ()); | ^^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - Bar::<'static, 'static, ()>(&()); LL + Bar::<'static, 'static, >(&()); diff --git a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr index edbe7a5e139c..b0973c477ff4 100644 --- a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr @@ -9,7 +9,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A` | LL | struct Vec( | ^^^ - -------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - Vec::::new(); LL + Vec::::new(); diff --git a/tests/ui/generics/generic-type-more-params-with-defaults.stderr b/tests/ui/generics/generic-type-more-params-with-defaults.stderr index 27752af1ad6c..e83a433b0605 100644 --- a/tests/ui/generics/generic-type-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-type-more-params-with-defaults.stderr @@ -9,7 +9,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A` | LL | struct Vec( | ^^^ - -------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let _: Vec; LL + let _: Vec; diff --git a/tests/ui/generics/wrong-number-of-args.rs b/tests/ui/generics/wrong-number-of-args.rs index 95463d1c32c3..6524bd538b6b 100644 --- a/tests/ui/generics/wrong-number-of-args.rs +++ b/tests/ui/generics/wrong-number-of-args.rs @@ -5,19 +5,19 @@ mod no_generics { type B = Ty<'static>; //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument - //~| HELP remove these generics + //~| HELP remove the unnecessary generics type C = Ty<'static, usize>; //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument //~| ERROR struct takes 0 generic arguments but 1 generic argument - //~| HELP remove this lifetime argument - //~| HELP remove this generic argument + //~| HELP remove the lifetime argument + //~| HELP remove the unnecessary generic argument type D = Ty<'static, usize, { 0 }>; //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument //~| ERROR struct takes 0 generic arguments but 2 generic arguments - //~| HELP remove this lifetime argument - //~| HELP remove these generic arguments + //~| HELP remove the lifetime argument + //~| HELP remove the unnecessary generic arguments } mod type_and_type { @@ -35,7 +35,7 @@ mod type_and_type { type D = Ty; //~^ ERROR struct takes 2 generic arguments but 3 generic arguments - //~| HELP remove this + //~| HELP remove the type E = Ty<>; //~^ ERROR struct takes 2 generic arguments but 0 generic arguments were supplied @@ -70,8 +70,8 @@ mod lifetime_and_type { type F = Ty<'static, usize, 'static, usize>; //~^ ERROR struct takes 1 lifetime argument but 2 lifetime arguments //~| ERROR struct takes 1 generic argument but 2 generic arguments - //~| HELP remove this lifetime argument - //~| HELP remove this generic argument + //~| HELP remove the lifetime argument + //~| HELP remove the unnecessary generic argument } mod type_and_type_and_type { @@ -317,13 +317,13 @@ mod stdlib { type C = HashMap<'static>; //~^ ERROR struct takes 0 lifetime arguments but 1 lifetime argument - //~| HELP remove these generics + //~| HELP remove the //~| ERROR struct takes at least 2 //~| HELP add missing type D = HashMap; //~^ ERROR struct takes at most 3 - //~| HELP remove this + //~| HELP remove the type E = HashMap<>; //~^ ERROR struct takes at least 2 generic arguments but 0 generic arguments @@ -341,7 +341,7 @@ mod stdlib { type C = Result<'static>; //~^ ERROR enum takes 0 lifetime arguments but 1 lifetime argument - //~| HELP remove these generics + //~| HELP remove the unnecessary generics //~| ERROR enum takes 2 generic arguments but 0 generic arguments //~| HELP add missing diff --git a/tests/ui/generics/wrong-number-of-args.stderr b/tests/ui/generics/wrong-number-of-args.stderr index 9df759bf29b1..1363032ad142 100644 --- a/tests/ui/generics/wrong-number-of-args.stderr +++ b/tests/ui/generics/wrong-number-of-args.stderr @@ -178,7 +178,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct Ty; | ^^ -help: remove these generics +help: remove the unnecessary generics | LL - type B = Ty<'static>; LL + type B = Ty; @@ -195,7 +195,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct Ty; | ^^ -help: remove this lifetime argument +help: remove the lifetime argument | LL - type C = Ty<'static, usize>; LL + type C = Ty<, usize>; @@ -212,7 +212,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Ty; | ^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type C = Ty<'static, usize>; LL + type C = Ty<'static, >; @@ -229,7 +229,7 @@ note: struct defined here, with 0 lifetime parameters | LL | struct Ty; | ^^ -help: remove this lifetime argument +help: remove the lifetime argument | LL - type D = Ty<'static, usize, { 0 }>; LL + type D = Ty<, usize, { 0 }>; @@ -246,7 +246,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Ty; | ^^ -help: remove these generic arguments +help: remove the unnecessary generic arguments | LL - type D = Ty<'static, usize, { 0 }>; LL + type D = Ty<'static, >; @@ -297,7 +297,7 @@ note: struct defined here, with 2 generic parameters: `A`, `B` | LL | struct Ty(A, B); | ^^ - - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type D = Ty; LL + type D = Ty; @@ -378,7 +378,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct Ty<'a, T>(&'a T); | ^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type F = Ty<'static, usize, 'static, usize>; LL + type F = Ty<'static, usize, , usize>; @@ -395,7 +395,7 @@ note: struct defined here, with 1 generic parameter: `T` | LL | struct Ty<'a, T>(&'a T); | ^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type F = Ty<'static, usize, 'static, usize>; LL + type F = Ty<'static, usize, 'static, >; @@ -446,7 +446,7 @@ note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C` | LL | struct Ty(A, B, C); | ^^ - - ---------------- -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type E = Ty; LL + type E = Ty; @@ -479,7 +479,7 @@ note: trait defined here, with 0 generic parameters | LL | trait NonGeneric { | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - type A = Box>; LL + type A = Box; @@ -496,7 +496,7 @@ note: trait defined here, with 1 lifetime parameter: `'a` | LL | trait GenericLifetime<'a> { | ^^^^^^^^^^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type C = Box>; LL + type C = Box>; @@ -529,7 +529,7 @@ note: trait defined here, with 1 generic parameter: `A` | LL | trait GenericType { | ^^^^^^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type E = Box>; LL + type E = Box>; @@ -562,7 +562,7 @@ note: trait defined here, with 0 generic parameters | LL | trait NonGenericAT { | ^^^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - type A = Box>; LL + type A = Box; @@ -579,7 +579,7 @@ note: trait defined here, with 1 lifetime parameter: `'a` | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type B = Box>; LL + type B = Box>; @@ -596,7 +596,7 @@ note: trait defined here, with 0 generic parameters | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type C = Box>; LL + type C = Box>; @@ -629,7 +629,7 @@ note: trait defined here, with 1 generic parameter: `A` | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type B = Box>; LL + type B = Box>; @@ -646,7 +646,7 @@ note: trait defined here, with 0 lifetime parameters | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - type C = Box>; LL + type C = Box; @@ -711,7 +711,7 @@ note: trait defined here, with 1 lifetime parameter: `'a` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type C = Box>; LL + type C = Box>; @@ -744,7 +744,7 @@ note: trait defined here, with 1 generic parameter: `A` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type E = Box>; LL + type E = Box>; @@ -761,7 +761,7 @@ note: trait defined here, with 1 lifetime parameter: `'a` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type F = Box>; LL + type F = Box>; @@ -778,7 +778,7 @@ note: trait defined here, with 1 generic parameter: `A` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type G = Box>; LL + type G = Box>; @@ -795,7 +795,7 @@ note: trait defined here, with 1 lifetime parameter: `'a` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - type H = Box>; LL + type H = Box>; @@ -812,7 +812,7 @@ note: trait defined here, with 1 generic parameter: `A` | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type H = Box>; LL + type H = Box>; @@ -863,7 +863,7 @@ note: trait defined here, with 2 generic parameters: `A`, `B` | LL | trait GenericTypeTypeAT { | ^^^^^^^^^^^^^^^^^ - - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type C = Box>; LL + type C = Box>; @@ -985,7 +985,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp LL | type C = HashMap<'static>; | ^^^^^^^ expected 0 lifetime arguments | -help: remove these generics +help: remove the unnecessary generics | LL - type C = HashMap<'static>; LL + type C = HashMap; @@ -1008,7 +1008,7 @@ error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments w LL | type D = HashMap; | ^^^^^^^ expected at most 3 generic arguments | -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type D = HashMap; LL + type D = HashMap; @@ -1055,7 +1055,7 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli LL | type C = Result<'static>; | ^^^^^^ expected 0 lifetime arguments | -help: remove these generics +help: remove the unnecessary generics | LL - type C = Result<'static>; LL + type C = Result; @@ -1078,7 +1078,7 @@ error[E0107]: enum takes 2 generic arguments but 3 generic arguments were suppli LL | type D = Result; | ^^^^^^ expected 2 generic arguments | -help: remove this generic argument +help: remove the unnecessary generic argument | LL - type D = Result; LL + type D = Result; diff --git a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index d184110c4534..1c22e77e8171 100644 --- a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -10,7 +10,7 @@ note: function defined here, with 1 generic parameter: `T` LL | fn foo(_f: impl AsRef) {} | ^^^ - = note: `impl Trait` cannot be explicitly specified as a generic argument -help: remove this generic argument +help: remove the unnecessary generic argument | LL - foo::("".to_string()); LL + foo::("".to_string()); diff --git a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr index aba82084f225..1802a22d6cfe 100644 --- a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr @@ -45,7 +45,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - fn bar() -> Wrapper; LL + fn bar() -> Wrapper<>; @@ -62,7 +62,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - fn foo() -> Wrapper; LL + fn foo() -> Wrapper<>; @@ -106,7 +106,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - fn foo() -> Wrapper { LL + fn foo() -> Wrapper<> { diff --git a/tests/ui/issues/issue-18423.stderr b/tests/ui/issues/issue-18423.stderr index a73688205ac8..c1a4aacd2a54 100644 --- a/tests/ui/issues/issue-18423.stderr +++ b/tests/ui/issues/issue-18423.stderr @@ -4,7 +4,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp LL | x: Box<'a, isize> | ^^^ expected 0 lifetime arguments | -help: remove this lifetime argument +help: remove the lifetime argument | LL - x: Box<'a, isize> LL + x: Box<, isize> diff --git a/tests/ui/issues/issue-53251.stderr b/tests/ui/issues/issue-53251.stderr index db9df7d911c4..854e9bc0c9b3 100644 --- a/tests/ui/issues/issue-53251.stderr +++ b/tests/ui/issues/issue-53251.stderr @@ -13,7 +13,7 @@ note: associated function defined here, with 0 generic parameters LL | fn f() {} | ^ = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) -help: remove these generics +help: remove the unnecessary generics | LL - S::f::(); LL + S::f(); @@ -35,7 +35,7 @@ LL | fn f() {} | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) -help: remove these generics +help: remove the unnecessary generics | LL - S::f::(); LL + S::f(); diff --git a/tests/ui/issues/issue-60622.stderr b/tests/ui/issues/issue-60622.stderr index e694a92213c8..66e96131f5e0 100644 --- a/tests/ui/issues/issue-60622.stderr +++ b/tests/ui/issues/issue-60622.stderr @@ -27,7 +27,7 @@ note: method defined here, with 0 generic parameters | LL | fn a(&self) {} | ^ -help: remove this generic argument +help: remove the unnecessary generic argument | LL - b.a::<'_, T>(); LL + b.a::<'_, >(); diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr index de0a0631bf88..02dbfca15a4a 100644 --- a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr @@ -9,7 +9,7 @@ note: type alias defined here, with 1 lifetime parameter: `'a` | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.stderr b/tests/ui/lifetimes/noisy-follow-up-erro.stderr index 38465c7ac963..90dfc88e19f0 100644 --- a/tests/ui/lifetimes/noisy-follow-up-erro.stderr +++ b/tests/ui/lifetimes/noisy-follow-up-erro.stderr @@ -9,7 +9,7 @@ note: struct defined here, with 2 lifetime parameters: `'c`, `'d` | LL | struct Foo<'c, 'd>(&'c (), &'d ()); | ^^^ -- -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { LL + fn boom(&self, foo: &mut Foo<'_, '_, >) -> Result<(), &'a ()> { diff --git a/tests/ui/methods/method-call-lifetime-args-fail.stderr b/tests/ui/methods/method-call-lifetime-args-fail.stderr index d431e0721ccb..60ef1060aaca 100644 --- a/tests/ui/methods/method-call-lifetime-args-fail.stderr +++ b/tests/ui/methods/method-call-lifetime-args-fail.stderr @@ -27,7 +27,7 @@ note: method defined here, with 2 lifetime parameters: `'a`, `'b` | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - S.early::<'static, 'static, 'static>(); LL + S.early::<'static, 'static, >(); @@ -230,7 +230,7 @@ note: method defined here, with 2 lifetime parameters: `'a`, `'b` | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - S::early::<'static, 'static, 'static>(S); LL + S::early::<'static, 'static, >(S); diff --git a/tests/ui/resolve/issue-3214.stderr b/tests/ui/resolve/issue-3214.stderr index 614d3b21ff2c..f6f8c3b77467 100644 --- a/tests/ui/resolve/issue-3214.stderr +++ b/tests/ui/resolve/issue-3214.stderr @@ -19,7 +19,7 @@ note: struct defined here, with 0 generic parameters | LL | struct Foo { | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - impl Drop for Foo { LL + impl Drop for Foo { diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr index 3d9df78b196e..6945e8465da7 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr @@ -9,7 +9,7 @@ note: function defined here, with 0 generic parameters | LL | pub const fn foo() {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - foo::(); LL + foo(); @@ -42,7 +42,7 @@ note: function defined here, with 0 generic parameters | LL | pub const fn foo() {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - foo::(); LL + foo(); diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr index 8412a3d0a8a0..0f9380de2862 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr @@ -23,7 +23,7 @@ note: function defined here, with 0 generic parameters | LL | const fn foo() {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - foo::(); LL + foo(); @@ -65,7 +65,7 @@ note: function defined here, with 0 generic parameters | LL | const fn foo() {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - foo::(); LL + foo(); diff --git a/tests/ui/seq-args.stderr b/tests/ui/seq-args.stderr index bb46a11d9026..47c5119b9173 100644 --- a/tests/ui/seq-args.stderr +++ b/tests/ui/seq-args.stderr @@ -9,7 +9,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Seq { } | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - impl Seq for Vec { LL + impl Seq for Vec { @@ -26,7 +26,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Seq { } | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - impl Seq for u32 { LL + impl Seq for u32 { diff --git a/tests/ui/structs/struct-path-associated-type.stderr b/tests/ui/structs/struct-path-associated-type.stderr index edcb0bcc8332..1a2a346b0e30 100644 --- a/tests/ui/structs/struct-path-associated-type.stderr +++ b/tests/ui/structs/struct-path-associated-type.stderr @@ -15,7 +15,7 @@ note: associated type defined here, with 0 generic parameters | LL | type A; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - let z = T::A:: {}; LL + let z = T::A {}; @@ -44,7 +44,7 @@ note: associated type defined here, with 0 generic parameters | LL | type A; | ^ -help: remove these generics +help: remove the unnecessary generics | LL - let z = T::A:: {}; LL + let z = T::A {}; diff --git a/tests/ui/structs/structure-constructor-type-mismatch.stderr b/tests/ui/structs/structure-constructor-type-mismatch.stderr index 50ebd86a2166..606381251157 100644 --- a/tests/ui/structs/structure-constructor-type-mismatch.stderr +++ b/tests/ui/structs/structure-constructor-type-mismatch.stderr @@ -75,7 +75,7 @@ note: type alias defined here, with 0 generic parameters | LL | type PointF = Point; | ^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - let pt3 = PointF:: { LL + let pt3 = PointF { @@ -114,7 +114,7 @@ note: type alias defined here, with 0 generic parameters | LL | type PointF = Point; | ^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - PointF:: { .. } => {} LL + PointF { .. } => {} diff --git a/tests/ui/suggestions/issue-101421.stderr b/tests/ui/suggestions/issue-101421.stderr index 1a64f5313cf5..7adf07aa531c 100644 --- a/tests/ui/suggestions/issue-101421.stderr +++ b/tests/ui/suggestions/issue-101421.stderr @@ -9,7 +9,7 @@ note: method defined here, with 0 generic parameters | LL | fn f(&self, _: ()); | ^ -help: remove these generics +help: remove the unnecessary generics | LL - ().f::<()>(()); LL + ().f(()); diff --git a/tests/ui/suggestions/issue-104287.stderr b/tests/ui/suggestions/issue-104287.stderr index b65d3ad4d318..808f95628058 100644 --- a/tests/ui/suggestions/issue-104287.stderr +++ b/tests/ui/suggestions/issue-104287.stderr @@ -9,7 +9,7 @@ note: method defined here, with 0 generic parameters | LL | fn foo(&self) {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - foo::<()>(x); LL + foo(x); diff --git a/tests/ui/suggestions/issue-89064.rs b/tests/ui/suggestions/issue-89064.rs index fa5fc899dc08..014d15a87f17 100644 --- a/tests/ui/suggestions/issue-89064.rs +++ b/tests/ui/suggestions/issue-89064.rs @@ -16,20 +16,20 @@ impl B for S {} fn main() { let _ = A::foo::(); //~^ ERROR - //~| HELP remove these generics + //~| HELP remove the unnecessary generics //~| HELP consider moving this generic argument let _ = B::bar::(); //~^ ERROR - //~| HELP remove these generics + //~| HELP remove the unnecessary generics //~| HELP consider moving these generic arguments let _ = A::::foo::(); //~^ ERROR - //~| HELP remove these generics + //~| HELP remove the unnecessary generics let _ = 42.into::>(); //~^ ERROR - //~| HELP remove these generics + //~| HELP remove the unnecessary generics //~| HELP consider moving this generic argument } diff --git a/tests/ui/suggestions/issue-89064.stderr b/tests/ui/suggestions/issue-89064.stderr index f1bb3c2adc74..a64a1986af84 100644 --- a/tests/ui/suggestions/issue-89064.stderr +++ b/tests/ui/suggestions/issue-89064.stderr @@ -14,7 +14,7 @@ help: consider moving this generic argument to the `A` trait, which takes up to LL - let _ = A::foo::(); LL + let _ = A::::foo(); | -help: remove these generics +help: remove the unnecessary generics | LL - let _ = A::foo::(); LL + let _ = A::foo(); @@ -36,7 +36,7 @@ help: consider moving these generic arguments to the `B` trait, which takes up t LL - let _ = B::bar::(); LL + let _ = B::::bar(); | -help: remove these generics +help: remove the unnecessary generics | LL - let _ = B::bar::(); LL + let _ = B::bar(); @@ -53,7 +53,7 @@ note: associated function defined here, with 0 generic parameters | LL | fn foo() {} | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - let _ = A::::foo::(); LL + let _ = A::::foo(); @@ -69,7 +69,7 @@ help: consider moving this generic argument to the `Into` trait, which takes up | LL | let _ = Into::>::into(42); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -help: remove these generics +help: remove the unnecessary generics | LL - let _ = 42.into::>(); LL + let _ = 42.into(); diff --git a/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.rs b/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.rs index 4066cd3b11a3..a719ddc4b16a 100644 --- a/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.rs +++ b/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.rs @@ -14,5 +14,5 @@ fn main() { 1.bar::(0); //~^ ERROR method takes 0 generic arguments but 1 generic argument was supplied //~| HELP consider moving this generic argument to the `Foo` trait, which takes up to 1 argument - //~| HELP remove these generics + //~| HELP remove the unnecessary generics } diff --git a/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr b/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr index aa11bc7cf1d9..cc735ef4c5ea 100644 --- a/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr +++ b/tests/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr @@ -13,7 +13,7 @@ help: consider moving this generic argument to the `Foo` trait, which takes up t | LL | Foo::::bar(1, 0); | ~~~~~~~~~~~~~~~~~~~~~ -help: remove these generics +help: remove the unnecessary generics | LL - 1.bar::(0); LL + 1.bar(0); diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index 9193faeb1aa9..5a54ca181ce6 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -124,7 +124,7 @@ note: struct defined here, with 1 generic parameter: `T` | LL | struct Struct> { | ^^^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - impl, U> YetAnotherTrait for Struct {} LL + impl, U> YetAnotherTrait for Struct {} diff --git a/tests/ui/traits/object/vs-lifetime.stderr b/tests/ui/traits/object/vs-lifetime.stderr index aab4845a2742..e02c750055bc 100644 --- a/tests/ui/traits/object/vs-lifetime.stderr +++ b/tests/ui/traits/object/vs-lifetime.stderr @@ -15,7 +15,7 @@ note: struct defined here, with 1 lifetime parameter: `'a` | LL | struct S<'a, T>(&'a u8, T); | ^ -- -help: remove this lifetime argument +help: remove the lifetime argument | LL - let _: S<'static, 'static>; LL + let _: S<'static, >; diff --git a/tests/ui/traits/test-2.stderr b/tests/ui/traits/test-2.stderr index 9916cf97fca9..d1a003aa3f42 100644 --- a/tests/ui/traits/test-2.stderr +++ b/tests/ui/traits/test-2.stderr @@ -9,7 +9,7 @@ note: method defined here, with 0 generic parameters | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^ -help: remove these generics +help: remove the unnecessary generics | LL - 10.dup::(); LL + 10.dup(); @@ -26,7 +26,7 @@ note: method defined here, with 1 generic parameter: `X` | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - 10.blah::(); LL + 10.blah::(); diff --git a/tests/ui/transmutability/issue-101739-2.stderr b/tests/ui/transmutability/issue-101739-2.stderr index 93323049760a..1f640f21ad17 100644 --- a/tests/ui/transmutability/issue-101739-2.stderr +++ b/tests/ui/transmutability/issue-101739-2.stderr @@ -4,7 +4,7 @@ error[E0107]: trait takes at most 2 generic arguments but 5 generic arguments we LL | Dst: BikeshedIntrinsicFrom< | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments | -help: remove these generic arguments +help: remove the unnecessary generic arguments | LL - ASSUME_LIFETIMES, LL - ASSUME_VALIDITY, diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index a2dd6805f3d5..aaed6a9b5446 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -315,7 +315,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::TSVariant(()); LL + AliasFixed::TSVariant(()); @@ -332,7 +332,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::TSVariant::<()>(()); LL + AliasFixed::TSVariant::<()>(()); @@ -412,7 +412,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::SVariant { v: () }; LL + AliasFixed::SVariant { v: () }; @@ -429,7 +429,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::SVariant::<()> { v: () }; LL + AliasFixed::SVariant::<()> { v: () }; @@ -493,7 +493,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::UVariant; LL + AliasFixed::UVariant; @@ -510,7 +510,7 @@ note: type alias defined here, with 0 generic parameters | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - AliasFixed::<()>::UVariant::<()>; LL + AliasFixed::UVariant::<()>; diff --git a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr index 3be83682ec9a..dbcc03ee955f 100644 --- a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr +++ b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr @@ -4,7 +4,7 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie LL | fn foo1, U>(x: T) {} | ^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - fn foo1, U>(x: T) {} LL + fn foo1(x: T) {} @@ -16,7 +16,7 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie LL | trait Trait: Copy {} | ^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - trait Trait: Copy {} LL + trait Trait: Copy {} @@ -29,7 +29,7 @@ LL | trait Trait: Copy {} | ^^^^ expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - trait Trait: Copy {} LL + trait Trait: Copy {} @@ -42,7 +42,7 @@ LL | trait Trait: Copy {} | ^^^^ expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove these generics +help: remove the unnecessary generics | LL - trait Trait: Copy {} LL + trait Trait: Copy {} @@ -54,7 +54,7 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie LL | struct MyStruct1>(T); | ^^^^ expected 0 generic arguments | -help: remove these generics +help: remove the unnecessary generics | LL - struct MyStruct1>(T); LL + struct MyStruct1(T); @@ -66,7 +66,7 @@ error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was suppl LL | struct MyStruct2<'a, T: Copy<'a>>(&'a T); | ^^^^ expected 0 lifetime arguments | -help: remove these generics +help: remove the unnecessary generics | LL - struct MyStruct2<'a, T: Copy<'a>>(&'a T); LL + struct MyStruct2<'a, T: Copy>(&'a T); @@ -78,7 +78,7 @@ error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was suppl LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} | ^^^^ expected 0 lifetime arguments | -help: remove this lifetime argument +help: remove the lifetime argument | LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} LL + fn foo2<'a, T:Copy<, U>, U>(x: T) {} @@ -90,7 +90,7 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} | ^^^^ expected 0 generic arguments | -help: remove this generic argument +help: remove the unnecessary generic argument | LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} LL + fn foo2<'a, T:Copy<'a, >, U>(x: T) {} diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr index 65f07bb08320..83679f4b1f6b 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr @@ -9,7 +9,7 @@ note: struct defined here, with 1 generic parameter: `T` | LL | struct Foo<'a, T:'a> { | ^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let c: Foo<_, _> = Foo { r: &5 }; LL + let c: Foo<_, > = Foo { r: &5 }; diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr index b07cc225ba87..8d519600edcd 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr @@ -9,7 +9,7 @@ note: struct defined here, with 1 generic parameter: `T` | LL | struct Foo<'a, T:'a> { | ^^^ - -help: remove this generic argument +help: remove the unnecessary generic argument | LL - let c: Foo<_, usize> = Foo { r: &5 }; LL + let c: Foo<_, > = Foo { r: &5 }; diff --git a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr index 0ae92d204b6f..e7e576d7c663 100644 --- a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr +++ b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr @@ -41,7 +41,7 @@ note: method defined here, with 0 generic parameters | LL | fn into_cow(self) -> Cow<'a, B>; | ^^^^^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - ::into_cow::("foo".to_string()); LL + ::into_cow("foo".to_string()); diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr index ac56d1d05fae..509009732826 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr @@ -9,7 +9,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove these parenthetical generics +help: remove the unnecessary parenthetical generics | LL - fn foo1(_: &dyn Zero()) { LL + fn foo1(_: &dyn Zero) { @@ -32,7 +32,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - fn foo2(_: &dyn Zero) { LL + fn foo2(_: &dyn Zero) { @@ -49,7 +49,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove these generics +help: remove the unnecessary generics | LL - fn foo3(_: &dyn Zero < usize >) { LL + fn foo3(_: &dyn Zero) { @@ -66,7 +66,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove these parenthetical generics +help: remove the unnecessary parenthetical generics | LL - fn foo4(_: &dyn Zero(usize)) { LL + fn foo4(_: &dyn Zero) { @@ -89,7 +89,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove these parenthetical generics +help: remove the unnecessary parenthetical generics | LL - fn foo5(_: &dyn Zero ( usize )) { LL + fn foo5(_: &dyn Zero) { diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr index 3736f25a51ff..aecfe502cf98 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr @@ -9,7 +9,7 @@ note: trait defined here, with 0 generic parameters | LL | trait Trait {} | ^^^^^ -help: remove these parenthetical generics +help: remove the unnecessary parenthetical generics | LL - fn f isize>(x: F) {} LL + fn f isize>(x: F) {} From b30fdec5fb283641fc0452fa6ca60193a16bb30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 5 Jul 2024 17:24:23 +0000 Subject: [PATCH 22/54] On generic and lifetime removal suggestion, do not leave behind stray `,` --- .../errors/wrong_number_of_generic_args.rs | 26 +++++++++----- tests/rustdoc-ui/mismatched_arg_count.stderr | 2 +- .../transmutable-ice-110969.stderr | 2 +- .../generic_arg_infer/infer-arg-test.stderr | 2 +- .../const_kind_expr/issue_114151.stderr | 2 +- .../incorrect-number-of-const-args.stderr | 2 +- .../invalid-constant-in-args.stderr | 2 +- tests/ui/constructor-lifetime-args.stderr | 4 +-- tests/ui/error-codes/E0107.stderr | 12 +++---- .../parameter_number_and_kind.stderr | 4 +-- .../generics/bad-mid-path-type-params.stderr | 6 ++-- .../generics/foreign-generic-mismatch.stderr | 2 +- .../generic-arg-mismatch-recover.stderr | 4 +-- ...eric-impl-more-params-with-defaults.stderr | 2 +- ...eric-type-more-params-with-defaults.stderr | 2 +- tests/ui/generics/wrong-number-of-args.stderr | 36 +++++++++---------- .../explicit-generic-args-for-impl.stderr | 2 +- .../mismatched_arg_count.stderr | 2 +- .../ui/lifetimes/noisy-follow-up-erro.stderr | 2 +- .../method-call-lifetime-args-fail.stderr | 4 +-- ...assoc-type-suggestion-in-trait-impl.stderr | 2 +- tests/ui/traits/object/vs-lifetime.stderr | 2 +- tests/ui/traits/test-2.stderr | 2 +- .../ui/transmutability/issue-101739-2.stderr | 3 +- .../typeck_type_placeholder_lifetime_1.stderr | 2 +- .../typeck_type_placeholder_lifetime_2.stderr | 2 +- 26 files changed, 71 insertions(+), 62 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 6c2ec1acdf96..7443070b9dee 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -939,17 +939,20 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - let span_lo_redundant_lt_args = lt_arg_spans[self.num_expected_lifetime_args()]; + let span_lo_redundant_lt_args = if self.num_expected_lifetime_args() == 0 { + lt_arg_spans[0] + } else { + lt_arg_spans[self.num_expected_lifetime_args() - 1] + }; let span_hi_redundant_lt_args = lt_arg_spans[lt_arg_spans.len() - 1]; - let span_redundant_lt_args = span_lo_redundant_lt_args.to(span_hi_redundant_lt_args); + let span_redundant_lt_args = + span_lo_redundant_lt_args.shrink_to_hi().to(span_hi_redundant_lt_args); debug!("span_redundant_lt_args: {:?}", span_redundant_lt_args); let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args(); - let msg_lifetimes = format!( - "remove the lifetime argument{s}", - s = pluralize!(num_redundant_lt_args), - ); + let msg_lifetimes = + format!("remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args)); err.span_suggestion_verbose( span_redundant_lt_args, @@ -978,11 +981,16 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } let span_lo_redundant_type_or_const_args = - gen_arg_spans[self.num_expected_type_or_const_args()]; + if self.num_expected_type_or_const_args() == 0 { + gen_arg_spans[0] + } else { + gen_arg_spans[self.num_expected_type_or_const_args() - 1] + }; let span_hi_redundant_type_or_const_args = gen_arg_spans[gen_arg_spans.len() - 1]; + let span_redundant_type_or_const_args = span_lo_redundant_type_or_const_args + .shrink_to_hi() + .to(span_hi_redundant_type_or_const_args); - let span_redundant_type_or_const_args = - span_lo_redundant_type_or_const_args.to(span_hi_redundant_type_or_const_args); debug!("span_redundant_type_or_const_args: {:?}", span_redundant_type_or_const_args); let num_redundant_gen_args = diff --git a/tests/rustdoc-ui/mismatched_arg_count.stderr b/tests/rustdoc-ui/mismatched_arg_count.stderr index 8e7def04f527..9a698d8f5ad6 100644 --- a/tests/rustdoc-ui/mismatched_arg_count.stderr +++ b/tests/rustdoc-ui/mismatched_arg_count.stderr @@ -12,7 +12,7 @@ LL | type Alias<'a, T> = >::Assoc; help: remove the lifetime argument | LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} -LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} +LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, T>) {} | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr index 3f32b0eb6746..ceac2c95bfae 100644 --- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr +++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr @@ -7,7 +7,7 @@ LL | Dst: BikeshedIntrinsicFrom, help: remove the unnecessary generic argument | LL - Dst: BikeshedIntrinsicFrom, -LL + Dst: BikeshedIntrinsicFrom, +LL + Dst: BikeshedIntrinsicFrom, | error[E0308]: mismatched types diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr index d8e794a7a652..61688f3acab6 100644 --- a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr +++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr @@ -33,7 +33,7 @@ LL | struct All<'a, T, const N: usize> { help: remove the unnecessary generic argument | LL - let a: All<_, _, _>; -LL + let a: All<_, _, >; +LL + let a: All<_, _>; | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr index a7232ef780e3..c66f351ea7f0 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr @@ -12,7 +12,7 @@ LL | fn foo( help: remove the unnecessary generic argument | LL - foo::<_, L>([(); L + 1 + L]); -LL + foo::<_, >([(); L + 1 + L]); +LL + foo::<_>([(); L + 1 + L]); | error[E0308]: mismatched types diff --git a/tests/ui/const-generics/incorrect-number-of-const-args.stderr b/tests/ui/const-generics/incorrect-number-of-const-args.stderr index 05c4a0a1a727..f670ebc8ab0b 100644 --- a/tests/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/tests/ui/const-generics/incorrect-number-of-const-args.stderr @@ -30,7 +30,7 @@ LL | fn foo() -> usize { help: remove the unnecessary generic argument | LL - foo::<0, 0, 0>(); -LL + foo::<0, 0, >(); +LL + foo::<0, 0>(); | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/invalid-constant-in-args.stderr b/tests/ui/const-generics/invalid-constant-in-args.stderr index 10334e0d896c..c3a3f251d467 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.stderr +++ b/tests/ui/const-generics/invalid-constant-in-args.stderr @@ -7,7 +7,7 @@ LL | let _: Cell<&str, "a"> = Cell::new(""); help: remove the unnecessary generic argument | LL - let _: Cell<&str, "a"> = Cell::new(""); -LL + let _: Cell<&str, > = Cell::new(""); +LL + let _: Cell<&str> = Cell::new(""); | error: aborting due to 1 previous error diff --git a/tests/ui/constructor-lifetime-args.stderr b/tests/ui/constructor-lifetime-args.stderr index 37b13cd048fe..980a812e3b4e 100644 --- a/tests/ui/constructor-lifetime-args.stderr +++ b/tests/ui/constructor-lifetime-args.stderr @@ -30,7 +30,7 @@ LL | struct S<'a, 'b>(&'a u8, &'b u8); help: remove the lifetime argument | LL - S::<'static, 'static, 'static>(&0, &0); -LL + S::<'static, 'static, >(&0, &0); +LL + S::<'static, 'static>(&0, &0); | error[E0107]: enum takes 2 lifetime arguments but 1 lifetime argument was supplied @@ -65,7 +65,7 @@ LL | enum E<'a, 'b> { help: remove the lifetime argument | LL - E::V::<'static, 'static, 'static>(&0); -LL + E::V::<'static, 'static, >(&0); +LL + E::V::<'static, 'static>(&0); | error: aborting due to 4 previous errors diff --git a/tests/ui/error-codes/E0107.stderr b/tests/ui/error-codes/E0107.stderr index d8bd96e0ad46..3271abd8a79b 100644 --- a/tests/ui/error-codes/E0107.stderr +++ b/tests/ui/error-codes/E0107.stderr @@ -47,7 +47,7 @@ LL | struct Foo<'a>(&'a str); help: remove the lifetime arguments | LL - foo2: Foo<'a, 'b, 'c>, -LL + foo2: Foo<'a, >, +LL + foo2: Foo<'a>, | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied @@ -64,7 +64,7 @@ LL | struct Qux<'a, T>(&'a T); help: remove the lifetime argument | LL - qux1: Qux<'a, 'b, i32>, -LL + qux1: Qux<'a, , i32>, +LL + qux1: Qux<'a, i32>, | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied @@ -81,7 +81,7 @@ LL | struct Qux<'a, T>(&'a T); help: remove the lifetime argument | LL - qux2: Qux<'a, i32, 'b>, -LL + qux2: Qux<'a, i32, >, +LL + qux2: Qux<'a>, | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied @@ -98,7 +98,7 @@ LL | struct Qux<'a, T>(&'a T); help: remove the lifetime arguments | LL - qux3: Qux<'a, 'b, 'c, i32>, -LL + qux3: Qux<'a, , i32>, +LL + qux3: Qux<'a, i32>, | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied @@ -115,7 +115,7 @@ LL | struct Qux<'a, T>(&'a T); help: remove the lifetime arguments | LL - qux4: Qux<'a, i32, 'b, 'c>, -LL + qux4: Qux<'a, i32, >, +LL + qux4: Qux<'a>, | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied @@ -132,7 +132,7 @@ LL | struct Qux<'a, T>(&'a T); help: remove the lifetime argument | LL - qux5: Qux<'a, 'b, i32, 'c>, -LL + qux5: Qux<'a, , i32, 'c>, +LL + qux5: Qux<'a, i32, 'c>, | error[E0107]: struct takes 0 lifetime arguments but 2 lifetime arguments were supplied diff --git a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr index 7b7f21b00c5a..1c9351cb351a 100644 --- a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr +++ b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr @@ -12,7 +12,7 @@ LL | type E<'a, T>; help: remove the lifetime argument | LL - type FErr1 = Self::E<'static, 'static>; -LL + type FErr1 = Self::E<'static, >; +LL + type FErr1 = Self::E<'static>; | error[E0107]: associated type takes 1 generic argument but 0 generic arguments were supplied @@ -45,7 +45,7 @@ LL | type E<'a, T>; help: remove the unnecessary generic argument | LL - type FErr2 = Self::E<'static, T, u32>; -LL + type FErr2 = Self::E<'static, T, >; +LL + type FErr2 = Self::E<'static, T>; | error: aborting due to 3 previous errors diff --git a/tests/ui/generics/bad-mid-path-type-params.stderr b/tests/ui/generics/bad-mid-path-type-params.stderr index ba1d48f1210b..cff5464dce49 100644 --- a/tests/ui/generics/bad-mid-path-type-params.stderr +++ b/tests/ui/generics/bad-mid-path-type-params.stderr @@ -12,7 +12,7 @@ LL | fn new(x: T, _: U) -> S { help: remove the unnecessary generic argument | LL - let _ = S::new::(1, 1.0); -LL + let _ = S::new::(1, 1.0); +LL + let _ = S::new::(1, 1.0); | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied @@ -46,7 +46,7 @@ LL | fn new(x: T, y: U) -> Self; help: remove the unnecessary generic argument | LL - let _: S2 = Trait::new::(1, 1.0); -LL + let _: S2 = Trait::new::(1, 1.0); +LL + let _: S2 = Trait::new::(1, 1.0); | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied @@ -80,7 +80,7 @@ LL | fn new(x: T, y: U) -> Self; help: remove the unnecessary generic argument | LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); -LL + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); +LL + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); | error: aborting due to 5 previous errors diff --git a/tests/ui/generics/foreign-generic-mismatch.stderr b/tests/ui/generics/foreign-generic-mismatch.stderr index 740963aeec54..4cf76cde9203 100644 --- a/tests/ui/generics/foreign-generic-mismatch.stderr +++ b/tests/ui/generics/foreign-generic-mismatch.stderr @@ -30,7 +30,7 @@ LL | pub fn lt_arg<'a: 'a>() {} help: remove the lifetime argument | LL - foreign_generic_mismatch::lt_arg::<'static, 'static>(); -LL + foreign_generic_mismatch::lt_arg::<'static, >(); +LL + foreign_generic_mismatch::lt_arg::<'static>(); | error: aborting due to 2 previous errors diff --git a/tests/ui/generics/generic-arg-mismatch-recover.stderr b/tests/ui/generics/generic-arg-mismatch-recover.stderr index e8c2a4665f3d..d2953e37c8cc 100644 --- a/tests/ui/generics/generic-arg-mismatch-recover.stderr +++ b/tests/ui/generics/generic-arg-mismatch-recover.stderr @@ -12,7 +12,7 @@ LL | struct Foo<'a, T: 'a>(&'a T); help: remove the lifetime argument | LL - Foo::<'static, 'static, ()>(&0); -LL + Foo::<'static, , ()>(&0); +LL + Foo::<'static, ()>(&0); | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied @@ -29,7 +29,7 @@ LL | struct Bar<'a>(&'a ()); help: remove the lifetime argument | LL - Bar::<'static, 'static, ()>(&()); -LL + Bar::<'static, , ()>(&()); +LL + Bar::<'static, ()>(&()); | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied diff --git a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr index b0973c477ff4..a180e348a686 100644 --- a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr @@ -12,7 +12,7 @@ LL | struct Vec( help: remove the unnecessary generic argument | LL - Vec::::new(); -LL + Vec::::new(); +LL + Vec::::new(); | error: aborting due to 1 previous error diff --git a/tests/ui/generics/generic-type-more-params-with-defaults.stderr b/tests/ui/generics/generic-type-more-params-with-defaults.stderr index e83a433b0605..9b73b7375d79 100644 --- a/tests/ui/generics/generic-type-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-type-more-params-with-defaults.stderr @@ -12,7 +12,7 @@ LL | struct Vec( help: remove the unnecessary generic argument | LL - let _: Vec; -LL + let _: Vec; +LL + let _: Vec; | error: aborting due to 1 previous error diff --git a/tests/ui/generics/wrong-number-of-args.stderr b/tests/ui/generics/wrong-number-of-args.stderr index 1363032ad142..17503b86e19c 100644 --- a/tests/ui/generics/wrong-number-of-args.stderr +++ b/tests/ui/generics/wrong-number-of-args.stderr @@ -249,7 +249,7 @@ LL | struct Ty; help: remove the unnecessary generic arguments | LL - type D = Ty<'static, usize, { 0 }>; -LL + type D = Ty<'static, >; +LL + type D = Ty<'static, usize>; | error[E0107]: missing generics for struct `type_and_type::Ty` @@ -300,7 +300,7 @@ LL | struct Ty(A, B); help: remove the unnecessary generic argument | LL - type D = Ty; -LL + type D = Ty; +LL + type D = Ty; | error[E0107]: struct takes 2 generic arguments but 0 generic arguments were supplied @@ -381,7 +381,7 @@ LL | struct Ty<'a, T>(&'a T); help: remove the lifetime argument | LL - type F = Ty<'static, usize, 'static, usize>; -LL + type F = Ty<'static, usize, , usize>; +LL + type F = Ty<'static, usize>; | error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied @@ -398,7 +398,7 @@ LL | struct Ty<'a, T>(&'a T); help: remove the unnecessary generic argument | LL - type F = Ty<'static, usize, 'static, usize>; -LL + type F = Ty<'static, usize, 'static, >; +LL + type F = Ty<'static, usize>; | error[E0107]: missing generics for struct `type_and_type_and_type::Ty` @@ -449,7 +449,7 @@ LL | struct Ty(A, B, C); help: remove the unnecessary generic argument | LL - type E = Ty; -LL + type E = Ty; +LL + type E = Ty; | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied @@ -499,7 +499,7 @@ LL | trait GenericLifetime<'a> { help: remove the lifetime argument | LL - type C = Box>; -LL + type C = Box>; +LL + type C = Box>; | error[E0107]: missing generics for trait `GenericType` @@ -532,7 +532,7 @@ LL | trait GenericType { help: remove the unnecessary generic argument | LL - type E = Box>; -LL + type E = Box>; +LL + type E = Box>; | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied @@ -582,7 +582,7 @@ LL | trait GenericLifetimeAT<'a> { help: remove the lifetime argument | LL - type B = Box>; -LL + type B = Box>; +LL + type B = Box>; | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied @@ -632,7 +632,7 @@ LL | trait GenericTypeAT { help: remove the unnecessary generic argument | LL - type B = Box>; -LL + type B = Box>; +LL + type B = Box>; | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied @@ -714,7 +714,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the lifetime argument | LL - type C = Box>; -LL + type C = Box>; +LL + type C = Box>; | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied @@ -747,7 +747,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the unnecessary generic argument | LL - type E = Box>; -LL + type E = Box>; +LL + type E = Box>; | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied @@ -764,7 +764,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the lifetime argument | LL - type F = Box>; -LL + type F = Box>; +LL + type F = Box>; | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied @@ -781,7 +781,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the unnecessary generic argument | LL - type G = Box>; -LL + type G = Box>; +LL + type G = Box>; | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied @@ -798,7 +798,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the lifetime argument | LL - type H = Box>; -LL + type H = Box>; +LL + type H = Box>; | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied @@ -815,7 +815,7 @@ LL | trait GenericLifetimeTypeAT<'a, A> { help: remove the unnecessary generic argument | LL - type H = Box>; -LL + type H = Box>; +LL + type H = Box>; | error[E0107]: trait takes 2 generic arguments but 0 generic arguments were supplied @@ -866,7 +866,7 @@ LL | trait GenericTypeTypeAT { help: remove the unnecessary generic argument | LL - type C = Box>; -LL + type C = Box>; +LL + type C = Box>; | error[E0107]: trait takes 2 lifetime arguments but 1 lifetime argument was supplied @@ -1011,7 +1011,7 @@ LL | type D = HashMap; help: remove the unnecessary generic argument | LL - type D = HashMap; -LL + type D = HashMap; +LL + type D = HashMap; | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied @@ -1081,7 +1081,7 @@ LL | type D = Result; help: remove the unnecessary generic argument | LL - type D = Result; -LL + type D = Result; +LL + type D = Result; | error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied diff --git a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index 1c22e77e8171..e225d7076b8c 100644 --- a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -13,7 +13,7 @@ LL | fn foo(_f: impl AsRef) {} help: remove the unnecessary generic argument | LL - foo::("".to_string()); -LL + foo::("".to_string()); +LL + foo::("".to_string()); | error: aborting due to 1 previous error diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr index 02dbfca15a4a..c0a5b62a56a2 100644 --- a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr @@ -12,7 +12,7 @@ LL | type Alias<'a, T> = >::Assoc; help: remove the lifetime argument | LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} -LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {} +LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, T>) {} | error: aborting due to 1 previous error diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.stderr b/tests/ui/lifetimes/noisy-follow-up-erro.stderr index 90dfc88e19f0..3c2d0df683a9 100644 --- a/tests/ui/lifetimes/noisy-follow-up-erro.stderr +++ b/tests/ui/lifetimes/noisy-follow-up-erro.stderr @@ -12,7 +12,7 @@ LL | struct Foo<'c, 'd>(&'c (), &'d ()); help: remove the lifetime argument | LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { -LL + fn boom(&self, foo: &mut Foo<'_, '_, >) -> Result<(), &'a ()> { +LL + fn boom(&self, foo: &mut Foo<'_, '_>) -> Result<(), &'a ()> { | error[E0621]: explicit lifetime required in the type of `foo` diff --git a/tests/ui/methods/method-call-lifetime-args-fail.stderr b/tests/ui/methods/method-call-lifetime-args-fail.stderr index 60ef1060aaca..2eda01fa20c3 100644 --- a/tests/ui/methods/method-call-lifetime-args-fail.stderr +++ b/tests/ui/methods/method-call-lifetime-args-fail.stderr @@ -30,7 +30,7 @@ LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } help: remove the lifetime argument | LL - S.early::<'static, 'static, 'static>(); -LL + S.early::<'static, 'static, >(); +LL + S.early::<'static, 'static>(); | error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present @@ -233,7 +233,7 @@ LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } help: remove the lifetime argument | LL - S::early::<'static, 'static, 'static>(S); -LL + S::early::<'static, 'static, >(S); +LL + S::early::<'static, 'static>(S); | error: aborting due to 18 previous errors diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index 5a54ca181ce6..d25192b3d6d8 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -127,7 +127,7 @@ LL | struct Struct> { help: remove the unnecessary generic argument | LL - impl, U> YetAnotherTrait for Struct {} -LL + impl, U> YetAnotherTrait for Struct {} +LL + impl, U> YetAnotherTrait for Struct {} | error: aborting due to 9 previous errors diff --git a/tests/ui/traits/object/vs-lifetime.stderr b/tests/ui/traits/object/vs-lifetime.stderr index e02c750055bc..889e1e82876a 100644 --- a/tests/ui/traits/object/vs-lifetime.stderr +++ b/tests/ui/traits/object/vs-lifetime.stderr @@ -18,7 +18,7 @@ LL | struct S<'a, T>(&'a u8, T); help: remove the lifetime argument | LL - let _: S<'static, 'static>; -LL + let _: S<'static, >; +LL + let _: S<'static>; | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied diff --git a/tests/ui/traits/test-2.stderr b/tests/ui/traits/test-2.stderr index d1a003aa3f42..d64497309ef9 100644 --- a/tests/ui/traits/test-2.stderr +++ b/tests/ui/traits/test-2.stderr @@ -29,7 +29,7 @@ LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } help: remove the unnecessary generic argument | LL - 10.blah::(); -LL + 10.blah::(); +LL + 10.blah::(); | error[E0038]: the trait `bar` cannot be made into an object diff --git a/tests/ui/transmutability/issue-101739-2.stderr b/tests/ui/transmutability/issue-101739-2.stderr index 1f640f21ad17..dabb51ee7aef 100644 --- a/tests/ui/transmutability/issue-101739-2.stderr +++ b/tests/ui/transmutability/issue-101739-2.stderr @@ -6,10 +6,11 @@ LL | Dst: BikeshedIntrinsicFrom< | help: remove the unnecessary generic arguments | +LL - ASSUME_ALIGNMENT, LL - ASSUME_LIFETIMES, LL - ASSUME_VALIDITY, LL - ASSUME_VISIBILITY, -LL + , +LL + ASSUME_ALIGNMENT, | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr index 83679f4b1f6b..116dd1866459 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr @@ -12,7 +12,7 @@ LL | struct Foo<'a, T:'a> { help: remove the unnecessary generic argument | LL - let c: Foo<_, _> = Foo { r: &5 }; -LL + let c: Foo<_, > = Foo { r: &5 }; +LL + let c: Foo<_> = Foo { r: &5 }; | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr index 8d519600edcd..d2734f4acc89 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr @@ -12,7 +12,7 @@ LL | struct Foo<'a, T:'a> { help: remove the unnecessary generic argument | LL - let c: Foo<_, usize> = Foo { r: &5 }; -LL + let c: Foo<_, > = Foo { r: &5 }; +LL + let c: Foo<_> = Foo { r: &5 }; | error: aborting due to 1 previous error From 921de9d8eae16947c375febe0ab8709797b37119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 22 Jul 2024 22:51:53 +0000 Subject: [PATCH 23/54] Revert suggestion verbosity change --- .../errors/wrong_number_of_generic_args.rs | 6 +- .../invalid_const_in_lifetime_position.stderr | 27 +- tests/rustdoc-ui/mismatched_arg_count.stderr | 9 +- .../argument-suggestions/issue-100154.stderr | 9 +- ...ssue-82126-mismatched-subst-and-hir.stderr | 18 +- .../transmutable-ice-110969.stderr | 10 +- .../generic_arg_infer/infer-arg-test.stderr | 9 +- .../const_kind_expr/issue_114151.stderr | 9 +- .../generic_const_exprs/issue-102768.stderr | 27 +- .../incorrect-number-of-const-args.stderr | 9 +- .../invalid-const-arg-for-type-param.stderr | 9 +- .../invalid-constant-in-args.stderr | 10 +- tests/ui/constructor-lifetime-args.stderr | 18 +- tests/ui/consts/effect_param.stderr | 40 +-- tests/ui/error-codes/E0107.stderr | 72 ++--- .../gat-trait-path-parenthesised-args.stderr | 27 +- .../parameter_number_and_kind.stderr | 18 +- ...it-path-type-error-once-implemented.stderr | 27 +- .../generics/bad-mid-path-type-params.stderr | 45 +-- .../generics/foreign-generic-mismatch.stderr | 9 +- .../generic-arg-mismatch-recover.stderr | 27 +- ...eric-impl-more-params-with-defaults.stderr | 9 +- ...eric-type-more-params-with-defaults.stderr | 9 +- tests/ui/generics/wrong-number-of-args.stderr | 256 ++++++------------ .../explicit-generic-args-for-impl.stderr | 9 +- .../opaque-and-lifetime-mismatch.stderr | 27 +- tests/ui/issues/issue-18423.stderr | 10 +- tests/ui/issues/issue-53251.stderr | 18 +- tests/ui/issues/issue-60622.stderr | 9 +- .../mismatched_arg_count.stderr | 9 +- .../ui/lifetimes/noisy-follow-up-erro.stderr | 9 +- .../method-call-lifetime-args-fail.stderr | 18 +- tests/ui/resolve/issue-3214.stderr | 9 +- ...o-explicit-const-params-cross-crate.stderr | 18 +- .../effects/no-explicit-const-params.stderr | 18 +- tests/ui/seq-args.stderr | 18 +- .../struct-path-associated-type.stderr | 18 +- ...structure-constructor-type-mismatch.stderr | 18 +- tests/ui/suggestions/issue-101421.stderr | 9 +- tests/ui/suggestions/issue-104287.stderr | 9 +- tests/ui/suggestions/issue-89064.stderr | 9 +- ...assoc-type-suggestion-in-trait-impl.stderr | 9 +- tests/ui/traits/object/vs-lifetime.stderr | 9 +- tests/ui/traits/test-2.stderr | 18 +- .../ui/transmutability/issue-101739-2.stderr | 20 +- .../enum-variant-generic-args.stderr | 54 ++-- ...ypeck-builtin-bound-type-parameters.stderr | 78 ++---- .../typeck_type_placeholder_lifetime_1.stderr | 9 +- .../typeck_type_placeholder_lifetime_2.stderr | 9 +- .../ui/ufcs/ufcs-qpath-missing-params.stderr | 9 +- ...wrong-number-number-type-parameters.stderr | 45 +-- .../unboxed-closure-sugar-wrong-trait.stderr | 9 +- 52 files changed, 402 insertions(+), 811 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 7443070b9dee..db91a6ab2f49 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -954,7 +954,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let msg_lifetimes = format!("remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args)); - err.span_suggestion_verbose( + err.span_suggestion( span_redundant_lt_args, msg_lifetimes, "", @@ -1000,7 +1000,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { s = pluralize!(num_redundant_gen_args), ); - err.span_suggestion_verbose( + err.span_suggestion( span_redundant_type_or_const_args, msg_types_or_consts, "", @@ -1050,7 +1050,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { }, ); - err.span_suggestion_verbose(span, msg, "", Applicability::MaybeIncorrect); + err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect); } else if redundant_lifetime_args && redundant_type_or_const_args { remove_lifetime_args(err); remove_type_or_const_args(err); diff --git a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr index 755a0bba508f..ef551cbea3e6 100644 --- a/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr +++ b/tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr @@ -18,18 +18,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 | LL | type Y<'a>; | ^ -help: remove the unnecessary generics - | -LL - fn f<'a>(arg : Box = &'a ()>>) {} -LL + fn f<'a>(arg : Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/invalid_const_in_lifetime_position.rs:4:26 @@ -52,7 +49,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 @@ -60,11 +59,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f<'a>(arg : Box = &'a ()>>) {} -LL + fn f<'a>(arg : Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/invalid_const_in_lifetime_position.rs:4:26 @@ -87,7 +81,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/invalid_const_in_lifetime_position.rs:4:26 | LL | fn f<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/invalid_const_in_lifetime_position.rs:2:10 @@ -95,11 +91,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f<'a>(arg : Box = &'a ()>>) {} -LL + fn f<'a>(arg : Box>) {} - | error[E0038]: the trait `X` cannot be made into an object --> $DIR/invalid_const_in_lifetime_position.rs:4:20 diff --git a/tests/rustdoc-ui/mismatched_arg_count.stderr b/tests/rustdoc-ui/mismatched_arg_count.stderr index 9a698d8f5ad6..5daeef2eb18f 100644 --- a/tests/rustdoc-ui/mismatched_arg_count.stderr +++ b/tests/rustdoc-ui/mismatched_arg_count.stderr @@ -2,18 +2,15 @@ error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were --> $DIR/mismatched_arg_count.rs:7:29 | LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} - | ^^^^^ expected 1 lifetime argument + | ^^^^^ ---- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: type alias defined here, with 1 lifetime parameter: `'a` --> $DIR/mismatched_arg_count.rs:5:6 | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- -help: remove the lifetime argument - | -LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} -LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, T>) {} - | error: aborting due to 1 previous error diff --git a/tests/ui/argument-suggestions/issue-100154.stderr b/tests/ui/argument-suggestions/issue-100154.stderr index 8a650099b818..7eaebcafb595 100644 --- a/tests/ui/argument-suggestions/issue-100154.stderr +++ b/tests/ui/argument-suggestions/issue-100154.stderr @@ -2,7 +2,9 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/issue-100154.rs:4:5 | LL | foo::<()>(()); - | ^^^ expected 0 generic arguments + | ^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/issue-100154.rs:1:4 @@ -10,11 +12,6 @@ note: function defined here, with 0 generic parameters LL | fn foo(i: impl std::fmt::Display) {} | ^^^ = note: `impl Trait` cannot be explicitly specified as a generic argument -help: remove the unnecessary generics - | -LL - foo::<()>(()); -LL + foo(()); - | error[E0277]: `()` doesn't implement `std::fmt::Display` --> $DIR/issue-100154.rs:4:11 diff --git a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr index aaca4dc91c93..e9efc932ea8a 100644 --- a/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr +++ b/tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { - | ^^^^^^^^^^^^ expected 0 lifetime arguments + | ^^^^^^^^^^^^---- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 | LL | struct LockedMarket(T); | ^^^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { -LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { - | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 @@ -35,7 +32,9 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 | LL | async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { - | ^^^^^^^^^^^^ expected 0 lifetime arguments + | ^^^^^^^^^^^^---- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8 @@ -43,11 +42,6 @@ note: struct defined here, with 0 lifetime parameters LL | struct LockedMarket(T); | ^^^^^^^^^^^^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - async fn buy_lock(coroutine: &Mutex) -> LockedMarket<'_> { -LL + async fn buy_lock(coroutine: &Mutex) -> LockedMarket { - | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59 diff --git a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr index ceac2c95bfae..5c04c4c9d5b5 100644 --- a/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr +++ b/tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr @@ -2,13 +2,9 @@ error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments we --> $DIR/transmutable-ice-110969.rs:11:14 | LL | Dst: BikeshedIntrinsicFrom, - | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments - | -help: remove the unnecessary generic argument - | -LL - Dst: BikeshedIntrinsicFrom, -LL + Dst: BikeshedIntrinsicFrom, - | + | ^^^^^^^^^^^^^^^^^^^^^ -------- help: remove the unnecessary generic argument + | | + | expected at most 2 generic arguments error[E0308]: mismatched types --> $DIR/transmutable-ice-110969.rs:25:74 diff --git a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr index 61688f3acab6..a9c57dbf26a0 100644 --- a/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr +++ b/tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr @@ -23,18 +23,15 @@ error[E0107]: struct takes 2 generic arguments but 3 generic arguments were supp --> $DIR/infer-arg-test.rs:18:10 | LL | let a: All<_, _, _>; - | ^^^ expected 2 generic arguments + | ^^^ --- help: remove the unnecessary generic argument + | | + | expected 2 generic arguments | note: struct defined here, with 2 generic parameters: `T`, `N` --> $DIR/infer-arg-test.rs:3:8 | LL | struct All<'a, T, const N: usize> { | ^^^ - -------------- -help: remove the unnecessary generic argument - | -LL - let a: All<_, _, _>; -LL + let a: All<_, _>; - | error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr index c66f351ea7f0..4d1fb02b59e9 100644 --- a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr @@ -2,18 +2,15 @@ error[E0107]: function takes 1 generic argument but 2 generic arguments were sup --> $DIR/issue_114151.rs:17:5 | LL | foo::<_, L>([(); L + 1 + L]); - | ^^^ expected 1 generic argument + | ^^^ --- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: function defined here, with 1 generic parameter: `N` --> $DIR/issue_114151.rs:4:4 | LL | fn foo( | ^^^ -------------- -help: remove the unnecessary generic argument - | -LL - foo::<_, L>([(); L + 1 + L]); -LL + foo::<_>([(); L + 1 + L]); - | error[E0308]: mismatched types --> $DIR/issue_114151.rs:17:18 diff --git a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr index 416219117522..37e09a075fe3 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr @@ -18,18 +18,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 | LL | type Y<'a>; | ^ -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg: Box = &'a ()>>) {} -LL + fn f2<'a>(arg: Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-102768.rs:9:30 @@ -52,7 +49,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 @@ -60,11 +59,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg: Box = &'a ()>>) {} -LL + fn f2<'a>(arg: Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-102768.rs:9:30 @@ -87,7 +81,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/issue-102768.rs:5:10 @@ -95,11 +91,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg: Box = &'a ()>>) {} -LL + fn f2<'a>(arg: Box>) {} - | error[E0038]: the trait `X` cannot be made into an object --> $DIR/issue-102768.rs:9:24 diff --git a/tests/ui/const-generics/incorrect-number-of-const-args.stderr b/tests/ui/const-generics/incorrect-number-of-const-args.stderr index f670ebc8ab0b..09c963c350ef 100644 --- a/tests/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/tests/ui/const-generics/incorrect-number-of-const-args.stderr @@ -20,18 +20,15 @@ error[E0107]: function takes 2 generic arguments but 3 generic arguments were su --> $DIR/incorrect-number-of-const-args.rs:9:5 | LL | foo::<0, 0, 0>(); - | ^^^ expected 2 generic arguments + | ^^^ --- help: remove the unnecessary generic argument + | | + | expected 2 generic arguments | note: function defined here, with 2 generic parameters: `X`, `Y` --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { | ^^^ -------------- -------------- -help: remove the unnecessary generic argument - | -LL - foo::<0, 0, 0>(); -LL + foo::<0, 0>(); - | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr index dadb67343312..4004ad190325 100644 --- a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr +++ b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr @@ -27,18 +27,15 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/invalid-const-arg-for-type-param.rs:12:5 | LL | S::<0>; - | ^ expected 0 generic arguments + | ^----- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/invalid-const-arg-for-type-param.rs:3:8 | LL | struct S; | ^ -help: remove the unnecessary generics - | -LL - S::<0>; -LL + S; - | error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/invalid-constant-in-args.stderr b/tests/ui/const-generics/invalid-constant-in-args.stderr index c3a3f251d467..3e1263e8e8c0 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.stderr +++ b/tests/ui/const-generics/invalid-constant-in-args.stderr @@ -2,13 +2,9 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/invalid-constant-in-args.rs:4:12 | LL | let _: Cell<&str, "a"> = Cell::new(""); - | ^^^^ expected 1 generic argument - | -help: remove the unnecessary generic argument - | -LL - let _: Cell<&str, "a"> = Cell::new(""); -LL + let _: Cell<&str> = Cell::new(""); - | + | ^^^^ ----- help: remove the unnecessary generic argument + | | + | expected 1 generic argument error: aborting due to 1 previous error diff --git a/tests/ui/constructor-lifetime-args.stderr b/tests/ui/constructor-lifetime-args.stderr index 980a812e3b4e..d3759f4b3658 100644 --- a/tests/ui/constructor-lifetime-args.stderr +++ b/tests/ui/constructor-lifetime-args.stderr @@ -20,18 +20,15 @@ error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/constructor-lifetime-args.rs:19:5 | LL | S::<'static, 'static, 'static>(&0, &0); - | ^ expected 2 lifetime arguments + | ^ --------- help: remove the lifetime argument + | | + | expected 2 lifetime arguments | note: struct defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/constructor-lifetime-args.rs:9:8 | LL | struct S<'a, 'b>(&'a u8, &'b u8); | ^ -- -- -help: remove the lifetime argument - | -LL - S::<'static, 'static, 'static>(&0, &0); -LL + S::<'static, 'static>(&0, &0); - | error[E0107]: enum takes 2 lifetime arguments but 1 lifetime argument was supplied --> $DIR/constructor-lifetime-args.rs:22:8 @@ -55,18 +52,15 @@ error[E0107]: enum takes 2 lifetime arguments but 3 lifetime arguments were supp --> $DIR/constructor-lifetime-args.rs:24:8 | LL | E::V::<'static, 'static, 'static>(&0); - | ^ expected 2 lifetime arguments + | ^ --------- help: remove the lifetime argument + | | + | expected 2 lifetime arguments | note: enum defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/constructor-lifetime-args.rs:10:6 | LL | enum E<'a, 'b> { | ^ -- -- -help: remove the lifetime argument - | -LL - E::V::<'static, 'static, 'static>(&0); -LL + E::V::<'static, 'static>(&0); - | error: aborting due to 4 previous errors diff --git a/tests/ui/consts/effect_param.stderr b/tests/ui/consts/effect_param.stderr index fafc20b41924..c63be8035f30 100644 --- a/tests/ui/consts/effect_param.stderr +++ b/tests/ui/consts/effect_param.stderr @@ -2,49 +2,33 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/effect_param.rs:11:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - i8::checked_sub::(42, 43); -LL + i8::checked_sub(42, 43); - | + | ^^^^^^^^^^^--------- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:13:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - i8::checked_sub::(42, 43); -LL + i8::checked_sub(42, 43); - | + | ^^^^^^^^^^^-------- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:4:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - i8::checked_sub::(42, 43); -LL + i8::checked_sub(42, 43); - | + | ^^^^^^^^^^^-------- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/effect_param.rs:6:9 | LL | i8::checked_sub::(42, 43); - | ^^^^^^^^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - i8::checked_sub::(42, 43); -LL + i8::checked_sub(42, 43); - | + | ^^^^^^^^^^^--------- help: remove the unnecessary generics + | | + | expected 0 generic arguments error: aborting due to 4 previous errors diff --git a/tests/ui/error-codes/E0107.stderr b/tests/ui/error-codes/E0107.stderr index 3271abd8a79b..4aa83cf7f5ff 100644 --- a/tests/ui/error-codes/E0107.stderr +++ b/tests/ui/error-codes/E0107.stderr @@ -20,137 +20,113 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli --> $DIR/E0107.rs:17:10 | LL | bar: Bar<'a>, - | ^^^ expected 0 lifetime arguments + | ^^^---- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments | note: enum defined here, with 0 lifetime parameters --> $DIR/E0107.rs:6:6 | LL | enum Bar { | ^^^ -help: remove the unnecessary generics - | -LL - bar: Bar<'a>, -LL + bar: Bar, - | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:21:11 | LL | foo2: Foo<'a, 'b, 'c>, - | ^^^ expected 1 lifetime argument + | ^^^ -------- help: remove the lifetime arguments + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:1:8 | LL | struct Foo<'a>(&'a str); | ^^^ -- -help: remove the lifetime arguments - | -LL - foo2: Foo<'a, 'b, 'c>, -LL + foo2: Foo<'a>, - | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/E0107.rs:25:11 | LL | qux1: Qux<'a, 'b, i32>, - | ^^^ expected 1 lifetime argument + | ^^^ ---- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove the lifetime argument - | -LL - qux1: Qux<'a, 'b, i32>, -LL + qux1: Qux<'a, i32>, - | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/E0107.rs:29:11 | LL | qux2: Qux<'a, i32, 'b>, - | ^^^ expected 1 lifetime argument + | ^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove the lifetime argument - | -LL - qux2: Qux<'a, i32, 'b>, -LL + qux2: Qux<'a>, - | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:33:11 | LL | qux3: Qux<'a, 'b, 'c, i32>, - | ^^^ expected 1 lifetime argument + | ^^^ -------- help: remove the lifetime arguments + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove the lifetime arguments - | -LL - qux3: Qux<'a, 'b, 'c, i32>, -LL + qux3: Qux<'a, i32>, - | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:37:11 | LL | qux4: Qux<'a, i32, 'b, 'c>, - | ^^^ expected 1 lifetime argument + | ^^^ ------------- help: remove the lifetime arguments + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove the lifetime arguments - | -LL - qux4: Qux<'a, i32, 'b, 'c>, -LL + qux4: Qux<'a>, - | error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied --> $DIR/E0107.rs:41:11 | LL | qux5: Qux<'a, 'b, i32, 'c>, - | ^^^ expected 1 lifetime argument + | ^^^ ---- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/E0107.rs:3:8 | LL | struct Qux<'a, T>(&'a T); | ^^^ -- -help: remove the lifetime argument - | -LL - qux5: Qux<'a, 'b, i32, 'c>, -LL + qux5: Qux<'a, i32, 'c>, - | error[E0107]: struct takes 0 lifetime arguments but 2 lifetime arguments were supplied --> $DIR/E0107.rs:45:11 | LL | quux: Quux<'a, i32, 'b>, - | ^^^^ expected 0 lifetime arguments + | ^^^^ -- help: remove the lifetime argument + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/E0107.rs:4:8 | LL | struct Quux(T); | ^^^^ -help: remove the lifetime argument - | -LL - quux: Quux<'a, i32, 'b>, -LL + quux: Quux<, i32, 'b>, - | error[E0107]: trait takes 0 generic arguments but 2 generic arguments were supplied --> $DIR/E0107.rs:55:27 diff --git a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr index 252d81fa6f35..9d8e91c02ca3 100644 --- a/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr +++ b/tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr @@ -43,18 +43,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^ expected 0 generic arguments + | ^---- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 | LL | type Y<'a>; | ^ -help: remove the unnecessary generics - | -LL - fn foo<'a>(arg: Box>) {} -LL + fn foo<'a>(arg: Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 @@ -77,7 +74,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^ expected 0 generic arguments + | ^---- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 @@ -85,11 +84,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn foo<'a>(arg: Box>) {} -LL + fn foo<'a>(arg: Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 @@ -112,7 +106,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/gat-trait-path-parenthesised-args.rs:5:27 | LL | fn foo<'a>(arg: Box>) {} - | ^ expected 0 generic arguments + | ^---- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/gat-trait-path-parenthesised-args.rs:2:8 @@ -120,11 +116,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn foo<'a>(arg: Box>) {} -LL + fn foo<'a>(arg: Box>) {} - | error[E0224]: at least one trait is required for an object type --> $DIR/gat-trait-path-parenthesised-args.rs:5:29 diff --git a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr index 1c9351cb351a..4a20cf55cae7 100644 --- a/tests/ui/generic-associated-types/parameter_number_and_kind.stderr +++ b/tests/ui/generic-associated-types/parameter_number_and_kind.stderr @@ -2,18 +2,15 @@ error[E0107]: associated type takes 1 lifetime argument but 2 lifetime arguments --> $DIR/parameter_number_and_kind.rs:11:24 | LL | type FErr1 = Self::E<'static, 'static>; - | ^ expected 1 lifetime argument + | ^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` --> $DIR/parameter_number_and_kind.rs:8:10 | LL | type E<'a, T>; | ^ -- -help: remove the lifetime argument - | -LL - type FErr1 = Self::E<'static, 'static>; -LL + type FErr1 = Self::E<'static>; - | error[E0107]: associated type takes 1 generic argument but 0 generic arguments were supplied --> $DIR/parameter_number_and_kind.rs:11:24 @@ -35,18 +32,15 @@ error[E0107]: associated type takes 1 generic argument but 2 generic arguments w --> $DIR/parameter_number_and_kind.rs:14:27 | LL | type FErr2 = Self::E<'static, T, u32>; - | ^ expected 1 generic argument + | ^ ----- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: associated type defined here, with 1 generic parameter: `T` --> $DIR/parameter_number_and_kind.rs:8:10 | LL | type E<'a, T>; | ^ - -help: remove the unnecessary generic argument - | -LL - type FErr2 = Self::E<'static, T, u32>; -LL + type FErr2 = Self::E<'static, T>; - | error: aborting due to 3 previous errors diff --git a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr index 6ea96b6228ef..539b6695e9e8 100644 --- a/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr +++ b/tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr @@ -18,18 +18,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 | LL | type Y<'a>; | ^ -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg : Box = &'a ()>>) {} -LL + fn f2<'a>(arg : Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/trait-path-type-error-once-implemented.rs:6:29 @@ -52,7 +49,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 @@ -60,11 +59,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg : Box = &'a ()>>) {} -LL + fn f2<'a>(arg : Box>) {} - | error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/trait-path-type-error-once-implemented.rs:6:29 @@ -87,7 +81,9 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/trait-path-type-error-once-implemented.rs:6:29 | LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^ expected 0 generic arguments + | ^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/trait-path-type-error-once-implemented.rs:2:10 @@ -95,11 +91,6 @@ note: associated type defined here, with 0 generic parameters LL | type Y<'a>; | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - fn f2<'a>(arg : Box = &'a ()>>) {} -LL + fn f2<'a>(arg : Box>) {} - | error[E0038]: the trait `X` cannot be made into an object --> $DIR/trait-path-type-error-once-implemented.rs:6:23 diff --git a/tests/ui/generics/bad-mid-path-type-params.stderr b/tests/ui/generics/bad-mid-path-type-params.stderr index cff5464dce49..de3c0289fc6e 100644 --- a/tests/ui/generics/bad-mid-path-type-params.stderr +++ b/tests/ui/generics/bad-mid-path-type-params.stderr @@ -2,86 +2,71 @@ error[E0107]: associated function takes 1 generic argument but 2 generic argumen --> $DIR/bad-mid-path-type-params.rs:30:16 | LL | let _ = S::new::(1, 1.0); - | ^^^ expected 1 generic argument + | ^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:6:8 | LL | fn new(x: T, _: U) -> S { | ^^^ - -help: remove the unnecessary generic argument - | -LL - let _ = S::new::(1, 1.0); -LL + let _ = S::new::(1, 1.0); - | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/bad-mid-path-type-params.rs:33:13 | LL | let _ = S::<'a,isize>::new::(1, 1.0); - | ^ expected 0 lifetime arguments + | ^ -- help: remove the lifetime argument + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/bad-mid-path-type-params.rs:1:8 | LL | struct S { | ^ -help: remove the lifetime argument - | -LL - let _ = S::<'a,isize>::new::(1, 1.0); -LL + let _ = S::<,isize>::new::(1, 1.0); - | error[E0107]: associated function takes 1 generic argument but 2 generic arguments were supplied --> $DIR/bad-mid-path-type-params.rs:36:24 | LL | let _: S2 = Trait::new::(1, 1.0); - | ^^^ expected 1 generic argument + | ^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:14:8 | LL | fn new(x: T, y: U) -> Self; | ^^^ - -help: remove the unnecessary generic argument - | -LL - let _: S2 = Trait::new::(1, 1.0); -LL + let _: S2 = Trait::new::(1, 1.0); - | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/bad-mid-path-type-params.rs:39:17 | LL | let _: S2 = Trait::<'a,isize>::new::(1, 1.0); - | ^^^^^ expected 0 lifetime arguments + | ^^^^^ -- help: remove the lifetime argument + | | + | expected 0 lifetime arguments | note: trait defined here, with 0 lifetime parameters --> $DIR/bad-mid-path-type-params.rs:13:7 | LL | trait Trait { | ^^^^^ -help: remove the lifetime argument - | -LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); -LL + let _: S2 = Trait::<,isize>::new::(1, 1.0); - | error[E0107]: associated function takes 1 generic argument but 2 generic arguments were supplied --> $DIR/bad-mid-path-type-params.rs:39:36 | LL | let _: S2 = Trait::<'a,isize>::new::(1, 1.0); - | ^^^ expected 1 generic argument + | ^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: associated function defined here, with 1 generic parameter: `U` --> $DIR/bad-mid-path-type-params.rs:14:8 | LL | fn new(x: T, y: U) -> Self; | ^^^ - -help: remove the unnecessary generic argument - | -LL - let _: S2 = Trait::<'a,isize>::new::(1, 1.0); -LL + let _: S2 = Trait::<'a,isize>::new::(1, 1.0); - | error: aborting due to 5 previous errors diff --git a/tests/ui/generics/foreign-generic-mismatch.stderr b/tests/ui/generics/foreign-generic-mismatch.stderr index 4cf76cde9203..32beac41b21b 100644 --- a/tests/ui/generics/foreign-generic-mismatch.stderr +++ b/tests/ui/generics/foreign-generic-mismatch.stderr @@ -20,18 +20,15 @@ error[E0107]: function takes 1 lifetime argument but 2 lifetime arguments were s --> $DIR/foreign-generic-mismatch.rs:8:31 | LL | foreign_generic_mismatch::lt_arg::<'static, 'static>(); - | ^^^^^^ expected 1 lifetime argument + | ^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: function defined here, with 1 lifetime parameter: `'a` --> $DIR/auxiliary/foreign-generic-mismatch.rs:3:8 | LL | pub fn lt_arg<'a: 'a>() {} | ^^^^^^ -- -help: remove the lifetime argument - | -LL - foreign_generic_mismatch::lt_arg::<'static, 'static>(); -LL + foreign_generic_mismatch::lt_arg::<'static>(); - | error: aborting due to 2 previous errors diff --git a/tests/ui/generics/generic-arg-mismatch-recover.stderr b/tests/ui/generics/generic-arg-mismatch-recover.stderr index d2953e37c8cc..172683a8f9b3 100644 --- a/tests/ui/generics/generic-arg-mismatch-recover.stderr +++ b/tests/ui/generics/generic-arg-mismatch-recover.stderr @@ -2,52 +2,43 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/generic-arg-mismatch-recover.rs:6:5 | LL | Foo::<'static, 'static, ()>(&0); - | ^^^ expected 1 lifetime argument + | ^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/generic-arg-mismatch-recover.rs:1:8 | LL | struct Foo<'a, T: 'a>(&'a T); | ^^^ -- -help: remove the lifetime argument - | -LL - Foo::<'static, 'static, ()>(&0); -LL + Foo::<'static, ()>(&0); - | error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/generic-arg-mismatch-recover.rs:9:5 | LL | Bar::<'static, 'static, ()>(&()); - | ^^^ expected 1 lifetime argument + | ^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/generic-arg-mismatch-recover.rs:3:8 | LL | struct Bar<'a>(&'a ()); | ^^^ -- -help: remove the lifetime argument - | -LL - Bar::<'static, 'static, ()>(&()); -LL + Bar::<'static, ()>(&()); - | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/generic-arg-mismatch-recover.rs:9:5 | LL | Bar::<'static, 'static, ()>(&()); - | ^^^ expected 0 generic arguments + | ^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/generic-arg-mismatch-recover.rs:3:8 | LL | struct Bar<'a>(&'a ()); | ^^^ -help: remove the unnecessary generic argument - | -LL - Bar::<'static, 'static, ()>(&()); -LL + Bar::<'static, 'static, >(&()); - | error: aborting due to 3 previous errors diff --git a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr index a180e348a686..16bdc2de2520 100644 --- a/tests/ui/generics/generic-impl-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-impl-more-params-with-defaults.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes at most 2 generic arguments but 3 generic arguments w --> $DIR/generic-impl-more-params-with-defaults.rs:13:5 | LL | Vec::::new(); - | ^^^ expected at most 2 generic arguments + | ^^^ ------ help: remove the unnecessary generic argument + | | + | expected at most 2 generic arguments | note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-impl-more-params-with-defaults.rs:5:8 | LL | struct Vec( | ^^^ - -------- -help: remove the unnecessary generic argument - | -LL - Vec::::new(); -LL + Vec::::new(); - | error: aborting due to 1 previous error diff --git a/tests/ui/generics/generic-type-more-params-with-defaults.stderr b/tests/ui/generics/generic-type-more-params-with-defaults.stderr index 9b73b7375d79..1eb76e043e04 100644 --- a/tests/ui/generics/generic-type-more-params-with-defaults.stderr +++ b/tests/ui/generics/generic-type-more-params-with-defaults.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes at most 2 generic arguments but 3 generic arguments w --> $DIR/generic-type-more-params-with-defaults.rs:9:12 | LL | let _: Vec; - | ^^^ expected at most 2 generic arguments + | ^^^ ------ help: remove the unnecessary generic argument + | | + | expected at most 2 generic arguments | note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-type-more-params-with-defaults.rs:5:8 | LL | struct Vec( | ^^^ - -------- -help: remove the unnecessary generic argument - | -LL - let _: Vec; -LL + let _: Vec; - | error: aborting due to 1 previous error diff --git a/tests/ui/generics/wrong-number-of-args.stderr b/tests/ui/generics/wrong-number-of-args.stderr index 17503b86e19c..bac0d26b622d 100644 --- a/tests/ui/generics/wrong-number-of-args.stderr +++ b/tests/ui/generics/wrong-number-of-args.stderr @@ -171,86 +171,71 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/wrong-number-of-args.rs:6:14 | LL | type B = Ty<'static>; - | ^^ expected 0 lifetime arguments + | ^^--------- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ -help: remove the unnecessary generics - | -LL - type B = Ty<'static>; -LL + type B = Ty; - | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:10:14 | LL | type C = Ty<'static, usize>; - | ^^ expected 0 lifetime arguments + | ^^ ------- help: remove the lifetime argument + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ -help: remove the lifetime argument - | -LL - type C = Ty<'static, usize>; -LL + type C = Ty<, usize>; - | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/wrong-number-of-args.rs:10:14 | LL | type C = Ty<'static, usize>; - | ^^ expected 0 generic arguments + | ^^ ----- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ -help: remove the unnecessary generic argument - | -LL - type C = Ty<'static, usize>; -LL + type C = Ty<'static, >; - | error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:16:14 | LL | type D = Ty<'static, usize, { 0 }>; - | ^^ expected 0 lifetime arguments + | ^^ ------- help: remove the lifetime argument + | | + | expected 0 lifetime arguments | note: struct defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ -help: remove the lifetime argument - | -LL - type D = Ty<'static, usize, { 0 }>; -LL + type D = Ty<, usize, { 0 }>; - | error[E0107]: struct takes 0 generic arguments but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:16:14 | LL | type D = Ty<'static, usize, { 0 }>; - | ^^ expected 0 generic arguments + | ^^ ------- help: remove the unnecessary generic arguments + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:2:12 | LL | struct Ty; | ^^ -help: remove the unnecessary generic arguments - | -LL - type D = Ty<'static, usize, { 0 }>; -LL + type D = Ty<'static, usize>; - | error[E0107]: missing generics for struct `type_and_type::Ty` --> $DIR/wrong-number-of-args.rs:26:14 @@ -290,18 +275,15 @@ error[E0107]: struct takes 2 generic arguments but 3 generic arguments were supp --> $DIR/wrong-number-of-args.rs:36:14 | LL | type D = Ty; - | ^^ expected 2 generic arguments + | ^^ ------ help: remove the unnecessary generic argument + | | + | expected 2 generic arguments | note: struct defined here, with 2 generic parameters: `A`, `B` --> $DIR/wrong-number-of-args.rs:24:12 | LL | struct Ty(A, B); | ^^ - - -help: remove the unnecessary generic argument - | -LL - type D = Ty; -LL + type D = Ty; - | error[E0107]: struct takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:40:14 @@ -371,35 +353,29 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/wrong-number-of-args.rs:70:14 | LL | type F = Ty<'static, usize, 'static, usize>; - | ^^ expected 1 lifetime argument + | ^^ ---------------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>(&'a T); | ^^ -- -help: remove the lifetime argument - | -LL - type F = Ty<'static, usize, 'static, usize>; -LL + type F = Ty<'static, usize>; - | error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:70:14 | LL | type F = Ty<'static, usize, 'static, usize>; - | ^^ expected 1 generic argument + | ^^ ---------------- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>(&'a T); | ^^ - -help: remove the unnecessary generic argument - | -LL - type F = Ty<'static, usize, 'static, usize>; -LL + type F = Ty<'static, usize>; - | error[E0107]: missing generics for struct `type_and_type_and_type::Ty` --> $DIR/wrong-number-of-args.rs:80:14 @@ -439,18 +415,15 @@ error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments w --> $DIR/wrong-number-of-args.rs:92:14 | LL | type E = Ty; - | ^^ expected at most 3 generic arguments + | ^^ ----- help: remove the unnecessary generic argument + | | + | expected at most 3 generic arguments | note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C` --> $DIR/wrong-number-of-args.rs:78:12 | LL | struct Ty(A, B, C); | ^^ - - ---------------- -help: remove the unnecessary generic argument - | -LL - type E = Ty; -LL + type E = Ty; - | error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:96:14 @@ -472,35 +445,29 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/wrong-number-of-args.rs:116:22 | LL | type A = Box>; - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:104:11 | LL | trait NonGeneric { | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - type A = Box>; -LL + type A = Box; - | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:125:22 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^ expected 1 lifetime argument + | ^^^^^^^^^^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:108:11 | LL | trait GenericLifetime<'a> { | ^^^^^^^^^^^^^^^ -- -help: remove the lifetime argument - | -LL - type C = Box>; -LL + type C = Box>; - | error[E0107]: missing generics for trait `GenericType` --> $DIR/wrong-number-of-args.rs:129:22 @@ -522,18 +489,15 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:133:22 | LL | type E = Box>; - | ^^^^^^^^^^^ expected 1 generic argument + | ^^^^^^^^^^^ ------- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:112:11 | LL | trait GenericType { | ^^^^^^^^^^^ - -help: remove the unnecessary generic argument - | -LL - type E = Box>; -LL + type E = Box>; - | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:142:22 @@ -555,52 +519,43 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/wrong-number-of-args.rs:153:26 | LL | type A = Box>; - | ^^^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^^^------------------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:149:15 | LL | trait NonGenericAT { | ^^^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - type A = Box>; -LL + type A = Box; - | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:168:26 | LL | type B = Box>; - | ^^^^^^^^^^^^^^^^^ expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:159:15 | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ -- -help: remove the lifetime argument - | -LL - type B = Box>; -LL + type B = Box>; - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/wrong-number-of-args.rs:172:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/wrong-number-of-args.rs:159:15 | LL | trait GenericLifetimeAT<'a> { | ^^^^^^^^^^^^^^^^^ -help: remove the unnecessary generic argument - | -LL - type C = Box>; -LL + type C = Box>; - | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:185:26 @@ -622,35 +577,29 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:189:26 | LL | type B = Box>; - | ^^^^^^^^^^^^^ expected 1 generic argument + | ^^^^^^^^^^^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:181:15 | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ - -help: remove the unnecessary generic argument - | -LL - type B = Box>; -LL + type B = Box>; - | error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:193:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^ expected 0 lifetime arguments + | ^^^^^^^^^^^^^--------------------- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments | note: trait defined here, with 0 lifetime parameters --> $DIR/wrong-number-of-args.rs:181:15 | LL | trait GenericTypeAT { | ^^^^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - type C = Box>; -LL + type C = Box; - | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:193:26 @@ -704,18 +653,15 @@ error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supp --> $DIR/wrong-number-of-args.rs:216:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove the lifetime argument - | -LL - type C = Box>; -LL + type C = Box>; - | error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:216:26 @@ -737,86 +683,71 @@ error[E0107]: trait takes 1 generic argument but 2 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:227:26 | LL | type E = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove the unnecessary generic argument - | -LL - type E = Box>; -LL + type E = Box>; - | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:234:26 | LL | type F = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove the lifetime argument - | -LL - type F = Box>; -LL + type F = Box>; - | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:238:26 | LL | type G = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove the unnecessary generic argument - | -LL - type G = Box>; -LL + type G = Box>; - | error[E0107]: trait takes 1 lifetime argument but 2 lifetime arguments were supplied --> $DIR/wrong-number-of-args.rs:242:26 | LL | type H = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 lifetime argument + | ^^^^^^^^^^^^^^^^^^^^^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ -- -help: remove the lifetime argument - | -LL - type H = Box>; -LL + type H = Box>; - | error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:242:26 | LL | type H = Box>; - | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | ^^^^^^^^^^^^^^^^^^^^^ ---- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` --> $DIR/wrong-number-of-args.rs:201:15 | LL | trait GenericLifetimeTypeAT<'a, A> { | ^^^^^^^^^^^^^^^^^^^^^ - -help: remove the unnecessary generic argument - | -LL - type H = Box>; -LL + type H = Box>; - | error[E0107]: trait takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:254:26 @@ -856,18 +787,15 @@ error[E0107]: trait takes 2 generic arguments but 3 generic arguments were suppl --> $DIR/wrong-number-of-args.rs:262:26 | LL | type C = Box>; - | ^^^^^^^^^^^^^^^^^ expected 2 generic arguments + | ^^^^^^^^^^^^^^^^^ ---- help: remove the unnecessary generic argument + | | + | expected 2 generic arguments | note: trait defined here, with 2 generic parameters: `A`, `B` --> $DIR/wrong-number-of-args.rs:250:15 | LL | trait GenericTypeTypeAT { | ^^^^^^^^^^^^^^^^^ - - -help: remove the unnecessary generic argument - | -LL - type C = Box>; -LL + type C = Box>; - | error[E0107]: trait takes 2 lifetime arguments but 1 lifetime argument was supplied --> $DIR/wrong-number-of-args.rs:277:26 @@ -983,13 +911,9 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/wrong-number-of-args.rs:318:18 | LL | type C = HashMap<'static>; - | ^^^^^^^ expected 0 lifetime arguments - | -help: remove the unnecessary generics - | -LL - type C = HashMap<'static>; -LL + type C = HashMap; - | + | ^^^^^^^--------- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:318:18 @@ -1006,13 +930,9 @@ error[E0107]: struct takes at most 3 generic arguments but 4 generic arguments w --> $DIR/wrong-number-of-args.rs:324:18 | LL | type D = HashMap; - | ^^^^^^^ expected at most 3 generic arguments - | -help: remove the unnecessary generic argument - | -LL - type D = HashMap; -LL + type D = HashMap; - | + | ^^^^^^^ ----- help: remove the unnecessary generic argument + | | + | expected at most 3 generic arguments error[E0107]: struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:328:18 @@ -1053,13 +973,9 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli --> $DIR/wrong-number-of-args.rs:342:18 | LL | type C = Result<'static>; - | ^^^^^^ expected 0 lifetime arguments - | -help: remove the unnecessary generics - | -LL - type C = Result<'static>; -LL + type C = Result; - | + | ^^^^^^--------- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:342:18 @@ -1076,13 +992,9 @@ error[E0107]: enum takes 2 generic arguments but 3 generic arguments were suppli --> $DIR/wrong-number-of-args.rs:348:18 | LL | type D = Result; - | ^^^^^^ expected 2 generic arguments - | -help: remove the unnecessary generic argument - | -LL - type D = Result; -LL + type D = Result; - | + | ^^^^^^ ------ help: remove the unnecessary generic argument + | | + | expected 2 generic arguments error[E0107]: enum takes 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:352:18 diff --git a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index e225d7076b8c..9b0d0c554f01 100644 --- a/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/tests/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -2,7 +2,9 @@ error[E0107]: function takes 1 generic argument but 2 generic arguments were sup --> $DIR/explicit-generic-args-for-impl.rs:4:5 | LL | foo::("".to_string()); - | ^^^ expected 1 generic argument + | ^^^ -------- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: function defined here, with 1 generic parameter: `T` --> $DIR/explicit-generic-args-for-impl.rs:1:4 @@ -10,11 +12,6 @@ note: function defined here, with 1 generic parameter: `T` LL | fn foo(_f: impl AsRef) {} | ^^^ - = note: `impl Trait` cannot be explicitly specified as a generic argument -help: remove the unnecessary generic argument - | -LL - foo::("".to_string()); -LL + foo::("".to_string()); - | error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr index 1802a22d6cfe..81570781b27d 100644 --- a/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr +++ b/tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr @@ -38,35 +38,29 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/opaque-and-lifetime-mismatch.rs:4:17 | LL | fn bar() -> Wrapper; - | ^^^^^^^ expected 0 generic arguments + | ^^^^^^^ ---------- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove the unnecessary generic argument - | -LL - fn bar() -> Wrapper; -LL + fn bar() -> Wrapper<>; - | error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/opaque-and-lifetime-mismatch.rs:18:17 | LL | fn foo() -> Wrapper; - | ^^^^^^^ expected 0 generic arguments + | ^^^^^^^ ---------- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove the unnecessary generic argument - | -LL - fn foo() -> Wrapper; -LL + fn foo() -> Wrapper<>; - | error[E0053]: method `bar` has an incompatible return type for trait --> $DIR/opaque-and-lifetime-mismatch.rs:10:17 @@ -99,18 +93,15 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/opaque-and-lifetime-mismatch.rs:24:17 | LL | fn foo() -> Wrapper { - | ^^^^^^^ expected 0 generic arguments + | ^^^^^^^ ---------- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/opaque-and-lifetime-mismatch.rs:1:8 | LL | struct Wrapper<'rom>(&'rom ()); | ^^^^^^^ -help: remove the unnecessary generic argument - | -LL - fn foo() -> Wrapper { -LL + fn foo() -> Wrapper<> { - | error: aborting due to 8 previous errors diff --git a/tests/ui/issues/issue-18423.stderr b/tests/ui/issues/issue-18423.stderr index c1a4aacd2a54..b5f19b5c9b23 100644 --- a/tests/ui/issues/issue-18423.stderr +++ b/tests/ui/issues/issue-18423.stderr @@ -2,13 +2,9 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp --> $DIR/issue-18423.rs:4:8 | LL | x: Box<'a, isize> - | ^^^ expected 0 lifetime arguments - | -help: remove the lifetime argument - | -LL - x: Box<'a, isize> -LL + x: Box<, isize> - | + | ^^^ -- help: remove the lifetime argument + | | + | expected 0 lifetime arguments error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-53251.stderr b/tests/ui/issues/issue-53251.stderr index 854e9bc0c9b3..981966354b97 100644 --- a/tests/ui/issues/issue-53251.stderr +++ b/tests/ui/issues/issue-53251.stderr @@ -2,7 +2,9 @@ error[E0107]: associated function takes 0 generic arguments but 1 generic argume --> $DIR/issue-53251.rs:11:20 | LL | S::f::(); - | ^ expected 0 generic arguments + | ^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments ... LL | impl_add!(a b); | -------------- in this macro invocation @@ -13,17 +15,14 @@ note: associated function defined here, with 0 generic parameters LL | fn f() {} | ^ = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) -help: remove the unnecessary generics - | -LL - S::f::(); -LL + S::f(); - | error[E0107]: associated function takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-53251.rs:11:20 | LL | S::f::(); - | ^ expected 0 generic arguments + | ^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments ... LL | impl_add!(a b); | -------------- in this macro invocation @@ -35,11 +34,6 @@ LL | fn f() {} | ^ = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: this error originates in the macro `impl_add` (in Nightly builds, run with -Z macro-backtrace for more info) -help: remove the unnecessary generics - | -LL - S::f::(); -LL + S::f(); - | error: aborting due to 2 previous errors diff --git a/tests/ui/issues/issue-60622.stderr b/tests/ui/issues/issue-60622.stderr index 66e96131f5e0..298ef3799f24 100644 --- a/tests/ui/issues/issue-60622.stderr +++ b/tests/ui/issues/issue-60622.stderr @@ -20,18 +20,15 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-60622.rs:10:7 | LL | b.a::<'_, T>(); - | ^ expected 0 generic arguments + | ^ - help: remove the unnecessary generic argument + | | + | expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-60622.rs:6:8 | LL | fn a(&self) {} | ^ -help: remove the unnecessary generic argument - | -LL - b.a::<'_, T>(); -LL + b.a::<'_, >(); - | error: aborting due to 2 previous errors diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr index c0a5b62a56a2..1717b6aa1242 100644 --- a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr @@ -2,18 +2,15 @@ error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were --> $DIR/mismatched_arg_count.rs:9:29 | LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} - | ^^^^^ expected 1 lifetime argument + | ^^^^^ ---- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: type alias defined here, with 1 lifetime parameter: `'a` --> $DIR/mismatched_arg_count.rs:7:6 | LL | type Alias<'a, T> = >::Assoc; | ^^^^^ -- -help: remove the lifetime argument - | -LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} -LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, T>) {} - | error: aborting due to 1 previous error diff --git a/tests/ui/lifetimes/noisy-follow-up-erro.stderr b/tests/ui/lifetimes/noisy-follow-up-erro.stderr index 3c2d0df683a9..04863badbd1e 100644 --- a/tests/ui/lifetimes/noisy-follow-up-erro.stderr +++ b/tests/ui/lifetimes/noisy-follow-up-erro.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/noisy-follow-up-erro.rs:12:30 | LL | fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { - | ^^^ expected 2 lifetime arguments + | ^^^ ---- help: remove the lifetime argument + | | + | expected 2 lifetime arguments | note: struct defined here, with 2 lifetime parameters: `'c`, `'d` --> $DIR/noisy-follow-up-erro.rs:1:8 | LL | struct Foo<'c, 'd>(&'c (), &'d ()); | ^^^ -- -- -help: remove the lifetime argument - | -LL - fn boom(&self, foo: &mut Foo<'_, '_, 'a>) -> Result<(), &'a ()> { -LL + fn boom(&self, foo: &mut Foo<'_, '_>) -> Result<(), &'a ()> { - | error[E0621]: explicit lifetime required in the type of `foo` --> $DIR/noisy-follow-up-erro.rs:14:9 diff --git a/tests/ui/methods/method-call-lifetime-args-fail.stderr b/tests/ui/methods/method-call-lifetime-args-fail.stderr index 2eda01fa20c3..b251dd4d342f 100644 --- a/tests/ui/methods/method-call-lifetime-args-fail.stderr +++ b/tests/ui/methods/method-call-lifetime-args-fail.stderr @@ -20,18 +20,15 @@ error[E0107]: method takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/method-call-lifetime-args-fail.rs:18:7 | LL | S.early::<'static, 'static, 'static>(); - | ^^^^^ expected 2 lifetime arguments + | ^^^^^ --------- help: remove the lifetime argument + | | + | expected 2 lifetime arguments | note: method defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/method-call-lifetime-args-fail.rs:6:8 | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- -help: remove the lifetime argument - | -LL - S.early::<'static, 'static, 'static>(); -LL + S.early::<'static, 'static>(); - | error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present --> $DIR/method-call-lifetime-args-fail.rs:27:15 @@ -223,18 +220,15 @@ error[E0107]: method takes 2 lifetime arguments but 3 lifetime arguments were su --> $DIR/method-call-lifetime-args-fail.rs:65:8 | LL | S::early::<'static, 'static, 'static>(S); - | ^^^^^ expected 2 lifetime arguments + | ^^^^^ --------- help: remove the lifetime argument + | | + | expected 2 lifetime arguments | note: method defined here, with 2 lifetime parameters: `'a`, `'b` --> $DIR/method-call-lifetime-args-fail.rs:6:8 | LL | fn early<'a, 'b>(self) -> (&'a u8, &'b u8) { loop {} } | ^^^^^ -- -- -help: remove the lifetime argument - | -LL - S::early::<'static, 'static, 'static>(S); -LL + S::early::<'static, 'static>(S); - | error: aborting due to 18 previous errors diff --git a/tests/ui/resolve/issue-3214.stderr b/tests/ui/resolve/issue-3214.stderr index f6f8c3b77467..1c64fdc1711f 100644 --- a/tests/ui/resolve/issue-3214.stderr +++ b/tests/ui/resolve/issue-3214.stderr @@ -12,18 +12,15 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-3214.rs:6:22 | LL | impl Drop for Foo { - | ^^^ expected 0 generic arguments + | ^^^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: struct defined here, with 0 generic parameters --> $DIR/issue-3214.rs:2:12 | LL | struct Foo { | ^^^ -help: remove the unnecessary generics - | -LL - impl Drop for Foo { -LL + impl Drop for Foo { - | error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr index 6945e8465da7..8c591edac540 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr @@ -2,18 +2,15 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params-cross-crate.rs:14:5 | LL | foo::(); - | ^^^ expected 0 generic arguments + | ^^^--------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/auxiliary/cross-crate.rs:5:14 | LL | pub const fn foo() {} | ^^^ -help: remove the unnecessary generics - | -LL - foo::(); -LL + foo(); - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params-cross-crate.rs:16:12 @@ -35,18 +32,15 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params-cross-crate.rs:7:5 | LL | foo::(); - | ^^^ expected 0 generic arguments + | ^^^-------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/auxiliary/cross-crate.rs:5:14 | LL | pub const fn foo() {} | ^^^ -help: remove the unnecessary generics - | -LL - foo::(); -LL + foo(); - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params-cross-crate.rs:9:12 diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr index 0f9380de2862..cc08114ddb56 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr @@ -16,18 +16,15 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params.rs:22:5 | LL | foo::(); - | ^^^ expected 0 generic arguments + | ^^^--------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/no-explicit-const-params.rs:3:10 | LL | const fn foo() {} | ^^^ -help: remove the unnecessary generics - | -LL - foo::(); -LL + foo(); - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params.rs:24:12 @@ -58,18 +55,15 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp --> $DIR/no-explicit-const-params.rs:15:5 | LL | foo::(); - | ^^^ expected 0 generic arguments + | ^^^-------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: function defined here, with 0 generic parameters --> $DIR/no-explicit-const-params.rs:3:10 | LL | const fn foo() {} | ^^^ -help: remove the unnecessary generics - | -LL - foo::(); -LL + foo(); - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/no-explicit-const-params.rs:17:12 diff --git a/tests/ui/seq-args.stderr b/tests/ui/seq-args.stderr index 47c5119b9173..6e0d484d013d 100644 --- a/tests/ui/seq-args.stderr +++ b/tests/ui/seq-args.stderr @@ -2,35 +2,29 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/seq-args.rs:4:13 | LL | impl Seq for Vec { - | ^^^ expected 0 generic arguments + | ^^^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/seq-args.rs:2:11 | LL | trait Seq { } | ^^^ -help: remove the unnecessary generics - | -LL - impl Seq for Vec { -LL + impl Seq for Vec { - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/seq-args.rs:9:10 | LL | impl Seq for u32 { - | ^^^ expected 0 generic arguments + | ^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/seq-args.rs:2:11 | LL | trait Seq { } | ^^^ -help: remove the unnecessary generics - | -LL - impl Seq for u32 { -LL + impl Seq for u32 { - | error: aborting due to 2 previous errors diff --git a/tests/ui/structs/struct-path-associated-type.stderr b/tests/ui/structs/struct-path-associated-type.stderr index 1a2a346b0e30..de396e875b0c 100644 --- a/tests/ui/structs/struct-path-associated-type.stderr +++ b/tests/ui/structs/struct-path-associated-type.stderr @@ -8,18 +8,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/struct-path-associated-type.rs:14:16 | LL | let z = T::A:: {}; - | ^ expected 0 generic arguments + | ^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/struct-path-associated-type.rs:4:10 | LL | type A; | ^ -help: remove the unnecessary generics - | -LL - let z = T::A:: {}; -LL + let z = T::A {}; - | error[E0071]: expected struct, variant or union type, found associated type --> $DIR/struct-path-associated-type.rs:14:13 @@ -37,18 +34,15 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w --> $DIR/struct-path-associated-type.rs:25:16 | LL | let z = T::A:: {}; - | ^ expected 0 generic arguments + | ^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated type defined here, with 0 generic parameters --> $DIR/struct-path-associated-type.rs:4:10 | LL | type A; | ^ -help: remove the unnecessary generics - | -LL - let z = T::A:: {}; -LL + let z = T::A {}; - | error[E0223]: ambiguous associated type --> $DIR/struct-path-associated-type.rs:32:13 diff --git a/tests/ui/structs/structure-constructor-type-mismatch.stderr b/tests/ui/structs/structure-constructor-type-mismatch.stderr index 606381251157..819b65ffb716 100644 --- a/tests/ui/structs/structure-constructor-type-mismatch.stderr +++ b/tests/ui/structs/structure-constructor-type-mismatch.stderr @@ -68,18 +68,15 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/structure-constructor-type-mismatch.rs:48:15 | LL | let pt3 = PointF:: { - | ^^^^^^ expected 0 generic arguments + | ^^^^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/structure-constructor-type-mismatch.rs:6:6 | LL | type PointF = Point; | ^^^^^^ -help: remove the unnecessary generics - | -LL - let pt3 = PointF:: { -LL + let pt3 = PointF { - | error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:49:12 @@ -107,18 +104,15 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/structure-constructor-type-mismatch.rs:54:9 | LL | PointF:: { .. } => {} - | ^^^^^^ expected 0 generic arguments + | ^^^^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/structure-constructor-type-mismatch.rs:6:6 | LL | type PointF = Point; | ^^^^^^ -help: remove the unnecessary generics - | -LL - PointF:: { .. } => {} -LL + PointF { .. } => {} - | error[E0308]: mismatched types --> $DIR/structure-constructor-type-mismatch.rs:54:9 diff --git a/tests/ui/suggestions/issue-101421.stderr b/tests/ui/suggestions/issue-101421.stderr index 7adf07aa531c..12b4c04c2a33 100644 --- a/tests/ui/suggestions/issue-101421.stderr +++ b/tests/ui/suggestions/issue-101421.stderr @@ -2,18 +2,15 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-101421.rs:10:8 | LL | ().f::<()>(()); - | ^ expected 0 generic arguments + | ^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-101421.rs:2:8 | LL | fn f(&self, _: ()); | ^ -help: remove the unnecessary generics - | -LL - ().f::<()>(()); -LL + ().f(()); - | error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/issue-104287.stderr b/tests/ui/suggestions/issue-104287.stderr index 808f95628058..d728e6c3d8c1 100644 --- a/tests/ui/suggestions/issue-104287.stderr +++ b/tests/ui/suggestions/issue-104287.stderr @@ -2,18 +2,15 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/issue-104287.rs:10:5 | LL | foo::<()>(x); - | ^^^ expected 0 generic arguments + | ^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/issue-104287.rs:6:8 | LL | fn foo(&self) {} | ^^^ -help: remove the unnecessary generics - | -LL - foo::<()>(x); -LL + foo(x); - | error[E0425]: cannot find function `foo` in this scope --> $DIR/issue-104287.rs:10:5 diff --git a/tests/ui/suggestions/issue-89064.stderr b/tests/ui/suggestions/issue-89064.stderr index a64a1986af84..837fef60d1e6 100644 --- a/tests/ui/suggestions/issue-89064.stderr +++ b/tests/ui/suggestions/issue-89064.stderr @@ -46,18 +46,15 @@ error[E0107]: associated function takes 0 generic arguments but 1 generic argume --> $DIR/issue-89064.rs:27:21 | LL | let _ = A::::foo::(); - | ^^^ expected 0 generic arguments + | ^^^----- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: associated function defined here, with 0 generic parameters --> $DIR/issue-89064.rs:4:8 | LL | fn foo() {} | ^^^ -help: remove the unnecessary generics - | -LL - let _ = A::::foo::(); -LL + let _ = A::::foo(); - | error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-89064.rs:31:16 diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index d25192b3d6d8..a22d88b7c59f 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -117,18 +117,15 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:40:58 | LL | impl, U> YetAnotherTrait for Struct {} - | ^^^^^^ expected 1 generic argument + | ^^^^^^ --- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:8 | LL | struct Struct> { | ^^^^^^ - -help: remove the unnecessary generic argument - | -LL - impl, U> YetAnotherTrait for Struct {} -LL + impl, U> YetAnotherTrait for Struct {} - | error: aborting due to 9 previous errors diff --git a/tests/ui/traits/object/vs-lifetime.stderr b/tests/ui/traits/object/vs-lifetime.stderr index 889e1e82876a..916197ff0965 100644 --- a/tests/ui/traits/object/vs-lifetime.stderr +++ b/tests/ui/traits/object/vs-lifetime.stderr @@ -8,18 +8,15 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup --> $DIR/vs-lifetime.rs:11:12 | LL | let _: S<'static, 'static>; - | ^ expected 1 lifetime argument + | ^ --------- help: remove the lifetime argument + | | + | expected 1 lifetime argument | note: struct defined here, with 1 lifetime parameter: `'a` --> $DIR/vs-lifetime.rs:4:8 | LL | struct S<'a, T>(&'a u8, T); | ^ -- -help: remove the lifetime argument - | -LL - let _: S<'static, 'static>; -LL + let _: S<'static>; - | error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/vs-lifetime.rs:11:12 diff --git a/tests/ui/traits/test-2.stderr b/tests/ui/traits/test-2.stderr index d64497309ef9..0ee64cc09522 100644 --- a/tests/ui/traits/test-2.stderr +++ b/tests/ui/traits/test-2.stderr @@ -2,35 +2,29 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/test-2.rs:9:8 | LL | 10.dup::(); - | ^^^ expected 0 generic arguments + | ^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/test-2.rs:4:16 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^ -help: remove the unnecessary generics - | -LL - 10.dup::(); -LL + 10.dup(); - | error[E0107]: method takes 1 generic argument but 2 generic arguments were supplied --> $DIR/test-2.rs:11:8 | LL | 10.blah::(); - | ^^^^ expected 1 generic argument + | ^^^^ ----- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: method defined here, with 1 generic parameter: `X` --> $DIR/test-2.rs:4:39 | LL | trait bar { fn dup(&self) -> Self; fn blah(&self); } | ^^^^ - -help: remove the unnecessary generic argument - | -LL - 10.blah::(); -LL + 10.blah::(); - | error[E0038]: the trait `bar` cannot be made into an object --> $DIR/test-2.rs:13:22 diff --git a/tests/ui/transmutability/issue-101739-2.stderr b/tests/ui/transmutability/issue-101739-2.stderr index dabb51ee7aef..6b0a36a414bf 100644 --- a/tests/ui/transmutability/issue-101739-2.stderr +++ b/tests/ui/transmutability/issue-101739-2.stderr @@ -1,17 +1,15 @@ error[E0107]: trait takes at most 2 generic arguments but 5 generic arguments were supplied --> $DIR/issue-101739-2.rs:17:14 | -LL | Dst: BikeshedIntrinsicFrom< - | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments - | -help: remove the unnecessary generic arguments - | -LL - ASSUME_ALIGNMENT, -LL - ASSUME_LIFETIMES, -LL - ASSUME_VALIDITY, -LL - ASSUME_VISIBILITY, -LL + ASSUME_ALIGNMENT, - | +LL | Dst: BikeshedIntrinsicFrom< + | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments +LL | Src, +LL | ASSUME_ALIGNMENT, + | _____________________________- +LL | | ASSUME_LIFETIMES, +LL | | ASSUME_VALIDITY, +LL | | ASSUME_VISIBILITY, + | |_____________________________- help: remove the unnecessary generic arguments error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index aaed6a9b5446..482a314db602 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -308,35 +308,29 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:64:5 | LL | AliasFixed::<()>::TSVariant(()); - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::TSVariant(()); -LL + AliasFixed::TSVariant(()); - | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:66:5 | LL | AliasFixed::<()>::TSVariant::<()>(()); - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::TSVariant::<()>(()); -LL + AliasFixed::TSVariant::<()>(()); - | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:66:35 @@ -405,35 +399,29 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:82:5 | LL | AliasFixed::<()>::SVariant { v: () }; - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::SVariant { v: () }; -LL + AliasFixed::SVariant { v: () }; - | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:84:5 | LL | AliasFixed::<()>::SVariant::<()> { v: () }; - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::SVariant::<()> { v: () }; -LL + AliasFixed::SVariant::<()> { v: () }; - | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:84:34 @@ -486,35 +474,29 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su --> $DIR/enum-variant-generic-args.rs:100:5 | LL | AliasFixed::<()>::UVariant; - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::UVariant; -LL + AliasFixed::UVariant; - | error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied --> $DIR/enum-variant-generic-args.rs:102:5 | LL | AliasFixed::<()>::UVariant::<()>; - | ^^^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: type alias defined here, with 0 generic parameters --> $DIR/enum-variant-generic-args.rs:9:6 | LL | type AliasFixed = Enum<()>; | ^^^^^^^^^^ -help: remove the unnecessary generics - | -LL - AliasFixed::<()>::UVariant::<()>; -LL + AliasFixed::UVariant::<()>; - | error[E0109]: type arguments are not allowed on this type --> $DIR/enum-variant-generic-args.rs:102:34 diff --git a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr index dbcc03ee955f..4235a14cdc00 100644 --- a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr +++ b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr @@ -2,99 +2,69 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/typeck-builtin-bound-type-parameters.rs:1:11 | LL | fn foo1, U>(x: T) {} - | ^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - fn foo1, U>(x: T) {} -LL + fn foo1(x: T) {} - | + | ^^^^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - trait Trait: Copy {} -LL + trait Trait: Copy {} - | + | ^^^^---------- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^ expected 0 generic arguments + | ^^^^---------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - trait Trait: Copy {} -LL + trait Trait: Copy {} - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 | LL | trait Trait: Copy {} - | ^^^^ expected 0 generic arguments + | ^^^^---------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: remove the unnecessary generics - | -LL - trait Trait: Copy {} -LL + trait Trait: Copy {} - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:9:21 | LL | struct MyStruct1>(T); - | ^^^^ expected 0 generic arguments - | -help: remove the unnecessary generics - | -LL - struct MyStruct1>(T); -LL + struct MyStruct1(T); - | + | ^^^^--- help: remove the unnecessary generics + | | + | expected 0 generic arguments error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:12:25 | LL | struct MyStruct2<'a, T: Copy<'a>>(&'a T); - | ^^^^ expected 0 lifetime arguments - | -help: remove the unnecessary generics - | -LL - struct MyStruct2<'a, T: Copy<'a>>(&'a T); -LL + struct MyStruct2<'a, T: Copy>(&'a T); - | + | ^^^^---- help: remove the unnecessary generics + | | + | expected 0 lifetime arguments error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:15:15 | LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} - | ^^^^ expected 0 lifetime arguments - | -help: remove the lifetime argument - | -LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} -LL + fn foo2<'a, T:Copy<, U>, U>(x: T) {} - | + | ^^^^ -- help: remove the lifetime argument + | | + | expected 0 lifetime arguments error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/typeck-builtin-bound-type-parameters.rs:15:15 | LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} - | ^^^^ expected 0 generic arguments - | -help: remove the unnecessary generic argument - | -LL - fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} -LL + fn foo2<'a, T:Copy<'a, >, U>(x: T) {} - | + | ^^^^ - help: remove the unnecessary generic argument + | | + | expected 0 generic arguments error: aborting due to 8 previous errors diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr index 116dd1866459..bb1b6e4fc730 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/typeck_type_placeholder_lifetime_1.rs:9:12 | LL | let c: Foo<_, _> = Foo { r: &5 }; - | ^^^ expected 1 generic argument + | ^^^ --- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/typeck_type_placeholder_lifetime_1.rs:4:8 | LL | struct Foo<'a, T:'a> { | ^^^ - -help: remove the unnecessary generic argument - | -LL - let c: Foo<_, _> = Foo { r: &5 }; -LL + let c: Foo<_> = Foo { r: &5 }; - | error: aborting due to 1 previous error diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr index d2734f4acc89..6b8f1e98d2c4 100644 --- a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr @@ -2,18 +2,15 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl --> $DIR/typeck_type_placeholder_lifetime_2.rs:9:12 | LL | let c: Foo<_, usize> = Foo { r: &5 }; - | ^^^ expected 1 generic argument + | ^^^ ------- help: remove the unnecessary generic argument + | | + | expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` --> $DIR/typeck_type_placeholder_lifetime_2.rs:4:8 | LL | struct Foo<'a, T:'a> { | ^^^ - -help: remove the unnecessary generic argument - | -LL - let c: Foo<_, usize> = Foo { r: &5 }; -LL + let c: Foo<_> = Foo { r: &5 }; - | error: aborting due to 1 previous error diff --git a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr index e7e576d7c663..048cf96bcc8e 100644 --- a/tests/ui/ufcs/ufcs-qpath-missing-params.stderr +++ b/tests/ui/ufcs/ufcs-qpath-missing-params.stderr @@ -34,18 +34,15 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli --> $DIR/ufcs-qpath-missing-params.rs:17:26 | LL | ::into_cow::("foo".to_string()); - | ^^^^^^^^ expected 0 generic arguments + | ^^^^^^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: method defined here, with 0 generic parameters --> $DIR/ufcs-qpath-missing-params.rs:4:8 | LL | fn into_cow(self) -> Cow<'a, B>; | ^^^^^^^^ -help: remove the unnecessary generics - | -LL - ::into_cow::("foo".to_string()); -LL + ::into_cow("foo".to_string()); - | error: aborting due to 3 previous errors diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr index 509009732826..a4e7232c8b35 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr @@ -2,18 +2,15 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:17 | LL | fn foo1(_: &dyn Zero()) { - | ^^^^ expected 0 generic arguments + | ^^^^-- help: remove the unnecessary parenthetical generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove the unnecessary parenthetical generics - | -LL - fn foo1(_: &dyn Zero()) { -LL + fn foo1(_: &dyn Zero) { - | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:17 @@ -25,52 +22,43 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:10:17 | LL | fn foo2(_: &dyn Zero) { - | ^^^^ expected 0 generic arguments + | ^^^^------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove the unnecessary generics - | -LL - fn foo2(_: &dyn Zero) { -LL + fn foo2(_: &dyn Zero) { - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:14:17 | LL | fn foo3(_: &dyn Zero < usize >) { - | ^^^^ expected 0 generic arguments + | ^^^^-------------- help: remove the unnecessary generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove the unnecessary generics - | -LL - fn foo3(_: &dyn Zero < usize >) { -LL + fn foo3(_: &dyn Zero) { - | error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:18:17 | LL | fn foo4(_: &dyn Zero(usize)) { - | ^^^^ expected 0 generic arguments + | ^^^^------- help: remove the unnecessary parenthetical generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove the unnecessary parenthetical generics - | -LL - fn foo4(_: &dyn Zero(usize)) { -LL + fn foo4(_: &dyn Zero) { - | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:18:17 @@ -82,18 +70,15 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:23:17 | LL | fn foo5(_: &dyn Zero ( usize )) { - | ^^^^ expected 0 generic arguments + | ^^^^-------------- help: remove the unnecessary parenthetical generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:3:7 | LL | trait Zero { fn dummy(&self); } | ^^^^ -help: remove the unnecessary parenthetical generics - | -LL - fn foo5(_: &dyn Zero ( usize )) { -LL + fn foo5(_: &dyn Zero) { - | error[E0220]: associated type `Output` not found for `Zero` --> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:23:17 diff --git a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr index aecfe502cf98..f5ef58fc91ee 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr @@ -2,18 +2,15 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplie --> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:8 | LL | fn f isize>(x: F) {} - | ^^^^^ expected 0 generic arguments + | ^^^^^------- help: remove the unnecessary parenthetical generics + | | + | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> $DIR/unboxed-closure-sugar-wrong-trait.rs:3:7 | LL | trait Trait {} | ^^^^^ -help: remove the unnecessary parenthetical generics - | -LL - fn f isize>(x: F) {} -LL + fn f isize>(x: F) {} - | error[E0220]: associated type `Output` not found for `Trait` --> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:24 From b2e5ccef5ed3947cfe06ec4ae1361fa9bfa5f2b9 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Mon, 22 Jul 2024 00:42:23 +0300 Subject: [PATCH 24/54] Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core" --- library/core/src/primitive.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/core/src/primitive.rs b/library/core/src/primitive.rs index e20b2c5c9382..435e211bac8f 100644 --- a/library/core/src/primitive.rs +++ b/library/core/src/primitive.rs @@ -12,7 +12,7 @@ //! const SOME_PROPERTY: bool = true; //! } //! -//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; } +//! # trait QueryId { const SOME_PROPERTY: ::core::primitive::bool; } //! ``` //! //! Note that the `SOME_PROPERTY` associated constant would not compile, as its @@ -25,11 +25,17 @@ //! pub struct bool; //! //! impl QueryId for bool { -//! const SOME_PROPERTY: core::primitive::bool = true; +//! const SOME_PROPERTY: ::core::primitive::bool = true; //! } //! -//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; } +//! # trait QueryId { const SOME_PROPERTY: ::core::primitive::bool; } //! ``` +//! +//! We also used `::core` instead of `core`, because `core` can be +//! shadowed, too. Paths, starting with `::`, are searched in +//! [extern prelude]. +//! +//! [extern prelude]: https://doc.rust-lang.org/nightly/reference/names/preludes.html#extern-prelude #[stable(feature = "core_primitive", since = "1.43.0")] pub use bool; From 2561d91983019e2be56e9033f9b14299a291f5f9 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Tue, 23 Jul 2024 10:47:01 +0530 Subject: [PATCH 25/54] Allow unused unsafe for vxworks in read_at and write at --- library/std/src/sys/pal/unix/fd.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std/src/sys/pal/unix/fd.rs b/library/std/src/sys/pal/unix/fd.rs index 1701717db597..c1ab20b4b35c 100644 --- a/library/std/src/sys/pal/unix/fd.rs +++ b/library/std/src/sys/pal/unix/fd.rs @@ -120,6 +120,7 @@ impl FileDesc { (&mut me).read_to_end(buf) } + #[cfg_attr(target_os = "vxworks", allow(unused_unsafe))] pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result { #[cfg(not(any( all(target_os = "linux", not(target_env = "musl")), @@ -313,6 +314,7 @@ impl FileDesc { cfg!(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))) } + #[cfg_attr(target_os = "vxworks", allow(unused_unsafe))] pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(not(any( all(target_os = "linux", not(target_env = "musl")), From a598ca0f86926c91f87992796f88d5dd80a5d244 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Tue, 23 Jul 2024 10:52:53 +0530 Subject: [PATCH 26/54] Disable dirfd for vxworks, Return unsupported error from set_times and lchown for vxworks --- library/std/src/sys/pal/unix/fs.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index f9d6b5fbc86a..553b09bf4088 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -857,6 +857,7 @@ impl Drop for Dir { target_os = "espidf", target_os = "fuchsia", target_os = "horizon", + target_os = "vxworks", )))] { let fd = unsafe { libc::dirfd(self.0) }; @@ -1313,7 +1314,12 @@ impl File { } pub fn set_times(&self, times: FileTimes) -> io::Result<()> { - #[cfg(not(any(target_os = "redox", target_os = "espidf", target_os = "horizon")))] + #[cfg(not(any( + target_os = "redox", + target_os = "espidf", + target_os = "horizon", + target_os = "vxworks" + )))] let to_timespec = |time: Option| match time { Some(time) if let Some(ts) = time.t.to_timespec() => Ok(ts), Some(time) if time > crate::sys::time::UNIX_EPOCH => Err(io::const_io_error!( @@ -1327,10 +1333,11 @@ impl File { None => Ok(libc::timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT as _ }), }; cfg_if::cfg_if! { - if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon"))] { + if #[cfg(any(target_os = "redox", target_os = "espidf", target_os = "horizon", target_os = "vxworks"))] { // Redox doesn't appear to support `UTIME_OMIT`. // ESP-IDF and HorizonOS do not support `futimens` at all and the behavior for those OS is therefore // the same as for Redox. + // `futimens` and `UTIME_OMIT` are a work in progress for vxworks. let _ = times; Err(io::const_io_error!( io::ErrorKind::Unsupported, @@ -1962,6 +1969,7 @@ pub fn fchown(fd: c_int, uid: u32, gid: u32) -> io::Result<()> { Ok(()) } +#[cfg(not(target_os = "vxworks"))] pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> { run_path_with_cstr(path, &|path| { cvt(unsafe { libc::lchown(path.as_ptr(), uid as libc::uid_t, gid as libc::gid_t) }) @@ -1969,6 +1977,12 @@ pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> { }) } +#[cfg(target_os = "vxworks")] +pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> { + let (_, _, _) = (path, uid, gid); + Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks",)) +} + #[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))] pub fn chroot(dir: &Path) -> io::Result<()> { run_path_with_cstr(dir, &|dir| cvt(unsafe { libc::chroot(dir.as_ptr()) }).map(|_| ())) From 5c9f3762d0e90ac97485f3b3eb99bcee647322c5 Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Tue, 23 Jul 2024 10:55:54 +0530 Subject: [PATCH 27/54] Cfg disable on_broken_pipe_flag_used() for vxworks --- library/std/src/sys/pal/unix/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index d016e5e32d40..17960e4fe128 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -210,6 +210,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { target_os = "emscripten", target_os = "fuchsia", target_os = "horizon", + target_os = "vxworks", )))] static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::AtomicBool = crate::sync::atomic::AtomicBool::new(false); @@ -219,6 +220,7 @@ static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::AtomicBool = target_os = "emscripten", target_os = "fuchsia", target_os = "horizon", + target_os = "vxworks", )))] pub(crate) fn on_broken_pipe_flag_used() -> bool { ON_BROKEN_PIPE_FLAG_USED.load(crate::sync::atomic::Ordering::Relaxed) From 8c3ce60e309d9592a50729a0dbc4a77f2b3c73c6 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 23 Jul 2024 10:51:24 +0000 Subject: [PATCH 28/54] Remove wrapper functions from c.rs --- library/std/src/sys/pal/windows/c.rs | 108 +++------------------- library/std/src/sys/pal/windows/handle.rs | 16 ++-- library/std/src/sys/pal/windows/pipe.rs | 45 ++++----- 3 files changed, 43 insertions(+), 126 deletions(-) diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs index 84f3d6a5399b..f8d8398b8250 100644 --- a/library/std/src/sys/pal/windows/c.rs +++ b/library/std/src/sys/pal/windows/c.rs @@ -9,7 +9,6 @@ use crate::ffi::CStr; use crate::mem; use crate::os::raw::{c_uint, c_ulong, c_ushort, c_void}; -use crate::os::windows::io::{AsRawHandle, BorrowedHandle}; use crate::ptr; pub(super) mod windows_targets; @@ -114,89 +113,6 @@ if #[cfg(not(target_vendor = "uwp"))] { } } -pub unsafe extern "system" fn WriteFileEx( - hFile: BorrowedHandle<'_>, - lpBuffer: *mut ::core::ffi::c_void, - nNumberOfBytesToWrite: u32, - lpOverlapped: *mut OVERLAPPED, - lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE, -) -> BOOL { - windows_sys::WriteFileEx( - hFile.as_raw_handle(), - lpBuffer.cast::(), - nNumberOfBytesToWrite, - lpOverlapped, - lpCompletionRoutine, - ) -} - -pub unsafe extern "system" fn ReadFileEx( - hFile: BorrowedHandle<'_>, - lpBuffer: *mut ::core::ffi::c_void, - nNumberOfBytesToRead: u32, - lpOverlapped: *mut OVERLAPPED, - lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE, -) -> BOOL { - windows_sys::ReadFileEx( - hFile.as_raw_handle(), - lpBuffer.cast::(), - nNumberOfBytesToRead, - lpOverlapped, - lpCompletionRoutine, - ) -} - -cfg_if::cfg_if! { -if #[cfg(not(target_vendor = "uwp"))] { -pub unsafe fn NtReadFile( - filehandle: BorrowedHandle<'_>, - event: HANDLE, - apcroutine: PIO_APC_ROUTINE, - apccontext: *mut c_void, - iostatusblock: &mut IO_STATUS_BLOCK, - buffer: *mut crate::mem::MaybeUninit, - length: u32, - byteoffset: Option<&i64>, - key: Option<&u32>, -) -> NTSTATUS { - windows_sys::NtReadFile( - filehandle.as_raw_handle(), - event, - apcroutine, - apccontext, - iostatusblock, - buffer.cast::(), - length, - byteoffset.map(|o| o as *const i64).unwrap_or(ptr::null()), - key.map(|k| k as *const u32).unwrap_or(ptr::null()), - ) -} -pub unsafe fn NtWriteFile( - filehandle: BorrowedHandle<'_>, - event: HANDLE, - apcroutine: PIO_APC_ROUTINE, - apccontext: *mut c_void, - iostatusblock: &mut IO_STATUS_BLOCK, - buffer: *const u8, - length: u32, - byteoffset: Option<&i64>, - key: Option<&u32>, -) -> NTSTATUS { - windows_sys::NtWriteFile( - filehandle.as_raw_handle(), - event, - apcroutine, - apccontext, - iostatusblock, - buffer.cast::(), - length, - byteoffset.map(|o| o as *const i64).unwrap_or(ptr::null()), - key.map(|k| k as *const u32).unwrap_or(ptr::null()), - ) -} -} -} - // Use raw-dylib to import ProcessPrng as we can't rely on there being an import library. cfg_if::cfg_if! { if #[cfg(not(target_vendor = "win7"))] { @@ -331,29 +247,29 @@ compat_fn_with_fallback! { } #[cfg(target_vendor = "uwp")] pub fn NtReadFile( - filehandle: BorrowedHandle<'_>, + filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *mut c_void, - iostatusblock: &mut IO_STATUS_BLOCK, - buffer: *mut crate::mem::MaybeUninit, + apccontext: *const core::ffi::c_void, + iostatusblock: *mut IO_STATUS_BLOCK, + buffer: *mut core::ffi::c_void, length: u32, - byteoffset: Option<&i64>, - key: Option<&u32> + byteoffset: *const i64, + key: *const u32 ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED } #[cfg(target_vendor = "uwp")] pub fn NtWriteFile( - filehandle: BorrowedHandle<'_>, + filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *mut c_void, - iostatusblock: &mut IO_STATUS_BLOCK, - buffer: *const u8, + apccontext: *const core::ffi::c_void, + iostatusblock: *mut IO_STATUS_BLOCK, + buffer: *const core::ffi::c_void, length: u32, - byteoffset: Option<&i64>, - key: Option<&u32> + byteoffset: *const i64, + key: *const u32 ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED } diff --git a/library/std/src/sys/pal/windows/handle.rs b/library/std/src/sys/pal/windows/handle.rs index aaa1831dcc24..5fdf5d7e8a4e 100644 --- a/library/std/src/sys/pal/windows/handle.rs +++ b/library/std/src/sys/pal/windows/handle.rs @@ -243,15 +243,15 @@ impl Handle { // the provided `len`. let status = unsafe { c::NtReadFile( - self.as_handle(), + self.as_raw_handle(), ptr::null_mut(), None, ptr::null_mut(), &mut io_status, - buf, + buf.cast::(), len, - offset.map(|n| n as _).as_ref(), - None, + offset.as_ref().map(|n| ptr::from_ref(n).cast::()).unwrap_or(ptr::null()), + ptr::null(), ) }; @@ -293,15 +293,15 @@ impl Handle { let len = cmp::min(buf.len(), u32::MAX as usize) as u32; let status = unsafe { c::NtWriteFile( - self.as_handle(), + self.as_raw_handle(), ptr::null_mut(), None, ptr::null_mut(), &mut io_status, - buf.as_ptr(), + buf.as_ptr().cast::(), len, - offset.map(|n| n as _).as_ref(), - None, + offset.as_ref().map(|n| ptr::from_ref(n).cast::()).unwrap_or(ptr::null()), + ptr::null(), ) }; let status = if status == c::STATUS_PENDING { diff --git a/library/std/src/sys/pal/windows/pipe.rs b/library/std/src/sys/pal/windows/pipe.rs index 7a309b9638bd..d780fea36ee2 100644 --- a/library/std/src/sys/pal/windows/pipe.rs +++ b/library/std/src/sys/pal/windows/pipe.rs @@ -221,15 +221,6 @@ fn random_number() -> usize { } } -// Abstracts over `ReadFileEx` and `WriteFileEx` -type AlertableIoFn = unsafe extern "system" fn( - BorrowedHandle<'_>, - *mut core::ffi::c_void, - u32, - *mut c::OVERLAPPED, - c::LPOVERLAPPED_COMPLETION_ROUTINE, -) -> c::BOOL; - impl AnonPipe { pub fn handle(&self) -> &Handle { &self.inner @@ -244,7 +235,10 @@ impl AnonPipe { pub fn read(&self, buf: &mut [u8]) -> io::Result { let result = unsafe { let len = crate::cmp::min(buf.len(), u32::MAX as usize) as u32; - self.alertable_io_internal(c::ReadFileEx, buf.as_mut_ptr() as _, len) + let ptr = buf.as_mut_ptr(); + self.alertable_io_internal(|overlapped, callback| { + c::ReadFileEx(self.inner.as_raw_handle(), ptr, len, overlapped, callback) + }) }; match result { @@ -260,7 +254,10 @@ impl AnonPipe { pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> { let result = unsafe { let len = crate::cmp::min(buf.capacity(), u32::MAX as usize) as u32; - self.alertable_io_internal(c::ReadFileEx, buf.as_mut().as_mut_ptr() as _, len) + let ptr = buf.as_mut().as_mut_ptr().cast::(); + self.alertable_io_internal(|overlapped, callback| { + c::ReadFileEx(self.inner.as_raw_handle(), ptr, len, overlapped, callback) + }) }; match result { @@ -295,7 +292,9 @@ impl AnonPipe { pub fn write(&self, buf: &[u8]) -> io::Result { unsafe { let len = crate::cmp::min(buf.len(), u32::MAX as usize) as u32; - self.alertable_io_internal(c::WriteFileEx, buf.as_ptr() as _, len) + self.alertable_io_internal(|overlapped, callback| { + c::WriteFileEx(self.inner.as_raw_handle(), buf.as_ptr(), len, overlapped, callback) + }) } } @@ -323,12 +322,9 @@ impl AnonPipe { /// [`ReadFileEx`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfileex /// [`WriteFileEx`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefileex /// [Asynchronous Procedure Call]: https://docs.microsoft.com/en-us/windows/win32/sync/asynchronous-procedure-calls - #[allow(unsafe_op_in_unsafe_fn)] unsafe fn alertable_io_internal( &self, - io: AlertableIoFn, - buf: *mut core::ffi::c_void, - len: u32, + io: impl FnOnce(&mut c::OVERLAPPED, c::LPOVERLAPPED_COMPLETION_ROUTINE) -> c::BOOL, ) -> io::Result { // Use "alertable I/O" to synchronize the pipe I/O. // This has four steps. @@ -366,20 +362,25 @@ impl AnonPipe { lpOverlapped: *mut c::OVERLAPPED, ) { // Set `async_result` using a pointer smuggled through `hEvent`. - let result = - AsyncResult { error: dwErrorCode, transferred: dwNumberOfBytesTransferred }; - *(*lpOverlapped).hEvent.cast::>() = Some(result); + // SAFETY: + // At this point, the OVERLAPPED struct will have been written to by the OS, + // except for our `hEvent` field which we set to a valid AsyncResult pointer (see below) + unsafe { + let result = + AsyncResult { error: dwErrorCode, transferred: dwNumberOfBytesTransferred }; + *(*lpOverlapped).hEvent.cast::>() = Some(result); + } } // STEP 1: Start the I/O operation. - let mut overlapped: c::OVERLAPPED = crate::mem::zeroed(); + let mut overlapped: c::OVERLAPPED = unsafe { crate::mem::zeroed() }; // `hEvent` is unused by `ReadFileEx` and `WriteFileEx`. // Therefore the documentation suggests using it to smuggle a pointer to the callback. overlapped.hEvent = core::ptr::addr_of_mut!(async_result) as *mut _; // Asynchronous read of the pipe. // If successful, `callback` will be called once it completes. - let result = io(self.inner.as_handle(), buf, len, &mut overlapped, Some(callback)); + let result = io(&mut overlapped, Some(callback)); if result == c::FALSE { // We can return here because the call failed. // After this we must not return until the I/O completes. @@ -390,7 +391,7 @@ impl AnonPipe { let result = loop { // STEP 2: Enter an alertable state. // The second parameter of `SleepEx` is used to make this sleep alertable. - c::SleepEx(c::INFINITE, c::TRUE); + unsafe { c::SleepEx(c::INFINITE, c::TRUE) }; if let Some(result) = async_result { break result; } From 786ad3d3ae8cd4dabf311d2cfcd5b03b420a249f Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Tue, 23 Jul 2024 16:58:00 +0530 Subject: [PATCH 29/54] Update process vxworks, set default stack size of 256 Kib for vxworks. User can set the stack size using RUST_MIN_STACK, with min size of libc::PTHREAD_STACK_MIN(4kib) --- library/std/src/sys/pal/unix/process/process_vxworks.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/pal/unix/process/process_vxworks.rs b/library/std/src/sys/pal/unix/process/process_vxworks.rs index 5007dbd34b4a..26b8a0a39dc4 100644 --- a/library/std/src/sys/pal/unix/process/process_vxworks.rs +++ b/library/std/src/sys/pal/unix/process/process_vxworks.rs @@ -3,8 +3,8 @@ use crate::io::{self, ErrorKind}; use crate::num::NonZero; use crate::sys; use crate::sys::cvt; +use crate::sys::pal::unix::thread; use crate::sys::process::process_common::*; -use crate::sys_common::thread; use libc::RTP_ID; use libc::{self, c_char, c_int}; @@ -68,7 +68,12 @@ impl Command { .as_ref() .map(|c| c.as_ptr()) .unwrap_or_else(|| *sys::os::environ() as *const _); - let stack_size = thread::min_stack(); + let stack_size = crate::cmp::max( + crate::env::var_os("RUST_MIN_STACK") + .and_then(|s| s.to_str().and_then(|s| s.parse().ok())) + .unwrap_or(thread::DEFAULT_MIN_STACK_SIZE), + libc::PTHREAD_STACK_MIN, + ); // ensure that access to the environment is synchronized let _lock = sys::os::env_read_lock(); From 1f59a8030d40d7a6e3a047ed7620f5813497b7ea Mon Sep 17 00:00:00 2001 From: Taylor Foxhall Date: Tue, 23 Jul 2024 12:36:52 -0400 Subject: [PATCH 30/54] Fix return type of FileAttr methods on AIX target At some point it seems `SystemTime::new` changed from returning `SystemTime` to `io::Result`. This seems to have been addressed on other platforms, but was never changed for AIX. This was caught by running ``` python3 x.py build --host x86_64-unknown-linux-gnu --target powerpc64-ibm-aix ``` --- library/std/src/sys/pal/unix/fs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 8308a48f16a9..b323da8d859d 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -463,15 +463,15 @@ impl FileAttr { #[cfg(target_os = "aix")] impl FileAttr { pub fn modified(&self) -> io::Result { - Ok(SystemTime::new(self.stat.st_mtime.tv_sec as i64, self.stat.st_mtime.tv_nsec as i64)) + SystemTime::new(self.stat.st_mtime.tv_sec as i64, self.stat.st_mtime.tv_nsec as i64) } pub fn accessed(&self) -> io::Result { - Ok(SystemTime::new(self.stat.st_atime.tv_sec as i64, self.stat.st_atime.tv_nsec as i64)) + SystemTime::new(self.stat.st_atime.tv_sec as i64, self.stat.st_atime.tv_nsec as i64) } pub fn created(&self) -> io::Result { - Ok(SystemTime::new(self.stat.st_ctime.tv_sec as i64, self.stat.st_ctime.tv_nsec as i64)) + SystemTime::new(self.stat.st_ctime.tv_sec as i64, self.stat.st_ctime.tv_nsec as i64) } } From 2f55cedf501e06f932787248a17e6aaffd9785f1 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 23 Jul 2024 20:28:19 +0300 Subject: [PATCH 31/54] ensure std step before preparing sysroot When using download-rustc, any stage other than 0 or 1 (e.g., cargo +stage2 build/doc) will fail to find std while compiling on simple rust sources. Ensuring the rustc step fixes this issue. Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 3e79acad1c4b..9bbebf9b8703 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1700,6 +1700,7 @@ impl Step for Assemble { // If we're downloading a compiler from CI, we can use the same compiler for all stages other than 0. if builder.download_rustc() { + builder.ensure(Std::new(target_compiler, target_compiler.host)); let sysroot = builder.ensure(Sysroot { compiler: target_compiler, force_recompile: false }); // Ensure that `libLLVM.so` ends up in the newly created target directory, From 0728c155a3141a96abf648306c7ad11e30a49d65 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 23 Jul 2024 20:14:33 +0200 Subject: [PATCH 32/54] Allow to pass a full path for `run-make` tests --- src/tools/compiletest/src/lib.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index 0cf05b32e968..81a5acb5cf28 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -25,7 +25,7 @@ use build_helper::git::{get_git_modified_files, get_git_untracked_files}; use core::panic; use getopts::Options; use std::collections::HashSet; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::fs; use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; @@ -225,6 +225,29 @@ pub fn parse_config(args: Vec) -> Config { // Avoid spawning an external command when we know tidy won't be used. false }; + let filters = if mode == Mode::RunMake { + matches + .free + .iter() + .map(|f| { + let path = Path::new(f); + let mut iter = path.iter().skip(1); + + // We skip the test folder and check if the user passed `rmake.rs` or `Makefile`. + if iter + .next() + .is_some_and(|s| s == OsStr::new("rmake.rs") || s == OsStr::new("Makefile")) + && iter.next().is_none() + { + path.parent().unwrap().to_str().unwrap().to_string() + } else { + f.to_string() + } + }) + .collect::>() + } else { + matches.free.clone() + }; Config { bless: matches.opt_present("bless"), compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), @@ -249,7 +272,7 @@ pub fn parse_config(args: Vec) -> Config { debugger: None, run_ignored, with_debug_assertions, - filters: matches.free.clone(), + filters, skip: matches.opt_strs("skip"), filter_exact: matches.opt_present("exact"), force_pass_mode: matches.opt_str("pass").map(|mode| { From 23e346e706578d51ecbb873d71ab28bf154ebd45 Mon Sep 17 00:00:00 2001 From: donno2048 Date: Tue, 23 Jul 2024 19:38:47 +0000 Subject: [PATCH 33/54] make tidy fast without compromising case alternation --- src/tools/tidy/src/style.rs | 47 +++++++++++++++++++------------ src/tools/tidy/src/style/tests.rs | 19 ++++--------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 8e693c35adcb..8d8cc7ad6d39 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -18,9 +18,9 @@ // ignore-tidy-dbg use crate::walk::{filter_dirs, walk}; -use regex::RegexSet; +use regex::RegexSetBuilder; use rustc_hash::FxHashMap; -use std::{ffi::OsStr, path::Path}; +use std::{ffi::OsStr, path::Path, sync::LazyLock}; #[cfg(test)] mod tests; @@ -110,16 +110,26 @@ const ROOT_PROBLEMATIC_CONSTS: &[u32] = &[ 173390526, 721077, ]; +const LETTER_DIGIT: &[(char, char)] = &[('A', '4'), ('B', '8'), ('E', '3')]; + // Returns all permutations of problematic consts, over 2000 elements. fn generate_problematic_strings( consts: &[u32], letter_digit: &FxHashMap, ) -> Vec { generate_problems(consts, letter_digit) - .flat_map(|v| vec![v.to_string(), format!("{:x}", v), format!("{:X}", v)]) + .flat_map(|v| vec![v.to_string(), format!("{:X}", v)]) .collect() } +static PROBLEMATIC_CONSTS_STRINGS: LazyLock> = LazyLock::new(|| { + generate_problematic_strings(ROOT_PROBLEMATIC_CONSTS, &LETTER_DIGIT.iter().cloned().collect()) +}); + +fn contains_problematic_const(trimmed: &str) -> bool { + PROBLEMATIC_CONSTS_STRINGS.iter().any(|s| trimmed.to_uppercase().contains(s)) +} + const INTERNAL_COMPILER_DOCS_LINE: &str = "#### This error code is internal to the compiler and will not be emitted with normal Rust code."; /// Parser states for `line_is_url`. @@ -316,14 +326,14 @@ pub fn check(path: &Path, bad: &mut bool) { // We only check CSS files in rustdoc. path.extension().map_or(false, |e| e == "css") && !is_in(path, "src", "librustdoc") } - let problematic_consts_strings = generate_problematic_strings( - ROOT_PROBLEMATIC_CONSTS, - &[('A', '4'), ('B', '8'), ('E', '3')].iter().cloned().collect(), - ); + // This creates a RegexSet as regex contains performance optimizations to be able to deal with these over // 2000 needles efficiently. This runs over the entire source code, so performance matters. - let problematic_regex = RegexSet::new(problematic_consts_strings.as_slice()).unwrap(); - + let problematic_regex = RegexSetBuilder::new(PROBLEMATIC_CONSTS_STRINGS.as_slice()) + .case_insensitive(true) + .build() + .unwrap(); + let style_file = Path::new(file!()); walk(path, skip, &mut |entry, contents| { let file = entry.path(); let filename = file.file_name().unwrap().to_string_lossy(); @@ -389,10 +399,15 @@ pub fn check(path: &Path, bad: &mut bool) { let mut lines = 0; let mut last_safety_comment = false; let mut comment_block: Option<(usize, usize)> = None; - let is_test = file.components().any(|c| c.as_os_str() == "tests"); + let is_test = file.components().any(|c| c.as_os_str() == "tests") + || file.file_stem().unwrap() == "tests"; + let is_style = file.ends_with(style_file) || style_file.ends_with(file); + let is_style_test = + is_test && file.parent().unwrap().ends_with(style_file.with_extension("")); // scanning the whole file for multiple needles at once is more efficient than // executing lines times needles separate searches. - let any_problematic_line = problematic_regex.is_match(contents); + let any_problematic_line = + !is_style && !is_style_test && problematic_regex.is_match(contents); for (i, line) in contents.split('\n').enumerate() { if line.is_empty() { if i == 0 { @@ -451,7 +466,7 @@ pub fn check(path: &Path, bad: &mut bool) { if line.contains('\r') { suppressible_tidy_err!(err, skip_cr, "CR character"); } - if filename != "style.rs" { + if !is_style { // Allow using TODO in diagnostic suggestions by marking the // relevant line with `// ignore-tidy-todo`. if trimmed.contains("TODO") && !trimmed.contains("ignore-tidy-todo") { @@ -462,12 +477,8 @@ pub fn check(path: &Path, bad: &mut bool) { if trimmed.contains("//") && trimmed.contains(" XXX") { err("Instead of XXX use FIXME") } - if any_problematic_line { - for s in problematic_consts_strings.iter() { - if trimmed.contains(s) { - err("Don't use magic numbers that spell things (consider 0x12345678)"); - } - } + if any_problematic_line && contains_problematic_const(trimmed) { + err("Don't use magic numbers that spell things (consider 0x12345678)"); } } // for now we just check libcore diff --git a/src/tools/tidy/src/style/tests.rs b/src/tools/tidy/src/style/tests.rs index 292e23916d24..8a3586dad0e3 100644 --- a/src/tools/tidy/src/style/tests.rs +++ b/src/tools/tidy/src/style/tests.rs @@ -1,17 +1,10 @@ use super::*; #[test] -fn test_generate_problematic_strings() { - let problematic_regex = RegexSet::new( - generate_problematic_strings( - ROOT_PROBLEMATIC_CONSTS, - &[('A', '4'), ('B', '8'), ('E', '3'), ('0', 'F')].iter().cloned().collect(), // use "futile" F intentionally - ) - .as_slice(), - ) - .unwrap(); - assert!(problematic_regex.is_match("786357")); // check with no "decimal" hex digits - converted to integer - assert!(problematic_regex.is_match("589701")); // check with "decimal" replacements - converted to integer - assert!(problematic_regex.is_match("8FF85")); // check for hex display - assert!(!problematic_regex.is_match("1193046")); // check for non-matching value +fn test_contains_problematic_const() { + assert!(contains_problematic_const("721077")); // check with no "decimal" hex digits - converted to integer + assert!(contains_problematic_const("524421")); // check with "decimal" replacements - converted to integer + assert!(contains_problematic_const(&(285 * 281).to_string())); // check for hex display + assert!(contains_problematic_const(&format!("{:x}B5", 2816))); // check for case-alternating hex display + assert!(!contains_problematic_const("1193046")); // check for non-matching value } From b8f7ed239495ae9b6d043365e19965006f007572 Mon Sep 17 00:00:00 2001 From: Askar Safin Date: Tue, 23 Jul 2024 23:11:26 +0300 Subject: [PATCH 34/54] library/core/src/primitive.rs: small doc fix Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> --- library/core/src/primitive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/primitive.rs b/library/core/src/primitive.rs index 435e211bac8f..81a72118614d 100644 --- a/library/core/src/primitive.rs +++ b/library/core/src/primitive.rs @@ -33,7 +33,7 @@ //! //! We also used `::core` instead of `core`, because `core` can be //! shadowed, too. Paths, starting with `::`, are searched in -//! [extern prelude]. +//! the [extern prelude] since Edition 2018. //! //! [extern prelude]: https://doc.rust-lang.org/nightly/reference/names/preludes.html#extern-prelude From 557210c5c7f4045a2007583c741476a4a3aee1df Mon Sep 17 00:00:00 2001 From: wr7 Date: Fri, 14 Jun 2024 14:45:53 -0500 Subject: [PATCH 35/54] Add elem_offset and related methods --- library/core/src/slice/mod.rs | 115 ++++++++++++++++++++++++++++++++++ library/core/src/str/mod.rs | 34 ++++++++++ 2 files changed, 149 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 521c32482044..1fed92a3fa14 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -4540,6 +4540,121 @@ impl [T] { // are disjunct and in bounds. unsafe { Ok(self.get_many_unchecked_mut(indices)) } } + + /// Returns the index that an element reference points to. + /// + /// Returns `None` if `element` does not point within the slice or if it points between elements. + /// + /// This method is useful for extending slice iterators like [`slice::split`]. + /// + /// Note that this uses pointer arithmetic and **does not compare elements**. + /// To find the index of an element via comparison, use + /// [`.iter().position()`](crate::iter::Iterator::position) instead. + /// + /// # Panics + /// Panics if `T` is zero-sized. + /// + /// # Examples + /// Basic usage: + /// ``` + /// #![feature(substr_range)] + /// + /// let nums: &[u32] = &[1, 7, 1, 1]; + /// let num = &nums[2]; + /// + /// assert_eq!(num, &1); + /// assert_eq!(nums.elem_offset(num), Some(2)); + /// ``` + /// Returning `None` with an in-between element: + /// ``` + /// #![feature(substr_range)] + /// + /// let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; + /// let flat_arr: &[u32] = arr.as_flattened(); + /// + /// let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); + /// let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); + /// + /// assert_eq!(ok_elm, &[0, 1]); + /// assert_eq!(weird_elm, &[1, 2]); + /// + /// assert_eq!(arr.elem_offset(ok_elm), Some(0)); // Points to element 0 + /// assert_eq!(arr.elem_offset(weird_elm), None); // Points between element 0 and 1 + /// ``` + #[must_use] + #[unstable(feature = "substr_range", issue = "126769")] + pub fn elem_offset(&self, element: &T) -> Option { + if T::IS_ZST { + panic!("elements are zero-sized"); + } + + let self_start = self.as_ptr() as usize; + let elem_start = element as *const T as usize; + + let byte_offset = elem_start.wrapping_sub(self_start); + + if byte_offset % mem::size_of::() != 0 { + return None; + } + + let offset = byte_offset / mem::size_of::(); + + if offset < self.len() { Some(offset) } else { None } + } + + /// Returns the range of indices that a subslice points to. + /// + /// Returns `None` if `subslice` does not point within the slice or if it points between elements. + /// + /// This method **does not compare elements**. Instead, this method finds the location in the slice that + /// `subslice` was obtained from. To find the index of a subslice via comparison, instead use + /// [`.windows()`](slice::windows)[`.position()`](crate::iter::Iterator::position). + /// + /// This method is useful for extending slice iterators like [`slice::split`]. + /// + /// Note that this may return a false positive (either `Some(0..0)` or `Some(self.len()..self.len())`) + /// if `subslice` has a length of zero and points to the beginning or end of another, separate, slice. + /// + /// # Panics + /// Panics if `T` is zero-sized. + /// + /// # Examples + /// Basic usage: + /// ``` + /// #![feature(substr_range)] + /// + /// let nums = &[0, 5, 10, 0, 0, 5]; + /// + /// let mut iter = nums + /// .split(|t| *t == 0) + /// .map(|n| nums.subslice_range(n).unwrap()); + /// + /// assert_eq!(iter.next(), Some(0..0)); + /// assert_eq!(iter.next(), Some(1..3)); + /// assert_eq!(iter.next(), Some(4..4)); + /// assert_eq!(iter.next(), Some(5..6)); + /// ``` + #[must_use] + #[unstable(feature = "substr_range", issue = "126769")] + pub fn subslice_range(&self, subslice: &[T]) -> Option> { + if T::IS_ZST { + panic!("elements are zero-sized"); + } + + let self_start = self.as_ptr() as usize; + let subslice_start = subslice.as_ptr() as usize; + + let byte_start = subslice_start.wrapping_sub(self_start); + + if byte_start % core::mem::size_of::() != 0 { + return None; + } + + let start = byte_start / core::mem::size_of::(); + let end = start.wrapping_add(subslice.len()); + + if start <= self.len() && end <= self.len() { Some(start..end) } else { None } + } } impl [[T; N]] { diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 683109380439..1392fd7e7cd4 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -19,6 +19,7 @@ use self::pattern::{DoubleEndedSearcher, ReverseSearcher, Searcher}; use crate::ascii; use crate::char::{self, EscapeDebugExtArgs}; use crate::mem; +use crate::ops::Range; use crate::slice::{self, SliceIndex}; pub mod pattern; @@ -2721,6 +2722,39 @@ impl str { pub fn escape_unicode(&self) -> EscapeUnicode<'_> { EscapeUnicode { inner: self.chars().flat_map(CharEscapeUnicode) } } + + /// Returns the range that a substring points to. + /// + /// Returns `None` if `substr` does not point within `self`. + /// + /// Unlike [`str::find`], **this does not search through the string**. + /// Instead, it uses pointer arithmetic to find where in the string + /// `substr` is derived from. + /// + /// This is useful for extending [`str::split`] and similar methods. + /// + /// Note that this method may return false positives (typically either + /// `Some(0..0)` or `Some(self.len()..self.len())`) if `substr` is a + /// zero-length `str` that points at the beginning or end of another, + /// independent, `str`. + /// + /// # Examples + /// ``` + /// #![feature(substr_range)] + /// + /// let data = "a, b, b, a"; + /// let mut iter = data.split(", ").map(|s| data.substr_range(s).unwrap()); + /// + /// assert_eq!(iter.next(), Some(0..1)); + /// assert_eq!(iter.next(), Some(3..4)); + /// assert_eq!(iter.next(), Some(6..7)); + /// assert_eq!(iter.next(), Some(9..10)); + /// ``` + #[must_use] + #[unstable(feature = "substr_range", issue = "126769")] + pub fn substr_range(&self, substr: &str) -> Option> { + self.as_bytes().subslice_range(substr.as_bytes()) + } } #[stable(feature = "rust1", since = "1.0.0")] From b82f878f03a9133f61f4b652fea906322747a379 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 23 Jul 2024 19:10:22 -0400 Subject: [PATCH 36/54] Gate AsyncFn* under async_closure feature --- compiler/rustc_ast_lowering/src/path.rs | 22 +++++++++++++------ library/alloc/src/lib.rs | 1 + library/core/src/ops/async_function.rs | 6 ++--- tests/ui/async-await/async-fn/edition-2015.rs | 2 ++ .../async-await/async-fn/edition-2015.stderr | 22 ++++++++++++++++++- tests/ui/async-await/async-fn/simple.rs | 2 +- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 6303584bb784..ac36b0746096 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -44,13 +44,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let mut res = self.lower_res(base_res); // When we have an `async` kw on a bound, map the trait it resolves to. - let mut bound_modifier_allowed_features = None; if let Some(TraitBoundModifiers { asyncness: BoundAsyncness::Async(_), .. }) = modifiers { match res { Res::Def(DefKind::Trait, def_id) => { - if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) { + if let Some(async_def_id) = self.map_trait_to_async_trait(def_id) { res = Res::Def(DefKind::Trait, async_def_id); - bound_modifier_allowed_features = Some(features); } else { self.dcx().emit_err(AsyncBoundOnlyForFnTraits { span: p.span }); } @@ -67,6 +65,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } + // Ungate the `async_fn_traits` feature in the path if the trait is + // named via either `async Fn*()` or `AsyncFn*()`. + let bound_modifier_allowed_features = if let Res::Def(DefKind::Trait, async_def_id) = res + && self.tcx.async_fn_trait_kind_from_def_id(async_def_id).is_some() + { + Some(self.allow_async_fn_traits.clone()) + } else { + None + }; + let path_span_lo = p.span.shrink_to_lo(); let proj_start = p.segments.len() - unresolved_segments; let path = self.arena.alloc(hir::Path { @@ -506,14 +514,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// This only needs to be done until we unify `AsyncFn` and `Fn` traits into one /// that is generic over `async`ness, if that's ever possible, or modify the /// lowering of `async Fn()` bounds to desugar to another trait like `LendingFn`. - fn map_trait_to_async_trait(&self, def_id: DefId) -> Option<(DefId, Lrc<[Symbol]>)> { + fn map_trait_to_async_trait(&self, def_id: DefId) -> Option { let lang_items = self.tcx.lang_items(); if Some(def_id) == lang_items.fn_trait() { - Some((lang_items.async_fn_trait()?, self.allow_async_fn_traits.clone())) + lang_items.async_fn_trait() } else if Some(def_id) == lang_items.fn_mut_trait() { - Some((lang_items.async_fn_mut_trait()?, self.allow_async_fn_traits.clone())) + lang_items.async_fn_mut_trait() } else if Some(def_id) == lang_items.fn_once_trait() { - Some((lang_items.async_fn_once_trait()?, self.allow_async_fn_traits.clone())) + lang_items.async_fn_once_trait() } else { None } diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index a7715740cbd8..4491a717dc2e 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -101,6 +101,7 @@ #![feature(array_windows)] #![feature(ascii_char)] #![feature(assert_matches)] +#![feature(async_closure)] #![feature(async_fn_traits)] #![feature(async_iterator)] #![feature(clone_to_uninit)] diff --git a/library/core/src/ops/async_function.rs b/library/core/src/ops/async_function.rs index 48d1042d9df4..37fac2b126fa 100644 --- a/library/core/src/ops/async_function.rs +++ b/library/core/src/ops/async_function.rs @@ -4,7 +4,7 @@ use crate::marker::Tuple; /// An async-aware version of the [`Fn`](crate::ops::Fn) trait. /// /// All `async fn` and functions returning futures implement this trait. -#[unstable(feature = "async_fn_traits", issue = "none")] +#[unstable(feature = "async_closure", issue = "62290")] #[rustc_paren_sugar] #[fundamental] #[must_use = "async closures are lazy and do nothing unless called"] @@ -18,7 +18,7 @@ pub trait AsyncFn: AsyncFnMut { /// An async-aware version of the [`FnMut`](crate::ops::FnMut) trait. /// /// All `async fn` and functions returning futures implement this trait. -#[unstable(feature = "async_fn_traits", issue = "none")] +#[unstable(feature = "async_closure", issue = "62290")] #[rustc_paren_sugar] #[fundamental] #[must_use = "async closures are lazy and do nothing unless called"] @@ -39,7 +39,7 @@ pub trait AsyncFnMut: AsyncFnOnce { /// An async-aware version of the [`FnOnce`](crate::ops::FnOnce) trait. /// /// All `async fn` and functions returning futures implement this trait. -#[unstable(feature = "async_fn_traits", issue = "none")] +#[unstable(feature = "async_closure", issue = "62290")] #[rustc_paren_sugar] #[fundamental] #[must_use = "async closures are lazy and do nothing unless called"] diff --git a/tests/ui/async-await/async-fn/edition-2015.rs b/tests/ui/async-await/async-fn/edition-2015.rs index 83b9d415ddab..50448313b301 100644 --- a/tests/ui/async-await/async-fn/edition-2015.rs +++ b/tests/ui/async-await/async-fn/edition-2015.rs @@ -3,5 +3,7 @@ fn foo(x: impl async Fn()) -> impl async Fn() { x } //~| ERROR `async` trait bounds are only allowed in Rust 2018 or later //~| ERROR async closures are unstable //~| ERROR async closures are unstable +//~| ERROR use of unstable library feature 'async_closure' +//~| ERROR use of unstable library feature 'async_closure' fn main() {} diff --git a/tests/ui/async-await/async-fn/edition-2015.stderr b/tests/ui/async-await/async-fn/edition-2015.stderr index 0029d53868d4..23ffee0d0a6b 100644 --- a/tests/ui/async-await/async-fn/edition-2015.stderr +++ b/tests/ui/async-await/async-fn/edition-2015.stderr @@ -38,6 +38,26 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = help: to use an async block, remove the `||`: `async {` -error: aborting due to 4 previous errors +error[E0658]: use of unstable library feature 'async_closure' + --> $DIR/edition-2015.rs:1:22 + | +LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } + | ^^^^ + | + = note: see issue #62290 for more information + = help: add `#![feature(async_closure)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature 'async_closure' + --> $DIR/edition-2015.rs:1:42 + | +LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } + | ^^^^ + | + = note: see issue #62290 for more information + = help: add `#![feature(async_closure)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/async-fn/simple.rs b/tests/ui/async-await/async-fn/simple.rs index 21972ba5aefa..3f15b08560af 100644 --- a/tests/ui/async-await/async-fn/simple.rs +++ b/tests/ui/async-await/async-fn/simple.rs @@ -2,7 +2,7 @@ //@ edition: 2021 //@ build-pass -#![feature(async_fn_traits)] +#![feature(async_closure)] extern crate block_on; From 2fd41dfff9217d845c5ffdb49065ef9608893c5f Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Tue, 23 Jul 2024 19:42:47 -0700 Subject: [PATCH 37/54] Bump Fuchsia This includes changes to unblock merging #126024. --- src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh b/src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh index c806b886dae8..1a0b141e984b 100755 --- a/src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh +++ b/src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh @@ -35,7 +35,7 @@ PICK_REFS=() # commit hash of fuchsia.git and some other repos in the "monorepo" checkout, in # addition to versions of prebuilts. It should be bumped regularly by the # Fuchsia team – we aim for every 1-2 months. -INTEGRATION_SHA=d1d2f20efe46e22be179953dd6726c96eced54ab +INTEGRATION_SHA=1c5b42266fbfefb2337c6b2f0030a91bde15f9e9 checkout=fuchsia jiri=.jiri_root/bin/jiri From 0ea5694c7c7e2ecda818262ef043ef8ef765ad3c Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Wed, 24 Jul 2024 09:59:04 +0530 Subject: [PATCH 38/54] Add chroot unsupported implementation for VxWorks --- library/std/src/os/unix/fs.rs | 2 +- library/std/src/sys/pal/unix/fs.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index 970023d8cf19..20c472040fad 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -1064,7 +1064,7 @@ pub fn lchown>(dir: P, uid: Option, gid: Option) -> io: /// } /// ``` #[stable(feature = "unix_chroot", since = "1.56.0")] -#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))] +#[cfg(not(target_os = "fuchsia"))] pub fn chroot>(dir: P) -> io::Result<()> { sys::fs::chroot(dir.as_ref()) } diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 553b09bf4088..655565e614dc 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -1980,7 +1980,7 @@ pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> { #[cfg(target_os = "vxworks")] pub fn lchown(path: &Path, uid: u32, gid: u32) -> io::Result<()> { let (_, _, _) = (path, uid, gid); - Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks",)) + Err(io::const_io_error!(io::ErrorKind::Unsupported, "lchown not supported by vxworks")) } #[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))] @@ -1988,6 +1988,12 @@ pub fn chroot(dir: &Path) -> io::Result<()> { run_path_with_cstr(dir, &|dir| cvt(unsafe { libc::chroot(dir.as_ptr()) }).map(|_| ())) } +#[cfg(target_os = "vxworks")] +pub fn chroot(dir: &Path) -> io::Result<()> { + let _ = dir; + Err(io::const_io_error!(io::ErrorKind::Unsupported, "chroot not supported by vxworks")) +} + pub use remove_dir_impl::remove_dir_all; // Fallback for REDOX, ESP-ID, Horizon, Vita, Vxworks and Miri From 9b87fbc3e5394a93489003aea38e44c2d2735c7b Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 24 Jul 2024 08:27:22 +0000 Subject: [PATCH 39/54] Import `core::ffi::c_void` in more places --- library/std/src/sys/pal/windows/alloc.rs | 8 ++++---- library/std/src/sys/pal/windows/c.rs | 24 +++++++++++------------ library/std/src/sys/pal/windows/handle.rs | 11 ++++++----- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/library/std/src/sys/pal/windows/alloc.rs b/library/std/src/sys/pal/windows/alloc.rs index 987be6b69eec..020a2a4f3a28 100644 --- a/library/std/src/sys/pal/windows/alloc.rs +++ b/library/std/src/sys/pal/windows/alloc.rs @@ -37,7 +37,7 @@ windows_targets::link!("kernel32.dll" "system" fn GetProcessHeap() -> c::HANDLE) // Note that `dwBytes` is allowed to be zero, contrary to some other allocators. // // See https://docs.microsoft.com/windows/win32/api/heapapi/nf-heapapi-heapalloc -windows_targets::link!("kernel32.dll" "system" fn HeapAlloc(hheap: c::HANDLE, dwflags: u32, dwbytes: usize) -> *mut core::ffi::c_void); +windows_targets::link!("kernel32.dll" "system" fn HeapAlloc(hheap: c::HANDLE, dwflags: u32, dwbytes: usize) -> *mut c_void); // Reallocate a block of memory behind a given pointer `lpMem` from a given heap `hHeap`, // to a block of at least `dwBytes` bytes, either shrinking the block in place, @@ -61,9 +61,9 @@ windows_targets::link!("kernel32.dll" "system" fn HeapAlloc(hheap: c::HANDLE, dw windows_targets::link!("kernel32.dll" "system" fn HeapReAlloc( hheap: c::HANDLE, dwflags : u32, - lpmem: *const core::ffi::c_void, + lpmem: *const c_void, dwbytes: usize -) -> *mut core::ffi::c_void); +) -> *mut c_void); // Free a block of memory behind a given pointer `lpMem` from a given heap `hHeap`. // Returns a nonzero value if the operation is successful, and zero if the operation fails. @@ -79,7 +79,7 @@ windows_targets::link!("kernel32.dll" "system" fn HeapReAlloc( // Note that `lpMem` is allowed to be null, which will not cause the operation to fail. // // See https://docs.microsoft.com/windows/win32/api/heapapi/nf-heapapi-heapfree -windows_targets::link!("kernel32.dll" "system" fn HeapFree(hheap: c::HANDLE, dwflags: u32, lpmem: *const core::ffi::c_void) -> c::BOOL); +windows_targets::link!("kernel32.dll" "system" fn HeapFree(hheap: c::HANDLE, dwflags: u32, lpmem: *const c_void) -> c::BOOL); // Cached handle to the default heap of the current process. // Either a non-null handle returned by `GetProcessHeap`, or null when not yet initialized or `GetProcessHeap` failed. diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs index f8d8398b8250..fa350f4e5833 100644 --- a/library/std/src/sys/pal/windows/c.rs +++ b/library/std/src/sys/pal/windows/c.rs @@ -4,12 +4,10 @@ #![cfg_attr(test, allow(dead_code))] #![unstable(issue = "none", feature = "windows_c")] #![allow(clippy::style)] -#![allow(unsafe_op_in_unsafe_fn)] -use crate::ffi::CStr; -use crate::mem; -use crate::os::raw::{c_uint, c_ulong, c_ushort, c_void}; -use crate::ptr; +use core::ffi::{c_uint, c_ulong, c_ushort, c_void, CStr}; +use core::mem; +use core::ptr; pub(super) mod windows_targets; @@ -188,12 +186,12 @@ extern "system" { compat_fn_optional! { crate::sys::compat::load_synch_functions(); pub fn WaitOnAddress( - address: *const ::core::ffi::c_void, - compareaddress: *const ::core::ffi::c_void, + address: *const c_void, + compareaddress: *const c_void, addresssize: usize, dwmilliseconds: u32 ) -> BOOL; - pub fn WakeByAddressSingle(address: *const ::core::ffi::c_void); + pub fn WakeByAddressSingle(address: *const c_void); } #[cfg(any(target_vendor = "win7", target_vendor = "uwp"))] @@ -240,7 +238,7 @@ compat_fn_with_fallback! { shareaccess: FILE_SHARE_MODE, createdisposition: NTCREATEFILE_CREATE_DISPOSITION, createoptions: NTCREATEFILE_CREATE_OPTIONS, - eabuffer: *const ::core::ffi::c_void, + eabuffer: *const c_void, ealength: u32 ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED @@ -250,9 +248,9 @@ compat_fn_with_fallback! { filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *const core::ffi::c_void, + apccontext: *const c_void, iostatusblock: *mut IO_STATUS_BLOCK, - buffer: *mut core::ffi::c_void, + buffer: *mut c_void, length: u32, byteoffset: *const i64, key: *const u32 @@ -264,9 +262,9 @@ compat_fn_with_fallback! { filehandle: HANDLE, event: HANDLE, apcroutine: PIO_APC_ROUTINE, - apccontext: *const core::ffi::c_void, + apccontext: *const c_void, iostatusblock: *mut IO_STATUS_BLOCK, - buffer: *const core::ffi::c_void, + buffer: *const c_void, length: u32, byteoffset: *const i64, key: *const u32 diff --git a/library/std/src/sys/pal/windows/handle.rs b/library/std/src/sys/pal/windows/handle.rs index 94408f69e250..e5b2da697821 100644 --- a/library/std/src/sys/pal/windows/handle.rs +++ b/library/std/src/sys/pal/windows/handle.rs @@ -3,16 +3,17 @@ #[cfg(test)] mod tests; -use crate::cmp; use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut, Read}; -use crate::mem; use crate::os::windows::io::{ AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle, }; -use crate::ptr; use crate::sys::c; use crate::sys::cvt; use crate::sys_common::{AsInner, FromInner, IntoInner}; +use core::cmp; +use core::ffi::c_void; +use core::mem; +use core::ptr; /// An owned container for `HANDLE` object, closing them on Drop. /// @@ -255,7 +256,7 @@ impl Handle { None, ptr::null_mut(), &mut io_status, - buf.cast::(), + buf.cast::(), len, offset.as_ref().map(|n| ptr::from_ref(n).cast::()).unwrap_or(ptr::null()), ptr::null(), @@ -305,7 +306,7 @@ impl Handle { None, ptr::null_mut(), &mut io_status, - buf.as_ptr().cast::(), + buf.as_ptr().cast::(), len, offset.as_ref().map(|n| ptr::from_ref(n).cast::()).unwrap_or(ptr::null()), ptr::null(), From 7cd25b1b1183a58c1f6652826e3ec5ed23f8d9ef Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 24 Jul 2024 08:28:47 +0000 Subject: [PATCH 40/54] Forbid unsafe_op_in_unsafe_fn in sys/pal/windows --- library/std/src/sys/pal/windows/c.rs | 8 ++++---- library/std/src/sys/pal/windows/compat.rs | 14 +++++++++----- library/std/src/sys/pal/windows/mod.rs | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs index fa350f4e5833..8ebcf10dd1f2 100644 --- a/library/std/src/sys/pal/windows/c.rs +++ b/library/std/src/sys/pal/windows/c.rs @@ -134,26 +134,26 @@ compat_fn_with_fallback! { // >= Win10 1607 // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription pub fn SetThreadDescription(hthread: HANDLE, lpthreaddescription: PCWSTR) -> HRESULT { - SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL + unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL } } // >= Win10 1607 // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription pub fn GetThreadDescription(hthread: HANDLE, lpthreaddescription: *mut PWSTR) -> HRESULT { - SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL + unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL } } // >= Win8 / Server 2012 // https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime #[cfg(target_vendor = "win7")] pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> () { - GetSystemTimeAsFileTime(lpsystemtimeasfiletime) + unsafe { GetSystemTimeAsFileTime(lpsystemtimeasfiletime) } } // >= Win11 / Server 2022 // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 { - GetTempPathW(bufferlength, buffer) + unsafe { GetTempPathW(bufferlength, buffer) } } } diff --git a/library/std/src/sys/pal/windows/compat.rs b/library/std/src/sys/pal/windows/compat.rs index 49fa1603f3e1..75232dfc0b0f 100644 --- a/library/std/src/sys/pal/windows/compat.rs +++ b/library/std/src/sys/pal/windows/compat.rs @@ -158,8 +158,10 @@ macro_rules! compat_fn_with_fallback { static PTR: AtomicPtr = AtomicPtr::new(load as *mut _); unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype { - let func = load_from_module(Module::new($module)); - func($($argname),*) + unsafe { + let func = load_from_module(Module::new($module)); + func($($argname),*) + } } fn load_from_module(module: Option) -> F { @@ -182,8 +184,10 @@ macro_rules! compat_fn_with_fallback { #[inline(always)] pub unsafe fn call($($argname: $argtype),*) -> $rettype { - let func: F = mem::transmute(PTR.load(Ordering::Relaxed)); - func($($argname),*) + unsafe { + let func: F = mem::transmute(PTR.load(Ordering::Relaxed)); + func($($argname),*) + } } } #[allow(unused)] @@ -225,7 +229,7 @@ macro_rules! compat_fn_optional { } #[inline] pub unsafe extern "system" fn $symbol($($argname: $argtype),*) $(-> $rettype)? { - $symbol::option().unwrap()($($argname),*) + unsafe { $symbol::option().unwrap()($($argname),*) } } )+ ) diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs index b85a8318bcbb..881ca17936d3 100644 --- a/library/std/src/sys/pal/windows/mod.rs +++ b/library/std/src/sys/pal/windows/mod.rs @@ -1,5 +1,5 @@ #![allow(missing_docs, nonstandard_style)] -#![deny(unsafe_op_in_unsafe_fn)] +#![forbid(unsafe_op_in_unsafe_fn)] use crate::ffi::{OsStr, OsString}; use crate::io::ErrorKind; From 61b5e11c47c452ed987295b147783e8bd8e16434 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 15 Jul 2024 09:20:11 +0000 Subject: [PATCH 41/54] Don't use global caches if opaques can be defined --- compiler/rustc_trait_selection/src/traits/select/mod.rs | 8 +++++++- .../auto-traits/opaque_type_candidate_selection.rs} | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) rename tests/{crashes/119272.rs => ui/auto-traits/opaque_type_candidate_selection.rs} (91%) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d6590322caab..02ad361f9f59 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1498,7 +1498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } - // Avoid using the master cache during coherence and just rely + // Avoid using the global cache during coherence and just rely // on the local cache. This effectively disables caching // during coherence. It is really just a simplification to // avoid us having to fear that coherence results "pollute" @@ -1509,6 +1509,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } + // Avoid using the global cache when we're defining opaque types + // as their hidden type may impact the result of candidate selection. + if !self.infcx.defining_opaque_types().is_empty() { + return false; + } + // Otherwise, we can use the global cache. true } diff --git a/tests/crashes/119272.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs similarity index 91% rename from tests/crashes/119272.rs rename to tests/ui/auto-traits/opaque_type_candidate_selection.rs index 02e2cfd09e2f..d6973b76a6e1 100644 --- a/tests/crashes/119272.rs +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -1,4 +1,7 @@ -//@ known-bug: #119272 +//! used to ICE: #119272 + +//@ check-pass + #![feature(type_alias_impl_trait)] mod defining_scope { use super::*; From ac26b883bf3824de42e7adbf0fa69e24f2586ddf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 24 Jul 2024 20:29:28 +1000 Subject: [PATCH 42/54] Improve spans on evaluated `cfg_attr`s. When converting something like `#![cfg_attr(cond, attr)]` into `#![attr]`, we currently duplicate the `#` token and the `!` token. But weirdly, there is also this comment: // We don't really have a good span to use for the synthesized `[]` // in `#[attr]`, so just use the span of the `#` token. Maybe that comment used to be true? But now it is false: we can duplicate the existing delimiters (and their spans and spacing), much like we do for the `#` and `!`. This commit does that, thus removing the incorrect comment, and improving the spans on `Group`s in a few proc-macro tests. --- compiler/rustc_expand/src/config.rs | 54 +++++++++---------- tests/ui/proc-macro/cfg-eval-inner.stdout | 6 +-- tests/ui/proc-macro/cfg-eval.stdout | 4 +- tests/ui/proc-macro/expand-to-derive.stdout | 2 +- tests/ui/proc-macro/inner-attrs.stdout | 2 +- .../proc-macro/issue-75930-derive-cfg.stdout | 6 +-- .../proc-macro/macro-rules-derive-cfg.stdout | 6 +-- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 9da4aa84db52..6c02c237115c 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -6,7 +6,7 @@ use crate::errors::{ }; use rustc_ast::ptr::P; use rustc_ast::token::{Delimiter, Token, TokenKind}; -use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, DelimSpacing, DelimSpan, Spacing}; +use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, Spacing}; use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree}; use rustc_ast::NodeId; use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem}; @@ -298,47 +298,47 @@ impl<'a> StripUnconfigured<'a> { cfg_attr: &Attribute, (item, item_span): (ast::AttrItem, Span), ) -> Attribute { - // We are taking an attribute of the form `#[cfg_attr(pred, attr)]` - // and producing an attribute of the form `#[attr]`. We - // have captured tokens for `attr` itself, but we need to - // synthesize tokens for the wrapper `#` and `[]`, which - // we do below. + // Convert `#[cfg_attr(pred, attr)]` to `#[attr]`. - // Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token - // for `attr` when we expand it to `#[attr]` + // Use the `#` from `#[cfg_attr(pred, attr)]` in the result `#[attr]`. let mut orig_trees = cfg_attr.token_trees().into_iter(); - let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) = - orig_trees.next().unwrap().clone() + let Some(TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _)) = + orig_trees.next() else { panic!("Bad tokens for attribute {cfg_attr:?}"); }; - // We don't really have a good span to use for the synthesized `[]` - // in `#[attr]`, so just use the span of the `#` token. - let bracket_group = AttrTokenTree::Delimited( - DelimSpan::from_single(pound_token.span), - DelimSpacing::new(Spacing::JointHidden, Spacing::Alone), - Delimiter::Bracket, - item.tokens - .as_ref() - .unwrap_or_else(|| panic!("Missing tokens for {item:?}")) - .to_attr_token_stream(), - ); - let trees = if cfg_attr.style == AttrStyle::Inner { - // For inner attributes, we do the same thing for the `!` in `#![some_attr]` - let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) = - orig_trees.next().unwrap().clone() + // For inner attributes, we do the same thing for the `!` in `#![attr]`. + let mut trees = if cfg_attr.style == AttrStyle::Inner { + let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _)) = + orig_trees.next() else { panic!("Bad tokens for attribute {cfg_attr:?}"); }; vec![ AttrTokenTree::Token(pound_token, Spacing::Joint), AttrTokenTree::Token(bang_token, Spacing::JointHidden), - bracket_group, ] } else { - vec![AttrTokenTree::Token(pound_token, Spacing::JointHidden), bracket_group] + vec![AttrTokenTree::Token(pound_token, Spacing::JointHidden)] }; + + // And the same thing for the `[`/`]` delimiters in `#[attr]`. + let Some(TokenTree::Delimited(delim_span, delim_spacing, Delimiter::Bracket, _)) = + orig_trees.next() + else { + panic!("Bad tokens for attribute {cfg_attr:?}"); + }; + trees.push(AttrTokenTree::Delimited( + delim_span, + delim_spacing, + Delimiter::Bracket, + item.tokens + .as_ref() + .unwrap_or_else(|| panic!("Missing tokens for {item:?}")) + .to_attr_token_stream(), + )); + let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees))); let attr = attr::mk_attr_from_item( &self.sess.psess.attr_id_generator, diff --git a/tests/ui/proc-macro/cfg-eval-inner.stdout b/tests/ui/proc-macro/cfg-eval-inner.stdout index 9fa8f437d0ef..1aac28b2ec2f 100644 --- a/tests/ui/proc-macro/cfg-eval-inner.stdout +++ b/tests/ui/proc-macro/cfg-eval-inner.stdout @@ -73,7 +73,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/cfg-eval-inner.rs:19:40: 19:54 (#0), }, ], - span: $DIR/cfg-eval-inner.rs:19:5: 19:6 (#0), + span: $DIR/cfg-eval-inner.rs:19:7: 19:56 (#0), }, Punct { ch: '#', @@ -168,7 +168,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/cfg-eval-inner.rs:23:48: 23:70 (#0), }, ], - span: $DIR/cfg-eval-inner.rs:23:13: 23:14 (#0), + span: $DIR/cfg-eval-inner.rs:23:15: 23:72 (#0), }, Literal { kind: Integer, @@ -233,7 +233,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/cfg-eval-inner.rs:32:40: 32:56 (#0), }, ], - span: $DIR/cfg-eval-inner.rs:32:5: 32:6 (#0), + span: $DIR/cfg-eval-inner.rs:32:7: 32:58 (#0), }, Ident { ident: "fn", diff --git a/tests/ui/proc-macro/cfg-eval.stdout b/tests/ui/proc-macro/cfg-eval.stdout index e26e16f5a8ce..5d88297ad688 100644 --- a/tests/ui/proc-macro/cfg-eval.stdout +++ b/tests/ui/proc-macro/cfg-eval.stdout @@ -60,7 +60,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/cfg-eval.rs:22:36: 22:38 (#0), }, ], - span: $DIR/cfg-eval.rs:22:5: 22:6 (#0), + span: $DIR/cfg-eval.rs:22:6: 22:40 (#0), }, Ident { ident: "field_true", @@ -99,7 +99,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/cfg-eval.rs:35:62: 35:73 (#0), }, ], - span: $DIR/cfg-eval.rs:35:39: 35:40 (#0), + span: $DIR/cfg-eval.rs:35:40: 35:75 (#0), }, Group { delimiter: Parenthesis, diff --git a/tests/ui/proc-macro/expand-to-derive.stdout b/tests/ui/proc-macro/expand-to-derive.stdout index d59b7e5b88f4..81fc52ea22d7 100644 --- a/tests/ui/proc-macro/expand-to-derive.stdout +++ b/tests/ui/proc-macro/expand-to-derive.stdout @@ -57,7 +57,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/expand-to-derive.rs:27:28: 27:39 (#0), }, ], - span: $DIR/expand-to-derive.rs:27:5: 27:6 (#0), + span: $DIR/expand-to-derive.rs:27:6: 27:41 (#0), }, Ident { ident: "struct", diff --git a/tests/ui/proc-macro/inner-attrs.stdout b/tests/ui/proc-macro/inner-attrs.stdout index c8d93babe3a4..ed47ee2cf5ac 100644 --- a/tests/ui/proc-macro/inner-attrs.stdout +++ b/tests/ui/proc-macro/inner-attrs.stdout @@ -674,7 +674,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/inner-attrs.rs:41:52: 41:59 (#0), }, ], - span: $DIR/inner-attrs.rs:41:17: 41:18 (#0), + span: $DIR/inner-attrs.rs:41:19: 41:61 (#0), }, Ident { ident: "true", diff --git a/tests/ui/proc-macro/issue-75930-derive-cfg.stdout b/tests/ui/proc-macro/issue-75930-derive-cfg.stdout index cc712abf2a57..4dcf2b717d8a 100644 --- a/tests/ui/proc-macro/issue-75930-derive-cfg.stdout +++ b/tests/ui/proc-macro/issue-75930-derive-cfg.stdout @@ -119,7 +119,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/issue-75930-derive-cfg.rs:50:29: 50:40 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:50:1: 50:2 (#0), + span: $DIR/issue-75930-derive-cfg.rs:50:2: 50:42 (#0), }, Punct { ch: '#', @@ -1395,7 +1395,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/issue-75930-derive-cfg.rs:50:29: 50:40 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:50:1: 50:2 (#0), + span: $DIR/issue-75930-derive-cfg.rs:50:2: 50:42 (#0), }, Punct { ch: '#', @@ -1571,7 +1571,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/issue-75930-derive-cfg.rs:63:41: 63:51 (#0), }, ], - span: $DIR/issue-75930-derive-cfg.rs:63:13: 63:14 (#0), + span: $DIR/issue-75930-derive-cfg.rs:63:14: 63:53 (#0), }, Ident { ident: "false", diff --git a/tests/ui/proc-macro/macro-rules-derive-cfg.stdout b/tests/ui/proc-macro/macro-rules-derive-cfg.stdout index 257d59974b88..fadf210127e4 100644 --- a/tests/ui/proc-macro/macro-rules-derive-cfg.stdout +++ b/tests/ui/proc-macro/macro-rules-derive-cfg.stdout @@ -88,7 +88,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/macro-rules-derive-cfg.rs:19:59: 19:66 (#3), }, ], - span: $DIR/macro-rules-derive-cfg.rs:19:25: 19:26 (#3), + span: $DIR/macro-rules-derive-cfg.rs:19:26: 19:68 (#3), }, Punct { ch: '#', @@ -113,7 +113,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/macro-rules-derive-cfg.rs:26:47: 26:55 (#0), }, ], - span: $DIR/macro-rules-derive-cfg.rs:26:13: 26:14 (#0), + span: $DIR/macro-rules-derive-cfg.rs:26:14: 26:57 (#0), }, Group { delimiter: Brace, @@ -146,7 +146,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/macro-rules-derive-cfg.rs:27:34: 27:42 (#0), }, ], - span: $DIR/macro-rules-derive-cfg.rs:27:5: 27:6 (#0), + span: $DIR/macro-rules-derive-cfg.rs:27:7: 27:44 (#0), }, Literal { kind: Integer, From a4dd0d6899983fde238305bd6fb4befa61e6e9a6 Mon Sep 17 00:00:00 2001 From: joboet Date: Wed, 24 Jul 2024 14:13:57 +0200 Subject: [PATCH 43/54] std: use duplicate thread local state in tests With rust-lang/miri#3739 merged, the deduplication hack is no longer necessary. --- library/std/src/thread/mod.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index e9731bc85d61..c4e60d53216d 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -192,22 +192,14 @@ pub use scoped::{scope, Scope, ScopedJoinHandle}; #[macro_use] mod local; -cfg_if::cfg_if! { - if #[cfg(test)] { - // Avoid duplicating the global state associated with thread-locals between this crate and - // realstd. Miri relies on this. - pub use realstd::thread::{local_impl, AccessError, LocalKey}; - } else { - #[stable(feature = "rust1", since = "1.0.0")] - pub use self::local::{AccessError, LocalKey}; +#[stable(feature = "rust1", since = "1.0.0")] +pub use self::local::{AccessError, LocalKey}; - // Implementation details used by the thread_local!{} macro. - #[doc(hidden)] - #[unstable(feature = "thread_local_internals", issue = "none")] - pub mod local_impl { - pub use crate::sys::thread_local::*; - } - } +// Implementation details used by the thread_local!{} macro. +#[doc(hidden)] +#[unstable(feature = "thread_local_internals", issue = "none")] +pub mod local_impl { + pub use crate::sys::thread_local::*; } //////////////////////////////////////////////////////////////////////////////// From dfb3fb32cec8613cb2c3317493bc1b449de9246c Mon Sep 17 00:00:00 2001 From: rik86189 <75071538+rik86189@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:23:29 +0200 Subject: [PATCH 44/54] Improved clarity of documentation for std::fs::create_dir_all --- library/std/src/fs.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 6413b3515ece..536d0d1b356a 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -2400,13 +2400,8 @@ pub fn create_dir>(path: P) -> io::Result<()> { /// /// # Errors /// -/// This function will return an error in the following situations, but is not -/// limited to just these cases: -/// -/// * If any directory in the path specified by `path` -/// does not already exist and it could not be created otherwise. The specific -/// error conditions for when a directory is being created (after it is -/// determined to not exist) are outlined by [`fs::create_dir`]. +/// The function will return an error if any directory specified in path does not exist and +/// could not be created. There may be other error conditions; see [`fs::create_dir`] for specifics. /// /// Notable exception is made for situations where any of the directories /// specified in the `path` could not be created as it was being created concurrently. From 4d5ac84285e13a05c0ade4b83aeb309a1f351610 Mon Sep 17 00:00:00 2001 From: Veera Date: Wed, 24 Jul 2024 11:06:23 -0400 Subject: [PATCH 45/54] Remove Unnecessary `.as_str()` Conversions --- compiler/rustc_hir_typeck/src/method/probe.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 9cb6124ab217..ae34ddeaa87d 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1846,7 +1846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { /// Determine if the associated item with the given DefId matches /// the desired name via a doc alias. fn matches_by_doc_alias(&self, def_id: DefId) -> bool { - let Some(name) = self.method_name else { + let Some(method) = self.method_name else { return false; }; let Some(local_def_id) = def_id.as_local() else { @@ -1863,7 +1863,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // #[rustc_confusables("foo", "bar"))] for n in confusables { if let Some(lit) = n.lit() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { return true; } @@ -1883,14 +1883,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // #[doc(alias("foo", "bar"))] for n in nested { if let Some(lit) = n.lit() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { return true; } } } else if let Some(meta) = v.meta_item() && let Some(lit) = meta.name_value_literal() - && name.as_str() == lit.symbol.as_str() + && method.name == lit.symbol { // #[doc(alias = "foo")] return true; From fdff100545850376e0f48d382ca3f92c959ff1cc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 8 Mar 2024 06:36:37 +0000 Subject: [PATCH 46/54] Add regression test --- .../const_check_false_cycle.current.stderr | 34 +++++++++++++++++++ .../rpit/const_check_false_cycle.rs | 15 ++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr create mode 100644 tests/ui/impl-trait/rpit/const_check_false_cycle.rs diff --git a/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr b/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr new file mode 100644 index 000000000000..78c7c164f590 --- /dev/null +++ b/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr @@ -0,0 +1,34 @@ +error[E0391]: cycle detected when computing type of opaque `f::{opaque#0}` + --> $DIR/const_check_false_cycle.rs:9:17 + | +LL | const fn f() -> impl Eq { + | ^^^^^^^ + | +note: ...which requires borrow-checking `f`... + --> $DIR/const_check_false_cycle.rs:9:1 + | +LL | const fn f() -> impl Eq { + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires promoting constants in MIR for `f`... + --> $DIR/const_check_false_cycle.rs:9:1 + | +LL | const fn f() -> impl Eq { + | ^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires const checking `f`... + --> $DIR/const_check_false_cycle.rs:9:1 + | +LL | const fn f() -> impl Eq { + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which requires computing whether `f::{opaque#0}` is freeze... + = note: ...which requires evaluating trait selection obligation `f::{opaque#0}: core::marker::Freeze`... + = note: ...which again requires computing type of opaque `f::{opaque#0}`, completing the cycle +note: cycle used when computing type of `f::{opaque#0}` + --> $DIR/const_check_false_cycle.rs:9:17 + | +LL | const fn f() -> impl Eq { + | ^^^^^^^ + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/impl-trait/rpit/const_check_false_cycle.rs b/tests/ui/impl-trait/rpit/const_check_false_cycle.rs new file mode 100644 index 000000000000..5b6b667e1faf --- /dev/null +++ b/tests/ui/impl-trait/rpit/const_check_false_cycle.rs @@ -0,0 +1,15 @@ +//! This test causes a cycle error when checking whether the +//! return type is `Freeze` during const checking, even though +//! the information is readily available. + +//@ revisions: current next +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + +const fn f() -> impl Eq { + //[current]~^ ERROR cycle detected + g() +} +const fn g() {} + +fn main() {} From acba6449f8597c85b450d96eccda31025cdc0049 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 8 Mar 2024 12:39:26 +0000 Subject: [PATCH 47/54] Do not try to reveal hidden types when trying to prove Freeze in the defining scope --- .../src/check_consts/qualifs.rs | 28 ++++++++- compiler/rustc_middle/src/ty/util.rs | 2 +- .../src/traits/select/mod.rs | 18 +++--- tests/ui/const-generics/opaque_types.stderr | 2 - tests/ui/consts/const-fn-cycle.rs | 3 +- tests/ui/consts/const-fn-cycle.stderr | 34 ----------- .../const-promoted-opaque.atomic.stderr | 45 +++------------ tests/ui/consts/const-promoted-opaque.rs | 5 +- .../const-promoted-opaque.string.stderr | 57 ++----------------- ...method_on_inherent_impl_ref.current.stderr | 27 +-------- ...ll_method_on_inherent_impl_ref.next.stderr | 4 +- .../call_method_on_inherent_impl_ref.rs | 1 - .../const_check_false_cycle.current.stderr | 34 ----------- .../rpit/const_check_false_cycle.rs | 5 +- .../ice-120503-async-const-method.rs | 1 - .../ice-120503-async-const-method.stderr | 37 +----------- .../type-alias-impl-trait/in-where-clause.rs | 1 - .../in-where-clause.stderr | 24 +------- 18 files changed, 67 insertions(+), 261 deletions(-) delete mode 100644 tests/ui/consts/const-fn-cycle.stderr delete mode 100644 tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 9fd7219499b2..d5d3f7767b13 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -100,7 +100,33 @@ impl Qualif for HasMutInterior { } fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool { - !ty.is_freeze(cx.tcx, cx.param_env) + // Avoid selecting for simple cases, such as builtin types. + if ty.is_trivially_freeze() { + return false; + } + + // We do not use `ty.is_freeze` here, because that requires revealing opaque types, which + // requires borrowck, which in turn will invoke mir_const_qualifs again, causing a cycle error. + // Instead we invoke an obligation context manually, and provide the opaque type inference settings + // that allow the trait solver to just error out instead of cycling. + let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span)); + + let obligation = Obligation::new( + cx.tcx, + ObligationCause::dummy_with_span(cx.body.span), + cx.param_env, + ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]), + ); + + let infcx = cx + .tcx + .infer_ctxt() + .with_opaque_type_inference(cx.body.source.def_id().expect_local()) + .build(); + let ocx = ObligationCtxt::new(&infcx); + ocx.register_obligation(obligation); + let errors = ocx.select_all_or_error(); + !errors.is_empty() } fn in_adt_inherently<'tcx>( diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 9307e3806812..4335d96737aa 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1268,7 +1268,7 @@ impl<'tcx> Ty<'tcx> { /// /// Returning true means the type is known to be `Freeze`. Returning /// `false` means nothing -- could be `Freeze`, might not be. - fn is_trivially_freeze(self) -> bool { + pub fn is_trivially_freeze(self) -> bool { match self.kind() { ty::Int(_) | ty::Uint(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 02ad361f9f59..c007cd5314a8 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2386,13 +2386,17 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { - // We can resolve the `impl Trait` to its concrete type, - // which enforces a DAG between the functions requiring - // the auto trait bounds in question. - match self.tcx().type_of_opaque(def_id) { - Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]), - Err(_) => { - return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id)); + if self.infcx.can_define_opaque_ty(def_id) { + unreachable!() + } else { + // We can resolve the `impl Trait` to its concrete type, + // which enforces a DAG between the functions requiring + // the auto trait bounds in question. + match self.tcx().type_of_opaque(def_id) { + Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]), + Err(_) => { + return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id)); + } } } } diff --git a/tests/ui/const-generics/opaque_types.stderr b/tests/ui/const-generics/opaque_types.stderr index 2c7384984c69..3947d645fcbe 100644 --- a/tests/ui/const-generics/opaque_types.stderr +++ b/tests/ui/const-generics/opaque_types.stderr @@ -122,8 +122,6 @@ note: ...which requires const checking `main::{constant#0}`... | LL | foo::<42>(); | ^^ - = note: ...which requires computing whether `Foo` is freeze... - = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Freeze`... = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle note: cycle used when computing type of `Foo::{opaque#0}` --> $DIR/opaque_types.rs:3:12 diff --git a/tests/ui/consts/const-fn-cycle.rs b/tests/ui/consts/const-fn-cycle.rs index 5175296a53e5..2879e3049c0d 100644 --- a/tests/ui/consts/const-fn-cycle.rs +++ b/tests/ui/consts/const-fn-cycle.rs @@ -7,6 +7,8 @@ /// to end up revealing opaque types (the RPIT in `many`'s return type), /// which can quickly lead to cycles. +//@ check-pass + pub struct Parser(H); impl Parser @@ -18,7 +20,6 @@ where } pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - //~^ ERROR: cycle detected Parser::new(|_| unimplemented!()) } } diff --git a/tests/ui/consts/const-fn-cycle.stderr b/tests/ui/consts/const-fn-cycle.stderr deleted file mode 100644 index c851f7342be9..000000000000 --- a/tests/ui/consts/const-fn-cycle.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error[E0391]: cycle detected when computing type of opaque `::many::{opaque#0}` - --> $DIR/const-fn-cycle.rs:20:47 - | -LL | pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires borrow-checking `::many`... - --> $DIR/const-fn-cycle.rs:20:5 - | -LL | pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `::many`... - --> $DIR/const-fn-cycle.rs:20:5 - | -LL | pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `::many`... - --> $DIR/const-fn-cycle.rs:20:5 - | -LL | pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `Parser<::many::{opaque#0}>` is freeze... - = note: ...which requires evaluating trait selection obligation `Parser<::many::{opaque#0}>: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `::many::{opaque#0}`, completing the cycle -note: cycle used when computing type of `::many::{opaque#0}` - --> $DIR/const-fn-cycle.rs:20:47 - | -LL | pub const fn many<'s>(&'s self) -> Parser Fn(&'a str) -> Vec + 's> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/consts/const-promoted-opaque.atomic.stderr b/tests/ui/consts/const-promoted-opaque.atomic.stderr index a0459f4040ec..1f2a7753ff54 100644 --- a/tests/ui/consts/const-promoted-opaque.atomic.stderr +++ b/tests/ui/consts/const-promoted-opaque.atomic.stderr @@ -1,5 +1,5 @@ error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability - --> $DIR/const-promoted-opaque.rs:29:25 + --> $DIR/const-promoted-opaque.rs:28:25 | LL | let _: &'static _ = &FOO; | ^^^^ @@ -9,7 +9,7 @@ LL | let _: &'static _ = &FOO; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time - --> $DIR/const-promoted-opaque.rs:29:26 + --> $DIR/const-promoted-opaque.rs:28:26 | LL | let _: &'static _ = &FOO; | ^^^ the destructor for this type cannot be evaluated in constants @@ -18,13 +18,13 @@ LL | }; | - value is dropped here error[E0492]: constants cannot refer to interior mutable data - --> $DIR/const-promoted-opaque.rs:34:19 + --> $DIR/const-promoted-opaque.rs:33:19 | LL | const BAZ: &Foo = &FOO; | ^^^^ this borrow of an interior mutable value may end up in the final value error[E0716]: temporary value dropped while borrowed - --> $DIR/const-promoted-opaque.rs:38:26 + --> $DIR/const-promoted-opaque.rs:37:26 | LL | let _: &'static _ = &FOO; | ---------- ^^^ creates a temporary value which is freed while still in use @@ -34,38 +34,7 @@ LL | LL | } | - temporary value is freed at the end of this statement -error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}` - --> $DIR/const-promoted-opaque.rs:14:20 - | -LL | pub type Foo = impl Sized; - | ^^^^^^^^^^ - | -note: ...which requires borrow-checking `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:21:5 - | -LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); - | ^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:21:5 - | -LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); - | ^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:21:5 - | -LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); - | ^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `helper::Foo` is freeze... - = note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle -note: cycle used when computing type of `helper::Foo::{opaque#0}` - --> $DIR/const-promoted-opaque.rs:14:20 - | -LL | pub type Foo = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error: aborting due to 4 previous errors -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716. -For more information about an error, try `rustc --explain E0391`. +Some errors have detailed explanations: E0492, E0493, E0658, E0716. +For more information about an error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/const-promoted-opaque.rs b/tests/ui/consts/const-promoted-opaque.rs index e20823527f48..303618df9df0 100644 --- a/tests/ui/consts/const-promoted-opaque.rs +++ b/tests/ui/consts/const-promoted-opaque.rs @@ -12,7 +12,6 @@ mod helper { pub type Foo = impl Sized; - //[string,atomic]~^ ERROR cycle detected #[cfg(string)] pub const FOO: Foo = String::new(); @@ -28,11 +27,11 @@ use helper::*; const BAR: () = { let _: &'static _ = &FOO; //[string,atomic]~^ ERROR: destructor of `helper::Foo` cannot be evaluated at compile-time - //[string,atomic]~| ERROR: cannot borrow here + //[atomic]~| ERROR: cannot borrow here }; const BAZ: &Foo = &FOO; -//[string,atomic]~^ ERROR: constants cannot refer to interior mutable data +//[atomic]~^ ERROR: constants cannot refer to interior mutable data fn main() { let _: &'static _ = &FOO; diff --git a/tests/ui/consts/const-promoted-opaque.string.stderr b/tests/ui/consts/const-promoted-opaque.string.stderr index a613d517e68e..fa1dbb05d175 100644 --- a/tests/ui/consts/const-promoted-opaque.string.stderr +++ b/tests/ui/consts/const-promoted-opaque.string.stderr @@ -1,15 +1,5 @@ -error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability - --> $DIR/const-promoted-opaque.rs:29:25 - | -LL | let _: &'static _ = &FOO; - | ^^^^ - | - = note: see issue #80384 for more information - = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time - --> $DIR/const-promoted-opaque.rs:29:26 + --> $DIR/const-promoted-opaque.rs:28:26 | LL | let _: &'static _ = &FOO; | ^^^ the destructor for this type cannot be evaluated in constants @@ -17,14 +7,8 @@ LL | let _: &'static _ = &FOO; LL | }; | - value is dropped here -error[E0492]: constants cannot refer to interior mutable data - --> $DIR/const-promoted-opaque.rs:34:19 - | -LL | const BAZ: &Foo = &FOO; - | ^^^^ this borrow of an interior mutable value may end up in the final value - error[E0716]: temporary value dropped while borrowed - --> $DIR/const-promoted-opaque.rs:38:26 + --> $DIR/const-promoted-opaque.rs:37:26 | LL | let _: &'static _ = &FOO; | ---------- ^^^ creates a temporary value which is freed while still in use @@ -34,38 +18,7 @@ LL | LL | } | - temporary value is freed at the end of this statement -error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}` - --> $DIR/const-promoted-opaque.rs:14:20 - | -LL | pub type Foo = impl Sized; - | ^^^^^^^^^^ - | -note: ...which requires borrow-checking `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:18:5 - | -LL | pub const FOO: Foo = String::new(); - | ^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:18:5 - | -LL | pub const FOO: Foo = String::new(); - | ^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `helper::FOO`... - --> $DIR/const-promoted-opaque.rs:18:5 - | -LL | pub const FOO: Foo = String::new(); - | ^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `helper::Foo` is freeze... - = note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle -note: cycle used when computing type of `helper::Foo::{opaque#0}` - --> $DIR/const-promoted-opaque.rs:14:20 - | -LL | pub type Foo = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error: aborting due to 2 previous errors -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716. -For more information about an error, try `rustc --explain E0391`. +Some errors have detailed explanations: E0493, E0716. +For more information about an error, try `rustc --explain E0493`. diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr index fe6e166cb4fa..fb51bb7b4173 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope - --> $DIR/call_method_on_inherent_impl_ref.rs:20:11 + --> $DIR/call_method_on_inherent_impl_ref.rs:19:11 | LL | fn my_debug(&self); | -------- the method is available for `&impl Debug` here @@ -14,27 +14,6 @@ note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it LL | trait MyDebug { | ^^^^^^^^^^^^^ -error[E0391]: cycle detected when computing type of opaque `my_foo::{opaque#0}` - --> $DIR/call_method_on_inherent_impl_ref.rs:15:16 - | -LL | fn my_foo() -> impl std::fmt::Debug { - | ^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires type-checking `my_foo`... - --> $DIR/call_method_on_inherent_impl_ref.rs:20:9 - | -LL | x.my_debug(); - | ^ - = note: ...which requires evaluating trait selection obligation `my_foo::{opaque#0}: core::marker::Unpin`... - = note: ...which again requires computing type of opaque `my_foo::{opaque#0}`, completing the cycle -note: cycle used when computing type of `my_foo::{opaque#0}` - --> $DIR/call_method_on_inherent_impl_ref.rs:15:16 - | -LL | fn my_foo() -> impl std::fmt::Debug { - | ^^^^^^^^^^^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0391, E0599. -For more information about an error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr index 327f6ca3450f..7202cb6f90a6 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/call_method_on_inherent_impl_ref.rs:18:13 + --> $DIR/call_method_on_inherent_impl_ref.rs:17:13 | LL | let x = my_foo(); | ^ @@ -13,7 +13,7 @@ LL | let x: /* Type */ = my_foo(); | ++++++++++++ error[E0282]: type annotations needed for `&_` - --> $DIR/call_method_on_inherent_impl_ref.rs:28:13 + --> $DIR/call_method_on_inherent_impl_ref.rs:27:13 | LL | let x = &my_bar(); | ^ diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs index 40ad21532a4e..abe60e5e45a3 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs @@ -13,7 +13,6 @@ where } fn my_foo() -> impl std::fmt::Debug { - //[current]~^ cycle if false { let x = my_foo(); //[next]~^ type annotations needed diff --git a/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr b/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr deleted file mode 100644 index 78c7c164f590..000000000000 --- a/tests/ui/impl-trait/rpit/const_check_false_cycle.current.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error[E0391]: cycle detected when computing type of opaque `f::{opaque#0}` - --> $DIR/const_check_false_cycle.rs:9:17 - | -LL | const fn f() -> impl Eq { - | ^^^^^^^ - | -note: ...which requires borrow-checking `f`... - --> $DIR/const_check_false_cycle.rs:9:1 - | -LL | const fn f() -> impl Eq { - | ^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `f`... - --> $DIR/const_check_false_cycle.rs:9:1 - | -LL | const fn f() -> impl Eq { - | ^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `f`... - --> $DIR/const_check_false_cycle.rs:9:1 - | -LL | const fn f() -> impl Eq { - | ^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `f::{opaque#0}` is freeze... - = note: ...which requires evaluating trait selection obligation `f::{opaque#0}: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `f::{opaque#0}`, completing the cycle -note: cycle used when computing type of `f::{opaque#0}` - --> $DIR/const_check_false_cycle.rs:9:17 - | -LL | const fn f() -> impl Eq { - | ^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/impl-trait/rpit/const_check_false_cycle.rs b/tests/ui/impl-trait/rpit/const_check_false_cycle.rs index 5b6b667e1faf..d4ea0e3b1478 100644 --- a/tests/ui/impl-trait/rpit/const_check_false_cycle.rs +++ b/tests/ui/impl-trait/rpit/const_check_false_cycle.rs @@ -1,13 +1,12 @@ -//! This test causes a cycle error when checking whether the +//! This test caused a cycle error when checking whether the //! return type is `Freeze` during const checking, even though //! the information is readily available. //@ revisions: current next //@[next] compile-flags: -Znext-solver -//@[next] check-pass +//@ check-pass const fn f() -> impl Eq { - //[current]~^ ERROR cycle detected g() } const fn g() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.rs index ab46d49073c7..9cd18d4566da 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.rs @@ -9,7 +9,6 @@ impl MyTrait for i32 { //~| ERROR functions in trait impls cannot be declared const //~| ERROR functions cannot be both `const` and `async` //~| ERROR method `bar` is not a member - //~| ERROR cycle detected when computing type main8().await; //~^ ERROR cannot find function } diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.stderr index 1f309e1e8544..90771c344b51 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.stderr @@ -61,7 +61,7 @@ error: using `#![feature(effects)]` without enabling next trait solver globally = help: use `-Znext-solver` to enable error[E0425]: cannot find function `main8` in this scope - --> $DIR/ice-120503-async-const-method.rs:13:9 + --> $DIR/ice-120503-async-const-method.rs:12:9 | LL | main8().await; | ^^^^^ help: a function with a similar name exists: `main` @@ -69,38 +69,7 @@ LL | main8().await; LL | fn main() {} | --------- similarly named function `main` defined here -error[E0391]: cycle detected when computing type of opaque `::bar::{opaque#0}` - --> $DIR/ice-120503-async-const-method.rs:7:5 - | -LL | async const fn bar(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires borrow-checking `::bar`... - --> $DIR/ice-120503-async-const-method.rs:7:5 - | -LL | async const fn bar(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `::bar`... - --> $DIR/ice-120503-async-const-method.rs:7:5 - | -LL | async const fn bar(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `::bar`... - --> $DIR/ice-120503-async-const-method.rs:7:5 - | -LL | async const fn bar(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `::bar::{opaque#0}` is freeze... - = note: ...which requires evaluating trait selection obligation `::bar::{opaque#0}: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `::bar::{opaque#0}`, completing the cycle -note: cycle used when computing type of `::bar::{opaque#0}` - --> $DIR/ice-120503-async-const-method.rs:7:5 - | -LL | async const fn bar(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error: aborting due to 6 previous errors; 1 warning emitted -error: aborting due to 7 previous errors; 1 warning emitted - -Some errors have detailed explanations: E0379, E0391, E0407, E0425. +Some errors have detailed explanations: E0379, E0407, E0425. For more information about an error, try `rustc --explain E0379`. diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.rs b/tests/ui/type-alias-impl-trait/in-where-clause.rs index 7c0de39c7c91..6e104781d84f 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.rs +++ b/tests/ui/type-alias-impl-trait/in-where-clause.rs @@ -4,7 +4,6 @@ #![feature(type_alias_impl_trait)] type Bar = impl Sized; //~^ ERROR: cycle -//~| ERROR: cycle fn foo() -> Bar where diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.stderr b/tests/ui/type-alias-impl-trait/in-where-clause.stderr index 9c08b8f127d2..c486013f8874 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.stderr +++ b/tests/ui/type-alias-impl-trait/in-where-clause.stderr @@ -10,7 +10,7 @@ note: ...which requires computing type of opaque `Bar::{opaque#0}`... LL | type Bar = impl Sized; | ^^^^^^^^^^ note: ...which requires type-checking `foo`... - --> $DIR/in-where-clause.rs:9:1 + --> $DIR/in-where-clause.rs:8:1 | LL | / fn foo() -> Bar LL | | where @@ -25,26 +25,6 @@ LL | type Bar = impl Sized; | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of opaque `Bar::{opaque#0}` - --> $DIR/in-where-clause.rs:5:12 - | -LL | type Bar = impl Sized; - | ^^^^^^^^^^ - | -note: ...which requires type-checking `foo`... - --> $DIR/in-where-clause.rs:13:9 - | -LL | [0; 1 + 2] - | ^^^^^ - = note: ...which requires evaluating trait selection obligation `Bar: core::marker::Send`... - = note: ...which again requires computing type of opaque `Bar::{opaque#0}`, completing the cycle -note: cycle used when computing type of `Bar::{opaque#0}` - --> $DIR/in-where-clause.rs:5:12 - | -LL | type Bar = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0391`. From 548c44760f14c4547971e0359715f871ce9867bd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 4 Jun 2024 13:55:15 +0000 Subject: [PATCH 48/54] Add regression tests --- .../auto-trait-selection-freeze.next.stderr | 22 +++++++++++++++++ .../impl-trait/auto-trait-selection-freeze.rs | 24 +++++++++++++++++++ .../auto-trait-selection.next.stderr | 22 +++++++++++++++++ tests/ui/impl-trait/auto-trait-selection.rs | 20 ++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr create mode 100644 tests/ui/impl-trait/auto-trait-selection-freeze.rs create mode 100644 tests/ui/impl-trait/auto-trait-selection.next.stderr create mode 100644 tests/ui/impl-trait/auto-trait-selection.rs diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr new file mode 100644 index 000000000000..d9192e854971 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr @@ -0,0 +1,22 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection-freeze.rs:20:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ ----- type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `is_trait` + | + = note: cannot satisfy `_: Trait<_>` +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection-freeze.rs:12:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.rs b/tests/ui/impl-trait/auto-trait-selection-freeze.rs new file mode 100644 index 000000000000..72c24c519622 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.rs @@ -0,0 +1,24 @@ +//! This test shows how we fail selection in a way that can influence +//! selection in a code path that succeeds. + +//@ revisions: next old +//@[next] compile-flags: -Znext-solver +//@[old]check-pass + +#![feature(freeze)] + +use std::marker::Freeze; + +fn is_trait, U: Default>(_: T) -> U { + Default::default() +} + +trait Trait {} +impl Trait for T {} +impl Trait for T {} +fn foo() -> impl Sized { + if false { is_trait(foo()) } else { Default::default() } + //[next]~^ ERROR: type annotations needed +} + +fn main() {} diff --git a/tests/ui/impl-trait/auto-trait-selection.next.stderr b/tests/ui/impl-trait/auto-trait-selection.next.stderr new file mode 100644 index 000000000000..2e8d7ad99b29 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection.next.stderr @@ -0,0 +1,22 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection.rs:16:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ ----- type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `is_trait` + | + = note: cannot satisfy `_: Trait<_>` +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection.rs:8:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection.rs b/tests/ui/impl-trait/auto-trait-selection.rs new file mode 100644 index 000000000000..beb0b189fd7f --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection.rs @@ -0,0 +1,20 @@ +//! This test shows how we fail selection in a way that can influence +//! selection in a code path that succeeds. + +//@ revisions: next old +//@[next] compile-flags: -Znext-solver +//@[old]check-pass + +fn is_trait, U: Default>(_: T) -> U { + Default::default() +} + +trait Trait {} +impl Trait for T {} +impl Trait for T {} +fn foo() -> impl Sized { + if false { is_trait(foo()) } else { Default::default() } + //[next]~^ ERROR: type annotations needed +} + +fn main() {} From 8ea461da5595067433803555b3fdb00d75e95b83 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 4 Jun 2024 16:20:01 +0000 Subject: [PATCH 49/54] Do not assemble candidates for auto traits of opaque types in their defining scope --- .../src/traits/select/candidate_assembly.rs | 7 ++++- .../auto-trait-selection-freeze.next.stderr | 4 +-- .../auto-trait-selection-freeze.old.stderr | 26 +++++++++++++++++++ .../impl-trait/auto-trait-selection-freeze.rs | 3 +-- .../auto-trait-selection.next.stderr | 4 +-- .../auto-trait-selection.old.stderr | 26 +++++++++++++++++++ tests/ui/impl-trait/auto-trait-selection.rs | 3 +-- .../impl-trait/unsized_coercion3.next.stderr | 4 +-- .../impl-trait/unsized_coercion3.old.stderr | 16 +----------- tests/ui/impl-trait/unsized_coercion3.rs | 1 - .../impl-trait/unsized_coercion5.old.stderr | 16 +----------- tests/ui/impl-trait/unsized_coercion5.rs | 3 +-- .../type-alias-impl-trait/in-where-clause.rs | 1 + .../in-where-clause.stderr | 21 +++++++++++++-- .../ui/type-alias-impl-trait/reveal_local.rs | 2 +- .../type-alias-impl-trait/reveal_local.stderr | 10 +++---- 16 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr create mode 100644 tests/ui/impl-trait/auto-trait-selection.old.stderr 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 4c3d833b0f90..06b79ea63ca4 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -772,7 +772,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); } - ty::Alias(ty::Opaque, _) => { + ty::Alias(ty::Opaque, alias) => { if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(_))) { // We do not generate an auto impl candidate for `impl Trait`s which already // reference our auto trait. @@ -787,6 +787,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // We do not emit auto trait candidates for opaque types in coherence. // Doing so can result in weird dependency cycles. candidates.ambiguous = true; + } else if self.infcx.can_define_opaque_ty(alias.def_id) { + // We do not emit auto trait candidates for opaque types in their defining scope, as + // we need to know the hidden type first, which we can't reliably know within the defining + // scope. + candidates.ambiguous = true; } else { candidates.vec.push(AutoImplCandidate) } diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr index d9192e854971..5caf0eb2fd4e 100644 --- a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr @@ -1,5 +1,5 @@ error[E0283]: type annotations needed - --> $DIR/auto-trait-selection-freeze.rs:20:16 + --> $DIR/auto-trait-selection-freeze.rs:19:16 | LL | if false { is_trait(foo()) } else { Default::default() } | ^^^^^^^^ ----- type must be known at this point @@ -8,7 +8,7 @@ LL | if false { is_trait(foo()) } else { Default::default() } | = note: cannot satisfy `_: Trait<_>` note: required by a bound in `is_trait` - --> $DIR/auto-trait-selection-freeze.rs:12:16 + --> $DIR/auto-trait-selection-freeze.rs:11:16 | LL | fn is_trait, U: Default>(_: T) -> U { | ^^^^^^^^ required by this bound in `is_trait` diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr new file mode 100644 index 000000000000..b4d2229d408d --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr @@ -0,0 +1,26 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection-freeze.rs:19:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait` + | +note: multiple `impl`s satisfying `impl Sized: Trait<_>` found + --> $DIR/auto-trait-selection-freeze.rs:16:1 + | +LL | impl Trait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | impl Trait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection-freeze.rs:11:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::<_, U>(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.rs b/tests/ui/impl-trait/auto-trait-selection-freeze.rs index 72c24c519622..7306a1c41f74 100644 --- a/tests/ui/impl-trait/auto-trait-selection-freeze.rs +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.rs @@ -3,7 +3,6 @@ //@ revisions: next old //@[next] compile-flags: -Znext-solver -//@[old]check-pass #![feature(freeze)] @@ -18,7 +17,7 @@ impl Trait for T {} impl Trait for T {} fn foo() -> impl Sized { if false { is_trait(foo()) } else { Default::default() } - //[next]~^ ERROR: type annotations needed + //~^ ERROR: type annotations needed } fn main() {} diff --git a/tests/ui/impl-trait/auto-trait-selection.next.stderr b/tests/ui/impl-trait/auto-trait-selection.next.stderr index 2e8d7ad99b29..d34fdcc44967 100644 --- a/tests/ui/impl-trait/auto-trait-selection.next.stderr +++ b/tests/ui/impl-trait/auto-trait-selection.next.stderr @@ -1,5 +1,5 @@ error[E0283]: type annotations needed - --> $DIR/auto-trait-selection.rs:16:16 + --> $DIR/auto-trait-selection.rs:15:16 | LL | if false { is_trait(foo()) } else { Default::default() } | ^^^^^^^^ ----- type must be known at this point @@ -8,7 +8,7 @@ LL | if false { is_trait(foo()) } else { Default::default() } | = note: cannot satisfy `_: Trait<_>` note: required by a bound in `is_trait` - --> $DIR/auto-trait-selection.rs:8:16 + --> $DIR/auto-trait-selection.rs:7:16 | LL | fn is_trait, U: Default>(_: T) -> U { | ^^^^^^^^ required by this bound in `is_trait` diff --git a/tests/ui/impl-trait/auto-trait-selection.old.stderr b/tests/ui/impl-trait/auto-trait-selection.old.stderr new file mode 100644 index 000000000000..1b5fd95fdf90 --- /dev/null +++ b/tests/ui/impl-trait/auto-trait-selection.old.stderr @@ -0,0 +1,26 @@ +error[E0283]: type annotations needed + --> $DIR/auto-trait-selection.rs:15:16 + | +LL | if false { is_trait(foo()) } else { Default::default() } + | ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait` + | +note: multiple `impl`s satisfying `impl Sized: Trait<_>` found + --> $DIR/auto-trait-selection.rs:12:1 + | +LL | impl Trait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | impl Trait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `is_trait` + --> $DIR/auto-trait-selection.rs:7:16 + | +LL | fn is_trait, U: Default>(_: T) -> U { + | ^^^^^^^^ required by this bound in `is_trait` +help: consider specifying the generic arguments + | +LL | if false { is_trait::<_, U>(foo()) } else { Default::default() } + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/impl-trait/auto-trait-selection.rs b/tests/ui/impl-trait/auto-trait-selection.rs index beb0b189fd7f..ee5612459c25 100644 --- a/tests/ui/impl-trait/auto-trait-selection.rs +++ b/tests/ui/impl-trait/auto-trait-selection.rs @@ -3,7 +3,6 @@ //@ revisions: next old //@[next] compile-flags: -Znext-solver -//@[old]check-pass fn is_trait, U: Default>(_: T) -> U { Default::default() @@ -14,7 +13,7 @@ impl Trait for T {} impl Trait for T {} fn foo() -> impl Sized { if false { is_trait(foo()) } else { Default::default() } - //[next]~^ ERROR: type annotations needed + //~^ ERROR: type annotations needed } fn main() {} diff --git a/tests/ui/impl-trait/unsized_coercion3.next.stderr b/tests/ui/impl-trait/unsized_coercion3.next.stderr index bab8d1cd83b3..586ae0760282 100644 --- a/tests/ui/impl-trait/unsized_coercion3.next.stderr +++ b/tests/ui/impl-trait/unsized_coercion3.next.stderr @@ -5,7 +5,7 @@ LL | let x = hello(); | ^^^^^^^ types differ error[E0308]: mismatched types - --> $DIR/unsized_coercion3.rs:19:14 + --> $DIR/unsized_coercion3.rs:18:14 | LL | fn hello() -> Box { | ------------------- the expected opaque type @@ -21,7 +21,7 @@ note: associated function defined here --> $SRC_DIR/alloc/src/boxed.rs:LL:COL error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time - --> $DIR/unsized_coercion3.rs:19:14 + --> $DIR/unsized_coercion3.rs:18:14 | LL | Box::new(1u32) | -------- ^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/impl-trait/unsized_coercion3.old.stderr b/tests/ui/impl-trait/unsized_coercion3.old.stderr index 24a302d7007a..52a72b84a8dd 100644 --- a/tests/ui/impl-trait/unsized_coercion3.old.stderr +++ b/tests/ui/impl-trait/unsized_coercion3.old.stderr @@ -1,17 +1,3 @@ -error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/unsized_coercion3.rs:15:32 - | -LL | let y: Box = x; - | ^ - | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/unsized_coercion3.rs:11:19 - | -LL | fn hello() -> Box { - | ^^^^^^^^^^^^^^^^^^^ - = note: required for the cast from `Box` to `Box` - error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time --> $DIR/unsized_coercion3.rs:15:32 | @@ -21,6 +7,6 @@ LL | let y: Box = x; = help: the trait `Sized` is not implemented for `impl Trait + ?Sized` = note: required for the cast from `Box` to `Box` -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion3.rs b/tests/ui/impl-trait/unsized_coercion3.rs index 85950ac583eb..7e862de2157d 100644 --- a/tests/ui/impl-trait/unsized_coercion3.rs +++ b/tests/ui/impl-trait/unsized_coercion3.rs @@ -14,7 +14,6 @@ fn hello() -> Box { //[next]~^ ERROR: type mismatch resolving `impl Trait + ?Sized <: dyn Send` let y: Box = x; //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know - //[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits } Box::new(1u32) //[next]~^ ERROR: mismatched types diff --git a/tests/ui/impl-trait/unsized_coercion5.old.stderr b/tests/ui/impl-trait/unsized_coercion5.old.stderr index b6437266f27d..06ad54b1f1d8 100644 --- a/tests/ui/impl-trait/unsized_coercion5.old.stderr +++ b/tests/ui/impl-trait/unsized_coercion5.old.stderr @@ -9,20 +9,6 @@ LL | let y: Box = x as Box; = note: expected struct `Box` found struct `Box` -error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/unsized_coercion5.rs:16:32 - | -LL | let y: Box = x as Box; - | ^ - | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/unsized_coercion5.rs:13:19 - | -LL | fn hello() -> Box { - | ^^^^^^^^^^^^^^^^^^^ - = note: required for the cast from `Box` to `Box` - error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time --> $DIR/unsized_coercion5.rs:16:32 | @@ -32,7 +18,7 @@ LL | let y: Box = x as Box; = help: the trait `Sized` is not implemented for `impl Trait + ?Sized` = note: required for the cast from `Box` to `Box` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0277, E0308. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/unsized_coercion5.rs b/tests/ui/impl-trait/unsized_coercion5.rs index b007267a0066..85d313caa135 100644 --- a/tests/ui/impl-trait/unsized_coercion5.rs +++ b/tests/ui/impl-trait/unsized_coercion5.rs @@ -15,8 +15,7 @@ fn hello() -> Box { let x = hello(); let y: Box = x as Box; //[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know - //[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits - //~^^^ ERROR: mismatched types + //~^^ ERROR: mismatched types } Box::new(1u32) } diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.rs b/tests/ui/type-alias-impl-trait/in-where-clause.rs index 6e104781d84f..a089fdc90753 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.rs +++ b/tests/ui/type-alias-impl-trait/in-where-clause.rs @@ -10,6 +10,7 @@ where Bar: Send, { [0; 1 + 2] + //~^ ERROR: type annotations needed: cannot satisfy `Bar: Send` } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.stderr b/tests/ui/type-alias-impl-trait/in-where-clause.stderr index c486013f8874..f1361b47c56e 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.stderr +++ b/tests/ui/type-alias-impl-trait/in-where-clause.stderr @@ -25,6 +25,23 @@ LL | type Bar = impl Sized; | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error: aborting due to 1 previous error +error[E0283]: type annotations needed: cannot satisfy `Bar: Send` + --> $DIR/in-where-clause.rs:12:9 + | +LL | [0; 1 + 2] + | ^^^^^ + | + = note: cannot satisfy `Bar: Send` +note: required by a bound in `foo` + --> $DIR/in-where-clause.rs:10:10 + | +LL | fn foo() -> Bar + | --- required by a bound in this function +LL | where +LL | Bar: Send, + | ^^^^ required by this bound in `foo` -For more information about this error, try `rustc --explain E0391`. +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0283, E0391. +For more information about an error, try `rustc --explain E0283`. diff --git a/tests/ui/type-alias-impl-trait/reveal_local.rs b/tests/ui/type-alias-impl-trait/reveal_local.rs index 07fd989b0fa7..34f3788e2341 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.rs +++ b/tests/ui/type-alias-impl-trait/reveal_local.rs @@ -20,7 +20,7 @@ fn not_gooder() -> Foo { // while we could know this from the hidden type, it would // need extra roundabout logic to support it. is_send::(); - //~^ ERROR: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits + //~^ ERROR: type annotations needed: cannot satisfy `Foo: Send` x } diff --git a/tests/ui/type-alias-impl-trait/reveal_local.stderr b/tests/ui/type-alias-impl-trait/reveal_local.stderr index e1b320cc38e3..9829c58cf73b 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.stderr +++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr @@ -16,18 +16,13 @@ note: required by a bound in `is_send` LL | fn is_send() {} | ^^^^ required by this bound in `is_send` -error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits +error[E0283]: type annotations needed: cannot satisfy `Foo: Send` --> $DIR/reveal_local.rs:22:15 | LL | is_send::(); | ^^^ | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/reveal_local.rs:5:12 - | -LL | type Foo = impl Debug; - | ^^^^^^^^^^ + = note: cannot satisfy `Foo: Send` note: required by a bound in `is_send` --> $DIR/reveal_local.rs:7:15 | @@ -36,3 +31,4 @@ LL | fn is_send() {} error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0283`. From c9886a1ddf6b19e35b0361062825666d34f8dfee Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 23 Jul 2024 18:56:29 -0500 Subject: [PATCH 50/54] Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps` We are moving toward forbidding `missing_fragment_specifier` either in edition 2024 or unconditionally. Make a first step toward this by ensuring crates that rely on the old behavior are reported when used as dependencies. Tracking issue: --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- tests/ui/lint/expansion-time.stderr | 15 +++++++ tests/ui/macros/issue-39404.stderr | 11 +++++ .../ui/macros/macro-match-nonterminal.stderr | 22 +++++++++ ...acro-missing-fragment-deduplication.stderr | 11 +++++ tests/ui/macros/macro-missing-fragment.stderr | 45 +++++++++++++++++++ tests/ui/parser/macro/issue-33569.stderr | 11 +++++ 7 files changed, 116 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 2f4e6a323083..5d4cc7561a63 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1424,7 +1424,7 @@ declare_lint! { Deny, "detects missing fragment specifiers in unused `macro_rules!` patterns", @future_incompatible = FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps, + reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps, reference: "issue #40107 ", }; } diff --git a/tests/ui/lint/expansion-time.stderr b/tests/ui/lint/expansion-time.stderr index 626e51dd00c2..e490ae91a488 100644 --- a/tests/ui/lint/expansion-time.stderr +++ b/tests/ui/lint/expansion-time.stderr @@ -55,6 +55,21 @@ LL | #[warn(incomplete_include)] warning: 4 warnings emitted Future incompatibility report: Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/expansion-time.rs:9:19 + | +LL | macro_rules! m { ($i) => {} } + | ^^ + | + = 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 #40107 +note: the lint level is defined here + --> $DIR/expansion-time.rs:8:8 + | +LL | #[warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: warning: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable --> $DIR/expansion-time.rs:14:7 | diff --git a/tests/ui/macros/issue-39404.stderr b/tests/ui/macros/issue-39404.stderr index 33cafd93a404..176c8e9f073c 100644 --- a/tests/ui/macros/issue-39404.stderr +++ b/tests/ui/macros/issue-39404.stderr @@ -10,3 +10,14 @@ LL | macro_rules! m { ($i) => {} } error: aborting due to 1 previous error +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/issue-39404.rs:3:19 + | +LL | macro_rules! m { ($i) => {} } + | ^^ + | + = 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 #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-match-nonterminal.stderr b/tests/ui/macros/macro-match-nonterminal.stderr index ef7261c02394..831579c4fefd 100644 --- a/tests/ui/macros/macro-match-nonterminal.stderr +++ b/tests/ui/macros/macro-match-nonterminal.stderr @@ -25,3 +25,25 @@ LL | ($a, $b) => { error: aborting due to 3 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:2:8 + | +LL | ($a, $b) => { + | ^ + | + = 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 #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + +Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-match-nonterminal.rs:2:10 + | +LL | ($a, $b) => { + | ^^ + | + = 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 #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-missing-fragment-deduplication.stderr b/tests/ui/macros/macro-missing-fragment-deduplication.stderr index 3b9e716e194d..c46712f70fd5 100644 --- a/tests/ui/macros/macro-missing-fragment-deduplication.stderr +++ b/tests/ui/macros/macro-missing-fragment-deduplication.stderr @@ -16,3 +16,14 @@ LL | ($name) => {} error: aborting due to 2 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/macro-missing-fragment-deduplication.rs:4:6 + | +LL | ($name) => {} + | ^^^^^ + | + = 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 #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + diff --git a/tests/ui/macros/macro-missing-fragment.stderr b/tests/ui/macros/macro-missing-fragment.stderr index 1089f67f4336..abe4d4cd68a2 100644 --- a/tests/ui/macros/macro-missing-fragment.stderr +++ b/tests/ui/macros/macro-missing-fragment.stderr @@ -38,3 +38,48 @@ LL | ( $name ) => {}; error: aborting due to 1 previous error; 3 warnings emitted +Future incompatibility report: Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:4:20 + | +LL | ( $( any_token $field_rust_type )* ) => {}; + | ^^^^^^^^^^^^^^^^ + | + = 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 #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:12:7 + | +LL | ( $name ) => {}; + | ^^^^^ + | + = 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 #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Future breakage diagnostic: +warning: missing fragment specifier + --> $DIR/macro-missing-fragment.rs:18:7 + | +LL | ( $name ) => {}; + | ^^^^^ + | + = 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 #40107 +note: the lint level is defined here + --> $DIR/macro-missing-fragment.rs:1:9 + | +LL | #![warn(missing_fragment_specifier)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/ui/parser/macro/issue-33569.stderr b/tests/ui/parser/macro/issue-33569.stderr index 0dca090fb87c..d1b6abfeeebf 100644 --- a/tests/ui/parser/macro/issue-33569.stderr +++ b/tests/ui/parser/macro/issue-33569.stderr @@ -28,3 +28,14 @@ LL | { $+ } => { error: aborting due to 4 previous errors +Future incompatibility report: Future breakage diagnostic: +error: missing fragment specifier + --> $DIR/issue-33569.rs:2:8 + | +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 #40107 + = note: `#[deny(missing_fragment_specifier)]` on by default + From 53846925cabfd730489e3902a2840826325a9a60 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 24 Jul 2024 10:08:28 -0700 Subject: [PATCH 51/54] rustdoc: clean up and fix ord violations in item sorting Based on e3fdafc263a4a705a3bec1a6865a4d011b2ec7c5 with a few minor changes: - The name sorting function is changed to follow the [version sort] from the style guide - the `cmp` function is redesigned to more obviously make a partial order, by always return `cmp()` of the same variable as the `!=` above [version sort]: https://doc.rust-lang.org/nightly/style-guide/index.html#sorting Co-authored-by: Guillaume Gomez --- src/librustdoc/html/render/print_item.rs | 183 ++++++++++++++--------- src/librustdoc/html/render/tests.rs | 2 +- 2 files changed, 117 insertions(+), 68 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index a04313b4b790..cf78a1d223c8 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -316,7 +316,8 @@ trait ItemTemplate<'a, 'cx: 'a>: rinja::Template + fmt::Display { fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: &[clean::Item]) { write!(w, "{}", document(cx, item, None, HeadingOffset::H2)); - let mut indices = (0..items.len()).filter(|i| !items[*i].is_stripped()).collect::>(); + let mut not_stripped_items = + items.iter().filter(|i| !i.is_stripped()).enumerate().collect::>(); // the order of item types in the listing fn reorder(ty: ItemType) -> u8 { @@ -338,37 +339,29 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: } } - fn cmp( - i1: &clean::Item, - i2: &clean::Item, - idx1: usize, - idx2: usize, - tcx: TyCtxt<'_>, - ) -> Ordering { - let ty1 = i1.type_(); - let ty2 = i2.type_(); - if item_ty_to_section(ty1) != item_ty_to_section(ty2) - || (ty1 != ty2 && (ty1 == ItemType::ExternCrate || ty2 == ItemType::ExternCrate)) - { - return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2)); + fn cmp(i1: &clean::Item, i2: &clean::Item, tcx: TyCtxt<'_>) -> Ordering { + let rty1 = reorder(i1.type_()); + let rty2 = reorder(i2.type_()); + if rty1 != rty2 { + return rty1.cmp(&rty2); } - let s1 = i1.stability(tcx).as_ref().map(|s| s.level); - let s2 = i2.stability(tcx).as_ref().map(|s| s.level); - if let (Some(a), Some(b)) = (s1, s2) { - match (a.is_stable(), b.is_stable()) { - (true, true) | (false, false) => {} - (false, true) => return Ordering::Greater, - (true, false) => return Ordering::Less, - } + let is_stable1 = i1.stability(tcx).as_ref().map(|s| s.level.is_stable()).unwrap_or(true); + let is_stable2 = i2.stability(tcx).as_ref().map(|s| s.level.is_stable()).unwrap_or(true); + if is_stable1 != is_stable2 { + // true is bigger than false in the standard bool ordering, + // but we actually want stable items to come first + return is_stable2.cmp(&is_stable1); } let lhs = i1.name.unwrap_or(kw::Empty); let rhs = i2.name.unwrap_or(kw::Empty); compare_names(lhs.as_str(), rhs.as_str()) } + let tcx = cx.tcx(); + match cx.shared.module_sorting { ModuleSorting::Alphabetical => { - indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2, cx.tcx())); + not_stripped_items.sort_by(|(_, i1), (_, i2)| cmp(i1, i2, tcx)); } ModuleSorting::DeclarationOrder => {} } @@ -391,24 +384,19 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: // can be identical even if the elements are different (mostly in imports). // So in case this is an import, we keep everything by adding a "unique id" // (which is the position in the vector). - indices.dedup_by_key(|i| { + not_stripped_items.dedup_by_key(|(idx, i)| { ( - items[*i].item_id, - if items[*i].name.is_some() { Some(full_path(cx, &items[*i])) } else { None }, - items[*i].type_(), - if items[*i].is_import() { *i } else { 0 }, + i.item_id, + if i.name.is_some() { Some(full_path(cx, i)) } else { None }, + i.type_(), + if i.is_import() { *idx } else { 0 }, ) }); - debug!("{indices:?}"); + debug!("{not_stripped_items:?}"); let mut last_section = None; - for &idx in &indices { - let myitem = &items[idx]; - if myitem.is_stripped() { - continue; - } - + for (_, myitem) in ¬_stripped_items { let my_section = item_ty_to_section(myitem.type_()); if Some(my_section) != last_section { if last_section.is_some() { @@ -424,7 +412,6 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: ); } - let tcx = cx.tcx(); match *myitem.kind { clean::ExternCrateItem { ref src } => { use crate::html::format::anchor; @@ -453,7 +440,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: let stab_tags = if let Some(import_def_id) = import.source.did { // Just need an item with the correct def_id and attrs let import_item = - clean::Item { item_id: import_def_id.into(), ..myitem.clone() }; + clean::Item { item_id: import_def_id.into(), ..(*myitem).clone() }; let stab_tags = Some(extra_info_tags(&import_item, item, tcx).to_string()); stab_tags @@ -2010,40 +1997,102 @@ fn item_keyword(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) { } /// Compare two strings treating multi-digit numbers as single units (i.e. natural sort order). -pub(crate) fn compare_names(mut lhs: &str, mut rhs: &str) -> Ordering { - /// Takes a non-numeric and a numeric part from the given &str. - fn take_parts<'a>(s: &mut &'a str) -> (&'a str, &'a str) { - let i = s.find(|c: char| c.is_ascii_digit()); - let (a, b) = s.split_at(i.unwrap_or(s.len())); - let i = b.find(|c: char| !c.is_ascii_digit()); - let (b, c) = b.split_at(i.unwrap_or(b.len())); - *s = c; - (a, b) - } +/// +/// This code is copied from [`rustfmt`], and should probably be released as a crate at some point. +/// +/// [`rustfmt`]:https://github.com/rust-lang/rustfmt/blob/rustfmt-2.0.0-rc.2/src/formatting/reorder.rs#L32 +pub(crate) fn compare_names(left: &str, right: &str) -> Ordering { + let mut left = left.chars().peekable(); + let mut right = right.chars().peekable(); - while !lhs.is_empty() || !rhs.is_empty() { - let (la, lb) = take_parts(&mut lhs); - let (ra, rb) = take_parts(&mut rhs); - // First process the non-numeric part. - match la.cmp(ra) { - Ordering::Equal => (), - x => return x, - } - // Then process the numeric part, if both sides have one (and they fit in a u64). - if let (Ok(ln), Ok(rn)) = (lb.parse::(), rb.parse::()) { - match ln.cmp(&rn) { - Ordering::Equal => (), - x => return x, + loop { + // The strings are equal so far and not inside a number in both sides + let (l, r) = match (left.next(), right.next()) { + // Is this the end of both strings? + (None, None) => return Ordering::Equal, + // If for one, the shorter one is considered smaller + (None, Some(_)) => return Ordering::Less, + (Some(_), None) => return Ordering::Greater, + (Some(l), Some(r)) => (l, r), + }; + let next_ordering = match (l.to_digit(10), r.to_digit(10)) { + // If neither is a digit, just compare them + (None, None) => Ord::cmp(&l, &r), + // The one with shorter non-digit run is smaller + // For `strverscmp` it's smaller iff next char in longer is greater than digits + (None, Some(_)) => Ordering::Greater, + (Some(_), None) => Ordering::Less, + // If both start numbers, we have to compare the numbers + (Some(l), Some(r)) => { + if l == 0 || r == 0 { + // Fraction mode: compare as if there was leading `0.` + let ordering = Ord::cmp(&l, &r); + if ordering != Ordering::Equal { + return ordering; + } + loop { + // Get next pair + let (l, r) = match (left.peek(), right.peek()) { + // Is this the end of both strings? + (None, None) => return Ordering::Equal, + // If for one, the shorter one is considered smaller + (None, Some(_)) => return Ordering::Less, + (Some(_), None) => return Ordering::Greater, + (Some(l), Some(r)) => (l, r), + }; + // Are they digits? + match (l.to_digit(10), r.to_digit(10)) { + // If out of digits, use the stored ordering due to equal length + (None, None) => break Ordering::Equal, + // If one is shorter, it's smaller + (None, Some(_)) => return Ordering::Less, + (Some(_), None) => return Ordering::Greater, + // If both are digits, consume them and take into account + (Some(l), Some(r)) => { + left.next(); + right.next(); + let ordering = Ord::cmp(&l, &r); + if ordering != Ordering::Equal { + return ordering; + } + } + } + } + } else { + // Integer mode + let mut same_length_ordering = Ord::cmp(&l, &r); + loop { + // Get next pair + let (l, r) = match (left.peek(), right.peek()) { + // Is this the end of both strings? + (None, None) => return same_length_ordering, + // If for one, the shorter one is considered smaller + (None, Some(_)) => return Ordering::Less, + (Some(_), None) => return Ordering::Greater, + (Some(l), Some(r)) => (l, r), + }; + // Are they digits? + match (l.to_digit(10), r.to_digit(10)) { + // If out of digits, use the stored ordering due to equal length + (None, None) => break same_length_ordering, + // If one is shorter, it's smaller + (None, Some(_)) => return Ordering::Less, + (Some(_), None) => return Ordering::Greater, + // If both are digits, consume them and take into account + (Some(l), Some(r)) => { + left.next(); + right.next(); + same_length_ordering = same_length_ordering.then(Ord::cmp(&l, &r)); + } + } + } + } } - } - // Then process the numeric part again, but this time as strings. - match lb.cmp(rb) { - Ordering::Equal => (), - x => return x, + }; + if next_ordering != Ordering::Equal { + return next_ordering; } } - - Ordering::Equal } pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String { diff --git a/src/librustdoc/html/render/tests.rs b/src/librustdoc/html/render/tests.rs index 3175fbe5666d..4a9724a6f840 100644 --- a/src/librustdoc/html/render/tests.rs +++ b/src/librustdoc/html/render/tests.rs @@ -34,7 +34,7 @@ fn test_compare_names() { #[test] fn test_name_sorting() { let names = [ - "Apple", "Banana", "Fruit", "Fruit0", "Fruit00", "Fruit01", "Fruit1", "Fruit02", "Fruit2", + "Apple", "Banana", "Fruit", "Fruit0", "Fruit00", "Fruit01", "Fruit02", "Fruit1", "Fruit2", "Fruit20", "Fruit30x", "Fruit100", "Pear", ]; let mut sorted = names.to_owned(); From 6da04f95a7233089cf714d24a160a5dbaa8d84b9 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Thu, 25 Jul 2024 05:10:15 +0000 Subject: [PATCH 52/54] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 60497630ae0d..9868188eeee7 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -42103d69b73fb4e9d03d5cf66ec12985bb526f6e +e7d66eac5e8e8f60370c98d186aee9fa0ebd7845 From 118a70f38c8f4898329d701a17d131a5b7bd7b48 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 22 Jul 2024 20:36:43 +1000 Subject: [PATCH 53/54] Various notes on match lowering --- .../rustc_mir_build/src/build/matches/mod.rs | 236 ++++++++++++++---- .../rustc_mir_build/src/build/matches/test.rs | 16 +- 2 files changed, 198 insertions(+), 54 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 95bc8b3d0cbc..bd9a38579058 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -528,12 +528,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { end_block.unit() } - /// Binds the variables and ascribes types for a given `match` arm or - /// `let` binding. + /// For a top-level `match` arm or a `let` binding, binds the variables and + /// ascribes types, and also checks the match arm guard (if present). /// - /// Also check if the guard matches, if it's provided. /// `arm_scope` should be `Some` if and only if this is called for a /// `match` arm. + /// + /// In the presence of or-patterns, a match arm might have multiple + /// sub-branches representing different ways to match, with each sub-branch + /// requiring its own bindings and its own copy of the guard. This method + /// handles those sub-branches individually, and then has them jump together + /// to a common block. + /// + /// Returns a single block that the match arm can be lowered into. + /// (For `let` bindings, this is the code that can use the bindings.) fn bind_pattern( &mut self, outer_source_info: SourceInfo, @@ -1022,7 +1030,8 @@ impl<'tcx> PatternExtraData<'tcx> { } } -/// A pattern in a form suitable for generating code. +/// A pattern in a form suitable for lowering the match tree, with all irrefutable +/// patterns simplified away, and or-patterns sorted to the end. /// /// Here, "flat" indicates that the pattern's match pairs have been recursively /// simplified by [`Builder::simplify_match_pairs`]. They are not necessarily @@ -1055,36 +1064,89 @@ impl<'tcx, 'pat> FlatPat<'pat, 'tcx> { ascriptions: Vec::new(), is_never: pattern.is_never_pattern(), }; - // Partly-flatten and sort the match pairs, while recording extra data. + // Recursively remove irrefutable match pairs, while recording their + // bindings/ascriptions, and sort or-patterns after other match pairs. cx.simplify_match_pairs(&mut match_pairs, &mut extra_data); Self { match_pairs, extra_data } } } +/// Candidates are a generalization of (a) top-level match arms, and +/// (b) sub-branches of or-patterns, allowing the match-lowering process to handle +/// them both in a mostly-uniform way. For example, the list of candidates passed +/// to [`Builder::match_candidates`] will often contain a mixture of top-level +/// candidates and or-pattern subcandidates. +/// +/// At the start of match lowering, there is one candidate for each match arm. +/// During match lowering, arms with or-patterns will be expanded into a tree +/// of candidates, where each "leaf" candidate represents one of the ways for +/// the arm pattern to successfully match. #[derive(Debug)] struct Candidate<'pat, 'tcx> { /// For the candidate to match, all of these must be satisfied... - // Invariant: all the match pairs are recursively simplified. - // Invariant: or-patterns must be sorted at the end. + /// + /// --- + /// Initially contains a list of match pairs created by [`FlatPat`], but is + /// subsequently mutated (in a queue-like way) while lowering the match tree. + /// When this list becomes empty, the candidate is fully matched and becomes + /// a leaf (see [`Builder::select_matched_candidate`]). + /// + /// Key mutations include: + /// + /// - When a match pair is fully satisfied by a test, it is removed from the + /// list, and its subpairs are added instead (see [`Builder::sort_candidate`]). + /// - During or-pattern expansion, any leading or-pattern is removed, and is + /// converted into subcandidates (see [`Builder::expand_and_match_or_candidates`]). + /// - After a candidate's subcandidates have been lowered, a copy of any remaining + /// or-patterns is added to each leaf subcandidate + /// (see [`Builder::test_remaining_match_pairs_after_or`]). + /// + /// Invariants: + /// - All [`TestCase::Irrefutable`] patterns have been removed by simplification. + /// - All or-patterns ([`TestCase::Or`]) have been sorted to the end. match_pairs: Vec>, /// ...and if this is non-empty, one of these subcandidates also has to match... - // Invariant: at the end of the algorithm, this must never contain a `is_never` candidate - // because that would break binding consistency. + /// + /// --- + /// Initially a candidate has no subcandidates; they are added (and then immediately + /// lowered) during or-pattern expansion. Their main function is to serve as _output_ + /// of match tree lowering, allowing later steps to see the leaf candidates that + /// represent a match of the entire match arm. + /// + /// A candidate no subcandidates is either incomplete (if it has match pairs left), + /// or is a leaf in the match tree. A candidate with one or more subcandidates is + /// an internal node in the match tree. + /// + /// Invariant: at the end of match tree lowering, this must not contain an + /// `is_never` candidate, because that would break binding consistency. + /// - See [`Builder::remove_never_subcandidates`]. subcandidates: Vec>, /// ...and if there is a guard it must be evaluated; if it's `false` then branch to `otherwise_block`. + /// + /// --- + /// For subcandidates, this is copied from the parent candidate, so it indicates + /// whether the enclosing match arm has a guard. has_guard: bool, - /// If the candidate matches, bindings and ascriptions must be established. + /// Holds extra pattern data that was prepared by [`FlatPat`], including bindings and + /// ascriptions that must be established if this candidate succeeds. extra_data: PatternExtraData<'tcx>, - /// If we filled `self.subcandidate`, we store here the span of the or-pattern they came from. - // Invariant: it is `None` iff `subcandidates.is_empty()`. + /// When setting `self.subcandidates`, we store here the span of the or-pattern they came from. + /// + /// --- + /// Invariant: it is `None` iff `subcandidates.is_empty()`. + /// - FIXME: We sometimes don't unset this when clearing `subcandidates`. or_span: Option, /// The block before the `bindings` have been established. + /// + /// After the match tree has been lowered, [`Builder::lower_match_arms`] + /// will use this as the start point for lowering bindings and guards, and + /// then jump to a shared block containing the arm body. pre_binding_block: Option, /// The block to branch to if the guard or a nested candidate fails to match. @@ -1144,14 +1206,24 @@ impl<'tcx, 'pat> Candidate<'pat, 'tcx> { /// A depth-first traversal of the `Candidate` and all of its recursive /// subcandidates. +/// +/// This signature is very generic, to support traversing candidate trees by +/// reference or by value, and to allow a mutable "context" to be shared by the +/// traversal callbacks. Most traversals can use the simpler +/// [`Candidate::visit_leaves`] wrapper instead. fn traverse_candidate<'pat, 'tcx: 'pat, C, T, I>( candidate: C, context: &mut T, + // Called when visiting a "leaf" candidate (with no subcandidates). visit_leaf: &mut impl FnMut(C, &mut T), + // Called when visiting a "node" candidate (with one or more subcandidates). + // Returns an iterator over the candidate's children (by value or reference). + // Can perform setup before visiting the node's children. get_children: impl Copy + Fn(C, &mut T) -> I, + // Called after visiting a "node" candidate's children. complete_children: impl Copy + Fn(&mut T), ) where - C: Borrow>, + C: Borrow>, // Typically `Candidate` or `&mut Candidate` I: Iterator, { if candidate.borrow().subcandidates.is_empty() { @@ -1182,6 +1254,24 @@ struct Ascription<'tcx> { variance: ty::Variance, } +/// Partial summary of a [`thir::Pat`], indicating what sort of test should be +/// performed to match/reject the pattern, and what the desired test outcome is. +/// This avoids having to perform a full match on [`thir::PatKind`] in some places, +/// and helps [`TestKind::Switch`] and [`TestKind::SwitchInt`] know what target +/// values to use. +/// +/// Created by [`MatchPairTree::for_pattern`], and then inspected primarily by: +/// - [`Builder::pick_test_for_match_pair`] (to choose a test) +/// - [`Builder::sort_candidate`] (to see how the test interacts with a match pair) +/// +/// Two variants are unlike the others and deserve special mention: +/// +/// - [`Self::Irrefutable`] is only used temporarily when building a [`MatchPairTree`]. +/// They are then flattened away by [`Builder::simplify_match_pairs`], with any +/// bindings/ascriptions incorporated into the enclosing [`FlatPat`]. +/// - [`Self::Or`] are not tested directly like the other variants. Instead they +/// participate in or-pattern expansion, where they are transformed into subcandidates. +/// - See [`Builder::expand_and_match_or_candidates`]. #[derive(Debug, Clone)] enum TestCase<'pat, 'tcx> { Irrefutable { binding: Option>, ascription: Option> }, @@ -1224,6 +1314,12 @@ pub(crate) struct MatchPairTree<'pat, 'tcx> { test_case: TestCase<'pat, 'tcx>, /// ... and these subpairs must match. + /// + /// --- + /// Subpairs typically represent tests that can only be performed after their + /// parent has succeeded. For example, the pattern `Some(3)` might have an + /// outer match pair that tests for the variant `Some`, and then a subpair + /// that tests its field for the value `3`. subpairs: Vec, /// The pattern this was created from. @@ -1234,15 +1330,22 @@ pub(crate) struct MatchPairTree<'pat, 'tcx> { #[derive(Clone, Debug, PartialEq)] enum TestKind<'tcx> { /// Test what enum variant a value is. + /// + /// The subset of expected variants is not stored here; instead they are + /// extracted from the [`TestCase`]s of the candidates participating in the + /// test. Switch { /// The enum type being tested. adt_def: ty::AdtDef<'tcx>, }, /// Test what value an integer or `char` has. + /// + /// The test's target values are not stored here; instead they are extracted + /// from the [`TestCase`]s of the candidates participating in the test. SwitchInt, - /// Test what value a `bool` has. + /// Test whether a `bool` is `true` or `false`. If, /// Test for equality with value, possibly after an unsizing coercion to @@ -1258,7 +1361,7 @@ enum TestKind<'tcx> { /// Test whether the value falls within an inclusive or exclusive range. Range(Box>), - /// Test that the length of the slice is equal to `len`. + /// Test that the length of the slice is `== len` or `>= len`. Len { len: u64, op: BinOp }, /// Call `Deref::deref[_mut]` on the value. @@ -1385,20 +1488,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// The main match algorithm. It begins with a set of candidates `candidates` and has the job of /// generating code that branches to an appropriate block if the scrutinee matches one of these /// candidates. The - /// candidates are sorted such that the first item in the list + /// candidates are ordered such that the first item in the list /// has the highest priority. When a candidate is found to match /// the value, we will set and generate a branch to the appropriate /// pre-binding block. /// /// If none of the candidates apply, we continue to the returned `otherwise_block`. /// - /// It might be surprising that the input can be non-exhaustive. - /// Indeed, for matches, initially, it is not, because all matches are - /// exhaustive in Rust. But during processing we sometimes divide - /// up the list of candidates and recurse with a non-exhaustive - /// list. This is how our lowering approach (called "backtracking - /// automaton" in the literature) works. - /// See [`Builder::test_candidates`] for more details. + /// Note that while `match` expressions in the Rust language are exhaustive, + /// candidate lists passed to this method are often _non-exhaustive_. + /// For example, the match lowering process will frequently divide up the + /// list of candidates, and recursively call this method with a non-exhaustive + /// subset of candidates. + /// See [`Builder::test_candidates`] for more details on this + /// "backtracking automata" approach. /// /// For an example of how we use `otherwise_block`, consider: /// ``` @@ -1478,14 +1581,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { return start_block; } [first, remaining @ ..] if first.match_pairs.is_empty() => { - // The first candidate has satisfied all its match pairs; we link it up and continue - // with the remaining candidates. + // The first candidate has satisfied all its match pairs. + // We record the blocks that will be needed by match arm lowering, + // and then continue with the remaining candidates. let remainder_start = self.select_matched_candidate(first, start_block); remainder_start.and(remaining) } candidates if candidates.iter().any(|candidate| candidate.starts_with_or_pattern()) => { - // If any candidate starts with an or-pattern, we have to expand the or-pattern before we - // can proceed further. + // If any candidate starts with an or-pattern, we want to expand or-patterns + // before we do any more tests. + // + // The only candidate we strictly _need_ to expand here is the first one. + // But by expanding other candidates as early as possible, we unlock more + // opportunities to include them in test outcomes, making the match tree + // smaller and simpler. self.expand_and_match_or_candidates(span, scrutinee_span, start_block, candidates) } candidates => { @@ -1588,6 +1697,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let (candidates_to_expand, remaining_candidates) = candidates.split_at_mut(expand_until); // Expand one level of or-patterns for each candidate in `candidates_to_expand`. + // We take care to preserve the relative ordering of candidates, so that + // or-patterns are expanded in their parent's relative position. let mut expanded_candidates = Vec::new(); for candidate in candidates_to_expand.iter_mut() { if candidate.starts_with_or_pattern() { @@ -1608,7 +1719,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - // Process the expanded candidates. + // Recursively lower the part of the match tree represented by the + // expanded candidates. This is where subcandidates actually get lowered! let remainder_start = self.match_candidates( span, scrutinee_span, @@ -1628,6 +1740,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.remove_never_subcandidates(candidate); } } + // It's important to perform the above simplifications _before_ dealing + // with remaining match pairs, to avoid exponential blowup if possible + // (for trivial or-patterns), and avoid useless work (for never patterns). if let Some(last_candidate) = candidates_to_expand.last_mut() { self.test_remaining_match_pairs_after_or(span, scrutinee_span, last_candidate); } @@ -1808,6 +1923,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .all(|match_pair| matches!(match_pair.test_case, TestCase::Or { .. })) ); + // Visit each leaf candidate within this subtree, add a copy of the remaining + // match pairs to it, and then recursively lower the rest of the match tree + // from that point. candidate.visit_leaves(|leaf_candidate| { // At this point the leaf's own match pairs have all been lowered // and removed, so `extend` and assignment are equivalent, @@ -1860,17 +1978,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (match_place, test) } - /// Given a test, we sort the input candidates into several buckets. If a candidate only matches - /// in one of the branches of `test`, we move it there. If it could match in more than one of - /// the branches of `test`, we stop sorting candidates. + /// Given a test, we partition the input candidates into several buckets. + /// If a candidate matches in exactly one of the branches of `test` + /// (and no other branches), we put it into the corresponding bucket. + /// If it could match in more than one of the branches of `test`, the test + /// doesn't usefully apply to it, and we stop partitioning candidates. + /// + /// Importantly, we also **mutate** the branched candidates to remove match pairs + /// that are entailed by the outcome of the test, and add any sub-pairs of the + /// removed pairs. /// /// This returns a pair of /// - the candidates that weren't sorted; /// - for each possible outcome of the test, the candidates that match in that outcome. /// - /// Moreover, we transform the branched candidates to reflect the fact that we know which - /// outcome of `test` occurred. - /// /// For example: /// ``` /// # let (x, y, z) = (true, true, true); @@ -1883,14 +2004,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// # ; /// ``` /// - /// Assume we are testing on `x`. There are 2 overlapping candidate sets: - /// - If the outcome is that `x` is true, candidates 0, 2, and 3 - /// - If the outcome is that `x` is false, candidates 1 and 2 + /// Assume we are testing on `x`. Conceptually, there are 2 overlapping candidate sets: + /// - If the outcome is that `x` is true, candidates {0, 2, 3} are possible + /// - If the outcome is that `x` is false, candidates {1, 2} are possible /// - /// Following our algorithm, candidate 0 is sorted into outcome `x == true`, candidate 1 goes - /// into outcome `x == false`, and candidate 2 and 3 remain unsorted. + /// Following our algorithm: + /// - Candidate 0 is sorted into outcome `x == true` + /// - Candidate 1 is sorted into outcome `x == false` + /// - Candidate 2 remains unsorted, because testing `x` has no effect on it + /// - Candidate 3 remains unsorted, because a previous candidate (2) was unsorted + /// - This helps preserve the illusion that candidates are tested "in order" /// - /// The sorted candidates are transformed: + /// The sorted candidates are mutated to remove entailed match pairs: /// - candidate 0 becomes `[z @ true]` since we know that `x` was `true`; /// - candidate 1 becomes `[y @ false]` since we know that `x` was `false`. fn sort_candidates<'b, 'c, 'pat>( @@ -1933,15 +2058,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (candidates, target_candidates) } - /// This is the most subtle part of the match lowering algorithm. At this point, the input - /// candidates have been fully simplified, so all remaining match-pairs require some sort of - /// test. + /// This is the most subtle part of the match lowering algorithm. At this point, there are + /// no fully-satisfied candidates, and no or-patterns to expand, so we actually need to + /// perform some sort of test to make progress. /// /// Once we pick what sort of test we are going to perform, this test will help us winnow down /// our candidates. So we walk over the candidates (from high to low priority) and check. We - /// compute, for each outcome of the test, a transformed list of candidates. If a candidate - /// matches in a single branch of our test, we add it to the corresponding outcome. We also - /// transform it to record the fact that we know which outcome occurred. + /// compute, for each outcome of the test, a list of (modified) candidates. If a candidate + /// matches in exactly one branch of our test, we add it to the corresponding outcome. We also + /// **mutate its list of match pairs** if appropriate, to reflect the fact that we know which + /// outcome occurred. /// /// For example, if we are testing `x.0`'s variant, and we have a candidate `(x.0 @ Some(v), x.1 /// @ 22)`, then we would have a resulting candidate of `((x.0 as Some).0 @ v, x.1 @ 22)` in the @@ -2036,32 +2162,38 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>], start_block: BasicBlock, ) -> BlockAnd<&'b mut [&'c mut Candidate<'pat, 'tcx>]> { - // Extract the match-pair from the highest priority candidate and build a test from it. + // Choose a match pair from the first candidate, and use it to determine a + // test to perform that will confirm or refute that match pair. let (match_place, test) = self.pick_test(candidates); // For each of the N possible test outcomes, build the vector of candidates that applies if - // the test has that particular outcome. + // the test has that particular outcome. This also mutates the candidates to remove match + // pairs that are fully satisfied by the relevant outcome. let (remaining_candidates, target_candidates) = self.sort_candidates(match_place, &test, candidates); - // The block that we should branch to if none of the - // `target_candidates` match. + // The block that we should branch to if none of the `target_candidates` match. let remainder_start = self.cfg.start_new_block(); - // For each outcome of test, process the candidates that still apply. + // For each outcome of the test, recursively lower the rest of the match tree + // from that point. (Note that we haven't lowered the actual test yet!) let target_blocks: FxIndexMap<_, _> = target_candidates .into_iter() .map(|(branch, mut candidates)| { let branch_start = self.cfg.start_new_block(); + // Recursively lower the rest of the match tree after the relevant outcome. let branch_otherwise = self.match_candidates(span, scrutinee_span, branch_start, &mut *candidates); + + // Link up the `otherwise` block of the subtree to `remainder_start`. let source_info = self.source_info(span); self.cfg.goto(branch_otherwise, source_info, remainder_start); (branch, branch_start) }) .collect(); - // Perform the test, branching to one of N blocks. + // Perform the chosen test, branching to one of the N subtrees prepared above + // (or to `remainder_start` if no outcome was satisfied). self.perform_test( span, scrutinee_span, diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 8a02ea1a06de..802193b8ddfd 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -51,6 +51,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { TestCase::Never => TestKind::Never, + // Or-patterns are not tested directly; instead they are expanded into subcandidates, + // which are then distinguished by testing whatever non-or patterns they contain. TestCase::Or { .. } => bug!("or-patterns should have already been handled"), TestCase::Irrefutable { .. } => span_bug!( @@ -544,6 +546,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .enumerate() .find(|&(_, mp)| mp.place == Some(test_place))?; + // If true, the match pair is completely entailed by its corresponding test + // branch, so it can be removed. If false, the match pair is _compatible_ + // with its test branch, but still needs a more specific test. let fully_matched; let ret = match (&test.kind, &match_pair.test_case) { // If we are performing a variant switch, then this @@ -565,8 +570,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (TestKind::SwitchInt, &TestCase::Constant { value }) if is_switch_ty(match_pair.pattern.ty) => { - // Beware: there might be some ranges sorted into the failure case; we must not add - // a success case that could be matched by one of these ranges. + // An important invariant of candidate sorting is that a candidate + // must not match in multiple branches. For `SwitchInt` tests, adding + // a new value might invalidate that property for range patterns that + // have already been sorted into the failure arm, so we must take care + // not to add such values here. let is_covering_range = |test_case: &TestCase<'_, 'tcx>| { test_case.as_range().is_some_and(|range| { matches!(range.contains(value, self.tcx, self.param_env), None | Some(true)) @@ -591,6 +599,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } (TestKind::SwitchInt, TestCase::Range(range)) => { + // When performing a `SwitchInt` test, a range pattern can be + // sorted into the failure arm if it doesn't contain _any_ of + // the values being tested. (This restricts what values can be + // added to the test by subsequent candidates.) fully_matched = false; let not_contained = sorted_candidates.keys().filter_map(|br| br.as_constant()).copied().all( From 31f31aa4714ff677befa50d95fb60cc47681b638 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 25 Jul 2024 16:41:51 +1000 Subject: [PATCH 54/54] Remove an obsolete comment The test mentioned by this comment was deleted long ago by . --- compiler/rustc_mir_build/src/build/matches/mod.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index bd9a38579058..6ac8f0d00234 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -646,12 +646,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Optimize the case of `let x: T = ...` to write directly // into `x` and then require that `T == typeof(x)`. - // - // Weirdly, this is needed to prevent the - // `intrinsic-move-val.rs` test case from crashing. That - // test works with uninitialized values in a rather - // dubious way, so it may be that the test is kind of - // broken. PatKind::AscribeUserType { subpattern: box Pat {