diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 99b42ee548029..c49dc14615d8a 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -675,6 +675,7 @@ lint_path_statement_drop = path statement drops value .suggestion = use `drop` to clarify the intent lint_path_statement_no_effect = path statement with no effect + .suggestion = remove this statement lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies .label = pattern not allowed in function without body diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 487184b836a43..bbf980479e252 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2077,7 +2077,10 @@ pub(crate) enum PathStatementDropSub { #[derive(LintDiagnostic)] #[diag(lint_path_statement_no_effect)] -pub(crate) struct PathStatementNoEffect; +pub(crate) struct PathStatementNoEffect { + #[suggestion(lint_suggestion, code = "", applicability = "machine-applicable")] + pub suggestion: Span, +} #[derive(LintDiagnostic)] #[diag(lint_unused_delim)] diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 50a27d7e84f58..d964d738bea48 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -568,7 +568,11 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements { }; cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementDrop { sub }) } else { - cx.emit_span_lint(PATH_STATEMENTS, s.span, PathStatementNoEffect); + cx.emit_span_lint( + PATH_STATEMENTS, + s.span, + PathStatementNoEffect { suggestion: s.span }, + ); } } } diff --git a/tests/ui/lint/warn-path-statement.rs b/tests/ui/lint/warn-path-statement.rs index dc78aeb51ed89..6533e2ad41bb0 100644 --- a/tests/ui/lint/warn-path-statement.rs +++ b/tests/ui/lint/warn-path-statement.rs @@ -14,4 +14,12 @@ fn main() { let z = (Droppy,); z; //~ ERROR path statement drops value + + macro_rules! foo { + ($e:expr) => { + $e; + }; + } + + foo!(x); } diff --git a/tests/ui/lint/warn-path-statement.stderr b/tests/ui/lint/warn-path-statement.stderr index 248d2ef299be3..74248802437e6 100644 --- a/tests/ui/lint/warn-path-statement.stderr +++ b/tests/ui/lint/warn-path-statement.stderr @@ -2,7 +2,7 @@ error: path statement with no effect --> $DIR/warn-path-statement.rs:10:5 | LL | x; - | ^^ + | ^^ help: remove this statement | = note: requested on the command line with `-D path-statements` @@ -18,5 +18,16 @@ error: path statement drops value LL | z; | ^^ help: use `drop` to clarify the intent: `drop(z);` -error: aborting due to 3 previous errors +error: path statement with no effect + --> $DIR/warn-path-statement.rs:20:13 + | +LL | $e; + | ^^^ help: remove this statement +... +LL | foo!(x); + | ------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 4 previous errors