Skip to content

Commit 4096867

Browse files
committed
make path_statements lint machine applicable for statements with no effect
1 parent e964cca commit 4096867

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ lint_path_statement_drop = path statement drops value
675675
.suggestion = use `drop` to clarify the intent
676676
677677
lint_path_statement_no_effect = path statement with no effect
678+
.suggestion = remove this statement
678679
679680
lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
680681
.label = pattern not allowed in function without body

compiler/rustc_lint/src/lints.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,19 @@ pub(crate) enum PathStatementDropSub {
20772077

20782078
#[derive(LintDiagnostic)]
20792079
#[diag(lint_path_statement_no_effect)]
2080-
pub(crate) struct PathStatementNoEffect;
2080+
pub(crate) struct PathStatementNoEffect {
2081+
#[subdiagnostic]
2082+
pub sub: PathStatementNoEffectSub,
2083+
}
2084+
2085+
#[derive(Subdiagnostic)]
2086+
pub(crate) enum PathStatementNoEffectSub {
2087+
#[suggestion(lint_suggestion, code = "", applicability = "machine-applicable")]
2088+
Suggestion {
2089+
#[primary_span]
2090+
span: Span,
2091+
},
2092+
}
20812093

20822094
#[derive(LintDiagnostic)]
20832095
#[diag(lint_unused_delim)]

compiler/rustc_lint/src/unused.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use rustc_span::{BytePos, Span, Symbol, kw, sym};
1414
use tracing::instrument;
1515

1616
use crate::lints::{
17-
PathStatementDrop, PathStatementDropSub, PathStatementNoEffect, UnusedAllocationDiag,
18-
UnusedAllocationMutDiag, UnusedClosure, UnusedCoroutine, UnusedDef, UnusedDefSuggestion,
19-
UnusedDelim, UnusedDelimSuggestion, UnusedImportBracesDiag, UnusedOp, UnusedOpSuggestion,
20-
UnusedResult,
17+
PathStatementDrop, PathStatementDropSub, PathStatementNoEffect, PathStatementNoEffectSub,
18+
UnusedAllocationDiag, UnusedAllocationMutDiag, UnusedClosure, UnusedCoroutine, UnusedDef,
19+
UnusedDefSuggestion, UnusedDelim, UnusedDelimSuggestion, UnusedImportBracesDiag, UnusedOp,
20+
UnusedOpSuggestion, UnusedResult,
2121
};
2222
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Lint, LintContext};
2323

@@ -568,7 +568,13 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
568568
};
569569
cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementDrop { sub })
570570
} else {
571-
cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementNoEffect);
571+
cx.emit_span_lint(
572+
PATH_STATEMENTS,
573+
s.span,
574+
PathStatementNoEffect {
575+
sub: PathStatementNoEffectSub::Suggestion { span: s.span },
576+
},
577+
);
572578
}
573579
}
574580
}

tests/ui/lint/warn-path-statement.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: path statement with no effect
22
--> $DIR/warn-path-statement.rs:10:5
33
|
44
LL | x;
5-
| ^^
5+
| ^^ help: remove this statement
66
|
77
= note: requested on the command line with `-D path-statements`
88

0 commit comments

Comments
 (0)