Change:
() Removing the "no effect" line definitely has effect. The warning may instead suggest to explicitly use if that is what is needed.
Huh, I ran into this a couple weeks ago and typed up an issue, then decided at the last second to back out of it for some reason. Maybe I just figured that writing is more idiomatic anyways. This lint is old, by the way. (in Rust years, anyways)
requires adding before closure (somewhat suprisingly unlike ) Writing instead of may be more idiomatic if one wants to emphasize that running is significant.
Bumping this, as it's relevant to . (See also , ) When the path statement invokes a move, this lint is plain wrong; as the value has been moved, the old binding is no longer usable. When this move invokes drop glue, this lint is even more wrong, because the drop glue is an observable effect, and removing the statement would change the semantics of the program. "Path statement with no effect is further potentially damaging, as it may lead the user to write to silence the warning, which again changes the semantics of the program, because binding to the wildcard pattern does actually not perform a move from the place. I believe the correct behavior for this lint would be to suggest removing path statements that have no associated drop glue, but to suggest for types that do have drop glue, signaling clarity of intent.

Discussion:
impl<'tcx> LateLintPass<'tcx> for PathStatements { fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) { <del> if let hir::StmtKind::Semi(ref expr) = s.kind { </del> <ins> if let hir::StmtKind::Semi(expr) = s.kind { </ins> if let hir::ExprKind::Path(_) = expr.kind { cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| { <del> lint.build("path statement with no effect").emit() </del> <ins> let ty = cx.typeck_results().expr_ty(expr); if ty.needs_drop(cx.tcx, cx.param_env) { let mut lint = lint.build("path statement drops value"); if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) { lint.span_suggestion( s.span, "use `drop` to clarify the intent", format!("drop({});", snippet), Applicability::MachineApplicable, ); } else { lint.span_help(s.span, "use `drop` to clarify the intent"); } lint.emit() } else { lint.build("path statement with no effect").emit() } </ins> }); } }

// compile-flags: -D path-statements <del> fn main() { </del> <ins> struct Droppy; impl Drop for Droppy { fn drop(&mut self) {} } fn main() { </ins> let x = 10; x; //~ ERROR path statement with no effect <ins> let y = Droppy; y; //~ ERROR path statement drops value let z = (Droppy,); z; //~ ERROR path statement drops value </ins> }

error: path statement with no effect <del> --> $DIR/warn-path-statement.rs:5:5 </del> <ins> --> $DIR/warn-path-statement.rs:10:5 </ins> | LL |     x; |     ^^ | = note: requested on the command line with `-D path-statements` <del> error: aborting due to previous error </del> <ins> error: path statement drops value --> $DIR/warn-path-statement.rs:13:5 | LL |     y; |     ^^ help: use `drop` to clarify the intent: `drop(y);` error: path statement drops value --> $DIR/warn-path-statement.rs:16:5 | LL |     z; |     ^^ help: use `drop` to clarify the intent: `drop(z);` error: aborting due to 3 previous errors </ins>