Merge pull request #883 from marcusklaas/macro-with-name
Properly format macro's with an extra ident
This commit is contained in:
commit
50820c6a43
@ -154,7 +154,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
|
||||
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 @@ fn opener(&self) -> &'static str {
|
||||
}
|
||||
|
||||
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 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
|
||||
}
|
||||
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 @@ fn visit_item(&mut self, item: &ast::Item) {
|
||||
}
|
||||
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 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
|
||||
}
|
||||
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!{this, is.bracket().formatted()}
|
||||
|
||||
peg_file! modname ("mygrammarfile.rustpeg");
|
||||
|
||||
fn main() {
|
||||
foo! ( );
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
itemmacro!{this, is.bracket().formatted()}
|
||||
|
||||
peg_file! modname("mygrammarfile.rustpeg");
|
||||
|
||||
fn main() {
|
||||
foo!();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user