From 82d8e8420bf072cad7837edb70473622b986544b Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 14 Mar 2022 09:06:07 +0100 Subject: [PATCH] relax `suspicious_auto_trait_impls` lint --- compiler/rustc_typeck/src/coherence/orphan.rs | 16 +++++----------- .../ui/auto-traits/suspicious-impls-lint.rs | 6 ++++++ .../ui/auto-traits/suspicious-impls-lint.stderr | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index a1bcd141e1063..5dfd444133a37 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -297,17 +297,11 @@ impl<'tcx> TypeVisitor<'tcx> for AreUniqueParamsVisitor { _ => ControlFlow::Break(NotUniqueParam::NotParam(t.into())), } } - fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { - match *r { - ty::ReEarlyBound(p) => { - if self.seen.insert(p.index) { - ControlFlow::CONTINUE - } else { - ControlFlow::Break(NotUniqueParam::DuplicateParam(r.into())) - } - } - _ => ControlFlow::Break(NotUniqueParam::NotParam(r.into())), - } + fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow { + // We don't drop candidates during candidate assembly because of region + // constraints, so the behavior for impls only constrained by regions + // will not change. + ControlFlow::CONTINUE } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { match c.val() { diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.rs b/src/test/ui/auto-traits/suspicious-impls-lint.rs index 1574a7e02e97f..7712e84f4a243 100644 --- a/src/test/ui/auto-traits/suspicious-impls-lint.rs +++ b/src/test/ui/auto-traits/suspicious-impls-lint.rs @@ -41,4 +41,10 @@ unsafe impl Send for WithPhantomDataSend<*const T, i8> {} //~^ ERROR //~| WARNING this will change its meaning +pub struct WithLifetime<'a, T>(&'a (), T); +unsafe impl Send for WithLifetime<'static, T> {} // ok +unsafe impl Sync for WithLifetime<'static, Vec> {} +//~^ ERROR +//~| WARNING this will change its meaning + fn main() {} diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.stderr b/src/test/ui/auto-traits/suspicious-impls-lint.stderr index 084bfef49c029..e299e5369fe03 100644 --- a/src/test/ui/auto-traits/suspicious-impls-lint.stderr +++ b/src/test/ui/auto-traits/suspicious-impls-lint.stderr @@ -63,5 +63,20 @@ LL | pub struct WithPhantomDataSend(PhantomData, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: `*const T` is not a generic parameter -error: aborting due to 4 previous errors +error: cross-crate traits with a default impl, like `Sync`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:46:1 + | +LL | unsafe impl Sync for WithLifetime<'static, Vec> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:44:1 + | +LL | pub struct WithLifetime<'a, T>(&'a (), T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `Vec` is not a generic parameter + +error: aborting due to 5 previous errors