mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
Put spaces around braces
This commit is contained in:
parent
96a83b57e5
commit
f8109f8e9c
@ -496,7 +496,7 @@ fn delim_token_to_str(
|
||||
let (lhs, rhs) = match *delim_token {
|
||||
DelimToken::Paren => ("(", ")"),
|
||||
DelimToken::Bracket => ("[", "]"),
|
||||
DelimToken::Brace => ("{", "}"),
|
||||
DelimToken::Brace => ("{ ", " }"),
|
||||
DelimToken::NoDelim => ("", ""),
|
||||
};
|
||||
if use_multiple_lines {
|
||||
@ -515,6 +515,13 @@ fn delim_token_to_str(
|
||||
}
|
||||
|
||||
impl MacroArgKind {
|
||||
fn starts_with_brace(&self) -> bool {
|
||||
match *self {
|
||||
MacroArgKind::Repeat(DelimToken::Brace, _, _, _)
|
||||
| MacroArgKind::Delimited(DelimToken::Brace, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn starts_with_dollar(&self) -> bool {
|
||||
match *self {
|
||||
MacroArgKind::Repeat(..) | MacroArgKind::MetaVariable(..) => true,
|
||||
@ -855,12 +862,7 @@ fn wrap_macro_args_inner(
|
||||
let indent_str = shape.indent.to_string_with_newline(context.config);
|
||||
|
||||
while let Some(ref arg) = iter.next() {
|
||||
let nested_shape = if use_multiple_lines {
|
||||
shape.with_max_width(context.config)
|
||||
} else {
|
||||
shape
|
||||
};
|
||||
result.push_str(&arg.rewrite(context, nested_shape, use_multiple_lines)?);
|
||||
result.push_str(&arg.rewrite(context, shape, use_multiple_lines)?);
|
||||
|
||||
if use_multiple_lines
|
||||
&& (arg.kind.ends_with_space() || iter.peek().map_or(false, |a| a.kind.has_meta_var()))
|
||||
@ -872,7 +874,8 @@ fn wrap_macro_args_inner(
|
||||
} else if let Some(ref next_arg) = iter.peek() {
|
||||
let space_before_dollar =
|
||||
!arg.kind.ends_with_space() && next_arg.kind.starts_with_dollar();
|
||||
if space_before_dollar {
|
||||
let space_before_brace = next_arg.kind.starts_with_brace();
|
||||
if space_before_dollar || space_before_brace {
|
||||
result.push(' ');
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,26 @@ macro_rules! m {
|
||||
( $ x : tt foo bar foo bar foo bar $ y : tt => x*y*z $ z : tt , $ ( $a: tt ) , * ) => {};
|
||||
}
|
||||
|
||||
|
||||
macro_rules! impl_a_method {
|
||||
($n:ident ( $a:ident : $ta:ty ) -> $ret:ty { $body:expr }) => {
|
||||
fn $n($a:$ta) -> $ret { $body }
|
||||
macro_rules! $n { ($va:expr) => { $n($va) } }
|
||||
};
|
||||
($n:ident ( $a:ident : $ta:ty, $b:ident : $tb:ty ) -> $ret:ty { $body:expr }) => {
|
||||
fn $n($a:$ta, $b:$tb) -> $ret { $body }
|
||||
macro_rules! $n { ($va:expr, $vb:expr) => { $n($va, $vb) } }
|
||||
};
|
||||
($n:ident ( $a:ident : $ta:ty, $b:ident : $tb:ty, $c:ident : $tc:ty ) -> $ret:ty { $body:expr }) => {
|
||||
fn $n($a:$ta, $b:$tb, $c:$tc) -> $ret { $body }
|
||||
macro_rules! $n { ($va:expr, $vb:expr, $vc:expr) => { $n($va, $vb, $vc) } }
|
||||
};
|
||||
($n:ident ( $a:ident : $ta:ty, $b:ident : $tb:ty, $c:ident : $tc:ty, $d:ident : $td:ty ) -> $ret:ty { $body:expr }) => {
|
||||
fn $n($a:$ta, $b:$tb, $c:$tc, $d:$td) -> $ret { $body }
|
||||
macro_rules! $n { ($va:expr, $vb:expr, $vc:expr, $vd:expr) => { $n($va, $vb, $vc, $vd) } }
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
// a
|
||||
($expr :expr, $( $func : ident ) * ) => {
|
||||
|
@ -27,6 +27,55 @@ macro_rules! m {
|
||||
($x: tt foo bar foo bar foo bar $y: tt => x * y * z $z: tt, $($a: tt),*) => {};
|
||||
}
|
||||
|
||||
macro_rules! impl_a_method {
|
||||
($n: ident($a: ident: $ta: ty) -> $ret: ty { $body: expr }) => {
|
||||
fn $n($a: $ta) -> $ret {
|
||||
$body
|
||||
}
|
||||
macro_rules! $n {
|
||||
($va: expr) => {
|
||||
$n($va)
|
||||
};
|
||||
}
|
||||
};
|
||||
($n: ident($a: ident: $ta: ty, $b: ident: $tb: ty) -> $ret: ty { $body: expr }) => {
|
||||
fn $n($a: $ta, $b: $tb) -> $ret {
|
||||
$body
|
||||
}
|
||||
macro_rules! $n {
|
||||
($va: expr,$vb: expr) => {
|
||||
$n($va, $vb)
|
||||
};
|
||||
}
|
||||
};
|
||||
(
|
||||
$n: ident($a: ident: $ta: ty, $b: ident: $tb: ty, $c: ident: $tc: ty) ->
|
||||
$ret: ty { $body: expr }
|
||||
) => {
|
||||
fn $n($a: $ta, $b: $tb, $c: $tc) -> $ret {
|
||||
$body
|
||||
}
|
||||
macro_rules! $n {
|
||||
($va: expr,$vb: expr,$vc: expr) => {
|
||||
$n($va, $vb, $vc)
|
||||
};
|
||||
}
|
||||
};
|
||||
(
|
||||
$n: ident($a: ident: $ta: ty, $b: ident: $tb: ty, $c: ident: $tc: ty, $d: ident: $td: ty) ->
|
||||
$ret: ty { $body: expr }
|
||||
) => {
|
||||
fn $n($a: $ta, $b: $tb, $c: $tc, $d: $td) -> $ret {
|
||||
$body
|
||||
}
|
||||
macro_rules! $n {
|
||||
($va: expr,$vb: expr,$vc: expr,$vd: expr) => {
|
||||
$n($va, $vb, $vc, $vd)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
// a
|
||||
($expr: expr, $($func: ident)*) => {{
|
||||
|
Loading…
Reference in New Issue
Block a user