Skip to content

Commit ac045b0

Browse files
committed
Remove suspicious auto trait lint
1 parent e2a96c7 commit ac045b0

23 files changed

+184
-353
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.

src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![warn(clippy::non_send_fields_in_send_ty)]
2-
#![allow(suspicious_auto_trait_impls)]
32
#![feature(extern_types)]
43

54
use std::cell::UnsafeCell;
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,28 @@
1-
error: some fields in `RingBuffer<T>` are not safe to be sent to another thread
2-
--> $DIR/non_send_fields_in_send_ty.rs:17:1
3-
|
4-
LL | unsafe impl<T> Send for RingBuffer<T> {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
note: it is not safe to send field `data` to another thread
8-
--> $DIR/non_send_fields_in_send_ty.rs:12:5
9-
|
10-
LL | data: Vec<UnsafeCell<T>>,
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^
12-
= help: add bounds on type parameter `T` that satisfy `Vec<UnsafeCell<T>>: Send`
13-
= note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
14-
= help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]`
15-
16-
error: some fields in `MvccRwLock<T>` are not safe to be sent to another thread
17-
--> $DIR/non_send_fields_in_send_ty.rs:26:1
18-
|
19-
LL | unsafe impl<T> Send for MvccRwLock<T> {}
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
|
22-
note: it is not safe to send field `lock` to another thread
23-
--> $DIR/non_send_fields_in_send_ty.rs:23:5
24-
|
25-
LL | lock: Mutex<Box<T>>,
26-
| ^^^^^^^^^^^^^^^^^^^
27-
= help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send`
28-
29-
error: some fields in `ArcGuard<RC, T>` are not safe to be sent to another thread
30-
--> $DIR/non_send_fields_in_send_ty.rs:35:1
31-
|
32-
LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
|
35-
note: it is not safe to send field `head` to another thread
36-
--> $DIR/non_send_fields_in_send_ty.rs:32:5
37-
|
38-
LL | head: Arc<RC>,
39-
| ^^^^^^^^^^^^^
40-
= help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send`
41-
42-
error: some fields in `DeviceHandle<T>` are not safe to be sent to another thread
43-
--> $DIR/non_send_fields_in_send_ty.rs:52:1
44-
|
45-
LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
46-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47-
|
48-
note: it is not safe to send field `context` to another thread
49-
--> $DIR/non_send_fields_in_send_ty.rs:48:5
50-
|
51-
LL | context: T,
52-
| ^^^^^^^^^^
53-
= help: add `T: Send` bound in `Send` impl
54-
55-
error: some fields in `NoGeneric` are not safe to be sent to another thread
56-
--> $DIR/non_send_fields_in_send_ty.rs:60:1
57-
|
58-
LL | unsafe impl Send for NoGeneric {}
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
|
61-
note: it is not safe to send field `rc_is_not_send` to another thread
62-
--> $DIR/non_send_fields_in_send_ty.rs:57:5
63-
|
64-
LL | rc_is_not_send: Rc<String>,
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66-
= help: use a thread-safe type that implements `Send`
67-
68-
error: some fields in `MultiField<T>` are not safe to be sent to another thread
69-
--> $DIR/non_send_fields_in_send_ty.rs:69:1
70-
|
71-
LL | unsafe impl<T> Send for MultiField<T> {}
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73-
|
74-
note: it is not safe to send field `field1` to another thread
75-
--> $DIR/non_send_fields_in_send_ty.rs:64:5
76-
|
77-
LL | field1: T,
78-
| ^^^^^^^^^
79-
= help: add `T: Send` bound in `Send` impl
80-
note: it is not safe to send field `field2` to another thread
81-
--> $DIR/non_send_fields_in_send_ty.rs:65:5
82-
|
83-
LL | field2: T,
84-
| ^^^^^^^^^
85-
= help: add `T: Send` bound in `Send` impl
86-
note: it is not safe to send field `field3` to another thread
87-
--> $DIR/non_send_fields_in_send_ty.rs:66:5
88-
|
89-
LL | field3: T,
90-
| ^^^^^^^^^
91-
= help: add `T: Send` bound in `Send` impl
92-
93-
error: some fields in `MyOption<T>` are not safe to be sent to another thread
94-
--> $DIR/non_send_fields_in_send_ty.rs:77:1
95-
|
96-
LL | unsafe impl<T> Send for MyOption<T> {}
97-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98-
|
99-
note: it is not safe to send field `0` to another thread
100-
--> $DIR/non_send_fields_in_send_ty.rs:73:12
101-
|
102-
LL | MySome(T),
103-
| ^
104-
= help: add `T: Send` bound in `Send` impl
105-
106-
error: some fields in `MultiParam<A, B>` are not safe to be sent to another thread
107-
--> $DIR/non_send_fields_in_send_ty.rs:90:1
108-
|
109-
LL | unsafe impl<A, B> Send for MultiParam<A, B> {}
110-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111-
|
112-
note: it is not safe to send field `vec` to another thread
113-
--> $DIR/non_send_fields_in_send_ty.rs:87:5
114-
|
115-
LL | vec: Vec<(A, B)>,
116-
| ^^^^^^^^^^^^^^^^
117-
= help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send`
118-
119-
error: some fields in `HeuristicTest` are not safe to be sent to another thread
120-
--> $DIR/non_send_fields_in_send_ty.rs:109:1
121-
|
122-
LL | unsafe impl Send for HeuristicTest {}
123-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124-
|
125-
note: it is not safe to send field `field4` to another thread
126-
--> $DIR/non_send_fields_in_send_ty.rs:104:5
127-
|
128-
LL | field4: (*const NonSend, Rc<u8>),
129-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130-
= help: use a thread-safe type that implements `Send`
131-
132-
error: some fields in `AttrTest3<T>` are not safe to be sent to another thread
133-
--> $DIR/non_send_fields_in_send_ty.rs:129:1
134-
|
135-
LL | unsafe impl<T> Send for AttrTest3<T> {}
136-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137-
|
138-
note: it is not safe to send field `0` to another thread
139-
--> $DIR/non_send_fields_in_send_ty.rs:124:11
140-
|
141-
LL | Enum2(T),
142-
| ^
143-
= help: add `T: Send` bound in `Send` impl
144-
145-
error: some fields in `Complex<P, u32>` are not safe to be sent to another thread
146-
--> $DIR/non_send_fields_in_send_ty.rs:138:1
1+
error: cross-crate traits with a default impl, like `std::marker::Send`, should not be specialized
2+
--> $DIR/non_send_fields_in_send_ty.rs:137:1
1473
|
1484
LL | unsafe impl<P> Send for Complex<P, u32> {}
149-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1506
|
151-
note: it is not safe to send field `field1` to another thread
152-
--> $DIR/non_send_fields_in_send_ty.rs:134:5
7+
= note: `u32` is not a generic parameter
8+
note: try using the same sequence of generic parameters as the struct definition
9+
--> $DIR/non_send_fields_in_send_ty.rs:132:1
15310
|
154-
LL | field1: A,
155-
| ^^^^^^^^^
156-
= help: add `P: Send` bound in `Send` impl
11+
LL | pub struct Complex<A, B> {
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^
15713

158-
error: some fields in `Complex<Q, MutexGuard<'static, bool>>` are not safe to be sent to another thread
159-
--> $DIR/non_send_fields_in_send_ty.rs:142:1
14+
error: cross-crate traits with a default impl, like `std::marker::Send`, should not be specialized
15+
--> $DIR/non_send_fields_in_send_ty.rs:141:1
16016
|
16117
LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
162-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16319
|
164-
note: it is not safe to send field `field2` to another thread
165-
--> $DIR/non_send_fields_in_send_ty.rs:135:5
20+
= note: `std::sync::MutexGuard<'static, bool>` is not a generic parameter
21+
note: try using the same sequence of generic parameters as the struct definition
22+
--> $DIR/non_send_fields_in_send_ty.rs:132:1
16623
|
167-
LL | field2: B,
168-
| ^^^^^^^^^
169-
= help: use a thread-safe type that implements `Send`
24+
LL | pub struct Complex<A, B> {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^
17026

171-
error: aborting due to 12 previous errors
27+
error: aborting due to 2 previous errors
17228

src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs

-5
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,6 @@ pub const DEFAULT_LINTS: &[Lint] = &[
502502
label: "stable_features",
503503
description: r##"stable features found in `#[feature]` directive"##,
504504
},
505-
Lint {
506-
label: "suspicious_auto_trait_impls",
507-
description: r##"the rules governing auto traits have recently changed resulting in potential breakage"##,
508-
},
509505
Lint {
510506
label: "suspicious_double_ref_op",
511507
description: r##"suspicious call of trait method on `&&T`"##,
@@ -778,7 +774,6 @@ pub const DEFAULT_LINT_GROUPS: &[LintGroup] = &[
778774
"repr_transparent_external_private_fields",
779775
"semicolon_in_expressions_from_macros",
780776
"soft_unstable",
781-
"suspicious_auto_trait_impls",
782777
"uninhabited_static",
783778
"unstable_name_collisions",
784779
"unstable_syntax_pre_expansion",

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;

0 commit comments

Comments
 (0)