Skip to content

Commit b21d3ce

Browse files
committed
Remove suspicious auto trait lint
1 parent 9584f78 commit b21d3ce

20 files changed

+167
-186
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
//! crate or pertains to a type defined in this crate.
33
44
use rustc_data_structures::fx::FxHashSet;
5-
use rustc_errors::{DelayDm, ErrorGuaranteed};
5+
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
66
use rustc_hir as hir;
77
use rustc_middle::ty::util::CheckRegions;
88
use rustc_middle::ty::GenericArgs;
99
use rustc_middle::ty::{
1010
self, AliasKind, ImplPolarity, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1111
TypeVisitor,
1212
};
13-
use rustc_session::lint;
1413
use rustc_span::def_id::{DefId, LocalDefId};
1514
use rustc_span::Span;
1615
use rustc_trait_selection::traits;
@@ -496,36 +495,36 @@ fn lint_auto_trait_impl<'tcx>(
496495
return;
497496
}
498497

499-
tcx.node_span_lint(
500-
lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS,
501-
tcx.local_def_id_to_hir_id(impl_def_id),
502-
tcx.def_span(impl_def_id),
503-
DelayDm(|| {
504-
format!(
505-
"cross-crate traits with a default impl, like `{}`, \
498+
let msg = format!(
499+
"cross-crate traits with a default impl, like `{}`, \
506500
should not be specialized",
507-
tcx.def_path_str(trait_ref.def_id),
508-
)
509-
}),
510-
|lint| {
511-
let item_span = tcx.def_span(self_type_did);
512-
let self_descr = tcx.def_descr(self_type_did);
513-
match arg {
514-
ty::util::NotUniqueParam::DuplicateParam(arg) => {
515-
lint.note(format!("`{arg}` is mentioned multiple times"));
516-
}
517-
ty::util::NotUniqueParam::NotParam(arg) => {
518-
lint.note(format!("`{arg}` is not a generic parameter"));
519-
}
520-
}
521-
lint.span_note(
522-
item_span,
523-
format!(
524-
"try using the same sequence of generic parameters as the {self_descr} definition",
525-
),
526-
);
527-
},
501+
tcx.def_path_str(trait_ref.def_id),
528502
);
503+
let mut err: DiagnosticBuilder<'_, ()> =
504+
DiagnosticBuilder::new(tcx.sess.dcx(), rustc_errors::Level::Error, msg);
505+
506+
let impl_span = tcx.def_span(impl_def_id);
507+
err.span(impl_span);
508+
509+
match arg {
510+
ty::util::NotUniqueParam::DuplicateParam(arg) => {
511+
err.note(format!("`{arg}` is mentioned multiple times"));
512+
}
513+
ty::util::NotUniqueParam::NotParam(arg) => {
514+
err.note(format!("`{arg}` is not a generic parameter"));
515+
}
516+
}
517+
518+
let self_span = tcx.def_span(self_type_did);
519+
let self_descr = tcx.def_descr(self_type_did);
520+
err.span_note(
521+
self_span,
522+
format!(
523+
"try using the same sequence of generic parameters as the {self_descr} definition",
524+
),
525+
);
526+
527+
err.emit();
529528
}
530529

531530
fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: Ty<'tcx>) -> bool {

compiler/rustc_lint_defs/src/builtin.rs

-35
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ declare_lint_pass! {
9090
SOFT_UNSTABLE,
9191
STABLE_FEATURES,
9292
STATIC_MUT_REF,
93-
SUSPICIOUS_AUTO_TRAIT_IMPLS,
9493
TEST_UNSTABLE_LINT,
9594
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
9695
TRIVIAL_CASTS,
@@ -4032,40 +4031,6 @@ declare_lint! {
40324031
"duplicated attribute"
40334032
}
40344033

4035-
declare_lint! {
4036-
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
4037-
/// implementations of auto traits.
4038-
///
4039-
/// ### Example
4040-
///
4041-
/// ```rust
4042-
/// struct Foo<T>(T);
4043-
///
4044-
/// unsafe impl<T> Send for Foo<*const T> {}
4045-
/// ```
4046-
///
4047-
/// {{produces}}
4048-
///
4049-
/// ### Explanation
4050-
///
4051-
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
4052-
/// in two different ways: either by writing an explicit impl or if
4053-
/// all fields of the type implement that auto trait.
4054-
///
4055-
/// The compiler disables the automatic implementation if an explicit one
4056-
/// exists for given type constructor. The exact rules governing this
4057-
/// were previously unsound, quite subtle, and have been recently modified.
4058-
/// This change caused the automatic implementation to be disabled in more
4059-
/// cases, potentially breaking some code.
4060-
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
4061-
Warn,
4062-
"the rules governing auto traits have recently changed resulting in potential breakage",
4063-
@future_incompatible = FutureIncompatibleInfo {
4064-
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
4065-
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
4066-
};
4067-
}
4068-
40694034
declare_lint! {
40704035
/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
40714036
/// in an associated type.

tests/ui/auto-traits/issue-117789.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(suspicious_auto_trait_impls)]
2-
31
auto trait Trait<P> {} //~ ERROR auto traits cannot have generic parameters
42
//~^ ERROR auto traits are experimental and possibly buggy
53
impl<P> Trait<P> for () {}

tests/ui/auto-traits/issue-117789.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0567]: auto traits cannot have generic parameters
2-
--> $DIR/issue-117789.rs:3:17
2+
--> $DIR/issue-117789.rs:1:17
33
|
44
LL | auto trait Trait<P> {}
55
| -----^^^ help: remove the parameters
66
| |
77
| auto trait cannot have generic parameters
88

99
error[E0658]: auto traits are experimental and possibly buggy
10-
--> $DIR/issue-117789.rs:3:1
10+
--> $DIR/issue-117789.rs:1:1
1111
|
1212
LL | auto trait Trait<P> {}
1313
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/auto-traits/issue-83857-ub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(suspicious_auto_trait_impls)]
21
// Tests that we don't incorrectly allow overlap between a builtin auto trait
32
// impl and a user written one. See #83857 for more details
43

@@ -8,6 +7,7 @@ struct Foo<T, U>(Always<T, U>);
87

98
trait False {}
109
unsafe impl<U: False> Send for Foo<u32, U> {}
10+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
1111

1212
trait WithAssoc {
1313
type Output;

tests/ui/auto-traits/issue-83857-ub.stderr

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
error: cross-crate traits with a default impl, like `Send`, should not be specialized
2+
--> $DIR/issue-83857-ub.rs:9:1
3+
|
4+
LL | unsafe impl<U: False> Send for Foo<u32, U> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `u32` is not a generic parameter
8+
note: try using the same sequence of generic parameters as the struct definition
9+
--> $DIR/issue-83857-ub.rs:6:1
10+
|
11+
LL | struct Foo<T, U>(Always<T, U>);
12+
| ^^^^^^^^^^^^^^^^
13+
114
error[E0277]: `Foo<T, U>` cannot be sent between threads safely
215
--> $DIR/issue-83857-ub.rs:22:38
316
|
@@ -17,6 +30,6 @@ help: consider introducing a `where` clause, but there might be an alternative b
1730
LL | fn generic<T, U>(v: Foo<T, U>, f: fn(<Foo<T, U> as WithAssoc>::Output) -> i32) where Foo<T, U>: Send {
1831
| +++++++++++++++++++++
1932

20-
error: aborting due to 1 previous error
33+
error: aborting due to 2 previous errors
2134

2235
For more information about this error, try `rustc --explain E0277`.
+5-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
#![deny(suspicious_auto_trait_impls)]
2-
31
use std::marker::PhantomData;
42

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

86
struct MayImplementSendErr<T>(T);
97
unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
10-
//~^ ERROR
11-
//~| WARNING this will change its meaning
8+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
129

1310
struct ContainsNonSendDirect<T>(*const T);
1411
unsafe impl<T: Send> Send for ContainsNonSendDirect<&T> {} // ok
@@ -19,8 +16,7 @@ unsafe impl<T: Send> Send for ContainsIndirectNonSend<&T> {} // ok
1916

2017
struct ContainsVec<T>(Vec<T>);
2118
unsafe impl Send for ContainsVec<i32> {}
22-
//~^ ERROR
23-
//~| WARNING this will change its meaning
19+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
2420

2521
struct TwoParams<T, U>(T, U);
2622
unsafe impl<T: Send, U: Send> Send for TwoParams<T, U> {} // ok
@@ -30,21 +26,18 @@ unsafe impl<T: Send, U: Send> Send for TwoParamsFlipped<U, T> {} // ok
3026

3127
struct TwoParamsSame<T, U>(T, U);
3228
unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
33-
//~^ ERROR
34-
//~| WARNING this will change its meaning
29+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
3530

3631
pub struct WithPhantomDataNonSend<T, U>(PhantomData<*const T>, U);
3732
unsafe impl<T> Send for WithPhantomDataNonSend<T, i8> {} // ok
3833

3934
pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
4035
unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
41-
//~^ ERROR
42-
//~| WARNING this will change its meaning
36+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
4337

4438
pub struct WithLifetime<'a, T>(&'a (), T);
4539
unsafe impl<T> Send for WithLifetime<'static, T> {} // ok
4640
unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
47-
//~^ ERROR
48-
//~| WARNING this will change its meaning
41+
//~^ ERROR cross-crate traits with a default impl, like `Sync`, should not be specialized
4942

5043
fn main() {}

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

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,64 @@
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:7:1
33
|
44
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= warning: this will change its meaning in a future release!
8-
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
97
= note: `&T` is not a generic parameter
108
note: try using the same sequence of generic parameters as the struct definition
11-
--> $DIR/suspicious-impls-lint.rs:8:1
9+
--> $DIR/suspicious-impls-lint.rs:6:1
1210
|
1311
LL | struct MayImplementSendErr<T>(T);
1412
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
note: the lint level is defined here
16-
--> $DIR/suspicious-impls-lint.rs:1:9
17-
|
18-
LL | #![deny(suspicious_auto_trait_impls)]
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2013

2114
error: cross-crate traits with a default impl, like `Send`, should not be specialized
22-
--> $DIR/suspicious-impls-lint.rs:21:1
15+
--> $DIR/suspicious-impls-lint.rs:18:1
2316
|
2417
LL | unsafe impl Send for ContainsVec<i32> {}
2518
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2619
|
27-
= warning: this will change its meaning in a future release!
28-
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
2920
= note: `i32` is not a generic parameter
3021
note: try using the same sequence of generic parameters as the struct definition
31-
--> $DIR/suspicious-impls-lint.rs:20:1
22+
--> $DIR/suspicious-impls-lint.rs:17:1
3223
|
3324
LL | struct ContainsVec<T>(Vec<T>);
3425
| ^^^^^^^^^^^^^^^^^^^^^
3526

3627
error: cross-crate traits with a default impl, like `Send`, should not be specialized
37-
--> $DIR/suspicious-impls-lint.rs:32:1
28+
--> $DIR/suspicious-impls-lint.rs:28:1
3829
|
3930
LL | unsafe impl<T: Send> Send for TwoParamsSame<T, T> {}
4031
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4132
|
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>
4433
= note: `T` is mentioned multiple times
4534
note: try using the same sequence of generic parameters as the struct definition
46-
--> $DIR/suspicious-impls-lint.rs:31:1
35+
--> $DIR/suspicious-impls-lint.rs:27:1
4736
|
4837
LL | struct TwoParamsSame<T, U>(T, U);
4938
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5039

5140
error: cross-crate traits with a default impl, like `Send`, should not be specialized
52-
--> $DIR/suspicious-impls-lint.rs:40:1
41+
--> $DIR/suspicious-impls-lint.rs:35:1
5342
|
5443
LL | unsafe impl<T> Send for WithPhantomDataSend<*const T, i8> {}
5544
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5645
|
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>
5946
= note: `*const T` is not a generic parameter
6047
note: try using the same sequence of generic parameters as the struct definition
61-
--> $DIR/suspicious-impls-lint.rs:39:1
48+
--> $DIR/suspicious-impls-lint.rs:34:1
6249
|
6350
LL | pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
6451
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6552

6653
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
67-
--> $DIR/suspicious-impls-lint.rs:46:1
54+
--> $DIR/suspicious-impls-lint.rs:40:1
6855
|
6956
LL | unsafe impl<T> Sync for WithLifetime<'static, Vec<T>> {}
7057
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7158
|
72-
= warning: this will change its meaning in a future release!
73-
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
7459
= note: `Vec<T>` is not a generic parameter
7560
note: try using the same sequence of generic parameters as the struct definition
76-
--> $DIR/suspicious-impls-lint.rs:44:1
61+
--> $DIR/suspicious-impls-lint.rs:38:1
7762
|
7863
LL | pub struct WithLifetime<'a, T>(&'a (), T);
7964
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
#![feature(negative_impls)]
2-
#![deny(suspicious_auto_trait_impls)]
32

43
use std::marker::PhantomData;
54

65
struct ContainsVec<T>(Vec<T>);
76
impl !Send for ContainsVec<u32> {}
8-
//~^ ERROR
9-
//~| WARNING this will change its meaning
7+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
108

119
pub struct WithPhantomDataSend<T, U>(PhantomData<T>, U);
1210
impl<T> !Send for WithPhantomDataSend<*const T, u8> {}
13-
//~^ ERROR
14-
//~| WARNING this will change its meaning
11+
//~^ ERROR cross-crate traits with a default impl, like `Send`, should not be specialized
1512

1613
pub struct WithLifetime<'a, T>(&'a (), T);
1714
impl<T> !Sync for WithLifetime<'static, Option<T>> {}
18-
//~^ ERROR
19-
//~| WARNING this will change its meaning
15+
//~^ ERROR cross-crate traits with a default impl, like `Sync`, should not be specialized
2016

2117
fn main() {}

0 commit comments

Comments
 (0)