Skip to content

Commit facad76

Browse files
committed
Build no_effect suggestion only when necessary
1 parent cc18556 commit facad76

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

clippy_lints/src/no_effect.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,20 @@ impl LateLintPass for Pass {
9292
if has_no_effect(cx, expr) {
9393
span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect");
9494
} else if let Some(reduced) = reduce_expression(cx, expr) {
95-
let mut snippet = String::new();
96-
for e in reduced {
97-
if in_macro(cx, e.span) {
98-
return;
99-
}
100-
if let Some(snip) = snippet_opt(cx, e.span) {
101-
snippet.push_str(&snip);
102-
snippet.push(';');
103-
} else {
104-
return;
105-
}
106-
}
10795
span_lint_and_then(cx, UNNECESSARY_OPERATION, stmt.span, "statement can be reduced", |db| {
96+
let mut snippet = String::new();
97+
for e in reduced {
98+
if in_macro(cx, e.span) {
99+
return;
100+
}
101+
if let Some(snip) = snippet_opt(cx, e.span) {
102+
snippet.push_str(&snip);
103+
snippet.push(';');
104+
} else {
105+
return;
106+
}
107+
}
108+
108109
db.span_suggestion(stmt.span, "replace it with", snippet);
109110
});
110111
}

0 commit comments

Comments
 (0)