commit
3b24f6f7c4
@ -33,7 +33,7 @@
|
||||
static FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
|
||||
|
||||
// FIXME: use the enum from libsyntax?
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum MacroStyle {
|
||||
Parens,
|
||||
Brackets,
|
||||
@ -63,9 +63,7 @@ pub fn rewrite_macro(mac: &ast::Mac,
|
||||
original_style
|
||||
};
|
||||
|
||||
if let MacroStyle::Braces = style {
|
||||
return None;
|
||||
} else if mac.node.tts.is_empty() {
|
||||
if mac.node.tts.is_empty() {
|
||||
return if let MacroStyle::Parens = style {
|
||||
Some(format!("{}()", macro_name))
|
||||
} else {
|
||||
@ -76,22 +74,24 @@ pub fn rewrite_macro(mac: &ast::Mac,
|
||||
let mut parser = tts_to_parser(context.parse_session, mac.node.tts.clone(), Vec::new());
|
||||
let mut expr_vec = Vec::new();
|
||||
|
||||
loop {
|
||||
expr_vec.push(match parser.parse_expr() {
|
||||
Ok(expr) => expr,
|
||||
Err(..) => return None,
|
||||
});
|
||||
if MacroStyle::Braces != style {
|
||||
loop {
|
||||
expr_vec.push(match parser.parse_expr() {
|
||||
Ok(expr) => expr,
|
||||
Err(..) => return None,
|
||||
});
|
||||
|
||||
match parser.token {
|
||||
Token::Eof => break,
|
||||
Token::Comma => (),
|
||||
_ => return None,
|
||||
}
|
||||
match parser.token {
|
||||
Token::Eof => break,
|
||||
Token::Comma => (),
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
let _ = parser.bump();
|
||||
let _ = parser.bump();
|
||||
|
||||
if parser.token == Token::Eof {
|
||||
return None;
|
||||
if parser.token == Token::Eof {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,13 +253,9 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
self.format_missing_with_indent(item.span.lo);
|
||||
self.format_mod(module, item.vis, item.span, item.ident);
|
||||
}
|
||||
ast::Item_::ItemMac(..) => {
|
||||
ast::Item_::ItemMac(ref mac) => {
|
||||
self.format_missing_with_indent(item.span.lo);
|
||||
let snippet = self.snippet(item.span);
|
||||
self.buffer.push_str(&snippet);
|
||||
self.last_pos = item.span.hi;
|
||||
// FIXME: we cannot format these yet, because of a bad span.
|
||||
// See rust lang issue #28424.
|
||||
self.visit_mac(mac);
|
||||
}
|
||||
ast::Item_::ItemForeignMod(ref foreign_mod) => {
|
||||
self.format_missing_with_indent(item.span.lo);
|
||||
|
@ -1,4 +1,8 @@
|
||||
itemmacro!(this, is.not() .formatted(yet));
|
||||
itemmacro!(this, is.now() .formatted(yay));
|
||||
|
||||
itemmacro!(really, long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb() .is.formatted());
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
|
||||
fn main() {
|
||||
foo! ( );
|
||||
|
@ -1,4 +1,11 @@
|
||||
itemmacro!(this, is.not() .formatted(yet));
|
||||
itemmacro!(this, is.now().formatted(yay));
|
||||
|
||||
itemmacro!(really,
|
||||
long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb()
|
||||
.is
|
||||
.formatted());
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
|
||||
fn main() {
|
||||
foo!();
|
||||
|
Loading…
Reference in New Issue
Block a user