Skip to content

Commit 6ababd0

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

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
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.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ fn main() {
1414

1515
let z = (Droppy,);
1616
z; //~ ERROR path statement drops value
17+
18+
macro_rules! foo {
19+
($e:expr) => {
20+
$e;
21+
};
22+
}
23+
24+
foo!(x);
1725
}

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

Lines changed: 13 additions & 2 deletions
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

@@ -18,5 +18,16 @@ error: path statement drops value
1818
LL | z;
1919
| ^^ help: use `drop` to clarify the intent: `drop(z);`
2020

21-
error: aborting due to 3 previous errors
21+
error: path statement with no effect
22+
--> $DIR/warn-path-statement.rs:20:13
23+
|
24+
LL | $e;
25+
| ^^^ help: remove this statement
26+
...
27+
LL | foo!(x);
28+
| ------- in this macro invocation
29+
|
30+
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
31+
32+
error: aborting due to 4 previous errors
2233

0 commit comments

Comments
 (0)