Handle raw identifiers in chain

This commit is contained in:
Seiichi Uchida 2018-09-01 16:18:27 +09:00
parent 68015ecf52
commit 08e282877a
2 changed files with 11 additions and 7 deletions

View File

@ -74,8 +74,8 @@ use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
use utils::{
first_line_width, last_line_extendable, last_line_width, mk_sp, trimmed_last_line_width,
wrap_str,
first_line_width, last_line_extendable, last_line_width, mk_sp, rewrite_ident,
trimmed_last_line_width, wrap_str,
};
use std::borrow::Cow;
@ -190,10 +190,12 @@ impl Rewrite for ChainItem {
ChainItemKind::MethodCall(ref segment, ref types, ref exprs) => {
Self::rewrite_method_call(segment.ident, types, exprs, self.span, context, shape)?
}
ChainItemKind::StructField(ident) => format!(".{}", ident.name),
ChainItemKind::TupleField(ident, nested) => {
format!("{}.{}", if nested { " " } else { "" }, ident.name)
}
ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
ChainItemKind::TupleField(ident, nested) => format!(
"{}.{}",
if nested { " " } else { "" },
rewrite_ident(context, ident)
),
ChainItemKind::Comment(ref comment, _) => {
rewrite_comment(comment, false, shape, context.config)?
}
@ -241,7 +243,7 @@ impl ChainItem {
format!("::<{}>", type_list.join(", "))
};
let callee_str = format!(".{}{}", method_name, type_str);
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
rewrite_call(context, &callee_str, &args[1..], span, shape)
}
}

View File

@ -11,6 +11,8 @@ fn main() {
r#foo::r#bar();
let r#local = r#Struct { r#field: () };
r#local.r#field = 1;
r#foo.r#barr();
let r#async = r#foo(r#local);
r#macro!();