-
Notifications
You must be signed in to change notification settings - Fork 14k
Create unnecessary_send_constraint lint for &(dyn ... + Send)
#110961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
efbdc5b
532368c
6ed01d9
a00fd67
30af6f0
cd7bff1
cb9086b
cef8a0f
c16b474
ebf545f
657ec63
2321cb1
b914451
72adaec
63b0988
430e1db
8e02749
e9fe48c
b02fdd2
7083a31
df19546
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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`. | ||
john-h-k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// ### 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. | ||
john-h-k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
john-h-k marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the recommendation be to replace
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See this comment: #110961 (comment) In those situations, it stems from a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems like a fairly special case to me, I would not expect this to be common enough to warrant a general recommendation of dropping the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it should recommend replacing |
||
| } | ||
|
|
||
| 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 }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing by
Anyis a very strange suggestion. Why wouldtype_idmachinery be necessary? Can't the'staticbound cause a problem?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what else to put, this is for the scenario where
Sendis the only trait specified (so removing it would be invalid)