Skip to content

Commit c2bc926

Browse files
authored
Rollup merge of #145274 - compiler-errors:unused-must-use, r=fmease
Remove unused `#[must_use]` Self-explanatory Fixes #145257
2 parents 4b1deef + 2c0409c commit c2bc926

File tree

13 files changed

+358
-198
lines changed

13 files changed

+358
-198
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21552155
attr_name,
21562156
macro_name: pprust::path_to_string(&call.path),
21572157
invoc_span: call.path.span,
2158+
attr_span: attr.span,
21582159
},
21592160
);
21602161
}

compiler/rustc_lint/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ lint_unused_allocation_mut = unnecessary allocation, use `&mut` instead
983983
984984
lint_unused_builtin_attribute = unused attribute `{$attr_name}`
985985
.note = the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`
986+
.suggestion = remove the attribute
986987
987988
lint_unused_closure =
988989
unused {$pre}{$count ->

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ pub fn decorate_builtin_lint(
205205
}
206206
.decorate_lint(diag);
207207
}
208-
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
209-
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name }.decorate_lint(diag);
208+
BuiltinLintDiag::UnusedBuiltinAttribute {
209+
attr_name,
210+
macro_name,
211+
invoc_span,
212+
attr_span,
213+
} => {
214+
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name, attr_span }
215+
.decorate_lint(diag);
210216
}
211217
BuiltinLintDiag::TrailingMacro(is_trailing, name) => {
212218
lints::TrailingMacro { is_trailing, name }.decorate_lint(diag);

compiler/rustc_lint/src/lints.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,9 +2938,10 @@ pub(crate) struct RawPrefix {
29382938
pub(crate) struct UnusedBuiltinAttribute {
29392939
#[note]
29402940
pub invoc_span: Span,
2941-
29422941
pub attr_name: Symbol,
29432942
pub macro_name: String,
2943+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
2944+
pub attr_span: Span,
29442945
}
29452946

29462947
#[derive(LintDiagnostic)]

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ pub enum BuiltinLintDiag {
647647
attr_name: Symbol,
648648
macro_name: String,
649649
invoc_span: Span,
650+
attr_span: Span,
650651
},
651652
PatternsInFnsWithoutBody {
652653
span: Span,

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ passes_must_not_suspend =
510510
511511
passes_must_use_no_effect =
512512
`#[must_use]` has no effect when applied to {$article} {$target}
513+
.suggestion = remove the attribute
513514
514515
passes_no_link =
515516
attribute should be applied to an `extern crate` item

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16221622
UNUSED_ATTRIBUTES,
16231623
hir_id,
16241624
attr_span,
1625-
errors::MustUseNoEffect { article, target },
1625+
errors::MustUseNoEffect { article, target, attr_span },
16261626
);
16271627
}
16281628

compiler/rustc_passes/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ pub(crate) struct FfiConstInvalidTarget {
469469
pub(crate) struct MustUseNoEffect {
470470
pub article: &'static str,
471471
pub target: rustc_hir::Target,
472+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
473+
pub attr_span: Span,
472474
}
473475

474476
#[derive(Diagnostic)]

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
//~^^ WARN this was previously accepted by the compiler
7272
#![must_use]
7373
//~^ WARN `#[must_use]` has no effect
74+
//~| HELP remove the attribute
7475
// see issue-43106-gating-of-stable.rs
7576
// see issue-43106-gating-of-unstable.rs
7677
// see issue-43106-gating-of-deprecated.rs
@@ -599,16 +600,20 @@ mod deprecated {
599600
}
600601

601602
#[must_use] //~ WARN `#[must_use]` has no effect
603+
//~^ HELP remove the attribute
602604
mod must_use {
603605
mod inner { #![must_use] } //~ WARN `#[must_use]` has no effect
606+
//~^ HELP remove the attribute
604607

605608
#[must_use] fn f() { }
606609

607610
#[must_use] struct S;
608611

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

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

614619
#[windows_subsystem = "windows"]

0 commit comments

Comments
 (0)