Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update auto trait lint for PhantomData #94315

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
}

match t.kind() {
ty::Adt(def, substs) if def.is_phantom_data() => substs.super_visit_with(self),
ty::Adt(def, substs) => {
// @lcnr: This is the only place where cycles can happen. We avoid this
// by only visiting each `DefId` once.
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/auto-traits/suspicious-impls-lint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(suspicious_auto_trait_impls)]

use std::marker::PhantomData;

struct MayImplementSendOk<T>(T);
unsafe impl<T: Send> Send for MayImplementSendOk<T> {} // ok

Expand Down Expand Up @@ -31,4 +33,12 @@ 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

fn main() {}
29 changes: 22 additions & 7 deletions src/test/ui/auto-traits/suspicious-impls-lint.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: cross-crate traits with a default impl, like `Send`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:7:1
--> $DIR/suspicious-impls-lint.rs:9:1
|
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -12,41 +12,56 @@ LL | #![deny(suspicious_auto_trait_impls)]
= 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: try using the same sequence of generic parameters as the struct definition
--> $DIR/suspicious-impls-lint.rs:6:1
--> $DIR/suspicious-impls-lint.rs:8:1
|
LL | struct MayImplementSendErr<T>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `&T` is not a generic parameter

error: cross-crate traits with a default impl, like `Send`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:19:1
--> $DIR/suspicious-impls-lint.rs:21:1
|
LL | unsafe impl Send for ContainsVec<i32> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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: try using the same sequence of generic parameters as the struct definition
--> $DIR/suspicious-impls-lint.rs:18:1
--> $DIR/suspicious-impls-lint.rs:20:1
|
LL | struct ContainsVec<T>(Vec<T>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `i32` is not a generic parameter

error: cross-crate traits with a default impl, like `Send`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:30:1
--> $DIR/suspicious-impls-lint.rs:32:1
|
LL | unsafe impl<T: Send> Send for TwoParamsSame<T, 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: try using the same sequence of generic parameters as the struct definition
--> $DIR/suspicious-impls-lint.rs:29:1
--> $DIR/suspicious-impls-lint.rs:31:1
|
LL | struct TwoParamsSame<T, U>(T, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `T` is mentioned multiple times

error: aborting due to 3 previous errors
error: cross-crate traits with a default impl, like `Send`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:40:1
|
LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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: try using the same sequence of generic parameters as the struct definition
--> $DIR/suspicious-impls-lint.rs:39:1
|
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `*const T` is not a generic parameter

error: aborting due to 4 previous errors