Skip to content

Commit

Permalink
Add multiple tests for non root proc macro
Browse files Browse the repository at this point in the history
Add multiple tests to prevent regressions on procedural macros errors
when one is declared outside of the crate's top level.

gcc/testsuite/ChangeLog:

	* rust/compile/proc_macro_attribute_non_root_function.rs: New test.
	* rust/compile/proc_macro_attribute_non_root_method.rs: New test.
	* rust/compile/proc_macro_attribute_non_root_module.rs: New test.
	* rust/compile/proc_macro_derive_non_root_function.rs: New test.
	* rust/compile/proc_macro_derive_non_root_method.rs: New test.
	* rust/compile/proc_macro_derive_non_root_module.rs: New test.
	* rust/compile/proc_macro_non_root_function.rs: New test.
	* rust/compile/proc_macro_non_root_method.rs: New test.
	* rust/compile/proc_macro_non_root_module.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Jul 27, 2023
1 parent 67b2057 commit 1bc8f08
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

fn outer_function() {
#[proc_macro_attribute]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_attribute.. must currently reside in the root of the crate" }
}
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/proc_macro_attribute_non_root_method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

struct DummyStruct;

impl DummyStruct {
pub fn method(self) {
#[proc_macro_attribute]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_attribute.. must currently reside in the root of the crate" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

mod test_module {
#[proc_macro_attribute]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_attribute.. must currently reside in the root of the crate" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

fn outer_function() {
#[proc_macro_derive(SomeTrait)]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_derive.. must currently reside in the root of the crate" }
}
12 changes: 12 additions & 0 deletions gcc/testsuite/rust/compile/proc_macro_derive_non_root_method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

trait SomeTrait {}

struct DummyStruct;

impl DummyStruct {
pub fn method(self) {
#[proc_macro_derive(SomeTrait)]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_derive.. must currently reside in the root of the crate" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

mod test_module {
#[proc_macro_derive(SomeTrait)]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro_derive.. must currently reside in the root of the crate" }
}
6 changes: 6 additions & 0 deletions gcc/testsuite/rust/compile/proc_macro_non_root_function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

fn outer_function() {
#[proc_macro]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro.. must currently reside in the root of the crate" }
}
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/proc_macro_non_root_method.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

struct DummyStruct;

impl DummyStruct {
pub fn method(self) {
#[proc_macro]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro.. must currently reside in the root of the crate" }
}
}
6 changes: 6 additions & 0 deletions gcc/testsuite/rust/compile/proc_macro_non_root_module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-frust-crate-type=proc-macro" }

mod test_module {
#[proc_macro]
pub fn non_root_function() {} // { dg-error "functions tagged with .#.proc_macro.. must currently reside in the root of the crate" }
}

0 comments on commit 1bc8f08

Please sign in to comment.