Skip to content

Commit 2fe288f

Browse files
committed
emit the suspicious_auto_trait_impls for negative impls as well
1 parent 8c0f83d commit 2fe288f

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,6 @@ fn lint_auto_trait_impl<'tcx>(
478478
trait_ref: ty::TraitRef<'tcx>,
479479
impl_def_id: LocalDefId,
480480
) {
481-
if tcx.impl_polarity(impl_def_id) != ImplPolarity::Positive {
482-
return;
483-
}
484-
485481
assert_eq!(trait_ref.substs.len(), 1);
486482
let self_ty = trait_ref.self_ty();
487483
let (self_type_did, substs) = match self_ty.kind() {

tests/ui/auto-traits/suspicious-impls-lint.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(negative_impls)]
12
#![deny(suspicious_auto_trait_impls)]
23

34
use std::marker::PhantomData;
@@ -21,6 +22,9 @@ struct ContainsVec<T>(Vec<T>);
2122
unsafe impl Send for ContainsVec<i32> {}
2223
//~^ ERROR
2324
//~| WARNING this will change its meaning
25+
impl !Send for ContainsVec<u32> {}
26+
//~^ ERROR
27+
//~| WARNING this will change its meaning
2428

2529
struct TwoParams<T, U>(T, U);
2630
unsafe impl<T: Send, U: Send> Send for TwoParams<T, U> {} // ok
@@ -40,11 +44,17 @@ pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
4044
unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
4145
//~^ ERROR
4246
//~| WARNING this will change its meaning
47+
impl<T> !Send for WithPhantomDataSend<*const T, u8> {}
48+
//~^ ERROR
49+
//~| WARNING this will change its meaning
4350

4451
pub struct WithLifetime<'a, T>(&'a (), T);
4552
unsafe impl<T> Send for WithLifetime<'static, T> {} // ok
4653
unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
4754
//~^ ERROR
4855
//~| WARNING this will change its meaning
56+
impl<T> !Sync for WithLifetime<'static, Option<T>> {}
57+
//~^ ERROR
58+
//~| WARNING this will change its meaning
4959

5060
fn main() {}
Lines changed: 57 additions & 12 deletions
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:9:1
2+
--> $DIR/suspicious-impls-lint.rs:10:1
33
|
44
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,18 +8,18 @@ LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
88
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
99
= note: `&T` is not a generic parameter
1010
note: try using the same sequence of generic parameters as the struct definition
11-
--> $DIR/suspicious-impls-lint.rs:8:1
11+
--> $DIR/suspicious-impls-lint.rs:9:1
1212
|
1313
LL | struct MayImplementSendErr<T>(T);
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
note: the lint level is defined here
16-
--> $DIR/suspicious-impls-lint.rs:1:9
16+
--> $DIR/suspicious-impls-lint.rs:2:9
1717
|
1818
LL | #![deny(suspicious_auto_trait_impls)]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

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

3636
error: cross-crate traits with a default impl, like `Send`, should not be specialized
37-
--> $DIR/suspicious-impls-lint.rs:32:1
37+
--> $DIR/suspicious-impls-lint.rs:25:1
38+
|
39+
LL | impl !Send for ContainsVec<u32> {}
40+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
|
42+
= warning: this will change its meaning in a future release!
43+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
44+
= note: `u32` is not a generic parameter
45+
note: try using the same sequence of generic parameters as the struct definition
46+
--> $DIR/suspicious-impls-lint.rs:21:1
47+
|
48+
LL | struct ContainsVec<T>(Vec<T>);
49+
| ^^^^^^^^^^^^^^^^^^^^^
50+
51+
error: cross-crate traits with a default impl, like `Send`, should not be specialized
52+
--> $DIR/suspicious-impls-lint.rs:36:1
3853
|
3954
LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
4055
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,13 +58,13 @@ LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
4358
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
4459
= note: `T` is mentioned multiple times
4560
note: try using the same sequence of generic parameters as the struct definition
46-
--> $DIR/suspicious-impls-lint.rs:31:1
61+
--> $DIR/suspicious-impls-lint.rs:35:1
4762
|
4863
LL | struct TwoParamsSame<T, U>(T, U);
4964
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5065

5166
error: cross-crate traits with a default impl, like `Send`, should not be specialized
52-
--> $DIR/suspicious-impls-lint.rs:40:1
67+
--> $DIR/suspicious-impls-lint.rs:44:1
5368
|
5469
LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
5570
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -58,13 +73,28 @@ LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
5873
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
5974
= note: `*const T` is not a generic parameter
6075
note: try using the same sequence of generic parameters as the struct definition
61-
--> $DIR/suspicious-impls-lint.rs:39:1
76+
--> $DIR/suspicious-impls-lint.rs:43:1
77+
|
78+
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
81+
error: cross-crate traits with a default impl, like `Send`, should not be specialized
82+
--> $DIR/suspicious-impls-lint.rs:47:1
83+
|
84+
LL | impl<T> !Send for WithPhantomDataSend<*const T, u8> {}
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
|
87+
= warning: this will change its meaning in a future release!
88+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
89+
= note: `*const T` is not a generic parameter
90+
note: try using the same sequence of generic parameters as the struct definition
91+
--> $DIR/suspicious-impls-lint.rs:43:1
6292
|
6393
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
6494
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6595

6696
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
67-
--> $DIR/suspicious-impls-lint.rs:46:1
97+
--> $DIR/suspicious-impls-lint.rs:53:1
6898
|
6999
LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
70100
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,10 +103,25 @@ LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
73103
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
74104
= note: `Vec<T>` is not a generic parameter
75105
note: try using the same sequence of generic parameters as the struct definition
76-
--> $DIR/suspicious-impls-lint.rs:44:1
106+
--> $DIR/suspicious-impls-lint.rs:51:1
107+
|
108+
LL | pub struct WithLifetime<'a, T>(&'a (), T);
109+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
111+
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
112+
--> $DIR/suspicious-impls-lint.rs:56:1
113+
|
114+
LL | impl<T> !Sync for WithLifetime<'static, Option<T>> {}
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116+
|
117+
= warning: this will change its meaning in a future release!
118+
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
119+
= note: `Option<T>` is not a generic parameter
120+
note: try using the same sequence of generic parameters as the struct definition
121+
--> $DIR/suspicious-impls-lint.rs:51:1
77122
|
78123
LL | pub struct WithLifetime<'a, T>(&'a (), T);
79124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80125

81-
error: aborting due to 5 previous errors
126+
error: aborting due to 8 previous errors
82127

0 commit comments

Comments
 (0)