mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 00:24:03 +00:00
Properly format macro's with an extra ident
This commit is contained in:
parent
8fd95df54a
commit
9e5c0390a0
@ -154,7 +154,7 @@ impl Rewrite for ast::Expr {
|
||||
ast::ExprKind::Mac(ref mac) => {
|
||||
// Failure to rewrite a marco should not imply failure to
|
||||
// rewrite the expression.
|
||||
rewrite_macro(mac, context, width, offset).or_else(|| {
|
||||
rewrite_macro(mac, None, context, width, offset).or_else(|| {
|
||||
wrap_str(context.snippet(self.span),
|
||||
context.config.max_width,
|
||||
width,
|
||||
|
@ -51,12 +51,16 @@ impl MacroStyle {
|
||||
}
|
||||
|
||||
pub fn rewrite_macro(mac: &ast::Mac,
|
||||
extra_ident: Option<ast::Ident>,
|
||||
context: &RewriteContext,
|
||||
width: usize,
|
||||
offset: Indent)
|
||||
-> Option<String> {
|
||||
let original_style = macro_style(mac, context);
|
||||
let macro_name = format!("{}!", mac.node.path);
|
||||
let macro_name = match extra_ident {
|
||||
None | Some(ast::Ident { name: ast::Name(0), .. }) => format!("{}!", mac.node.path),
|
||||
Some(ident) => format!("{}! {}", mac.node.path, ident),
|
||||
};
|
||||
let style = if FORCED_BRACKET_MACROS.contains(&¯o_name[..]) {
|
||||
MacroStyle::Brackets
|
||||
} else {
|
||||
|
@ -8,10 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::{ast, visit};
|
||||
use syntax::codemap::{self, CodeMap, Span, BytePos};
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax::visit;
|
||||
|
||||
use strings::string_buffer::StringBuffer;
|
||||
|
||||
@ -56,7 +55,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
ast::StmtKind::Mac(ref mac, _macro_style, _) => {
|
||||
self.format_missing_with_indent(stmt.span.lo);
|
||||
self.visit_mac(mac);
|
||||
self.visit_mac(mac, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -254,7 +253,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
ast::ItemKind::Mac(ref mac) => {
|
||||
self.format_missing_with_indent(item.span.lo);
|
||||
self.visit_mac(mac);
|
||||
self.visit_mac(mac, Some(item.ident));
|
||||
}
|
||||
ast::ItemKind::ForeignMod(ref foreign_mod) => {
|
||||
self.format_missing_with_indent(item.span.lo);
|
||||
@ -380,15 +379,15 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
ast::ImplItemKind::Macro(ref mac) => {
|
||||
self.format_missing_with_indent(ii.span.lo);
|
||||
self.visit_mac(mac);
|
||||
self.visit_mac(mac, Some(ii.ident));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mac(&mut self, mac: &ast::Mac) {
|
||||
fn visit_mac(&mut self, mac: &ast::Mac, ident: Option<ast::Ident>) {
|
||||
// 1 = ;
|
||||
let width = self.config.max_width - self.block_indent.width() - 1;
|
||||
let rewrite = rewrite_macro(mac, &self.get_context(), width, self.block_indent);
|
||||
let rewrite = rewrite_macro(mac, ident, &self.get_context(), width, self.block_indent);
|
||||
|
||||
if let Some(res) = rewrite {
|
||||
self.buffer.push_str(&res);
|
||||
|
@ -4,6 +4,8 @@ itemmacro!(really, long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
|
||||
peg_file! modname ("mygrammarfile.rustpeg");
|
||||
|
||||
fn main() {
|
||||
foo! ( );
|
||||
|
||||
|
@ -7,6 +7,8 @@ itemmacro!(really,
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
|
||||
peg_file! modname("mygrammarfile.rustpeg");
|
||||
|
||||
fn main() {
|
||||
foo!();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user