Skip to content

Commit e9dac80

Browse files
powerboat9philberty
authored andcommitted
gccrs: Prevent warning on "unreachable" items
Items declared in a block expression can't be unreachable. gcc/rust/ChangeLog: * hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Check if a statement is an item before warning. gcc/testsuite/ChangeLog: * rust/compile/unreachable.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
1 parent 38fc892 commit e9dac80

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

gcc/rust/hir/rust-ast-lower.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr)
117117
"this point in "
118118
"the pipeline, they should all have been expanded");
119119

120-
if (block_did_terminate)
120+
if (s->get_stmt_kind () != AST::Stmt::Kind::Item && block_did_terminate)
121121
rust_warning_at (s->get_locus (), 0, "unreachable statement");
122122

123123
bool terminated = false;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
pub fn f1() {
5+
return f11();
6+
7+
// no warning
8+
fn f11() {}
9+
10+
f11() // { dg-warning "unreachable expression" }
11+
}
12+
13+
pub fn f2() {
14+
return;
15+
f1(); // { dg-warning "unreachable statement" }
16+
}
17+
18+
pub fn f3() {
19+
return;
20+
f1() // { dg-warning "unreachable expression" }
21+
}

0 commit comments

Comments
 (0)