use spanned::Spanned;
use utils::{
format_visibility, is_empty_line, mk_sp, remove_trailing_white_spaces, rewrite_ident,
- trim_left_preserve_layout, wrap_str,
+ trim_left_preserve_layout, wrap_str, NodeIdExt,
};
use visitor::FmtVisitor;
}
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!(),
};
}
}
}
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!(),
}
| Token::DotDot
| Token::DotDotDot
| Token::DotDotEq
- | Token::DotEq
| Token::Question => SpaceState::Punctuation,
Token::ModSep
let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect());
Some(ast::Expr {
- id: ast::NodeId::new(0), // dummy value
+ id: ast::NodeId::root(), // dummy value
node: ast::ExprKind::Try(parser.parse_expr().ok()?),
span: mac.span, // incorrect span, but shouldn't matter too much
attrs: ThinVec::new(),
// Indent the body since it is in a block.
let indent_str = body_indent.to_string(&config);
- let mut new_body = LineClasses::new(new_body.trim_right())
+ let mut new_body = LineClasses::new(new_body.trim_end())
.enumerate()
.fold(
(String::new(), true),