From 2fe288fd2974a781991f6050cdc13bd39e97563d Mon Sep 17 00:00:00 2001 From: Mu42 Date: Mon, 6 Mar 2023 20:04:33 +0800 Subject: [PATCH 1/4] emit the suspicious_auto_trait_impls for negative impls as well --- .../src/coherence/orphan.rs | 4 -- tests/ui/auto-traits/suspicious-impls-lint.rs | 10 +++ .../auto-traits/suspicious-impls-lint.stderr | 69 +++++++++++++++---- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 1f2de3f21f8d9..47c47de8cedba 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -478,10 +478,6 @@ fn lint_auto_trait_impl<'tcx>( trait_ref: ty::TraitRef<'tcx>, impl_def_id: LocalDefId, ) { - if tcx.impl_polarity(impl_def_id) != ImplPolarity::Positive { - return; - } - assert_eq!(trait_ref.substs.len(), 1); let self_ty = trait_ref.self_ty(); let (self_type_did, substs) = match self_ty.kind() { diff --git a/tests/ui/auto-traits/suspicious-impls-lint.rs b/tests/ui/auto-traits/suspicious-impls-lint.rs index 7712e84f4a243..86ee2fd67039d 100644 --- a/tests/ui/auto-traits/suspicious-impls-lint.rs +++ b/tests/ui/auto-traits/suspicious-impls-lint.rs @@ -1,3 +1,4 @@ +#![feature(negative_impls)] #![deny(suspicious_auto_trait_impls)] use std::marker::PhantomData; @@ -21,6 +22,9 @@ struct ContainsVec(Vec); unsafe impl Send for ContainsVec {} //~^ ERROR //~| WARNING this will change its meaning +impl !Send for ContainsVec {} +//~^ ERROR +//~| WARNING this will change its meaning struct TwoParams(T, U); unsafe impl Send for TwoParams {} // ok @@ -40,11 +44,17 @@ pub struct WithPhantomDataSend(PhantomData, U); unsafe impl Send for WithPhantomDataSend<*const T, i8> {} //~^ ERROR //~| WARNING this will change its meaning +impl !Send for WithPhantomDataSend<*const T, u8> {} +//~^ 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 +impl !Sync for WithLifetime<'static, Option> {} +//~^ ERROR +//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/auto-traits/suspicious-impls-lint.stderr b/tests/ui/auto-traits/suspicious-impls-lint.stderr index 9cd4e79f851eb..d4e7fe636e677 100644 --- a/tests/ui/auto-traits/suspicious-impls-lint.stderr +++ b/tests/ui/auto-traits/suspicious-impls-lint.stderr @@ -1,5 +1,5 @@ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:9:1 + --> $DIR/suspicious-impls-lint.rs:10:1 | LL | unsafe impl Send for MayImplementSendErr<&T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,18 +8,18 @@ LL | unsafe impl Send for MayImplementSendErr<&T> {} = note: for more information, see issue #93367 = note: `&T` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:8:1 + --> $DIR/suspicious-impls-lint.rs:9:1 | LL | struct MayImplementSendErr(T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: the lint level is defined here - --> $DIR/suspicious-impls-lint.rs:1:9 + --> $DIR/suspicious-impls-lint.rs:2:9 | LL | #![deny(suspicious_auto_trait_impls)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:21:1 + --> $DIR/suspicious-impls-lint.rs:22:1 | LL | unsafe impl Send for ContainsVec {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,13 +28,28 @@ LL | unsafe impl Send for ContainsVec {} = note: for more information, see issue #93367 = note: `i32` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:20:1 + --> $DIR/suspicious-impls-lint.rs:21:1 | LL | struct ContainsVec(Vec); | ^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:32:1 + --> $DIR/suspicious-impls-lint.rs:25:1 + | +LL | impl !Send for ContainsVec {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `u32` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:21:1 + | +LL | struct ContainsVec(Vec); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:36:1 | LL | unsafe impl Send for TwoParamsSame {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,13 +58,13 @@ LL | unsafe impl Send for TwoParamsSame {} = note: for more information, see issue #93367 = note: `T` is mentioned multiple times note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:31:1 + --> $DIR/suspicious-impls-lint.rs:35:1 | LL | struct TwoParamsSame(T, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:40:1 + --> $DIR/suspicious-impls-lint.rs:44:1 | LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,13 +73,28 @@ LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} = note: for more information, see issue #93367 = note: `*const T` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:39:1 + --> $DIR/suspicious-impls-lint.rs:43:1 + | +LL | pub struct WithPhantomDataSend(PhantomData, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:47:1 + | +LL | impl !Send for WithPhantomDataSend<*const T, u8> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `*const T` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:43:1 | LL | pub struct WithPhantomDataSend(PhantomData, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:46:1 + --> $DIR/suspicious-impls-lint.rs:53:1 | LL | unsafe impl Sync for WithLifetime<'static, Vec> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,10 +103,25 @@ LL | unsafe impl Sync for WithLifetime<'static, Vec> {} = note: for more information, see issue #93367 = note: `Vec` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:44:1 + --> $DIR/suspicious-impls-lint.rs:51:1 + | +LL | pub struct WithLifetime<'a, T>(&'a (), T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Sync`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:56:1 + | +LL | impl !Sync for WithLifetime<'static, Option> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `Option` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-impls-lint.rs:51:1 | LL | pub struct WithLifetime<'a, T>(&'a (), T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 8 previous errors From 5c0f55d508b49dbea5b5d69a41d998a00e7d95d2 Mon Sep 17 00:00:00 2001 From: Mu42 Date: Mon, 6 Mar 2023 21:05:23 +0800 Subject: [PATCH 2/4] Moves the negative impls into a separate test file --- tests/ui/auto-traits/suspicious-impls-lint.rs | 10 --- .../auto-traits/suspicious-impls-lint.stderr | 69 +++------------- .../suspicious-negative-impls-lint.rs | 21 +++++ .../suspicious-negative-impls-lint.stderr | 82 +++++++++++++++++++ 4 files changed, 115 insertions(+), 67 deletions(-) create mode 100644 tests/ui/auto-traits/suspicious-negative-impls-lint.rs create mode 100644 tests/ui/auto-traits/suspicious-negative-impls-lint.stderr diff --git a/tests/ui/auto-traits/suspicious-impls-lint.rs b/tests/ui/auto-traits/suspicious-impls-lint.rs index 86ee2fd67039d..7712e84f4a243 100644 --- a/tests/ui/auto-traits/suspicious-impls-lint.rs +++ b/tests/ui/auto-traits/suspicious-impls-lint.rs @@ -1,4 +1,3 @@ -#![feature(negative_impls)] #![deny(suspicious_auto_trait_impls)] use std::marker::PhantomData; @@ -22,9 +21,6 @@ struct ContainsVec(Vec); unsafe impl Send for ContainsVec {} //~^ ERROR //~| WARNING this will change its meaning -impl !Send for ContainsVec {} -//~^ ERROR -//~| WARNING this will change its meaning struct TwoParams(T, U); unsafe impl Send for TwoParams {} // ok @@ -44,17 +40,11 @@ pub struct WithPhantomDataSend(PhantomData, U); unsafe impl Send for WithPhantomDataSend<*const T, i8> {} //~^ ERROR //~| WARNING this will change its meaning -impl !Send for WithPhantomDataSend<*const T, u8> {} -//~^ 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 -impl !Sync for WithLifetime<'static, Option> {} -//~^ ERROR -//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/auto-traits/suspicious-impls-lint.stderr b/tests/ui/auto-traits/suspicious-impls-lint.stderr index d4e7fe636e677..9cd4e79f851eb 100644 --- a/tests/ui/auto-traits/suspicious-impls-lint.stderr +++ b/tests/ui/auto-traits/suspicious-impls-lint.stderr @@ -1,5 +1,5 @@ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:10:1 + --> $DIR/suspicious-impls-lint.rs:9:1 | LL | unsafe impl Send for MayImplementSendErr<&T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,18 +8,18 @@ LL | unsafe impl Send for MayImplementSendErr<&T> {} = note: for more information, see issue #93367 = note: `&T` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:9:1 + --> $DIR/suspicious-impls-lint.rs:8:1 | LL | struct MayImplementSendErr(T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: the lint level is defined here - --> $DIR/suspicious-impls-lint.rs:2:9 + --> $DIR/suspicious-impls-lint.rs:1:9 | LL | #![deny(suspicious_auto_trait_impls)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:22:1 + --> $DIR/suspicious-impls-lint.rs:21:1 | LL | unsafe impl Send for ContainsVec {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,28 +28,13 @@ LL | unsafe impl Send for ContainsVec {} = note: for more information, see issue #93367 = note: `i32` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:21:1 + --> $DIR/suspicious-impls-lint.rs:20:1 | LL | struct ContainsVec(Vec); | ^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:25:1 - | -LL | impl !Send for ContainsVec {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `u32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:21:1 - | -LL | struct ContainsVec(Vec); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:36:1 + --> $DIR/suspicious-impls-lint.rs:32:1 | LL | unsafe impl Send for TwoParamsSame {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,13 +43,13 @@ LL | unsafe impl Send for TwoParamsSame {} = note: for more information, see issue #93367 = note: `T` is mentioned multiple times note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:35:1 + --> $DIR/suspicious-impls-lint.rs:31:1 | LL | struct TwoParamsSame(T, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:44:1 + --> $DIR/suspicious-impls-lint.rs:40:1 | LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,28 +58,13 @@ LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} = note: for more information, see issue #93367 = note: `*const T` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:43:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:47:1 - | -LL | impl !Send for WithPhantomDataSend<*const T, u8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:43:1 + --> $DIR/suspicious-impls-lint.rs:39:1 | LL | pub struct WithPhantomDataSend(PhantomData, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:53:1 + --> $DIR/suspicious-impls-lint.rs:46:1 | LL | unsafe impl Sync for WithLifetime<'static, Vec> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -103,25 +73,10 @@ LL | unsafe impl Sync for WithLifetime<'static, Vec> {} = note: for more information, see issue #93367 = note: `Vec` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:51:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:56:1 - | -LL | impl !Sync for WithLifetime<'static, Option> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `Option` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:51:1 + --> $DIR/suspicious-impls-lint.rs:44:1 | LL | pub struct WithLifetime<'a, T>(&'a (), T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 5 previous errors diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.rs b/tests/ui/auto-traits/suspicious-negative-impls-lint.rs new file mode 100644 index 0000000000000..34842e5944b46 --- /dev/null +++ b/tests/ui/auto-traits/suspicious-negative-impls-lint.rs @@ -0,0 +1,21 @@ +#![feature(negative_impls)] +#![deny(suspicious_auto_trait_impls)] + +use std::marker::PhantomData; + +struct ContainsVec(Vec); +impl !Send for ContainsVec {} +//~^ ERROR +//~| WARNING this will change its meaning + +pub struct WithPhantomDataSend(PhantomData, U); +impl !Send for WithPhantomDataSend<*const T, u8> {} +//~^ ERROR +//~| WARNING this will change its meaning + +pub struct WithLifetime<'a, T>(&'a (), T); +impl !Sync for WithLifetime<'static, Option> {} +//~^ ERROR +//~| WARNING this will change its meaning + +fn main() {} diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr new file mode 100644 index 0000000000000..14785b98a17dd --- /dev/null +++ b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr @@ -0,0 +1,82 @@ +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-negative-impls-lint.rs:7:1 + | +LL | impl !Send for ContainsVec {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `u32` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-negative-impls-lint.rs:6:1 + | +LL | struct ContainsVec(Vec); + | ^^^^^^^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/suspicious-negative-impls-lint.rs:2:9 + | +LL | #![deny(suspicious_auto_trait_impls)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-negative-impls-lint.rs:12:1 + | +LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `*const T` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-negative-impls-lint.rs:11:1 + | +LL | pub struct WithPhantomDataSend(PhantomData, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-negative-impls-lint.rs:15:1 + | +LL | impl !Send for WithPhantomDataSend<*const T, u8> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `*const T` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-negative-impls-lint.rs:11:1 + | +LL | pub struct WithPhantomDataSend(PhantomData, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Sync`, should not be specialized + --> $DIR/suspicious-negative-impls-lint.rs:21: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: `Vec` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-negative-impls-lint.rs:19:1 + | +LL | pub struct WithLifetime<'a, T>(&'a (), T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Sync`, should not be specialized + --> $DIR/suspicious-negative-impls-lint.rs:24:1 + | +LL | impl !Sync for WithLifetime<'static, Option> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `Option` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/suspicious-negative-impls-lint.rs:19:1 + | +LL | pub struct WithLifetime<'a, T>(&'a (), T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + From 23ba4ceb9edbd3ab962c91f5852367b4529ad8a7 Mon Sep 17 00:00:00 2001 From: Mu42 Date: Mon, 6 Mar 2023 21:05:35 +0800 Subject: [PATCH 3/4] Bless the remaining ui tests --- ...oherence-conflicting-negative-trait-impl.rs | 2 ++ ...ence-conflicting-negative-trait-impl.stderr | 18 +++++++++++++++++- tests/ui/coherence/coherence-orphan.rs | 5 +++-- tests/ui/coherence/coherence-orphan.stderr | 15 ++++++++++++++- tests/ui/issues/issue-106755.rs | 2 ++ tests/ui/issues/issue-106755.stderr | 18 +++++++++++++++++- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs index 24b878927530c..76a57936e6985 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs @@ -13,5 +13,7 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} +//~^ WARNING +//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr index 2463f38a92251..020199da99141 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr @@ -16,7 +16,23 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -error: aborting due to 2 previous errors +warning: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/coherence-conflicting-negative-trait-impl.rs:15:1 + | +LL | impl !Send for TestType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `i32` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/coherence-conflicting-negative-trait-impl.rs:7:1 + | +LL | struct TestType(::std::marker::PhantomData); + | ^^^^^^^^^^^^^^^^^^ + = note: `#[warn(suspicious_auto_trait_impls)]` on by default + +error: aborting due to 2 previous errors; 1 warning emitted Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/coherence/coherence-orphan.rs b/tests/ui/coherence/coherence-orphan.rs index 3beac04c7e829..bed782203af50 100644 --- a/tests/ui/coherence/coherence-orphan.rs +++ b/tests/ui/coherence/coherence-orphan.rs @@ -14,7 +14,8 @@ impl TheTrait for isize { } impl TheTrait for TheType { } -impl !Send for Vec { } -//~^ ERROR E0117 +impl !Send for Vec { } //~ ERROR E0117 +//~^ WARNING +//~| WARNING this will change its meaning fn main() { } diff --git a/tests/ui/coherence/coherence-orphan.stderr b/tests/ui/coherence/coherence-orphan.stderr index 01f166a21f768..9ec1d0dc32aa4 100644 --- a/tests/ui/coherence/coherence-orphan.stderr +++ b/tests/ui/coherence/coherence-orphan.stderr @@ -21,6 +21,19 @@ LL | impl !Send for Vec { } | = note: define and implement a trait or new type instead -error: aborting due to 2 previous errors +warning: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/coherence-orphan.rs:17:1 + | +LL | impl !Send for Vec { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `isize` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL + = note: `#[warn(suspicious_auto_trait_impls)]` on by default + +error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0117`. diff --git a/tests/ui/issues/issue-106755.rs b/tests/ui/issues/issue-106755.rs index 46ece725fb7c1..5eabc3bfb1384 100644 --- a/tests/ui/issues/issue-106755.rs +++ b/tests/ui/issues/issue-106755.rs @@ -15,5 +15,7 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} +//~^ WARNING +//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/issues/issue-106755.stderr b/tests/ui/issues/issue-106755.stderr index 543970340620d..6b3a8427e7738 100644 --- a/tests/ui/issues/issue-106755.stderr +++ b/tests/ui/issues/issue-106755.stderr @@ -16,7 +16,23 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -error: aborting due to 2 previous errors +warning: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/issue-106755.rs:17:1 + | +LL | impl !Send for TestType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 + = note: `i32` is not a generic parameter +note: try using the same sequence of generic parameters as the struct definition + --> $DIR/issue-106755.rs:9:1 + | +LL | struct TestType(::std::marker::PhantomData); + | ^^^^^^^^^^^^^^^^^^ + = note: `#[warn(suspicious_auto_trait_impls)]` on by default + +error: aborting due to 2 previous errors; 1 warning emitted Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. From 717f93cec57606e83b20c26bedad1e0cdf5154c2 Mon Sep 17 00:00:00 2001 From: Mu42 Date: Mon, 6 Mar 2023 21:25:43 +0800 Subject: [PATCH 4/4] Bless the suspicious-negative-impls-lint.rs --- .../suspicious-negative-impls-lint.stderr | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr index 14785b98a17dd..ee03ea1255757 100644 --- a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr +++ b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr @@ -21,21 +21,6 @@ LL | #![deny(suspicious_auto_trait_impls)] error: cross-crate traits with a default impl, like `Send`, should not be specialized --> $DIR/suspicious-negative-impls-lint.rs:12:1 | -LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:11:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:15:1 - | LL | impl !Send for WithPhantomDataSend<*const T, u8> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -49,22 +34,7 @@ LL | pub struct WithPhantomDataSend(PhantomData, U); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:21: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: `Vec` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:19:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:24:1 + --> $DIR/suspicious-negative-impls-lint.rs:17:1 | LL | impl !Sync for WithLifetime<'static, Option> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,10 +43,10 @@ LL | impl !Sync for WithLifetime<'static, Option> {} = note: for more information, see issue #93367 = note: `Option` is not a generic parameter note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:19:1 + --> $DIR/suspicious-negative-impls-lint.rs:16:1 | LL | pub struct WithLifetime<'a, T>(&'a (), T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors