mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-25 05:14:27 +00:00
Format item macros
This commit is contained in:
parent
81516fe8ca
commit
f01ed6f507
@ -33,7 +33,7 @@ use utils::{wrap_str, span_after};
|
|||||||
static FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
|
static FORCED_BRACKET_MACROS: &'static [&'static str] = &["vec!"];
|
||||||
|
|
||||||
// FIXME: use the enum from libsyntax?
|
// FIXME: use the enum from libsyntax?
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
enum MacroStyle {
|
enum MacroStyle {
|
||||||
Parens,
|
Parens,
|
||||||
Brackets,
|
Brackets,
|
||||||
@ -63,9 +63,7 @@ pub fn rewrite_macro(mac: &ast::Mac,
|
|||||||
original_style
|
original_style
|
||||||
};
|
};
|
||||||
|
|
||||||
if let MacroStyle::Braces = style {
|
if mac.node.tts.is_empty() {
|
||||||
return None;
|
|
||||||
} else if mac.node.tts.is_empty() {
|
|
||||||
return if let MacroStyle::Parens = style {
|
return if let MacroStyle::Parens = style {
|
||||||
Some(format!("{}()", macro_name))
|
Some(format!("{}()", macro_name))
|
||||||
} else {
|
} 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 parser = tts_to_parser(context.parse_session, mac.node.tts.clone(), Vec::new());
|
||||||
let mut expr_vec = Vec::new();
|
let mut expr_vec = Vec::new();
|
||||||
|
|
||||||
loop {
|
if MacroStyle::Braces != style {
|
||||||
expr_vec.push(match parser.parse_expr() {
|
loop {
|
||||||
Ok(expr) => expr,
|
expr_vec.push(match parser.parse_expr() {
|
||||||
Err(..) => return None,
|
Ok(expr) => expr,
|
||||||
});
|
Err(..) => return None,
|
||||||
|
});
|
||||||
|
|
||||||
match parser.token {
|
match parser.token {
|
||||||
Token::Eof => break,
|
Token::Eof => break,
|
||||||
Token::Comma => (),
|
Token::Comma => (),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = parser.bump();
|
let _ = parser.bump();
|
||||||
|
|
||||||
if parser.token == Token::Eof {
|
if parser.token == Token::Eof {
|
||||||
return None;
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,13 +253,9 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
self.format_missing_with_indent(item.span.lo);
|
self.format_missing_with_indent(item.span.lo);
|
||||||
self.format_mod(module, item.vis, item.span, item.ident);
|
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);
|
self.format_missing_with_indent(item.span.lo);
|
||||||
let snippet = self.snippet(item.span);
|
self.visit_mac(mac);
|
||||||
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.
|
|
||||||
}
|
}
|
||||||
ast::Item_::ItemForeignMod(ref foreign_mod) => {
|
ast::Item_::ItemForeignMod(ref foreign_mod) => {
|
||||||
self.format_missing_with_indent(item.span.lo);
|
self.format_missing_with_indent(item.span.lo);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
itemmacro!(this, is.not() .formatted(yet));
|
itemmacro!(this, is.now() .formatted(yay));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo! ( );
|
foo! ( );
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
itemmacro!(this, is.not() .formatted(yet));
|
itemmacro!(this, is.now().formatted(yay));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo!();
|
foo!();
|
||||||
|
Loading…
Reference in New Issue
Block a user