Skip to content
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

fix must_use_unit suggestion when there're multiple attributes #13830

Merged
merged 1 commit into from
Dec 15, 2024

Conversation

lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Dec 15, 2024

fix #12320

When there're multiple attributes, clippy suggests leaving an extra comma and it makes an error.

changelog: [must_use_unit]: No longer make incorrect suggestions when multiple attributes present.

@rustbot
Copy link
Collaborator

rustbot commented Dec 15, 2024

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 15, 2024
Comment on lines +110 to +120
if attrs.len() == 1 {
span_lint_and_then(
cx,
MUST_USE_UNIT,
fn_header_span,
"this unit-returning function has a `#[must_use]` attribute",
|diag| {
diag.span_suggestion(attr.span, "remove the attribute", "", Applicability::MachineApplicable);
},
);
} else {
Copy link
Contributor Author

@lapla-cogito lapla-cogito Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this conditional branch is reached and the length of attrs is 1, then it should be #[must_use] and clippy can suggest in the same way as before

@llogiq
Copy link
Contributor

llogiq commented Dec 15, 2024

That's a good improvement, although just finding the span of the must_use, optionally including the comma and following whitespace would reduce the potential churn even more, especially when you consider the fact that those other attributes may be arbitrarily large.

@llogiq llogiq added this pull request to the merge queue Dec 15, 2024
Merged via the queue into rust-lang:master with commit f1f1165 Dec 15, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

must_use_unit fails to apply if it's one of many attrs
3 participants