Skip to content

Commit ba2de32

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

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,10 @@ 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+
#[suggestion(lint_suggestion, code = "", applicability = "machine-applicable")]
2082+
pub suggestion: Span,
2083+
}
20812084

20822085
#[derive(LintDiagnostic)]
20832086
#[diag(lint_unused_delim)]

compiler/rustc_lint/src/unused.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,11 @@ 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 { suggestion: s.span },
575+
);
572576
}
573577
}
574578
}

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)