From efbdc5b7fa10d078c698c9a6cfbb13f467050dfa Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 14:48:37 +0100 Subject: [PATCH 01/21] Initial impl of `lint_useless_send_constraint` Does not yet handle `Send` being only constraint (will still recommend removing it) --- compiler/rustc_lint/messages.ftl | 3 ++ compiler/rustc_lint/src/builtin.rs | 52 ++++++++++++++++++++++++++++++ compiler/rustc_lint/src/lints.rs | 8 +++++ 3 files changed, 63 insertions(+) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 3c6dbb466db7a..592001641916c 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -192,6 +192,9 @@ lint_redundant_semicolons = *[false] this semicolon } +lint_useless_send_constraint = + constraining a reference to `Send` is useless, consider removing it + lint_drop_trait_constraints = bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index aeb791901bd23..e38b85b0dd9aa 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -21,6 +21,7 @@ //! `late_lint_methods!` invocation in `lib.rs`. use crate::fluent_generated as fluent; +use crate::lints::UselessSendConstraintDiag; use crate::{ errors::BuiltinEllipsisInclusiveRangePatterns, lints::{ @@ -3320,3 +3321,54 @@ impl EarlyLintPass for UnexpectedCfgs { } } } + +declare_lint! { + /// The `lint_useless_send_constraint` lints useless constraint of references to `Send`. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// fn foo(_: &(dyn Any + Send>) {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// References cannot be sent across threads, so constraining them to `Send` is useless. + USELESS_SEND_CONSTRAINT, + Warn, + "constraining a reference to `Send` is useless, consider removing it" +} + +declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); + +impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { + fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { + let hir::TyKind::Ref(_, hir::MutTy { ty, mutbl: _mutbl }) = ty.kind else { return; }; + + let hir::TyKind::TraitObject(bounds, _, _) = ty.kind else { return; }; + + let send = cx.tcx.get_diagnostic_item(sym::Send); + + if bounds.iter().any(|b| b.trait_ref.trait_def_id() == send) { + if bounds.len() == 1 { + // We have a single bound, and it's `Send`. + // Suggest changing it to Any + cx.emit_spanned_lint( + USELESS_SEND_CONSTRAINT, + ty.span, + UselessSendConstraintDiag { suggestion: ty.span } + ) + } else { + // We have multiple bounds. one is `Send` + // Suggest removing it + cx.emit_spanned_lint( + USELESS_SEND_CONSTRAINT, + ty.span, + UselessSendConstraintDiag { suggestion: ty.span } + ) + } + } + } +} diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 848f6a9ecb532..16bf64f78091b 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1168,6 +1168,14 @@ pub struct RedundantSemicolonsDiag { pub suggestion: Span, } +// redundant_semicolon.rs +#[derive(LintDiagnostic)] +#[diag(lint_useless_send_constraint)] +pub struct UselessSendConstraintDiag { + #[suggestion(code = "", applicability = "maybe-incorrect")] + pub suggestion: Span, +} + // traits.rs pub struct DropTraitConstraintsDiag<'a> { pub predicate: Predicate<'a>, From 532368c768d132c7b2842779a3037deed3b735ae Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 15:10:07 +0100 Subject: [PATCH 02/21] Fixes --- compiler/rustc_lint/messages.ftl | 9 +++++- compiler/rustc_lint/src/builtin.rs | 30 ++++++++----------- compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint/src/lints.rs | 1 + .../useless-send-constraint.rs | 10 +++++++ 5 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 tests/ui/lint/useless-send-constraint/useless-send-constraint.rs diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 592001641916c..971b0192b5970 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -193,7 +193,14 @@ lint_redundant_semicolons = } lint_useless_send_constraint = - constraining a reference to `Send` is useless, consider removing it + constraining a reference to `Send` is useless, consider {$only_trait -> + [true] replacing it with `Any` + *[false] removing it + } + .suggestion = {$only_trait -> + [true] replace this with `Any` + *[false] remove this + } lint_drop_trait_constraints = bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index e38b85b0dd9aa..bfc73ea6fbb1c 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -3351,24 +3351,18 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { let send = cx.tcx.get_diagnostic_item(sym::Send); - if bounds.iter().any(|b| b.trait_ref.trait_def_id() == send) { - if bounds.len() == 1 { - // We have a single bound, and it's `Send`. - // Suggest changing it to Any - cx.emit_spanned_lint( - USELESS_SEND_CONSTRAINT, - ty.span, - UselessSendConstraintDiag { suggestion: ty.span } - ) - } else { - // We have multiple bounds. one is `Send` - // Suggest removing it - cx.emit_spanned_lint( - USELESS_SEND_CONSTRAINT, - ty.span, - UselessSendConstraintDiag { suggestion: ty.span } - ) - } + let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); + + if let Some(send_bound) = send_bound { + let only_trait = bounds.len() == 1; + + // We have multiple bounds. one is `Send` + // Suggest removing it + cx.emit_spanned_lint( + USELESS_SEND_CONSTRAINT, + send_bound.span, + UselessSendConstraintDiag { only_trait, suggestion: send_bound.span } + ) } } } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 319eb2ea445ed..2d4641e0a7bee 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -242,6 +242,7 @@ late_lint_methods!( OpaqueHiddenInferredBound: OpaqueHiddenInferredBound, MultipleSupertraitUpcastable: MultipleSupertraitUpcastable, MapUnitFn: MapUnitFn, + UselessSendConstraint: UselessSendConstraint, ] ] ); diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 16bf64f78091b..3f326c6909523 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1172,6 +1172,7 @@ pub struct RedundantSemicolonsDiag { #[derive(LintDiagnostic)] #[diag(lint_useless_send_constraint)] pub struct UselessSendConstraintDiag { + pub only_trait: bool, #[suggestion(code = "", applicability = "maybe-incorrect")] pub suggestion: Span, } diff --git a/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs b/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs new file mode 100644 index 0000000000000..364c172920c1f --- /dev/null +++ b/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs @@ -0,0 +1,10 @@ +// check-pass +#![warn(useless_send_constraint)] + +use std::any::Any; + +fn main() {} + +fn foo(_a: &(dyn Any + Send + Send)) { + +} From 6ed01d9e09b232460b51ebb6d22c2af9346955f2 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:17:13 +0100 Subject: [PATCH 03/21] Trait test and edge case handling --- compiler/rustc_lint/src/builtin.rs | 45 ------------------- compiler/rustc_lint/src/lints.rs | 2 +- .../rustc_lint/src/useless_send_constraint.rs | 44 ++++++++++++++++++ library/core/src/cell.rs | 1 + 4 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 compiler/rustc_lint/src/useless_send_constraint.rs diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index bfc73ea6fbb1c..e748be92b8d39 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -3321,48 +3321,3 @@ impl EarlyLintPass for UnexpectedCfgs { } } } - -declare_lint! { - /// The `lint_useless_send_constraint` lints useless constraint of references to `Send`. - /// - /// ### Example - /// - /// ```rust,compile_fail - /// fn foo(_: &(dyn Any + Send>) {} - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// References cannot be sent across threads, so constraining them to `Send` is useless. - USELESS_SEND_CONSTRAINT, - Warn, - "constraining a reference to `Send` is useless, consider removing it" -} - -declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); - -impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { - fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { - let hir::TyKind::Ref(_, hir::MutTy { ty, mutbl: _mutbl }) = ty.kind else { return; }; - - let hir::TyKind::TraitObject(bounds, _, _) = ty.kind else { return; }; - - let send = cx.tcx.get_diagnostic_item(sym::Send); - - let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); - - if let Some(send_bound) = send_bound { - let only_trait = bounds.len() == 1; - - // We have multiple bounds. one is `Send` - // Suggest removing it - cx.emit_spanned_lint( - USELESS_SEND_CONSTRAINT, - send_bound.span, - UselessSendConstraintDiag { only_trait, suggestion: send_bound.span } - ) - } - } -} diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 3f326c6909523..be98684f46ff5 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1168,7 +1168,7 @@ pub struct RedundantSemicolonsDiag { pub suggestion: Span, } -// redundant_semicolon.rs +// lint_useless_send_constraint.rs #[derive(LintDiagnostic)] #[diag(lint_useless_send_constraint)] pub struct UselessSendConstraintDiag { diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs new file mode 100644 index 0000000000000..776cc40a25eff --- /dev/null +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -0,0 +1,44 @@ +declare_lint! { + /// The `lint_useless_send_constraint` lints useless constraint of references to `Send`. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// fn foo(_: &(dyn Any + Send>) {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// References cannot be sent across threads, so constraining them to `Send` is useless. + pub USELESS_SEND_CONSTRAINT, + Warn, + "constraining a reference to `Send` is useless, consider removing it" +} + +declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); + +impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { + fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { + let hir::TyKind::Ref(_, hir::MutTy { ty, mutbl: _mutbl }) = ty.kind else { return; }; + + let hir::TyKind::TraitObject(bounds, _, _) = ty.kind else { return; }; + + let send = cx.tcx.get_diagnostic_item(sym::Send); + + let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); + + if let Some(send_bound) = send_bound { + let only_trait = bounds.len() == 1; + + // We have multiple bounds. one is `Send` + // Suggest removing it + cx.emit_spanned_lint( + USELESS_SEND_CONSTRAINT, + send_bound.span, + UselessSendConstraintDiag { only_trait, suggestion: send_bound.span } + ) + } + } +} diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index bcca8d924cdd6..c604c6b174b0d 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -2246,6 +2246,7 @@ impl, U> CoerceUnsized> for SyncUnsafeCell impl, U> DispatchFromDyn> for SyncUnsafeCell {} #[allow(unused)] +#[allow(useless_send_constraint)] fn assert_coerce_unsized( a: UnsafeCell<&i32>, b: SyncUnsafeCell<&i32>, From a00fd676ded497228c08bfe5df2e074877e730c9 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:17:52 +0100 Subject: [PATCH 04/21] fmt --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 776cc40a25eff..b996a014131cc 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { cx.emit_spanned_lint( USELESS_SEND_CONSTRAINT, send_bound.span, - UselessSendConstraintDiag { only_trait, suggestion: send_bound.span } + UselessSendConstraintDiag { only_trait, suggestion: send_bound.span }, ) } } From 30af6f089161b3a158ffab909ee77f6c3761b4dd Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:21:32 +0100 Subject: [PATCH 05/21] WIP tests --- .../useless-send-constraint/useless-send-constraint.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs b/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs index 364c172920c1f..469e62c6de3cf 100644 --- a/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs +++ b/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs @@ -1,10 +1,13 @@ -// check-pass #![warn(useless_send_constraint)] use std::any::Any; fn main() {} -fn foo(_a: &(dyn Any + Send + Send)) { +fn fine(_a: &dyn Any) {} -} +fn should_replace_with_any(_a: &(dyn Send)) {} + +fn should_remove_send(_a: &(dyn Any + Send)) {} + +fn should_remove_send_duplicate(_a: &(dyn Any + Send)) {} From cd7bff1b99cf759408531b1a5da63f1b50625a62 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:35:24 +0100 Subject: [PATCH 06/21] Comment round #1 --- compiler/rustc_lint/src/builtin.rs | 1 - compiler/rustc_lint/src/useless_send_constraint.rs | 13 ++++++++++--- library/core/src/cell.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index e748be92b8d39..aeb791901bd23 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -21,7 +21,6 @@ //! `late_lint_methods!` invocation in `lib.rs`. use crate::fluent_generated as fluent; -use crate::lints::UselessSendConstraintDiag; use crate::{ errors::BuiltinEllipsisInclusiveRangePatterns, lints::{ diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index b996a014131cc..22f86b96a63c9 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -21,9 +21,16 @@ declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { - let hir::TyKind::Ref(_, hir::MutTy { ty, mutbl: _mutbl }) = ty.kind else { return; }; - - let hir::TyKind::TraitObject(bounds, _, _) = ty.kind else { return; }; + let hir::TyKind::Ref( + _, + hir::MutTy { + ty: hir::Ty { + kind: hir::TyKind::TraitObject(bounds, ..) + .. + }, + .. + } + ) = ty.kind else { return; }; let send = cx.tcx.get_diagnostic_item(sym::Send); diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index c604c6b174b0d..149ae55af22a6 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -2246,7 +2246,7 @@ impl, U> CoerceUnsized> for SyncUnsafeCell impl, U> DispatchFromDyn> for SyncUnsafeCell {} #[allow(unused)] -#[allow(useless_send_constraint)] +#[cfg_attr(not(bootstrap), allow(useless_send_constraint))] fn assert_coerce_unsized( a: UnsafeCell<&i32>, b: SyncUnsafeCell<&i32>, From cb9086bec48b0ccab75a8978949bc6b3472460ac Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:35:33 +0100 Subject: [PATCH 07/21] Comment round #1 --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 22f86b96a63c9..dddc157550e47 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -25,7 +25,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { _, hir::MutTy { ty: hir::Ty { - kind: hir::TyKind::TraitObject(bounds, ..) + kind: hir::TyKind::TraitObject(bounds, ..), .. }, .. From cef8a0fd2aa451ae489c45877e71d29fc1d63554 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:42:08 +0100 Subject: [PATCH 08/21] Remove comment --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index dddc157550e47..5beb213be4cea 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -39,8 +39,6 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { if let Some(send_bound) = send_bound { let only_trait = bounds.len() == 1; - // We have multiple bounds. one is `Send` - // Suggest removing it cx.emit_spanned_lint( USELESS_SEND_CONSTRAINT, send_bound.span, From c16b47452f12ca7e40c4b4c84db4b25ba7cd05d0 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 20:49:03 +0100 Subject: [PATCH 09/21] Compiling except for the actual lint --- compiler/rustc_lint/src/lib.rs | 2 ++ compiler/rustc_lint/src/useless_send_constraint.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 2d4641e0a7bee..e3caf63bc56ae 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -74,6 +74,7 @@ mod opaque_hidden_inferred_bound; mod pass_by_value; mod passes; mod redundant_semicolon; +mod useless_send_constraint; mod traits; mod types; mod unused; @@ -125,6 +126,7 @@ pub use passes::{EarlyLintPass, LateLintPass}; pub use rustc_session::lint::Level::{self, *}; pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId}; pub use rustc_session::lint::{LintArray, LintPass}; +use useless_send_constraint::UselessSendConstraint; fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 5beb213be4cea..ab953b5b3cd93 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -1,3 +1,9 @@ +use rustc_span::sym; + +use crate::hir; + +use crate::{lints::UselessSendConstraintDiag, LateContext, LateLintPass}; + declare_lint! { /// The `lint_useless_send_constraint` lints useless constraint of references to `Send`. /// @@ -39,8 +45,9 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { if let Some(send_bound) = send_bound { let only_trait = bounds.len() == 1; - cx.emit_spanned_lint( + cx.tcx.emit_spanned_lint( USELESS_SEND_CONSTRAINT, + send_bound.trait_ref.hir_ref_id, // is this correct? send_bound.span, UselessSendConstraintDiag { only_trait, suggestion: send_bound.span }, ) From ebf545fecc9a1a5670f7055d47be881b3196ad64 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 21:00:09 +0100 Subject: [PATCH 10/21] Remove comment --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 +- library/core/src/panic.rs | 2 +- library/core/src/panic/panic_info.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index ab953b5b3cd93..6037b2e3943fe 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -34,7 +34,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { kind: hir::TyKind::TraitObject(bounds, ..), .. }, - .. + mutbl: hir::Mutability::Not, // only immutable references } ) = ty.kind else { return; }; diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index 8338a5d7e5a21..1cf9b5e937181 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -107,5 +107,5 @@ pub unsafe trait BoxMeUp { fn take_box(&mut self) -> *mut (dyn Any + Send); /// Just borrow the contents. - fn get(&mut self) -> &(dyn Any + Send); + fn get(&mut self) -> &dyn Any; } diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs index 06fbe083ca13d..f95ca251118aa 100644 --- a/library/core/src/panic/panic_info.rs +++ b/library/core/src/panic/panic_info.rs @@ -24,7 +24,7 @@ use crate::panic::Location; #[stable(feature = "panic_hooks", since = "1.10.0")] #[derive(Debug)] pub struct PanicInfo<'a> { - payload: &'a (dyn Any + Send), + payload: &'a dyn Any, message: Option<&'a fmt::Arguments<'a>>, location: &'a Location<'a>, can_unwind: bool, @@ -54,7 +54,7 @@ impl<'a> PanicInfo<'a> { )] #[doc(hidden)] #[inline] - pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) { + pub fn set_payload(&mut self, info: &'a dyn Any) { self.payload = info; } @@ -81,7 +81,7 @@ impl<'a> PanicInfo<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn payload(&self) -> &(dyn Any + Send) { + pub fn payload(&self) -> &dyn Any { self.payload } From 657ec633cdde254b77e07d9b228a98ee53ce1569 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Fri, 28 Apr 2023 23:59:32 +0100 Subject: [PATCH 11/21] Remove uses of send --- library/core/src/any.rs | 4 ++-- library/std/src/io/error.rs | 2 +- library/std/src/panicking.rs | 10 +++++----- library/test/src/test_result.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index bb93ea509d8ee..3f7402d306cf4 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -398,7 +398,7 @@ impl dyn Any + Send { /// ``` /// use std::any::Any; /// - /// fn is_string(s: &(dyn Any + Send)) { + /// fn is_string(s: &dyn Any) { /// if s.is::() { /// println!("It's a string!"); /// } else { @@ -422,7 +422,7 @@ impl dyn Any + Send { /// ``` /// use std::any::Any; /// - /// fn print_if_string(s: &(dyn Any + Send)) { + /// fn print_if_string(s: &dyn Any) { /// if let Some(string) = s.downcast_ref::() { /// println!("It's a string({}): '{}'", string.len(), string); /// } else { diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 34c0ce9dcf848..a19be676abe1c 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -695,7 +695,7 @@ impl Error { #[stable(feature = "io_error_inner", since = "1.3.0")] #[must_use] #[inline] - pub fn get_ref(&self) -> Option<&(dyn error::Error + Send + Sync + 'static)> { + pub fn get_ref(&self) -> Option<&(dyn error::Error + Sync + 'static)> { match self.repr.data() { ErrorData::Os(..) => None, ErrorData::Simple(..) => None, diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index a46a29cbad608..c3b25d11b9061 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -220,7 +220,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { #[unstable(feature = "panic_update_hook", issue = "92649")] pub fn update_hook(hook_fn: F) where - F: Fn(&(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), &PanicInfo<'_>) + F: Fn(&(dyn Fn(&PanicInfo<'_>) + Sync + 'static), &PanicInfo<'_>) + Sync + Send + 'static, @@ -556,7 +556,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { Box::into_raw(Box::new(contents)) } - fn get(&mut self) -> &(dyn Any + Send) { + fn get(&mut self) -> &dyn Any { self.fill() } } @@ -568,7 +568,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { Box::into_raw(Box::new(self.0)) } - fn get(&mut self) -> &(dyn Any + Send) { + fn get(&mut self) -> &dyn Any { &self.0 } } @@ -635,7 +635,7 @@ pub const fn begin_panic(msg: M) -> ! { Box::into_raw(data) } - fn get(&mut self) -> &(dyn Any + Send) { + fn get(&mut self) -> &dyn Any { match self.inner { Some(ref a) => a, None => process::abort(), @@ -725,7 +725,7 @@ pub fn rust_panic_without_hook(payload: Box) -> ! { Box::into_raw(mem::replace(&mut self.0, Box::new(()))) } - fn get(&mut self) -> &(dyn Any + Send) { + fn get(&mut self) -> &dyn Any { &*self.0 } } diff --git a/library/test/src/test_result.rs b/library/test/src/test_result.rs index 1da238e3e8c0f..c0cfd196d8845 100644 --- a/library/test/src/test_result.rs +++ b/library/test/src/test_result.rs @@ -27,7 +27,7 @@ pub enum TestResult { /// and associated data. pub fn calc_result<'a>( desc: &TestDesc, - task_result: Result<(), &'a (dyn Any + 'static + Send)>, + task_result: Result<(), &'a (dyn Any + 'static)>, time_opts: &Option, exec_time: &Option, ) -> TestResult { From 2321cb176505220150489b93c8214cbbffed941b Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sat, 29 Apr 2023 08:41:49 +0100 Subject: [PATCH 12/21] Comments --- compiler/rustc_lint/messages.ftl | 2 +- compiler/rustc_lint/src/useless_send_constraint.rs | 7 ++++--- library/core/src/panicking.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 971b0192b5970..7388bda60ca51 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -193,7 +193,7 @@ lint_redundant_semicolons = } lint_useless_send_constraint = - constraining a reference to `Send` is useless, consider {$only_trait -> + constraining a reference to `Send` without `Sync` is useless, consider {$only_trait -> [true] replacing it with `Any` *[false] removing it } diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 6037b2e3943fe..584bbbf3ccb9e 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -17,10 +17,10 @@ declare_lint! { /// /// ### Explanation /// - /// References cannot be sent across threads, so constraining them to `Send` is useless. + /// References cannot be sent across threads unless thay have a `Sync` bound, so constraining them to `Send` without `Sync` is useless. pub USELESS_SEND_CONSTRAINT, Warn, - "constraining a reference to `Send` is useless, consider removing it" + "constraining a reference to `Send` without `Sync` is useless, consider removing it" } declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); @@ -39,10 +39,11 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { ) = ty.kind else { return; }; let send = cx.tcx.get_diagnostic_item(sym::Send); + let sync = cx.tcx.get_diagnostic_item(sym::Sync); let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); - if let Some(send_bound) = send_bound { + if let Some(send_bound) = send_bound && sync.is_none() { let only_trait = bounds.len() == 1; cx.tcx.emit_spanned_lint( diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index efeb726ab8eb8..3ca81b70a69aa 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -11,7 +11,7 @@ //! ``` //! //! This definition allows for panicking with any general message, but it does not -//! allow for failing with a `Box` value. (`PanicInfo` just contains a `&(dyn Any + Send)`, +//! allow for failing with a `Box` value. (`PanicInfo` just contains a `&dyn Any`, //! for which we fill in a dummy value in `PanicInfo::internal_constructor`.) //! The reason for this is that core is not allowed to allocate. //! From b914451e0fb2397ec70ce6e5b1cacd1a79b58324 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sat, 29 Apr 2023 08:51:20 +0100 Subject: [PATCH 13/21] Style --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 584bbbf3ccb9e..1966af74fe116 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -28,7 +28,6 @@ declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { let hir::TyKind::Ref( - _, hir::MutTy { ty: hir::Ty { kind: hir::TyKind::TraitObject(bounds, ..), @@ -36,6 +35,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { }, mutbl: hir::Mutability::Not, // only immutable references } + .., ) = ty.kind else { return; }; let send = cx.tcx.get_diagnostic_item(sym::Send); From 72adaec92a77961749d87f561b5d0587cd32c80b Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sat, 29 Apr 2023 08:57:27 +0100 Subject: [PATCH 14/21] Fix sync behaviour --- compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_lint/src/useless_send_constraint.rs | 7 ++++--- library/std/src/panicking.rs | 5 +---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index e3caf63bc56ae..ef1b5b660a0f4 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -74,10 +74,10 @@ mod opaque_hidden_inferred_bound; mod pass_by_value; mod passes; mod redundant_semicolon; -mod useless_send_constraint; mod traits; mod types; mod unused; +mod useless_send_constraint; pub use array_into_iter::ARRAY_INTO_ITER; diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 1966af74fe116..441a291cc497d 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -34,16 +34,17 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { .. }, mutbl: hir::Mutability::Not, // only immutable references - } - .., + }, + .. ) = ty.kind else { return; }; let send = cx.tcx.get_diagnostic_item(sym::Send); let sync = cx.tcx.get_diagnostic_item(sym::Sync); let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); + let sync_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == sync); - if let Some(send_bound) = send_bound && sync.is_none() { + if let Some(send_bound) = send_bound && sync_bound.is_none() { let only_trait = bounds.len() == 1; cx.tcx.emit_spanned_lint( diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index c3b25d11b9061..c3a4fbf2154c5 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -220,10 +220,7 @@ pub fn take_hook() -> Box) + 'static + Sync + Send> { #[unstable(feature = "panic_update_hook", issue = "92649")] pub fn update_hook(hook_fn: F) where - F: Fn(&(dyn Fn(&PanicInfo<'_>) + Sync + 'static), &PanicInfo<'_>) - + Sync - + Send - + 'static, + F: Fn(&(dyn Fn(&PanicInfo<'_>) + Sync + 'static), &PanicInfo<'_>) + Sync + Send + 'static, { if thread::panicking() { panic!("cannot modify the panic hook from a panicking thread"); From 63b0988aacd68dd629abecf3af32074a70e21119 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sat, 29 Apr 2023 15:14:19 +0100 Subject: [PATCH 15/21] Update compiler/rustc_lint/src/useless_send_constraint.rs Co-authored-by: est31 --- compiler/rustc_lint/src/useless_send_constraint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index 441a291cc497d..cbc7b10c5649c 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -17,7 +17,7 @@ declare_lint! { /// /// ### Explanation /// - /// References cannot be sent across threads unless thay have a `Sync` bound, so constraining them to `Send` without `Sync` is useless. + /// References cannot be sent across threads unless they have a `Sync` bound, so constraining them to `Send` without `Sync` is useless. pub USELESS_SEND_CONSTRAINT, Warn, "constraining a reference to `Send` without `Sync` is useless, consider removing it" From 430e1dbab0c1119a363cbf8d12e0ff6f6f5e61e1 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sun, 30 Apr 2023 12:13:27 +0100 Subject: [PATCH 16/21] Voila --- compiler/rustc_lint/messages.ftl | 8 ++------ compiler/rustc_lint/src/useless_send_constraint.rs | 13 +++++++------ library/std/src/io/error.rs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 7388bda60ca51..f0c3dac24ae2f 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -192,13 +192,9 @@ lint_redundant_semicolons = *[false] this semicolon } -lint_useless_send_constraint = - constraining a reference to `Send` without `Sync` is useless, consider {$only_trait -> - [true] replacing it with `Any` - *[false] removing it - } +lint_useless_send_constraint = constraining a reference to `Send` is meaningless .suggestion = {$only_trait -> - [true] replace this with `Any` + [true] replace this with `std::any::Any` *[false] remove this } diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index cbc7b10c5649c..d56d264c1c84a 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -28,30 +28,31 @@ declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { let hir::TyKind::Ref( + .., hir::MutTy { ty: hir::Ty { kind: hir::TyKind::TraitObject(bounds, ..), .. }, - mutbl: hir::Mutability::Not, // only immutable references + .. }, - .. ) = ty.kind else { return; }; let send = cx.tcx.get_diagnostic_item(sym::Send); - let sync = cx.tcx.get_diagnostic_item(sym::Sync); let send_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == send); - let sync_bound = bounds.iter().find(|b| b.trait_ref.trait_def_id() == sync); - if let Some(send_bound) = send_bound && sync_bound.is_none() { + if let Some(send_bound) = send_bound { let only_trait = bounds.len() == 1; cx.tcx.emit_spanned_lint( USELESS_SEND_CONSTRAINT, send_bound.trait_ref.hir_ref_id, // is this correct? send_bound.span, - UselessSendConstraintDiag { only_trait, suggestion: send_bound.span }, + UselessSendConstraintDiag { + only_trait, + suggestion: send_bound.span, + }, ) } } diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index a19be676abe1c..107a48bcb655f 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -769,7 +769,7 @@ impl Error { #[stable(feature = "io_error_inner", since = "1.3.0")] #[must_use] #[inline] - pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)> { + pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Sync + 'static)> { match self.repr.data_mut() { ErrorData::Os(..) => None, ErrorData::Simple(..) => None, From 8e0274954489a93a443f47aee378949e60fcf82c Mon Sep 17 00:00:00 2001 From: John Kelly Date: Sun, 30 Apr 2023 12:14:38 +0100 Subject: [PATCH 17/21] Update useless_send_constraint.rs --- compiler/rustc_lint/src/useless_send_constraint.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/useless_send_constraint.rs index d56d264c1c84a..ddc5809791cdf 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/useless_send_constraint.rs @@ -49,10 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { USELESS_SEND_CONSTRAINT, send_bound.trait_ref.hir_ref_id, // is this correct? send_bound.span, - UselessSendConstraintDiag { - only_trait, - suggestion: send_bound.span, - }, + UselessSendConstraintDiag { only_trait, suggestion: send_bound.span }, ) } } From e9fe48c919e956df18df17b52d667e103051ecdb Mon Sep 17 00:00:00 2001 From: John Kelly Date: Tue, 2 May 2023 18:08:33 +0100 Subject: [PATCH 18/21] Comments --- compiler/rustc_lint/messages.ftl | 2 +- compiler/rustc_lint/src/lib.rs | 4 ++-- ...raint.rs => unnecessary_send_constraint.rs} | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) rename compiler/rustc_lint/src/{useless_send_constraint.rs => unnecessary_send_constraint.rs} (65%) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index f0c3dac24ae2f..396b2cefa81c3 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -192,7 +192,7 @@ lint_redundant_semicolons = *[false] this semicolon } -lint_useless_send_constraint = constraining a reference to `Send` is meaningless +lint_unnecessary_send_constraint = constraining a reference to `Send` is meaningless .suggestion = {$only_trait -> [true] replace this with `std::any::Any` *[false] remove this diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index ef1b5b660a0f4..2306799ec3819 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -77,7 +77,7 @@ mod redundant_semicolon; mod traits; mod types; mod unused; -mod useless_send_constraint; +mod unnecessary_send_constraint; pub use array_into_iter::ARRAY_INTO_ITER; @@ -126,7 +126,7 @@ pub use passes::{EarlyLintPass, LateLintPass}; pub use rustc_session::lint::Level::{self, *}; pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId}; pub use rustc_session::lint::{LintArray, LintPass}; -use useless_send_constraint::UselessSendConstraint; +use unnecessary_send_constraint::UselessSendConstraint; fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_lint/src/useless_send_constraint.rs b/compiler/rustc_lint/src/unnecessary_send_constraint.rs similarity index 65% rename from compiler/rustc_lint/src/useless_send_constraint.rs rename to compiler/rustc_lint/src/unnecessary_send_constraint.rs index ddc5809791cdf..2477dc41aea43 100644 --- a/compiler/rustc_lint/src/useless_send_constraint.rs +++ b/compiler/rustc_lint/src/unnecessary_send_constraint.rs @@ -2,10 +2,10 @@ use rustc_span::sym; use crate::hir; -use crate::{lints::UselessSendConstraintDiag, LateContext, LateLintPass}; +use crate::{lints::UnnecessarySendConstraintDiag, LateContext, LateLintPass}; declare_lint! { - /// The `lint_useless_send_constraint` lints useless constraint of references to `Send`. + /// The `lint_unnecessary_send_constraint` lints unnecessary constraint of references to `Send`. /// /// ### Example /// @@ -17,15 +17,15 @@ declare_lint! { /// /// ### Explanation /// - /// References cannot be sent across threads unless they have a `Sync` bound, so constraining them to `Send` without `Sync` is useless. - pub USELESS_SEND_CONSTRAINT, + /// References cannot be sent across threads unless they have a `Sync` bound, so constraining them to `Send` without `Sync` is unnecessary. + pub UNNECESSARY_SEND_CONSTRAINT, Warn, - "constraining a reference to `Send` without `Sync` is useless, consider removing it" + "constraining a reference to `Send` without `Sync` is unnecessary, consider removing it" } -declare_lint_pass!(UselessSendConstraint => [USELESS_SEND_CONSTRAINT]); +declare_lint_pass!(UnnecessarySendConstraint => [UNNECESSARY_SEND_CONSTRAINT]); -impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { +impl<'tcx> LateLintPass<'tcx> for UnnecessarySendConstraint { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'tcx>) { let hir::TyKind::Ref( .., @@ -46,10 +46,10 @@ impl<'tcx> LateLintPass<'tcx> for UselessSendConstraint { let only_trait = bounds.len() == 1; cx.tcx.emit_spanned_lint( - USELESS_SEND_CONSTRAINT, + UNNECESSARY_SEND_CONSTRAINT, send_bound.trait_ref.hir_ref_id, // is this correct? send_bound.span, - UselessSendConstraintDiag { only_trait, suggestion: send_bound.span }, + UnnecessarySendConstraintDiag { only_trait, suggestion: send_bound.span }, ) } } From b02fdd2835d6c248e21cb22df861df76e6dc252c Mon Sep 17 00:00:00 2001 From: John Kelly Date: Tue, 2 May 2023 18:09:25 +0100 Subject: [PATCH 19/21] fmt --- compiler/rustc_lint/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 2306799ec3819..db1f99b700473 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -76,8 +76,8 @@ mod passes; mod redundant_semicolon; mod traits; mod types; -mod unused; mod unnecessary_send_constraint; +mod unused; pub use array_into_iter::ARRAY_INTO_ITER; From 7083a317997a48f78b28aff82d6982d78205a80a Mon Sep 17 00:00:00 2001 From: John Kelly Date: Tue, 2 May 2023 18:11:02 +0100 Subject: [PATCH 20/21] renaming --- compiler/rustc_lint/src/lib.rs | 4 ++-- compiler/rustc_lint/src/lints.rs | 6 +++--- library/core/src/cell.rs | 2 +- .../unnecessary-send-constraint.rs} | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename tests/ui/lint/{useless-send-constraint/useless-send-constraint.rs => unnecessary-send-constraint/unnecessary-send-constraint.rs} (85%) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index db1f99b700473..a555d8b8aafa4 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -126,7 +126,7 @@ pub use passes::{EarlyLintPass, LateLintPass}; pub use rustc_session::lint::Level::{self, *}; pub use rustc_session::lint::{BufferedEarlyLint, FutureIncompatibleInfo, Lint, LintId}; pub use rustc_session::lint::{LintArray, LintPass}; -use unnecessary_send_constraint::UselessSendConstraint; +use unnecessary_send_constraint::UnnecessarySendConstraint; fluent_messages! { "../messages.ftl" } @@ -244,7 +244,7 @@ late_lint_methods!( OpaqueHiddenInferredBound: OpaqueHiddenInferredBound, MultipleSupertraitUpcastable: MultipleSupertraitUpcastable, MapUnitFn: MapUnitFn, - UselessSendConstraint: UselessSendConstraint, + UnnecessarySendConstraint: UnnecessarySendConstraint, ] ] ); diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index be98684f46ff5..7e18d2dd0e938 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1168,10 +1168,10 @@ pub struct RedundantSemicolonsDiag { pub suggestion: Span, } -// lint_useless_send_constraint.rs +// lint_unnecessary_send_constraint.rs #[derive(LintDiagnostic)] -#[diag(lint_useless_send_constraint)] -pub struct UselessSendConstraintDiag { +#[diag(lint_unnecessary_send_constraint)] +pub struct UnnecessarySendConstraintDiag { pub only_trait: bool, #[suggestion(code = "", applicability = "maybe-incorrect")] pub suggestion: Span, diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 149ae55af22a6..8031052b90061 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -2246,7 +2246,7 @@ impl, U> CoerceUnsized> for SyncUnsafeCell impl, U> DispatchFromDyn> for SyncUnsafeCell {} #[allow(unused)] -#[cfg_attr(not(bootstrap), allow(useless_send_constraint))] +#[cfg_attr(not(bootstrap), allow(unnecessary_send_constraint))] fn assert_coerce_unsized( a: UnsafeCell<&i32>, b: SyncUnsafeCell<&i32>, diff --git a/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs b/tests/ui/lint/unnecessary-send-constraint/unnecessary-send-constraint.rs similarity index 85% rename from tests/ui/lint/useless-send-constraint/useless-send-constraint.rs rename to tests/ui/lint/unnecessary-send-constraint/unnecessary-send-constraint.rs index 469e62c6de3cf..f6484a41c1f04 100644 --- a/tests/ui/lint/useless-send-constraint/useless-send-constraint.rs +++ b/tests/ui/lint/unnecessary-send-constraint/unnecessary-send-constraint.rs @@ -1,4 +1,4 @@ -#![warn(useless_send_constraint)] +#![warn(unnecessary_send_constraint)] use std::any::Any; From df19546bf7d62a45ae6287590691127f29706b24 Mon Sep 17 00:00:00 2001 From: John Kelly Date: Thu, 31 Aug 2023 14:17:58 +0100 Subject: [PATCH 21/21] Address review comments --- compiler/rustc_lint/src/unnecessary_send_constraint.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_lint/src/unnecessary_send_constraint.rs b/compiler/rustc_lint/src/unnecessary_send_constraint.rs index 2477dc41aea43..40395869843a4 100644 --- a/compiler/rustc_lint/src/unnecessary_send_constraint.rs +++ b/compiler/rustc_lint/src/unnecessary_send_constraint.rs @@ -5,19 +5,20 @@ use crate::hir; use crate::{lints::UnnecessarySendConstraintDiag, LateContext, LateLintPass}; declare_lint! { - /// The `lint_unnecessary_send_constraint` lints unnecessary constraint of references to `Send`. + /// The `unnecessary_send_constraint` lints unnecessary constraint of references to `Send`. /// /// ### Example /// /// ```rust,compile_fail - /// fn foo(_: &(dyn Any + Send>) {} + /// #[deny(unnecessary_send_constraint)] + /// fn foo(_: &(dyn Any + Send)) {} /// ``` /// /// {{produces}} /// /// ### Explanation /// - /// References cannot be sent across threads unless they have a `Sync` bound, so constraining them to `Send` without `Sync` is unnecessary. + /// Shared references cannot be sent across threads unless they have a `Sync` bound, so constraining them to `Send` without `Sync` is unnecessary. pub UNNECESSARY_SEND_CONSTRAINT, Warn, "constraining a reference to `Send` without `Sync` is unnecessary, consider removing it"