Skip to content

Commit 7bab48c

Browse files
committed
Remove suspicious auto trait lint
1 parent cc1a618 commit 7bab48c

22 files changed

+76
-351
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+4-37
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::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;
@@ -461,8 +460,8 @@ fn lint_auto_trait_impl<'tcx>(
461460
return;
462461
}
463462
let self_ty = trait_ref.self_ty();
464-
let (self_type_did, args) = match self_ty.kind() {
465-
ty::Adt(def, args) => (def.did(), args),
463+
let args = match self_ty.kind() {
464+
ty::Adt(_, args) => args,
466465
_ => {
467466
// FIXME: should also lint for stuff like `&i32` but
468467
// considering that auto traits are unstable, that
@@ -475,8 +474,7 @@ fn lint_auto_trait_impl<'tcx>(
475474
// Impls which completely cover a given root type are fine as they
476475
// disable auto impls entirely. So only lint if the args
477476
// are not a permutation of the identity args.
478-
let Err(arg) = tcx.uses_unique_generic_params(args, CheckRegions::No) else {
479-
// ok
477+
if tcx.uses_unique_generic_params(args, CheckRegions::No).is_ok() {
480478
return;
481479
};
482480

@@ -495,37 +493,6 @@ fn lint_auto_trait_impl<'tcx>(
495493
// ok
496494
return;
497495
}
498-
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 `{}`, \
506-
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-
},
528-
);
529496
}
530497

531498
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;

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

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
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
2+
--> $DIR/non_send_fields_in_send_ty.rs:16:1
33
|
44
LL | unsafe impl<T> Send for RingBuffer<T> {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: it is not safe to send field `data` to another thread
8-
--> $DIR/non_send_fields_in_send_ty.rs:12:5
8+
--> $DIR/non_send_fields_in_send_ty.rs:11:5
99
|
1010
LL | data: Vec<UnsafeCell<T>>,
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -14,155 +14,155 @@ LL | data: Vec<UnsafeCell<T>>,
1414
= help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]`
1515

1616
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
17+
--> $DIR/non_send_fields_in_send_ty.rs:25:1
1818
|
1919
LL | unsafe impl<T> Send for MvccRwLock<T> {}
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2121
|
2222
note: it is not safe to send field `lock` to another thread
23-
--> $DIR/non_send_fields_in_send_ty.rs:23:5
23+
--> $DIR/non_send_fields_in_send_ty.rs:22:5
2424
|
2525
LL | lock: Mutex<Box<T>>,
2626
| ^^^^^^^^^^^^^^^^^^^
2727
= help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send`
2828

2929
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
30+
--> $DIR/non_send_fields_in_send_ty.rs:34:1
3131
|
3232
LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
|
3535
note: it is not safe to send field `head` to another thread
36-
--> $DIR/non_send_fields_in_send_ty.rs:32:5
36+
--> $DIR/non_send_fields_in_send_ty.rs:31:5
3737
|
3838
LL | head: Arc<RC>,
3939
| ^^^^^^^^^^^^^
4040
= help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send`
4141

4242
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
43+
--> $DIR/non_send_fields_in_send_ty.rs:51:1
4444
|
4545
LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4747
|
4848
note: it is not safe to send field `context` to another thread
49-
--> $DIR/non_send_fields_in_send_ty.rs:48:5
49+
--> $DIR/non_send_fields_in_send_ty.rs:47:5
5050
|
5151
LL | context: T,
5252
| ^^^^^^^^^^
5353
= help: add `T: Send` bound in `Send` impl
5454

5555
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
56+
--> $DIR/non_send_fields_in_send_ty.rs:59:1
5757
|
5858
LL | unsafe impl Send for NoGeneric {}
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060
|
6161
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
62+
--> $DIR/non_send_fields_in_send_ty.rs:56:5
6363
|
6464
LL | rc_is_not_send: Rc<String>,
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6666
= help: use a thread-safe type that implements `Send`
6767

6868
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
69+
--> $DIR/non_send_fields_in_send_ty.rs:68:1
7070
|
7171
LL | unsafe impl<T> Send for MultiField<T> {}
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373
|
7474
note: it is not safe to send field `field1` to another thread
75-
--> $DIR/non_send_fields_in_send_ty.rs:64:5
75+
--> $DIR/non_send_fields_in_send_ty.rs:63:5
7676
|
7777
LL | field1: T,
7878
| ^^^^^^^^^
7979
= help: add `T: Send` bound in `Send` impl
8080
note: it is not safe to send field `field2` to another thread
81-
--> $DIR/non_send_fields_in_send_ty.rs:65:5
81+
--> $DIR/non_send_fields_in_send_ty.rs:64:5
8282
|
8383
LL | field2: T,
8484
| ^^^^^^^^^
8585
= help: add `T: Send` bound in `Send` impl
8686
note: it is not safe to send field `field3` to another thread
87-
--> $DIR/non_send_fields_in_send_ty.rs:66:5
87+
--> $DIR/non_send_fields_in_send_ty.rs:65:5
8888
|
8989
LL | field3: T,
9090
| ^^^^^^^^^
9191
= help: add `T: Send` bound in `Send` impl
9292

9393
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
94+
--> $DIR/non_send_fields_in_send_ty.rs:76:1
9595
|
9696
LL | unsafe impl<T> Send for MyOption<T> {}
9797
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9898
|
9999
note: it is not safe to send field `0` to another thread
100-
--> $DIR/non_send_fields_in_send_ty.rs:73:12
100+
--> $DIR/non_send_fields_in_send_ty.rs:72:12
101101
|
102102
LL | MySome(T),
103103
| ^
104104
= help: add `T: Send` bound in `Send` impl
105105

106106
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
107+
--> $DIR/non_send_fields_in_send_ty.rs:89:1
108108
|
109109
LL | unsafe impl<A, B> Send for MultiParam<A, B> {}
110110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111111
|
112112
note: it is not safe to send field `vec` to another thread
113-
--> $DIR/non_send_fields_in_send_ty.rs:87:5
113+
--> $DIR/non_send_fields_in_send_ty.rs:86:5
114114
|
115115
LL | vec: Vec<(A, B)>,
116116
| ^^^^^^^^^^^^^^^^
117117
= help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send`
118118

119119
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
120+
--> $DIR/non_send_fields_in_send_ty.rs:108:1
121121
|
122122
LL | unsafe impl Send for HeuristicTest {}
123123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124124
|
125125
note: it is not safe to send field `field4` to another thread
126-
--> $DIR/non_send_fields_in_send_ty.rs:104:5
126+
--> $DIR/non_send_fields_in_send_ty.rs:103:5
127127
|
128128
LL | field4: (*const NonSend, Rc<u8>),
129129
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130130
= help: use a thread-safe type that implements `Send`
131131

132132
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
133+
--> $DIR/non_send_fields_in_send_ty.rs:128:1
134134
|
135135
LL | unsafe impl<T> Send for AttrTest3<T> {}
136136
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137137
|
138138
note: it is not safe to send field `0` to another thread
139-
--> $DIR/non_send_fields_in_send_ty.rs:124:11
139+
--> $DIR/non_send_fields_in_send_ty.rs:123:11
140140
|
141141
LL | Enum2(T),
142142
| ^
143143
= help: add `T: Send` bound in `Send` impl
144144

145145
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
146+
--> $DIR/non_send_fields_in_send_ty.rs:137:1
147147
|
148148
LL | unsafe impl<P> Send for Complex<P, u32> {}
149149
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
150150
|
151151
note: it is not safe to send field `field1` to another thread
152-
--> $DIR/non_send_fields_in_send_ty.rs:134:5
152+
--> $DIR/non_send_fields_in_send_ty.rs:133:5
153153
|
154154
LL | field1: A,
155155
| ^^^^^^^^^
156156
= help: add `P: Send` bound in `Send` impl
157157

158158
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
159+
--> $DIR/non_send_fields_in_send_ty.rs:141:1
160160
|
161161
LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
162162
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163163
|
164164
note: it is not safe to send field `field2` to another thread
165-
--> $DIR/non_send_fields_in_send_ty.rs:135:5
165+
--> $DIR/non_send_fields_in_send_ty.rs:134:5
166166
|
167167
LL | field2: B,
168168
| ^^^^^^^^^

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
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

0 commit comments

Comments
 (0)