Break before meta variables when using multiple lines

This commit is contained in:
Seiichi Uchida 2018-03-18 12:33:59 +09:00 committed by topecongiro
parent 95507e3a43
commit 3f7b59ca2b
3 changed files with 21 additions and 2 deletions

View File

@ -519,6 +519,14 @@ fn ends_with_space(&self) -> bool {
} }
} }
fn has_meta_var(&self) -> bool {
match *self {
MacroArgKind::MetaVariable(..) => true,
MacroArgKind::Repeat(_, ref args, _, _) => args.iter().any(|a| a.kind.has_meta_var()),
_ => false,
}
}
fn rewrite( fn rewrite(
&self, &self,
context: &RewriteContext, context: &RewriteContext,
@ -812,8 +820,12 @@ fn wrap_macro_args_inner(
}; };
result.push_str(&arg.rewrite(context, nested_shape, use_multiple_lines)?); result.push_str(&arg.rewrite(context, nested_shape, use_multiple_lines)?);
if use_multiple_lines && arg.kind.ends_with_space() { if use_multiple_lines
&& (arg.kind.ends_with_space() || iter.peek().map_or(false, |a| a.kind.has_meta_var()))
{
if arg.kind.ends_with_space() {
result.pop(); result.pop();
}
result.push_str(&indent_str); result.push_str(&indent_str);
} else if let Some(ref next_arg) = iter.peek() { } else if let Some(ref next_arg) = iter.peek() {
let space_before_dollar = let space_before_dollar =

View File

@ -7,6 +7,9 @@ macro_rules! m {
( $($beginning:ident),*;$middle:ident;$($end:ident),* ) => (); ( $($beginning:ident),*;$middle:ident;$($end:ident),* ) => ();
( $($beginning: ident),*; $middle: ident; $($end: ident),*; $($beginning: ident),*; $middle: ident; $($end: ident),* ) => {}; ( $($beginning: ident),*; $middle: ident; $($end: ident),*; $($beginning: ident),*; $middle: ident; $($end: ident),* ) => {};
( $ name : ident ( $ ( $ dol : tt $ var : ident ) * ) $ ( $ body : tt ) * ) => (); ( $ name : ident ( $ ( $ dol : tt $ var : ident ) * ) $ ( $ body : tt ) * ) => ();
( $( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
$( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
) => {};
} }
macro_rules! m { macro_rules! m {

View File

@ -14,6 +14,10 @@ macro_rules! m {
$($end: ident),* $($end: ident),*
) => {}; ) => {};
($name: ident($($dol: tt $var: ident)*) $($body: tt)*) => {}; ($name: ident($($dol: tt $var: ident)*) $($body: tt)*) => {};
(
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
) => {};
} }
macro_rules! m { macro_rules! m {