diff options
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/orphan.rs | 4 | ||||
| -rw-r--r-- | tests/ui/auto-traits/suspicious-impls-lint.rs | 10 | ||||
| -rw-r--r-- | tests/ui/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 1f2de3f21f8..47c47de8ced 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 7712e84f4a2..86ee2fd6703 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<T>(Vec<T>); unsafe impl Send for ContainsVec<i32> {} //~^ ERROR //~| WARNING this will change its meaning +impl !Send for ContainsVec<u32> {} +//~^ ERROR +//~| WARNING this will change its meaning struct TwoParams<T, U>(T, U); unsafe impl<T: Send, U: Send> Send for TwoParams<T, U> {} // ok @@ -40,11 +44,17 @@ pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U); unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {} //~^ ERROR //~| WARNING this will change its meaning +impl<T> !Send for WithPhantomDataSend<*const T, u8> {} +//~^ ERROR +//~| WARNING this will change its meaning pub struct WithLifetime<'a, T>(&'a (), T); unsafe impl<T> Send for WithLifetime<'static, T> {} // ok unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {} //~^ ERROR //~| WARNING this will change its meaning +impl<T> !Sync for WithLifetime<'static, Option<T>> {} +//~^ 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 9cd4e79f851..d4e7fe636e6 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<T: Send> Send for MayImplementSendErr<&T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,18 +8,18 @@ LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {} = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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>(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<i32> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,13 +28,28 @@ LL | unsafe impl Send for ContainsVec<i32> {} = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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<T>(Vec<T>); | ^^^^^^^^^^^^^^^^^^^^^ 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<u32> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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<T>(Vec<T>); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:36:1 | LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -43,13 +58,13 @@ LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {} = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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>(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<T> Send for WithPhantomDataSend<*const T, i8> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,13 +73,28 @@ LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {} = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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<T, U>(PhantomData<T>, U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: cross-crate traits with a default impl, like `Send`, should not be specialized + --> $DIR/suspicious-impls-lint.rs:47:1 + | +LL | impl<T> !Send for WithPhantomDataSend<*const T, u8> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/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<T, U>(PhantomData<T>, 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<T> Sync for WithLifetime<'static, Vec<T>> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,10 +103,25 @@ LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {} = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367> = note: `Vec<T>` 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<T> !Sync for WithLifetime<'static, Option<T>> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this will change its meaning in a future release! + = note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367> + = note: `Option<T>` 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 |
