diff options
Diffstat (limited to 'tests/ui/auto-traits/suspicious-impls-lint.rs')
-rw-r--r-- | tests/ui/auto-traits/suspicious-impls-lint.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/auto-traits/suspicious-impls-lint.rs b/tests/ui/auto-traits/suspicious-impls-lint.rs new file mode 100644 index 000000000..7712e84f4 --- /dev/null +++ b/tests/ui/auto-traits/suspicious-impls-lint.rs @@ -0,0 +1,50 @@ +#![deny(suspicious_auto_trait_impls)] + +use std::marker::PhantomData; + +struct MayImplementSendOk<T>(T); +unsafe impl<T: Send> Send for MayImplementSendOk<T> {} // ok + +struct MayImplementSendErr<T>(T); +unsafe impl<T: Send> Send for MayImplementSendErr<&T> {} +//~^ ERROR +//~| WARNING this will change its meaning + +struct ContainsNonSendDirect<T>(*const T); +unsafe impl<T: Send> Send for ContainsNonSendDirect<&T> {} // ok + +struct ContainsPtr<T>(*const T); +struct ContainsIndirectNonSend<T>(ContainsPtr<T>); +unsafe impl<T: Send> Send for ContainsIndirectNonSend<&T> {} // ok + +struct ContainsVec<T>(Vec<T>); +unsafe impl Send for ContainsVec<i32> {} +//~^ 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 + +struct TwoParamsFlipped<T, U>(T, U); +unsafe impl<T: Send, U: Send> Send for TwoParamsFlipped<U, T> {} // ok + +struct TwoParamsSame<T, U>(T, U); +unsafe impl<T: Send> Send for TwoParamsSame<T, T> {} +//~^ ERROR +//~| WARNING this will change its meaning + +pub struct WithPhantomDataNonSend<T, U>(PhantomData<*const T>, U); +unsafe impl<T> Send for WithPhantomDataNonSend<T, i8> {} // ok + +pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U); +unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {} +//~^ 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 + +fn main() {} |