Skip to content

Remove unused #[must_use] #145274

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

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr_name,
macro_name: pprust::path_to_string(&call.path),
invoc_span: call.path.span,
attr_span: attr.span,
},
);
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ lint_unused_allocation_mut = unnecessary allocation, use `&mut` instead
lint_unused_builtin_attribute = unused attribute `{$attr_name}`
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
.suggestion = remove the attribute
lint_unused_closure =
unused {$pre}{$count ->
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ pub fn decorate_builtin_lint(
}
.decorate_lint(diag);
}
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name }.decorate_lint(diag);
BuiltinLintDiag::UnusedBuiltinAttribute {
attr_name,
macro_name,
invoc_span,
attr_span,
} => {
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name, attr_span }
.decorate_lint(diag);
}
BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
lints::TrailingMacro { is_trailing, name }.decorate_lint(diag);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2935,9 +2935,10 @@ pub(crate) struct RawPrefix {
pub(crate) struct UnusedBuiltinAttribute {
#[note]
pub invoc_span: Span,

pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub attr_span: Span,
}

#[derive(LintDiagnostic)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ pub enum BuiltinLintDiag {
attr_name: Symbol,
macro_name: String,
invoc_span: Span,
attr_span: Span,
},
PatternsInFnsWithoutBody {
span: Span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ passes_must_not_suspend =

passes_must_use_no_effect =
`#[must_use]` has no effect when applied to {$article} {$target}
.suggestion = remove the attribute

passes_no_link =
attribute should be applied to an `extern crate` item
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
UNUSED_ATTRIBUTES,
hir_id,
attr_span,
errors::MustUseNoEffect { article, target },
errors::MustUseNoEffect { article, target, attr_span },
);
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ pub(crate) struct FfiConstInvalidTarget {
pub(crate) struct MustUseNoEffect {
pub article: &'static str,
pub target: rustc_hir::Target,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub attr_span: Span,
}

#[derive(Diagnostic)]
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
//~^^ WARN this was previously accepted by the compiler
#![must_use]
//~^ WARN `#[must_use]` has no effect
//~| HELP remove the attribute
// see issue-43106-gating-of-stable.rs
// see issue-43106-gating-of-unstable.rs
// see issue-43106-gating-of-deprecated.rs
Expand Down Expand Up @@ -599,16 +600,20 @@ mod deprecated {
}

#[must_use] //~ WARN `#[must_use]` has no effect
//~^ HELP remove the attribute
mod must_use {
mod inner { #![must_use] } //~ WARN `#[must_use]` has no effect
//~^ HELP remove the attribute

#[must_use] fn f() { }

#[must_use] struct S;

#[must_use] type T = S; //~ WARN `#[must_use]` has no effect
//~^ HELP remove the attribute

#[must_use] impl S { } //~ WARN `#[must_use]` has no effect
//~^ HELP remove the attribute
}

#[windows_subsystem = "windows"]
Expand Down
Loading
Loading