diff options
-rw-r--r-- | gcc/rust/expand/rust-macro-substitute-ctx.cc | 15 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro-issue1224.rs | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-substitute-ctx.cc b/gcc/rust/expand/rust-macro-substitute-ctx.cc index a6933bb..b7ab3ab 100644 --- a/gcc/rust/expand/rust-macro-substitute-ctx.cc +++ b/gcc/rust/expand/rust-macro-substitute-ctx.cc @@ -16,6 +16,21 @@ SubstituteCtx::substitute_metavar (std::unique_ptr<AST::Token> &metavar) } else { + // If we are expanding a metavar which has a lof of matches, we are + // currently expanding a repetition metavar - not a simple metavar. We + // need to error out and inform the user. + // Associated test case for an example: compile/macro-issue1224.rs + if (it->second.get_match_amount () != 1) + { + rust_error_at (metavar->get_locus (), + "metavariable is still repeating at this depth"); + rust_inform ( + metavar->get_locus (), + "you probably forgot the repetition operator: %<%s%s%s%>", "$(", + metavar->as_string ().c_str (), ")*"); + return expanded; + } + // We only care about the vector when expanding repetitions. // Just access the first element of the vector. auto &frag = it->second.get_single_fragment (); diff --git a/gcc/testsuite/rust/compile/macro-issue1224.rs b/gcc/testsuite/rust/compile/macro-issue1224.rs new file mode 100644 index 0000000..003bbcd --- /dev/null +++ b/gcc/testsuite/rust/compile/macro-issue1224.rs @@ -0,0 +1,9 @@ +macro_rules! impl_uint { + ($($ty:ident),*) => { + impl $ty {} // { dg-error "metavariable is still repeating at this depth" } + // { dg-error "unrecognised token" "" { target *-*-* } .-1 } // Spurious + // { dg-error "could not parse type" "" { target *-*-* } .-2 } // Spurious + }; +} + +impl_uint!(u8, u16, u32, u64, u128); |