Skip to content

Commit 2c801e8

Browse files
authored
Rollup merge of #94315 - lcnr:auto-trait-lint-update, r=oli-obk
update auto trait lint for `PhantomData` cc #93367 (comment)
2 parents b70d763 + 70018c1 commit 2c801e8

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

compiler/rustc_typeck/src/coherence/orphan.rs

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty:
439439
}
440440

441441
match t.kind() {
442+
ty::Adt(def, substs) if def.is_phantom_data() => substs.super_visit_with(self),
442443
ty::Adt(def, substs) => {
443444
// @lcnr: This is the only place where cycles can happen. We avoid this
444445
// by only visiting each `DefId` once.

src/test/ui/auto-traits/suspicious-impls-lint.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(suspicious_auto_trait_impls)]
22

3+
use std::marker::PhantomData;
4+
35
struct MayImplementSendOk<T>(T);
46
unsafe impl<T: Send> Send for MayImplementSendOk<T> {} // ok
57

@@ -31,4 +33,12 @@ unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
3133
//~^ ERROR
3234
//~| WARNING this will change its meaning
3335

36+
pub struct WithPhantomDataNonSend<T, U>(PhantomData<*const T>, U);
37+
unsafe impl<T> Send for WithPhantomDataNonSend<T, i8> {} // ok
38+
39+
pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
40+
unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
41+
//~^ ERROR
42+
//~| WARNING this will change its meaning
43+
3444
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: cross-crate traits with a default impl, like `Send`, should not be specialized
2-
--> $DIR/suspicious-impls-lint.rs:7:1
2+
--> $DIR/suspicious-impls-lint.rs:9:1
33
|
44
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,41 +12,56 @@ LL | #![deny(suspicious_auto_trait_impls)]
1212
= warning: this will change its meaning in a future release!
1313
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
1414
note: try using the same sequence of generic parameters as the struct definition
15-
--> $DIR/suspicious-impls-lint.rs:6:1
15+
--> $DIR/suspicious-impls-lint.rs:8:1
1616
|
1717
LL | struct MayImplementSendErr<T>(T);
1818
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919
= note: `&T` is not a generic parameter
2020

2121
error: cross-crate traits with a default impl, like `Send`, should not be specialized
22-
--> $DIR/suspicious-impls-lint.rs:19:1
22+
--> $DIR/suspicious-impls-lint.rs:21:1
2323
|
2424
LL | unsafe impl Send for ContainsVec<i32> {}
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
|
2727
= warning: this will change its meaning in a future release!
2828
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
2929
note: try using the same sequence of generic parameters as the struct definition
30-
--> $DIR/suspicious-impls-lint.rs:18:1
30+
--> $DIR/suspicious-impls-lint.rs:20:1
3131
|
3232
LL | struct ContainsVec<T>(Vec<T>);
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
= note: `i32` is not a generic parameter
3535

3636
error: cross-crate traits with a default impl, like `Send`, should not be specialized
37-
--> $DIR/suspicious-impls-lint.rs:30:1
37+
--> $DIR/suspicious-impls-lint.rs:32:1
3838
|
3939
LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4141
|
4242
= warning: this will change its meaning in a future release!
4343
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
4444
note: try using the same sequence of generic parameters as the struct definition
45-
--> $DIR/suspicious-impls-lint.rs:29:1
45+
--> $DIR/suspicious-impls-lint.rs:31:1
4646
|
4747
LL | struct TwoParamsSame<T, U>(T, U);
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949
= note: `T` is mentioned multiple times
5050

51-
error: aborting due to 3 previous errors
51+
error: cross-crate traits with a default impl, like `Send`, should not be specialized
52+
--> $DIR/suspicious-impls-lint.rs:40:1
53+
|
54+
LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
= warning: this will change its meaning in a future release!
58+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
59+
note: try using the same sequence of generic parameters as the struct definition
60+
--> $DIR/suspicious-impls-lint.rs:39:1
61+
|
62+
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64+
= note: `*const T` is not a generic parameter
65+
66+
error: aborting due to 4 previous errors
5267

0 commit comments

Comments
 (0)