Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gcc/rust/checks/lints/unused/rust-unused-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,14 @@ UnusedChecker::visit (HIR::LetStmt &stmt)
walk (stmt);
}

void
UnusedChecker::visit (HIR::ExprStmt &stmt)
{
if (stmt.get_expr ().get_expression_type () == HIR::Expr::ExprType::Path)
rust_warning_at (stmt.get_locus (), OPT_Wunused_value,
"path statement with no effect");
walk (stmt);
}

} // namespace Analysis
} // namespace Rust
1 change: 1 addition & 0 deletions gcc/rust/checks/lints/unused/rust-unused-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UnusedChecker : public HIR::DefaultHIRVisitor
virtual void visit (HIR::MatchExpr &expr) override;
virtual void visit (HIR::ExternBlock &block) override;
virtual void visit (HIR::LetStmt &stmt) override;
virtual void visit (HIR::ExprStmt &stmt) override;
virtual void visit_loop_label (HIR::LoopLabel &label) override;
};
} // namespace Analysis
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/rust-lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ grs_langhook_init_options_struct (struct gcc_options *opts)

/* We need to warn on unused variables by default */
opts->x_warn_unused_variable = 1;
/* Experimental lints under -frust-unused-check-2.0 warn by default */
opts->x_warn_unused_value = 1;
/* For const variables too */
opts->x_warn_unused_const_variable = 1;
/* And finally unused result for #[must_use] */
Expand Down
13 changes: 13 additions & 0 deletions gcc/testsuite/rust/compile/path-statements_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// { dg-additional-options "-frust-unused-check-2.0" }
#![feature(no_core)]
#![no_core]

pub fn foo() {
let x = 5;
x;
// { dg-warning "path statement with no effect" "" { target *-*-* } .-1 }
}

pub fn bar(y: i32) -> i32 {
y
}
Loading