diff options
-rw-r--r-- | samples/test/misc_macro_issues.rs | 33 | ||||
-rw-r--r-- | src/macro_rules/eval.cpp | 5 |
2 files changed, 37 insertions, 1 deletions
diff --git a/samples/test/misc_macro_issues.rs b/samples/test/misc_macro_issues.rs new file mode 100644 index 00000000..4d884166 --- /dev/null +++ b/samples/test/misc_macro_issues.rs @@ -0,0 +1,33 @@ +// compile-flags: --test + +// #55 - Doesn't allow macros for :item +macro_rules! outer { + ($it:item) => {} +} +outer! { + inner! {} +} + +// #59 - +macro_rules! outer2 { + ({ $($x:item)* }) => {} +} +outer2! { + {inner!{}} +} + + +// #56 - Unexpanded macro in type +macro_rules! m { + ($tt:tt) => { $tt } +} + +struct A; +struct B; + +impl From<m!(A)> for B { + fn from(_: A) -> B { + unimplemented!() + } +} + diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index 705addb3..24adac3e 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -616,6 +616,8 @@ namespace { } } +// TODO: This shouldn't exist, and can false-positives +// - Ideally, this would use consume_from_frag (which takes a clone-able input) bool Macro_TryPatternCap(TokenStream& lex, MacroPatEnt::Type type) { switch(type) @@ -652,7 +654,7 @@ bool Macro_TryPatternCap(TokenStream& lex, MacroPatEnt::Type type) case MacroPatEnt::PAT_META: return LOOK_AHEAD(lex) == TOK_IDENT || LOOK_AHEAD(lex) == TOK_INTERPOLATED_META; case MacroPatEnt::PAT_ITEM: - return is_token_item( LOOK_AHEAD(lex) ); + return is_token_item( LOOK_AHEAD(lex) ) || LOOK_AHEAD(lex) == TOK_IDENT; } BUG(lex.point_span(), "Fell through"); } @@ -1978,6 +1980,7 @@ unsigned int Macro_InvokeRules_MatchPattern(const Span& sp, const MacroRules& ru // NOTE: There can be multiple arms active, take the first. auto i = matches[0]; + DEBUG("Evalulating arm " << i); auto lex = TTStreamO(sp, mv$(input)); SET_MODULE(lex, mod); |