From eee9d2a773f8c38c83f251c41ea2ec879d7c825c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 6 Feb 2024 15:22:13 -0300 Subject: [PATCH 1/3] Change leak check lint message to behavior is likely to change in the future --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- tests/ui/coherence/coherence-fn-implied-bounds.rs | 2 +- tests/ui/coherence/coherence-fn-implied-bounds.stderr | 2 +- tests/ui/coherence/coherence-free-vs-bound-region.rs | 2 +- .../ui/coherence/coherence-free-vs-bound-region.stderr | 2 +- tests/ui/coherence/coherence-subtyping.rs | 4 ++-- tests/ui/coherence/coherence-subtyping.stderr | 2 +- tests/ui/coherence/coherence-wasm-bindgen.rs | 2 +- tests/ui/coherence/coherence-wasm-bindgen.stderr | 2 +- ...r-region-constraints-on-unification.explicit.stderr | 2 +- ...ce-placeholder-region-constraints-on-unification.rs | 2 +- tests/ui/const-generics/invariant.rs | 10 ++++------ tests/ui/const-generics/invariant.stderr | 4 ++-- 13 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 3f5d3c25971..8ba5942898c 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1503,7 +1503,7 @@ declare_lint! { Warn, "distinct impls distinguished only by the leak-check code", @future_incompatible = FutureIncompatibleInfo { - reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps, + reason: FutureIncompatibilityReason::Custom("the behavior may change in a future release"), reference: "issue #56105 ", }; } diff --git a/tests/ui/coherence/coherence-fn-implied-bounds.rs b/tests/ui/coherence/coherence-fn-implied-bounds.rs index 4539af9a32e..0ae54284102 100644 --- a/tests/ui/coherence/coherence-fn-implied-bounds.rs +++ b/tests/ui/coherence/coherence-fn-implied-bounds.rs @@ -20,7 +20,7 @@ impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {} impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 { //~^ ERROR conflicting implementations - //~| WARNING this was previously accepted by the compiler + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-fn-implied-bounds.stderr b/tests/ui/coherence/coherence-fn-implied-bounds.stderr index b0dea746709..ece3288989d 100644 --- a/tests/ui/coherence/coherence-fn-implied-bounds.stderr +++ b/tests/ui/coherence/coherence-fn-implied-bounds.stderr @@ -7,7 +7,7 @@ LL | LL | impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/coherence-free-vs-bound-region.rs b/tests/ui/coherence/coherence-free-vs-bound-region.rs index 2f5c49d293d..89d0005fb79 100644 --- a/tests/ui/coherence/coherence-free-vs-bound-region.rs +++ b/tests/ui/coherence/coherence-free-vs-bound-region.rs @@ -15,7 +15,7 @@ impl<'a> TheTrait for fn(&'a u8) {} impl TheTrait for fn(&u8) { //~^ ERROR conflicting implementations of trait - //~| WARNING this was previously accepted by the compiler + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-free-vs-bound-region.stderr b/tests/ui/coherence/coherence-free-vs-bound-region.stderr index c97b32e429d..e45cf5ad3a4 100644 --- a/tests/ui/coherence/coherence-free-vs-bound-region.stderr +++ b/tests/ui/coherence/coherence-free-vs-bound-region.stderr @@ -7,7 +7,7 @@ LL | LL | impl TheTrait for fn(&u8) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&u8)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/coherence-subtyping.rs b/tests/ui/coherence/coherence-subtyping.rs index da0cc2d0265..4365ad5c884 100644 --- a/tests/ui/coherence/coherence-subtyping.rs +++ b/tests/ui/coherence/coherence-subtyping.rs @@ -13,8 +13,8 @@ trait TheTrait { impl TheTrait for for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {} impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 { - //~^ WARNING conflicting implementation - //~^^ WARNING this was previously accepted by the compiler but is being phased out + //~^ WARN conflicting implementation + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-subtyping.stderr b/tests/ui/coherence/coherence-subtyping.stderr index 9d90019a50f..42f256ace78 100644 --- a/tests/ui/coherence/coherence-subtyping.stderr +++ b/tests/ui/coherence/coherence-subtyping.stderr @@ -7,7 +7,7 @@ LL | LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details = note: `#[warn(coherence_leak_check)]` on by default diff --git a/tests/ui/coherence/coherence-wasm-bindgen.rs b/tests/ui/coherence/coherence-wasm-bindgen.rs index ee09a72449b..57daaa134d4 100644 --- a/tests/ui/coherence/coherence-wasm-bindgen.rs +++ b/tests/ui/coherence/coherence-wasm-bindgen.rs @@ -31,7 +31,7 @@ where R: ReturnWasmAbi, { //~^^^^^ ERROR conflicting implementation - //~| WARNING this was previously accepted + //~| WARN the behavior may change in a future release } fn main() {} diff --git a/tests/ui/coherence/coherence-wasm-bindgen.stderr b/tests/ui/coherence/coherence-wasm-bindgen.stderr index b3c3dac612d..939f1fce9a4 100644 --- a/tests/ui/coherence/coherence-wasm-bindgen.stderr +++ b/tests/ui/coherence/coherence-wasm-bindgen.stderr @@ -13,7 +13,7 @@ LL | | A: RefFromWasmAbi, LL | | R: ReturnWasmAbi, | |_____________________^ conflicting implementation for `&dyn Fn(&_) -> _` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: downstream crates may implement trait `FromWasmAbi` for type `&_` = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details diff --git a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr index 5368db29338..832c56a4554 100644 --- a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr +++ b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.explicit.stderr @@ -6,7 +6,7 @@ LL | impl FnMarker for fn(T) {} LL | impl FnMarker for fn(&T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&_)` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details note: the lint level is defined here diff --git a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs index 7967002e021..e487dcc3c0e 100644 --- a/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs +++ b/tests/ui/coherence/negative-coherence-placeholder-region-constraints-on-unification.rs @@ -20,6 +20,6 @@ trait FnMarker {} impl FnMarker for fn(T) {} impl FnMarker for fn(&T) {} //[explicit]~^ ERROR conflicting implementations of trait `FnMarker` for type `fn(&_)` -//[explicit]~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! +//[explicit]~| WARN the behavior may change in a future release fn main() {} diff --git a/tests/ui/const-generics/invariant.rs b/tests/ui/const-generics/invariant.rs index 39d658be67d..ee4ad4e7c4e 100644 --- a/tests/ui/const-generics/invariant.rs +++ b/tests/ui/const-generics/invariant.rs @@ -12,18 +12,16 @@ impl SadBee for for<'a> fn(&'a ()) { const ASSOC: usize = 0; } impl SadBee for fn(&'static ()) { - //~^ WARNING conflicting implementations of trait - //~| WARNING this was previously accepted + //~^ WARN conflicting implementations of trait + //~| WARN the behavior may change in a future release const ASSOC: usize = 100; } struct Foo([u8; ::ASSOC], PhantomData) where - [(); ::ASSOC]: ; + [(); ::ASSOC]:; -fn covariant( - v: &'static Foo fn(&'a ())> -) -> &'static Foo { +fn covariant(v: &'static Foo fn(&'a ())>) -> &'static Foo { v //~^ ERROR mismatched types } diff --git a/tests/ui/const-generics/invariant.stderr b/tests/ui/const-generics/invariant.stderr index f631e131146..b4e46e55268 100644 --- a/tests/ui/const-generics/invariant.stderr +++ b/tests/ui/const-generics/invariant.stderr @@ -7,13 +7,13 @@ LL | impl SadBee for for<'a> fn(&'a ()) { LL | impl SadBee for fn(&'static ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a> fn(&'a ())` | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = warning: the behavior may change in a future release = note: for more information, see issue #56105 = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details = note: `#[warn(coherence_leak_check)]` on by default error[E0308]: mismatched types - --> $DIR/invariant.rs:27:5 + --> $DIR/invariant.rs:25:5 | LL | v | ^ one type is more general than the other From 086463b227ea12c244243609cce5c795dc3ec40a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Feb 2024 17:39:25 -0300 Subject: [PATCH 2/3] Remove suspicious auto trait lint --- .../src/coherence/orphan.rs | 164 +----------------- compiler/rustc_lint/src/lib.rs | 5 + compiler/rustc_lint_defs/src/builtin.rs | 35 ---- .../tests/ui/non_send_fields_in_send_ty.rs | 1 - .../ui/non_send_fields_in_send_ty.stderr | 52 +++--- .../crates/ide-db/src/generated/lints.rs | 5 - tests/ui/auto-traits/issue-117789.rs | 2 - tests/ui/auto-traits/issue-117789.stderr | 4 +- tests/ui/auto-traits/issue-83857-ub.rs | 1 - tests/ui/auto-traits/issue-83857-ub.stderr | 12 +- tests/ui/auto-traits/suspicious-impls-lint.rs | 50 ------ .../auto-traits/suspicious-impls-lint.stderr | 82 --------- .../suspicious-negative-impls-lint.rs | 21 --- .../suspicious-negative-impls-lint.stderr | 52 ------ ...herence-conflicting-negative-trait-impl.rs | 2 - ...nce-conflicting-negative-trait-impl.stderr | 18 +- tests/ui/coherence/coherence-orphan.rs | 12 +- tests/ui/coherence/coherence-orphan.stderr | 25 +-- .../coherence-overlap-negative-impls.rs | 13 +- tests/ui/issues/issue-106755.rs | 2 - tests/ui/issues/issue-106755.stderr | 18 +- ...efault-trait-impl-cross-crate-coherence.rs | 13 +- ...lt-trait-impl-cross-crate-coherence.stderr | 16 +- 23 files changed, 78 insertions(+), 527 deletions(-) delete mode 100644 tests/ui/auto-traits/suspicious-impls-lint.rs delete mode 100644 tests/ui/auto-traits/suspicious-impls-lint.stderr delete mode 100644 tests/ui/auto-traits/suspicious-negative-impls-lint.rs delete mode 100644 tests/ui/auto-traits/suspicious-negative-impls-lint.stderr diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 45641be52d2..faf676ddc09 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -1,20 +1,12 @@ //! Orphan checker: every impl either implements a trait defined in this //! 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_middle::ty::{self, AliasKind, Ty, TyCtxt, TypeVisitableExt}; +use rustc_span::def_id::LocalDefId; use rustc_span::Span; use rustc_trait_selection::traits; -use std::ops::ControlFlow; use crate::errors; @@ -26,12 +18,7 @@ pub(crate) fn orphan_check_impl( let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(); trait_ref.error_reported()?; - let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); - if tcx.trait_is_auto(trait_ref.def_id) { - lint_auto_trait_impl(tcx, trait_ref, impl_def_id); - } - - ret + do_orphan_check_impl(tcx, trait_ref, impl_def_id) } fn do_orphan_check_impl<'tcx>( @@ -445,146 +432,3 @@ fn emit_orphan_check_error<'tcx>( } }) } - -/// Lint impls of auto traits if they are likely to have -/// unsound or surprising effects on auto impls. -fn lint_auto_trait_impl<'tcx>( - tcx: TyCtxt<'tcx>, - trait_ref: ty::TraitRef<'tcx>, - impl_def_id: LocalDefId, -) { - if trait_ref.args.len() != 1 { - tcx.dcx().span_delayed_bug( - tcx.def_span(impl_def_id), - "auto traits cannot have generic parameters", - ); - return; - } - let self_ty = trait_ref.self_ty(); - let (self_type_did, args) = match self_ty.kind() { - ty::Adt(def, args) => (def.did(), args), - _ => { - // FIXME: should also lint for stuff like `&i32` but - // considering that auto traits are unstable, that - // isn't too important for now as this only affects - // crates using `nightly`, and std. - return; - } - }; - - // 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 - return; - }; - - // Ideally: - // - // - compute the requirements for the auto impl candidate - // - check whether these are implied by the non covering impls - // - if not, emit the lint - // - // What we do here is a bit simpler: - // - // - badly check if an auto impl candidate definitely does not apply - // for the given simplified type - // - if so, do not lint - if fast_reject_auto_impl(tcx, trait_ref.def_id, self_ty) { - // 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 { - struct DisableAutoTraitVisitor<'tcx> { - tcx: TyCtxt<'tcx>, - trait_def_id: DefId, - self_ty_root: Ty<'tcx>, - seen: FxHashSet, - } - - impl<'tcx> TypeVisitor> for DisableAutoTraitVisitor<'tcx> { - type BreakTy = (); - fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { - let tcx = self.tcx; - if ty != self.self_ty_root { - for impl_def_id in tcx.non_blanket_impls_for_ty(self.trait_def_id, ty) { - match tcx.impl_polarity(impl_def_id) { - ImplPolarity::Negative => return ControlFlow::Break(()), - ImplPolarity::Reservation => {} - // FIXME(@lcnr): That's probably not good enough, idk - // - // We might just want to take the rustdoc code and somehow avoid - // explicit impls for `Self`. - ImplPolarity::Positive => return ControlFlow::Continue(()), - } - } - } - - match ty.kind() { - ty::Adt(def, args) if def.is_phantom_data() => args.visit_with(self), - ty::Adt(def, args) => { - // @lcnr: This is the only place where cycles can happen. We avoid this - // by only visiting each `DefId` once. - // - // This will be is incorrect in subtle cases, but I don't care :) - if self.seen.insert(def.did()) { - for ty in def.all_fields().map(|field| field.ty(tcx, args)) { - ty.visit_with(self)?; - } - } - - ControlFlow::Continue(()) - } - _ => ty.super_visit_with(self), - } - } - } - - let self_ty_root = match self_ty.kind() { - ty::Adt(def, _) => Ty::new_adt(tcx, *def, GenericArgs::identity_for_item(tcx, def.did())), - _ => unimplemented!("unexpected self ty {:?}", self_ty), - }; - - self_ty_root - .visit_with(&mut DisableAutoTraitVisitor { - tcx, - self_ty_root, - trait_def_id, - seen: FxHashSet::default(), - }) - .is_break() -} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index e50f4ca338b..d6009324402 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -524,6 +524,11 @@ fn register_builtins(store: &mut LintStore) { "no longer needed, see RFC #3535 \ for more information", ); + store.register_removed( + "suspicious_auto_trait_impls", + "no longer needed, see #93367 \ + for more information", + ); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 8ba5942898c..84a050a242a 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -90,7 +90,6 @@ declare_lint_pass! { SOFT_UNSTABLE, STABLE_FEATURES, STATIC_MUT_REFS, - SUSPICIOUS_AUTO_TRAIT_IMPLS, TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT, TRIVIAL_CASTS, @@ -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); - /// - /// unsafe impl 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 ", - }; -} - declare_lint! { /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals /// in an associated type. diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs index c6855a09696..046ea70b08f 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.rs @@ -1,5 +1,4 @@ #![warn(clippy::non_send_fields_in_send_ty)] -#![allow(suspicious_auto_trait_impls)] #![feature(extern_types)] use std::cell::UnsafeCell; diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr index 1ea76196af9..99fd4ea60b6 100644 --- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr +++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr @@ -1,11 +1,11 @@ error: some fields in `RingBuffer` 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 Send for RingBuffer {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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>, | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -14,155 +14,155 @@ LL | data: Vec>, = help: to override `-D warnings` add `#[allow(clippy::non_send_fields_in_send_ty)]` error: some fields in `MvccRwLock` 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 Send for MvccRwLock {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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>, | ^^^^^^^^^^^^^^^^^^^ = help: add bounds on type parameter `T` that satisfy `Mutex>: Send` error: some fields in `ArcGuard` 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 Send for ArcGuard {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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, | ^^^^^^^^^^^^^ = help: add bounds on type parameter `RC` that satisfy `Arc: Send` error: some fields in `DeviceHandle` 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 Send for DeviceHandle {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `MultiField` 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 Send for MultiField {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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` 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 Send for MyOption {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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` 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 Send for MultiParam {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use a thread-safe type that implements `Send` error: some fields in `AttrTest3` 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 Send for AttrTest3 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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` 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

Send for Complex {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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>` 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 Send for Complex> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 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, | ^^^^^^^^^ diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index 2fc07933200..3329909e9da 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -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`"##, @@ -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", diff --git a/tests/ui/auto-traits/issue-117789.rs b/tests/ui/auto-traits/issue-117789.rs index 0c30931a1b5..63f796771db 100644 --- a/tests/ui/auto-traits/issue-117789.rs +++ b/tests/ui/auto-traits/issue-117789.rs @@ -1,5 +1,3 @@ -#![deny(suspicious_auto_trait_impls)] - auto trait Trait

{} //~ ERROR auto traits cannot have generic parameters //~^ ERROR auto traits are experimental and possibly buggy impl

Trait

for () {} diff --git a/tests/ui/auto-traits/issue-117789.stderr b/tests/ui/auto-traits/issue-117789.stderr index 1f8880b1ef4..99efb213417 100644 --- a/tests/ui/auto-traits/issue-117789.stderr +++ b/tests/ui/auto-traits/issue-117789.stderr @@ -1,5 +1,5 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/issue-117789.rs:3:17 + --> $DIR/issue-117789.rs:1:17 | LL | auto trait Trait

{} | -----^^^ help: remove the parameters @@ -7,7 +7,7 @@ LL | auto trait Trait

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

{} | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/auto-traits/issue-83857-ub.rs b/tests/ui/auto-traits/issue-83857-ub.rs index f9b47d2b0c6..20abfdd851a 100644 --- a/tests/ui/auto-traits/issue-83857-ub.rs +++ b/tests/ui/auto-traits/issue-83857-ub.rs @@ -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 diff --git a/tests/ui/auto-traits/issue-83857-ub.stderr b/tests/ui/auto-traits/issue-83857-ub.stderr index 6372bdfe762..20bfe7e36ca 100644 --- a/tests/ui/auto-traits/issue-83857-ub.stderr +++ b/tests/ui/auto-traits/issue-83857-ub.stderr @@ -1,12 +1,12 @@ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:22:38 + --> $DIR/issue-83857-ub.rs:21:38 | LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i32) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be sent between threads safely | = help: the trait `Send` is not implemented for `Foo`, which is required by `Foo: WithAssoc` note: required for `Foo` to implement `WithAssoc` - --> $DIR/issue-83857-ub.rs:15:15 + --> $DIR/issue-83857-ub.rs:14:15 | LL | impl WithAssoc for T { | ---- ^^^^^^^^^ ^ @@ -18,7 +18,7 @@ LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i | +++++++++++++++++++++ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:22:80 + --> $DIR/issue-83857-ub.rs:21:80 | LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i32) { | ________________________________________________________________________________^ @@ -31,7 +31,7 @@ LL | | } | = help: the trait `Send` is not implemented for `Foo`, which is required by `Foo: WithAssoc` note: required for `Foo` to implement `WithAssoc` - --> $DIR/issue-83857-ub.rs:15:15 + --> $DIR/issue-83857-ub.rs:14:15 | LL | impl WithAssoc for T { | ---- ^^^^^^^^^ ^ @@ -43,7 +43,7 @@ LL | fn generic(v: Foo, f: fn( as WithAssoc>::Output) -> i | +++++++++++++++++++++ error[E0277]: `Foo` cannot be sent between threads safely - --> $DIR/issue-83857-ub.rs:25:11 + --> $DIR/issue-83857-ub.rs:24:11 | LL | f(foo(v)); | --- ^ `Foo` cannot be sent between threads safely @@ -52,7 +52,7 @@ LL | f(foo(v)); | = help: the trait `Send` is not implemented for `Foo` note: required by a bound in `foo` - --> $DIR/issue-83857-ub.rs:29:11 + --> $DIR/issue-83857-ub.rs:28:11 | LL | fn foo(x: T) -> ::Output { | ^^^^ required by this bound in `foo` diff --git a/tests/ui/auto-traits/suspicious-impls-lint.rs b/tests/ui/auto-traits/suspicious-impls-lint.rs deleted file mode 100644 index 7712e84f4a2..00000000000 --- a/tests/ui/auto-traits/suspicious-impls-lint.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![deny(suspicious_auto_trait_impls)] - -use std::marker::PhantomData; - -struct MayImplementSendOk(T); -unsafe impl Send for MayImplementSendOk {} // ok - -struct MayImplementSendErr(T); -unsafe impl Send for MayImplementSendErr<&T> {} -//~^ ERROR -//~| WARNING this will change its meaning - -struct ContainsNonSendDirect(*const T); -unsafe impl Send for ContainsNonSendDirect<&T> {} // ok - -struct ContainsPtr(*const T); -struct ContainsIndirectNonSend(ContainsPtr); -unsafe impl Send for ContainsIndirectNonSend<&T> {} // ok - -struct ContainsVec(Vec); -unsafe impl Send for ContainsVec {} -//~^ ERROR -//~| WARNING this will change its meaning - -struct TwoParams(T, U); -unsafe impl Send for TwoParams {} // ok - -struct TwoParamsFlipped(T, U); -unsafe impl Send for TwoParamsFlipped {} // ok - -struct TwoParamsSame(T, U); -unsafe impl Send for TwoParamsSame {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithPhantomDataNonSend(PhantomData<*const T>, U); -unsafe impl Send for WithPhantomDataNonSend {} // ok - -pub struct WithPhantomDataSend(PhantomData, U); -unsafe impl Send for WithPhantomDataSend<*const T, i8> {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithLifetime<'a, T>(&'a (), T); -unsafe impl Send for WithLifetime<'static, T> {} // ok -unsafe impl Sync for WithLifetime<'static, Vec> {} -//~^ ERROR -//~| WARNING this will change its meaning - -fn main() {} diff --git a/tests/ui/auto-traits/suspicious-impls-lint.stderr b/tests/ui/auto-traits/suspicious-impls-lint.stderr deleted file mode 100644 index 9cd4e79f851..00000000000 --- a/tests/ui/auto-traits/suspicious-impls-lint.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:9:1 - | -LL | unsafe impl Send for MayImplementSendErr<&T> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `&T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:8:1 - | -LL | struct MayImplementSendErr(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/suspicious-impls-lint.rs:1:9 - | -LL | #![deny(suspicious_auto_trait_impls)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:21:1 - | -LL | unsafe impl Send for ContainsVec {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:20:1 - | -LL | struct ContainsVec(Vec); - | ^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:32:1 - | -LL | unsafe impl Send for TwoParamsSame {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `T` is mentioned multiple times -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:31:1 - | -LL | struct TwoParamsSame(T, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:40:1 - | -LL | unsafe impl Send for WithPhantomDataSend<*const T, i8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:39:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-impls-lint.rs:46:1 - | -LL | unsafe impl Sync for WithLifetime<'static, Vec> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `Vec` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-impls-lint.rs:44:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors - diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.rs b/tests/ui/auto-traits/suspicious-negative-impls-lint.rs deleted file mode 100644 index 34842e5944b..00000000000 --- a/tests/ui/auto-traits/suspicious-negative-impls-lint.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(negative_impls)] -#![deny(suspicious_auto_trait_impls)] - -use std::marker::PhantomData; - -struct ContainsVec(Vec); -impl !Send for ContainsVec {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithPhantomDataSend(PhantomData, U); -impl !Send for WithPhantomDataSend<*const T, u8> {} -//~^ ERROR -//~| WARNING this will change its meaning - -pub struct WithLifetime<'a, T>(&'a (), T); -impl !Sync for WithLifetime<'static, Option> {} -//~^ ERROR -//~| WARNING this will change its meaning - -fn main() {} diff --git a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr b/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr deleted file mode 100644 index ee03ea12557..00000000000 --- a/tests/ui/auto-traits/suspicious-negative-impls-lint.stderr +++ /dev/null @@ -1,52 +0,0 @@ -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:7:1 - | -LL | impl !Send for ContainsVec {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `u32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:6:1 - | -LL | struct ContainsVec(Vec); - | ^^^^^^^^^^^^^^^^^^^^^ -note: the lint level is defined here - --> $DIR/suspicious-negative-impls-lint.rs:2:9 - | -LL | #![deny(suspicious_auto_trait_impls)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:12:1 - | -LL | impl !Send for WithPhantomDataSend<*const T, u8> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `*const T` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:11:1 - | -LL | pub struct WithPhantomDataSend(PhantomData, U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: cross-crate traits with a default impl, like `Sync`, should not be specialized - --> $DIR/suspicious-negative-impls-lint.rs:17:1 - | -LL | impl !Sync for WithLifetime<'static, Option> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `Option` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/suspicious-negative-impls-lint.rs:16:1 - | -LL | pub struct WithLifetime<'a, T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs index 76a57936e69..24b87892753 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.rs @@ -13,7 +13,5 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} -//~^ WARNING -//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr index 020199da991..2463f38a922 100644 --- a/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr +++ b/tests/ui/coherence/coherence-conflicting-negative-trait-impl.stderr @@ -16,23 +16,7 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/coherence-conflicting-negative-trait-impl.rs:15:1 - | -LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/coherence-conflicting-negative-trait-impl.rs:7:1 - | -LL | struct TestType(::std::marker::PhantomData); - | ^^^^^^^^^^^^^^^^^^ - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/coherence/coherence-orphan.rs b/tests/ui/coherence/coherence-orphan.rs index c06705133c8..9c96958f21a 100644 --- a/tests/ui/coherence/coherence-orphan.rs +++ b/tests/ui/coherence/coherence-orphan.rs @@ -7,18 +7,16 @@ use lib::TheTrait; struct TheType; -impl TheTrait for isize { } +impl TheTrait for isize {} //~^ ERROR E0117 //~| ERROR not all trait items implemented -impl TheTrait for isize { } +impl TheTrait for isize {} //~^ ERROR not all trait items implemented -impl TheTrait for TheType { } +impl TheTrait for TheType {} //~^ ERROR not all trait items implemented -impl !Send for Vec { } //~ ERROR E0117 -//~^ WARNING -//~| WARNING this will change its meaning +impl !Send for Vec {} //~ ERROR E0117 -fn main() { } +fn main() {} diff --git a/tests/ui/coherence/coherence-orphan.stderr b/tests/ui/coherence/coherence-orphan.stderr index 78fad837647..b1bb75bfe51 100644 --- a/tests/ui/coherence/coherence-orphan.stderr +++ b/tests/ui/coherence/coherence-orphan.stderr @@ -1,7 +1,7 @@ error[E0117]: only traits defined in the current crate can be implemented for primitive types --> $DIR/coherence-orphan.rs:10:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^---------------^^^^^----- | | | | | | | `isize` is not defined in the current crate @@ -13,7 +13,7 @@ LL | impl TheTrait for isize { } error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> $DIR/coherence-orphan.rs:20:1 | -LL | impl !Send for Vec { } +LL | impl !Send for Vec {} | ^^^^^^^^^^^^^^^---------- | | | | | `Vec` is not defined in the current crate @@ -21,23 +21,10 @@ LL | impl !Send for Vec { } | = note: define and implement a trait or new type instead -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/coherence-orphan.rs:20:1 - | -LL | impl !Send for Vec { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `isize` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:10:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` @@ -45,7 +32,7 @@ LL | impl TheTrait for isize { } error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:14:1 | -LL | impl TheTrait for isize { } +LL | impl TheTrait for isize {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` @@ -53,12 +40,12 @@ LL | impl TheTrait for isize { } error[E0046]: not all trait items implemented, missing: `the_fn` --> $DIR/coherence-orphan.rs:17:1 | -LL | impl TheTrait for TheType { } +LL | impl TheTrait for TheType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `the_fn` in implementation | = help: implement the missing item: `fn the_fn(&self) { todo!() }` -error: aborting due to 5 previous errors; 1 warning emitted +error: aborting due to 5 previous errors Some errors have detailed explanations: E0046, E0117. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/coherence/coherence-overlap-negative-impls.rs b/tests/ui/coherence/coherence-overlap-negative-impls.rs index 9a85d8c5a63..ffcd56817e5 100644 --- a/tests/ui/coherence/coherence-overlap-negative-impls.rs +++ b/tests/ui/coherence/coherence-overlap-negative-impls.rs @@ -15,16 +15,20 @@ struct Test; trait Fold {} -impl Fold for Cons // 0 +impl Fold for Cons +// 0 where T: Fold, -{} +{ +} -impl Fold for Cons // 1 +impl Fold for Cons +// 1 where T: Fold, private::Is: private::NotNil, -{} +{ +} impl Fold for Test {} // 2 @@ -34,7 +38,6 @@ mod private { pub struct Is(T); pub auto trait NotNil {} - #[allow(suspicious_auto_trait_impls)] impl !NotNil for Is {} } diff --git a/tests/ui/issues/issue-106755.rs b/tests/ui/issues/issue-106755.rs index 40cb83fcabc..689b1d885ae 100644 --- a/tests/ui/issues/issue-106755.rs +++ b/tests/ui/issues/issue-106755.rs @@ -15,7 +15,5 @@ impl !Send for TestType {} //~ ERROR found both positive and nega unsafe impl Send for TestType {} //~ ERROR conflicting implementations impl !Send for TestType {} -//~^ WARNING -//~| WARNING this will change its meaning fn main() {} diff --git a/tests/ui/issues/issue-106755.stderr b/tests/ui/issues/issue-106755.stderr index 6b3a8427e77..54397034062 100644 --- a/tests/ui/issues/issue-106755.stderr +++ b/tests/ui/issues/issue-106755.stderr @@ -16,23 +16,7 @@ LL | unsafe impl Send for TestType {} LL | unsafe impl Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -warning: cross-crate traits with a default impl, like `Send`, should not be specialized - --> $DIR/issue-106755.rs:17:1 - | -LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this will change its meaning in a future release! - = note: for more information, see issue #93367 - = note: `i32` is not a generic parameter -note: try using the same sequence of generic parameters as the struct definition - --> $DIR/issue-106755.rs:9:1 - | -LL | struct TestType(::std::marker::PhantomData); - | ^^^^^^^^^^^^^^^^^^ - = note: `#[warn(suspicious_auto_trait_impls)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors Some errors have detailed explanations: E0119, E0751. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs index 3e15e28b8fd..ce0b60b6411 100644 --- a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs @@ -1,5 +1,4 @@ //@ aux-build:tdticc_coherence_lib.rs -#![allow(suspicious_auto_trait_impls)] // Test that we do not consider associated types to be sendable without // some applicable trait bound (and we don't ICE). @@ -11,15 +10,15 @@ extern crate tdticc_coherence_lib as lib; use lib::DefaultedTrait; struct A; -impl DefaultedTrait for (A,) { } //~ ERROR E0117 +impl DefaultedTrait for (A,) {} //~ ERROR E0117 struct B; -impl !DefaultedTrait for (B,) { } //~ ERROR E0117 +impl !DefaultedTrait for (B,) {} //~ ERROR E0117 struct C; struct D(T); -impl DefaultedTrait for Box { } //~ ERROR E0321 -impl DefaultedTrait for lib::Something { } //~ ERROR E0117 -impl DefaultedTrait for D { } // OK +impl DefaultedTrait for Box {} //~ ERROR E0321 +impl DefaultedTrait for lib::Something {} //~ ERROR E0117 +impl DefaultedTrait for D {} // OK -fn main() { } +fn main() {} diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr index fc3778b7967..32e6e88fc48 100644 --- a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -1,7 +1,7 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:14:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:13:1 | -LL | impl DefaultedTrait for (A,) { } +LL | impl DefaultedTrait for (A,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^---- | | | | | this is not defined in the current crate because tuples are always foreign @@ -10,9 +10,9 @@ LL | impl DefaultedTrait for (A,) { } = note: define and implement a trait or new type instead error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:17:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:16:1 | -LL | impl !DefaultedTrait for (B,) { } +LL | impl !DefaultedTrait for (B,) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^---- | | | | | this is not defined in the current crate because tuples are always foreign @@ -21,15 +21,15 @@ LL | impl !DefaultedTrait for (B,) { } = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can only be implemented for a struct/enum type defined in the current crate - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:20:1 | -LL | impl DefaultedTrait for Box { } +LL | impl DefaultedTrait for Box {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate - --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1 + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 | -LL | impl DefaultedTrait for lib::Something { } +LL | impl DefaultedTrait for lib::Something {} | ^^^^^^^^^^^^^^^^^^^^^^^^----------------- | | | | | `Something` is not defined in the current crate From 4803f173be0af812f8754c4d4e33c92436c8c4e6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 16 Feb 2024 23:12:20 -0300 Subject: [PATCH 3/3] Inline do_orphan_check_impl --- .../src/coherence/orphan.rs | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index faf676ddc09..07bbaa1926e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -18,25 +18,17 @@ pub(crate) fn orphan_check_impl( let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(); trait_ref.error_reported()?; - do_orphan_check_impl(tcx, trait_ref, impl_def_id) -} - -fn do_orphan_check_impl<'tcx>( - tcx: TyCtxt<'tcx>, - trait_ref: ty::TraitRef<'tcx>, - def_id: LocalDefId, -) -> Result<(), ErrorGuaranteed> { let trait_def_id = trait_ref.def_id; - match traits::orphan_check(tcx, def_id.to_def_id()) { + match traits::orphan_check(tcx, impl_def_id.to_def_id()) { Ok(()) => {} Err(err) => { - let item = tcx.hir().expect_item(def_id); + let item = tcx.hir().expect_item(impl_def_id); let hir::ItemKind::Impl(impl_) = item.kind else { - bug!("{:?} is not an impl: {:?}", def_id, item); + bug!("{:?} is not an impl: {:?}", impl_def_id, item); }; let tr = impl_.of_trait.as_ref().unwrap(); - let sp = tcx.def_span(def_id); + let sp = tcx.def_span(impl_def_id); emit_orphan_check_error( tcx, @@ -180,7 +172,7 @@ fn do_orphan_check_impl<'tcx>( // impl AutoTrait for T {} // impl AutoTrait for T {} ty::Param(..) => ( - if self_ty.is_sized(tcx, tcx.param_env(def_id)) { + if self_ty.is_sized(tcx, tcx.param_env(impl_def_id)) { LocalImpl::Allow } else { LocalImpl::Disallow { problematic_kind: "generic type" } @@ -237,7 +229,7 @@ fn do_orphan_check_impl<'tcx>( | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => { - let sp = tcx.def_span(def_id); + let sp = tcx.def_span(impl_def_id); span_bug!(sp, "weird self type for autotrait impl") } @@ -249,7 +241,7 @@ fn do_orphan_check_impl<'tcx>( LocalImpl::Allow => {} LocalImpl::Disallow { problematic_kind } => { return Err(tcx.dcx().emit_err(errors::TraitsWithDefaultImpl { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), problematic_kind, self_ty, @@ -261,13 +253,13 @@ fn do_orphan_check_impl<'tcx>( NonlocalImpl::Allow => {} NonlocalImpl::DisallowBecauseNonlocal => { return Err(tcx.dcx().emit_err(errors::CrossCrateTraitsDefined { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), })); } NonlocalImpl::DisallowOther => { return Err(tcx.dcx().emit_err(errors::CrossCrateTraits { - span: tcx.def_span(def_id), + span: tcx.def_span(impl_def_id), traits: tcx.def_path_str(trait_def_id), self_ty, }));