Always enforce exactly one space between macro!
and braces ({}
)
This commit is contained in:
parent
1a3bc79c68
commit
bc5124e016
@ -256,19 +256,7 @@ pub fn rewrite_macro_inner(
|
||||
}
|
||||
DelimToken::Paren => Some(format!("{}()", macro_name)),
|
||||
DelimToken::Bracket => Some(format!("{}[]", macro_name)),
|
||||
DelimToken::Brace => {
|
||||
// Preserve at most one space before the braces.
|
||||
let char_after_bang = context
|
||||
.snippet(mac.span)
|
||||
.split('!')
|
||||
.nth(1)
|
||||
.and_then(|x| x.chars().next());
|
||||
if let Some(' ') = char_after_bang {
|
||||
Some(format!("{} {{}}", macro_name))
|
||||
} else {
|
||||
Some(format!("{}{{}}", macro_name))
|
||||
}
|
||||
}
|
||||
DelimToken::Brace => Some(format!("{} {{}}", macro_name)),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
@ -428,8 +416,15 @@ pub fn rewrite_macro_inner(
|
||||
}
|
||||
}
|
||||
DelimToken::Brace => {
|
||||
// Skip macro invocations with braces, for now.
|
||||
trim_left_preserve_layout(context.snippet(mac.span), shape.indent, &context.config)
|
||||
// For macro invocations with braces, always put a space between
|
||||
// the `macro_name!` and `{ /* macro_body */ }` but skip modifying
|
||||
// anything in between the braces (for now).
|
||||
let snippet = context.snippet(mac.span);
|
||||
let macro_raw = snippet.split_at(snippet.find('!')? + 1).1.trim_start();
|
||||
match trim_left_preserve_layout(macro_raw, &shape.indent, &context.config) {
|
||||
Some(macro_body) => Some(format!("{} {}", macro_name, macro_body)),
|
||||
None => Some(format!("{} {}", macro_name, macro_raw)),
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ itemmacro!(this, is.now() .formatted(yay));
|
||||
|
||||
itemmacro!(really, long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb() .is.formatted());
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
itemmacro!{this, is.brace().formatted()}
|
||||
|
||||
peg_file! modname ("mygrammarfile.rustpeg");
|
||||
|
||||
@ -106,8 +106,6 @@ fn main() {
|
||||
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
|
||||
// Don't format empty either!
|
||||
empty_invoc! {}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ macro_rules! impl_from_vector {
|
||||
}
|
||||
*/
|
||||
|
||||
test_if!{
|
||||
test_if! {
|
||||
$test_tt:
|
||||
interpolate_idents! {
|
||||
mod [$id _from_ $source] {
|
||||
|
@ -10,7 +10,7 @@ lazy_static! {
|
||||
// We need to be able to format `lazy_static!` without known syntax.
|
||||
lazy_static!(xxx, yyyy, zzzzz);
|
||||
|
||||
lazy_static!{}
|
||||
lazy_static! {}
|
||||
|
||||
// #2354
|
||||
lazy_static! {
|
||||
|
@ -9,7 +9,7 @@ itemmacro!(
|
||||
.formatted()
|
||||
);
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
itemmacro! {this, is.brace().formatted()}
|
||||
|
||||
peg_file! modname("mygrammarfile.rustpeg");
|
||||
|
||||
@ -94,7 +94,7 @@ fn main() {
|
||||
|
||||
foo(makro!(1, 3));
|
||||
|
||||
hamkaas!{ () };
|
||||
hamkaas! { () };
|
||||
|
||||
macrowithbraces! {dont, format, me}
|
||||
|
||||
@ -104,11 +104,11 @@ fn main() {
|
||||
|
||||
some_macro![];
|
||||
|
||||
some_macro!{
|
||||
some_macro! {
|
||||
// comment
|
||||
};
|
||||
|
||||
some_macro!{
|
||||
some_macro! {
|
||||
// comment
|
||||
};
|
||||
|
||||
@ -131,9 +131,7 @@ fn main() {
|
||||
}
|
||||
|
||||
impl X {
|
||||
empty_invoc!{}
|
||||
|
||||
// Don't format empty either!
|
||||
empty_invoc! {}
|
||||
empty_invoc! {}
|
||||
}
|
||||
|
||||
@ -952,7 +950,7 @@ macro_rules! m {
|
||||
};
|
||||
}
|
||||
fn foo() {
|
||||
f!{r#"
|
||||
f! {r#"
|
||||
test
|
||||
"#};
|
||||
}
|
||||
|
@ -204,19 +204,19 @@ fn issue355() {
|
||||
vec![3; 4]
|
||||
}
|
||||
// Funky bracketing styles
|
||||
t => println!{"a", b},
|
||||
t => println! {"a", b},
|
||||
u => vec![1, 2],
|
||||
v => vec![3; 4],
|
||||
w => println!["a", b],
|
||||
x => vec![1, 2],
|
||||
y => vec![3; 4],
|
||||
// Brackets with comments
|
||||
tc => println!{"a", b}, // comment
|
||||
uc => vec![1, 2], // comment
|
||||
vc => vec![3; 4], // comment
|
||||
wc => println!["a", b], // comment
|
||||
xc => vec![1, 2], // comment
|
||||
yc => vec![3; 4], // comment
|
||||
tc => println! {"a", b}, // comment
|
||||
uc => vec![1, 2], // comment
|
||||
vc => vec![3; 4], // comment
|
||||
wc => println!["a", b], // comment
|
||||
xc => vec![1, 2], // comment
|
||||
yc => vec![3; 4], // comment
|
||||
yd => looooooooooooooooooooooooooooooooooooooooooooooooooooooooong_func(
|
||||
aaaaaaaaaa, bbbbbbbbbb, cccccccccc, dddddddddd,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user