diff --git a/src/macros.rs b/src/macros.rs index 16897e57dcb..eed6238acfc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -256,7 +256,8 @@ fn rewrite_macro_inner( } }; - if !arg_vec.is_empty() && arg_vec.iter().all(MacroArg::is_item) { + let has_item = arg_vec.iter().any(MacroArg::is_item); + if has_item && arg_vec.iter().all(MacroArg::is_item) { return rewrite_macro_with_items( context, &arg_vec, @@ -268,6 +269,9 @@ fn rewrite_macro_inner( mac.span(), ); } + if has_item { + return return_macro_parse_failure_fallback(context, shape.indent, position, mac.span()); + } match style { Delimiter::Parenthesis => { diff --git a/tests/source/issue-6629.rs b/tests/source/issue-6629.rs new file mode 100644 index 00000000000..1ed9927f132 --- /dev/null +++ b/tests/source/issue-6629.rs @@ -0,0 +1,13 @@ +macro_rules! reproduce { + (type Fail = $ty:ty; arr = $($arr:expr),+) => { + ( vec![$($arr),+] ) + }; + ( $expr:expr, $($arr:item),+) => { + 1 + }; +} + +fn main() { + reproduce!(type Fail = char; arr = 1); + reproduce!(23, type Fail = char;, type Fail = char;); +} diff --git a/tests/target/issue-6629.rs b/tests/target/issue-6629.rs new file mode 100644 index 00000000000..1ed9927f132 --- /dev/null +++ b/tests/target/issue-6629.rs @@ -0,0 +1,13 @@ +macro_rules! reproduce { + (type Fail = $ty:ty; arr = $($arr:expr),+) => { + ( vec![$($arr),+] ) + }; + ( $expr:expr, $($arr:item),+) => { + 1 + }; +} + +fn main() { + reproduce!(type Fail = char; arr = 1); + reproduce!(23, type Fail = char;, type Fail = char;); +}