Skip to content

Commit

Permalink
Remove suspicious auto trait lint
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Feb 15, 2024
1 parent cc1a618 commit 7bab48c
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 351 deletions.
41 changes: 4 additions & 37 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
//! crate or pertains to a type defined in this crate.

use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{DelayDm, ErrorGuaranteed};
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_middle::ty::util::CheckRegions;
use rustc_middle::ty::GenericArgs;
use rustc_middle::ty::{
self, AliasKind, ImplPolarity, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor,
};
use rustc_session::lint;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::Span;
use rustc_trait_selection::traits;
Expand Down Expand Up @@ -461,8 +460,8 @@ fn lint_auto_trait_impl<'tcx>(
return;
}
let self_ty = trait_ref.self_ty();
let (self_type_did, args) = match self_ty.kind() {
ty::Adt(def, args) => (def.did(), args),
let args = match self_ty.kind() {
ty::Adt(_, args) => args,
_ => {
// FIXME: should also lint for stuff like `&i32` but
// considering that auto traits are unstable, that
Expand All @@ -475,8 +474,7 @@ fn lint_auto_trait_impl<'tcx>(
// Impls which completely cover a given root type are fine as they
// disable auto impls entirely. So only lint if the args
// are not a permutation of the identity args.
let Err(arg) = tcx.uses_unique_generic_params(args, CheckRegions::No) else {
// ok
if tcx.uses_unique_generic_params(args, CheckRegions::No).is_ok() {
return;
};

Expand All @@ -495,37 +493,6 @@ fn lint_auto_trait_impl<'tcx>(
// ok
return;
}

tcx.node_span_lint(
lint::builtin::SUSPICIOUS_AUTO_TRAIT_IMPLS,
tcx.local_def_id_to_hir_id(impl_def_id),
tcx.def_span(impl_def_id),
DelayDm(|| {
format!(
"cross-crate traits with a default impl, like `{}`, \
should not be specialized",
tcx.def_path_str(trait_ref.def_id),
)
}),
|lint| {
let item_span = tcx.def_span(self_type_did);
let self_descr = tcx.def_descr(self_type_did);
match arg {
ty::util::NotUniqueParam::DuplicateParam(arg) => {
lint.note(format!("`{arg}` is mentioned multiple times"));
}
ty::util::NotUniqueParam::NotParam(arg) => {
lint.note(format!("`{arg}` is not a generic parameter"));
}
}
lint.span_note(
item_span,
format!(
"try using the same sequence of generic parameters as the {self_descr} definition",
),
);
},
);
}

fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: Ty<'tcx>) -> bool {
Expand Down
35 changes: 0 additions & 35 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ declare_lint_pass! {
SOFT_UNSTABLE,
STABLE_FEATURES,
STATIC_MUT_REF,
SUSPICIOUS_AUTO_TRAIT_IMPLS,
TEST_UNSTABLE_LINT,
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TRIVIAL_CASTS,
Expand Down Expand Up @@ -4032,40 +4031,6 @@ declare_lint! {
"duplicated attribute"
}

declare_lint! {
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
/// implementations of auto traits.
///
/// ### Example
///
/// ```rust
/// struct Foo<T>(T);
///
/// unsafe impl<T> Send for Foo<*const T> {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
/// in two different ways: either by writing an explicit impl or if
/// all fields of the type implement that auto trait.
///
/// The compiler disables the automatic implementation if an explicit one
/// exists for given type constructor. The exact rules governing this
/// were previously unsound, quite subtle, and have been recently modified.
/// This change caused the automatic implementation to be disabled in more
/// cases, potentially breaking some code.
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
Warn,
"the rules governing auto traits have recently changed resulting in potential breakage",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
};
}

declare_lint! {
/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
/// in an associated type.
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![warn(clippy::non_send_fields_in_send_ty)]
#![allow(suspicious_auto_trait_impls)]
#![feature(extern_types)]

use std::cell::UnsafeCell;
Expand Down
52 changes: 26 additions & 26 deletions src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: some fields in `RingBuffer<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:17:1
--> $DIR/non_send_fields_in_send_ty.rs:16:1
|
LL | unsafe impl<T> Send for RingBuffer<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `data` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:12:5
--> $DIR/non_send_fields_in_send_ty.rs:11:5
|
LL | data: Vec<UnsafeCell<T>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -14,155 +14,155 @@ LL | data: Vec<UnsafeCell<T>>,
= help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]`

error: some fields in `MvccRwLock<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:26:1
--> $DIR/non_send_fields_in_send_ty.rs:25:1
|
LL | unsafe impl<T> Send for MvccRwLock<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `lock` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:23:5
--> $DIR/non_send_fields_in_send_ty.rs:22:5
|
LL | lock: Mutex<Box<T>>,
| ^^^^^^^^^^^^^^^^^^^
= help: add bounds on type parameter `T` that satisfy `Mutex<Box<T>>: Send`

error: some fields in `ArcGuard<RC, T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:35:1
--> $DIR/non_send_fields_in_send_ty.rs:34:1
|
LL | unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `head` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:32:5
--> $DIR/non_send_fields_in_send_ty.rs:31:5
|
LL | head: Arc<RC>,
| ^^^^^^^^^^^^^
= help: add bounds on type parameter `RC` that satisfy `Arc<RC>: Send`

error: some fields in `DeviceHandle<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:52:1
--> $DIR/non_send_fields_in_send_ty.rs:51:1
|
LL | unsafe impl<T: UsbContext> Send for DeviceHandle<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `context` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:48:5
--> $DIR/non_send_fields_in_send_ty.rs:47:5
|
LL | context: T,
| ^^^^^^^^^^
= help: add `T: Send` bound in `Send` impl

error: some fields in `NoGeneric` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:60:1
--> $DIR/non_send_fields_in_send_ty.rs:59:1
|
LL | unsafe impl Send for NoGeneric {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `rc_is_not_send` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:57:5
--> $DIR/non_send_fields_in_send_ty.rs:56:5
|
LL | rc_is_not_send: Rc<String>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use a thread-safe type that implements `Send`

error: some fields in `MultiField<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:69:1
--> $DIR/non_send_fields_in_send_ty.rs:68:1
|
LL | unsafe impl<T> Send for MultiField<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `field1` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:64:5
--> $DIR/non_send_fields_in_send_ty.rs:63:5
|
LL | field1: T,
| ^^^^^^^^^
= help: add `T: Send` bound in `Send` impl
note: it is not safe to send field `field2` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:65:5
--> $DIR/non_send_fields_in_send_ty.rs:64:5
|
LL | field2: T,
| ^^^^^^^^^
= help: add `T: Send` bound in `Send` impl
note: it is not safe to send field `field3` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:66:5
--> $DIR/non_send_fields_in_send_ty.rs:65:5
|
LL | field3: T,
| ^^^^^^^^^
= help: add `T: Send` bound in `Send` impl

error: some fields in `MyOption<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:77:1
--> $DIR/non_send_fields_in_send_ty.rs:76:1
|
LL | unsafe impl<T> Send for MyOption<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `0` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:73:12
--> $DIR/non_send_fields_in_send_ty.rs:72:12
|
LL | MySome(T),
| ^
= help: add `T: Send` bound in `Send` impl

error: some fields in `MultiParam<A, B>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:90:1
--> $DIR/non_send_fields_in_send_ty.rs:89:1
|
LL | unsafe impl<A, B> Send for MultiParam<A, B> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `vec` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:87:5
--> $DIR/non_send_fields_in_send_ty.rs:86:5
|
LL | vec: Vec<(A, B)>,
| ^^^^^^^^^^^^^^^^
= help: add bounds on type parameters `A, B` that satisfy `Vec<(A, B)>: Send`

error: some fields in `HeuristicTest` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:109:1
--> $DIR/non_send_fields_in_send_ty.rs:108:1
|
LL | unsafe impl Send for HeuristicTest {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `field4` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:104:5
--> $DIR/non_send_fields_in_send_ty.rs:103:5
|
LL | field4: (*const NonSend, Rc<u8>),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use a thread-safe type that implements `Send`

error: some fields in `AttrTest3<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:129:1
--> $DIR/non_send_fields_in_send_ty.rs:128:1
|
LL | unsafe impl<T> Send for AttrTest3<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `0` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:124:11
--> $DIR/non_send_fields_in_send_ty.rs:123:11
|
LL | Enum2(T),
| ^
= help: add `T: Send` bound in `Send` impl

error: some fields in `Complex<P, u32>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:138:1
--> $DIR/non_send_fields_in_send_ty.rs:137:1
|
LL | unsafe impl<P> Send for Complex<P, u32> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `field1` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:134:5
--> $DIR/non_send_fields_in_send_ty.rs:133:5
|
LL | field1: A,
| ^^^^^^^^^
= help: add `P: Send` bound in `Send` impl

error: some fields in `Complex<Q, MutexGuard<'static, bool>>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:142:1
--> $DIR/non_send_fields_in_send_ty.rs:141:1
|
LL | unsafe impl<Q: Send> Send for Complex<Q, MutexGuard<'static, bool>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: it is not safe to send field `field2` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:135:5
--> $DIR/non_send_fields_in_send_ty.rs:134:5
|
LL | field2: B,
| ^^^^^^^^^
Expand Down
5 changes: 0 additions & 5 deletions src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,6 @@ pub const DEFAULT_LINTS: &[Lint] = &[
label: "stable_features",
description: r##"stable features found in `#[feature]` directive"##,
},
Lint {
label: "suspicious_auto_trait_impls",
description: r##"the rules governing auto traits have recently changed resulting in potential breakage"##,
},
Lint {
label: "suspicious_double_ref_op",
description: r##"suspicious call of trait method on `&&T`"##,
Expand Down Expand Up @@ -778,7 +774,6 @@ pub const DEFAULT_LINT_GROUPS: &[LintGroup] = &[
"repr_transparent_external_private_fields",
"semicolon_in_expressions_from_macros",
"soft_unstable",
"suspicious_auto_trait_impls",
"uninhabited_static",
"unstable_name_collisions",
"unstable_syntax_pre_expansion",
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/auto-traits/issue-117789.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(suspicious_auto_trait_impls)]

auto trait Trait<P> {} //~ ERROR auto traits cannot have generic parameters
//~^ ERROR auto traits are experimental and possibly buggy
impl<P> Trait<P> for () {}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/auto-traits/issue-117789.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0567]: auto traits cannot have generic parameters
--> $DIR/issue-117789.rs:3:17
--> $DIR/issue-117789.rs:1:17
|
LL | auto trait Trait<P> {}
| -----^^^ help: remove the parameters
| |
| auto trait cannot have generic parameters

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/issue-117789.rs:3:1
--> $DIR/issue-117789.rs:1:1
|
LL | auto trait Trait<P> {}
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/auto-traits/issue-83857-ub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(suspicious_auto_trait_impls)]
// Tests that we don't incorrectly allow overlap between a builtin auto trait
// impl and a user written one. See #83857 for more details

Expand Down
Loading

0 comments on commit 7bab48c

Please sign in to comment.