Skip to content

Commit 7620b4e

Browse files
committed
gccrs: Add missing context ast walker to check for free fn's
Fixes #3585 gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): missing visitor * ast/rust-ast-visitor.h: prototype gcc/testsuite/ChangeLog: * rust/compile/issue-3585-1.rs: New test. * rust/compile/issue-3585-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
1 parent d09ba8e commit 7620b4e

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

gcc/rust/ast/rust-ast-visitor.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,5 +1536,13 @@ ContextualASTVisitor::visit (AST::Trait &trait)
15361536
ctx.exit ();
15371537
}
15381538

1539+
void
1540+
ContextualASTVisitor::visit (AST::Function &function)
1541+
{
1542+
ctx.enter (Kind::FUNCTION);
1543+
DefaultASTVisitor::visit (function);
1544+
ctx.exit ();
1545+
}
1546+
15391547
} // namespace AST
15401548
} // namespace Rust

gcc/rust/ast/rust-ast-visitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ class ContextualASTVisitor : public DefaultASTVisitor
479479

480480
virtual void visit (AST::Trait &trait) override;
481481

482+
virtual void visit (AST::Function &function) override;
483+
482484
template <typename T> void visit (T &item)
483485
{
484486
DefaultASTVisitor::visit (item);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
macro_rules! mac_trait {
5+
($i:item) => {
6+
trait T { $i }
7+
}
8+
}
9+
10+
mac_trait! {
11+
fn foo() {
12+
fn foo();
13+
// { dg-error "free function without a body" "" { target *-*-* } .-1 }
14+
}
15+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
#![feature(lang_items)]
4+
5+
#[lang = "sized"]
6+
trait Sized {}
7+
8+
fn main() {}
9+
10+
macro_rules! mac_impl {
11+
($i:item) => {
12+
struct S;
13+
impl S { $i }
14+
}
15+
}
16+
17+
mac_impl! {
18+
fn foo() {}
19+
}
20+
21+
macro_rules! mac_trait {
22+
($i:item) => {
23+
trait T { $i }
24+
}
25+
}
26+
27+
mac_trait! {
28+
fn foo() {
29+
fn foo();
30+
// { dg-error "free function without a body" "" { target *-*-* } .-1 }
31+
}
32+
}
33+
34+
macro_rules! mac_extern {
35+
($i:item) => {
36+
extern "C" { $i }
37+
}
38+
}
39+
40+
mac_extern! {
41+
fn foo();
42+
}

0 commit comments

Comments
 (0)