[gccrs COMMIT] gccrs: Add missing context ast walker to check for free fn's

[email protected]
Newsgroups gmane.comp.gcc.rust,gmane.comp.gcc.patches
Message-ID <[email protected]>
From: Philip Herron <[email protected]>

Fixes Rust-GCC/gccrs#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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/7620b4e8c45fef22b046a3c299ffcd8a56443553

The commit has been mentioned in the following issue(s):
 - Rust-GCC/gccrs#3585: https://github.com/Rust-GCC/gccrs/issues/3585

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4779

 gcc/rust/ast/rust-ast-visitor.cc           |  8 +++++
 gcc/rust/ast/rust-ast-visitor.h            |  2 ++
 gcc/testsuite/rust/compile/issue-3585-1.rs | 15 ++++++++
 gcc/testsuite/rust/compile/issue-3585-2.rs | 42 ++++++++++++++++++++++
 4 files changed, 67 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-3585-1.rs
 create mode 100644 gcc/testsuite/rust/compile/issue-3585-2.rs

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index 892a35648..7e10ef750 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1536,5 +1536,13 @@ ContextualASTVisitor::visit (AST::Trait &trait)
   ctx.exit ();
 }
 
+void
+ContextualASTVisitor::visit (AST::Function &function)
+{
+  ctx.enter (Kind::FUNCTION);
+  DefaultASTVisitor::visit (function);
+  ctx.exit ();
+}
+
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 4ca56d139..e670cbe21 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -479,6 +479,8 @@ protected:
 
   virtual void visit (AST::Trait &trait) override;
 
+  virtual void visit (AST::Function &function) override;
+
   template <typename T> void visit (T &item)
   {
     DefaultASTVisitor::visit (item);
diff --git a/gcc/testsuite/rust/compile/issue-3585-1.rs b/gcc/testsuite/rust/compile/issue-3585-1.rs
new file mode 100644
index 000000000..2e901363a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3585-1.rs
@@ -0,0 +1,15 @@
+#![feature(no_core)]
+#![no_core]
+
+macro_rules! mac_trait {
+    ($i:item) => {
+        trait T { $i }
+    }
+}
+
+mac_trait! {
+    fn foo() {
+    fn foo();
+    // { dg-error "free function without a body" "" { target *-*-* } .-1 }
+}
+}
diff --git a/gcc/testsuite/rust/compile/issue-3585-2.rs b/gcc/testsuite/rust/compile/issue-3585-2.rs
new file mode 100644
index 000000000..1da358f9c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3585-2.rs
@@ -0,0 +1,42 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+trait Sized {}
+
+fn main() {}
+
+macro_rules! mac_impl {
+    ($i:item) => {
+        struct S;
+        impl S { $i }
+    }
+}
+
+mac_impl! {
+    fn foo() {}
+}
+
+macro_rules! mac_trait {
+    ($i:item) => {
+        trait T { $i }
+    }
+}
+
+mac_trait! {
+    fn foo() {
+    fn foo();
+    // { dg-error "free function without a body" "" { target *-*-* } .-1 }
+}
+}
+
+macro_rules! mac_extern {
+    ($i:item) => {
+        extern "C" { $i }
+    }
+}
+
+mac_extern! {
+    fn foo();
+}

base-commit: d09ba8e4ece68d9c6d76ad1f49483ae46f29e0f4
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.