Skip to content

Commit 5fb9418

Browse files
authored
Merge pull request #2991 from topecongiro/raw-identifier-in-chain
Handle raw identifiers in chain
2 parents 6277808 + 08e2828 commit 5fb9418

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/chains.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ use rewrite::{Rewrite, RewriteContext};
7474
use shape::Shape;
7575
use source_map::SpanUtils;
7676
use utils::{
77-
first_line_width, last_line_extendable, last_line_width, mk_sp, trimmed_last_line_width,
78-
wrap_str,
77+
first_line_width, last_line_extendable, last_line_width, mk_sp, rewrite_ident,
78+
trimmed_last_line_width, wrap_str,
7979
};
8080

8181
use std::borrow::Cow;
@@ -190,10 +190,12 @@ impl Rewrite for ChainItem {
190190
ChainItemKind::MethodCall(ref segment, ref types, ref exprs) => {
191191
Self::rewrite_method_call(segment.ident, types, exprs, self.span, context, shape)?
192192
}
193-
ChainItemKind::StructField(ident) => format!(".{}", ident.name),
194-
ChainItemKind::TupleField(ident, nested) => {
195-
format!("{}.{}", if nested { " " } else { "" }, ident.name)
196-
}
193+
ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)),
194+
ChainItemKind::TupleField(ident, nested) => format!(
195+
"{}.{}",
196+
if nested { " " } else { "" },
197+
rewrite_ident(context, ident)
198+
),
197199
ChainItemKind::Comment(ref comment, _) => {
198200
rewrite_comment(comment, false, shape, context.config)?
199201
}
@@ -241,7 +243,7 @@ impl ChainItem {
241243

242244
format!("::<{}>", type_list.join(", "))
243245
};
244-
let callee_str = format!(".{}{}", method_name, type_str);
246+
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
245247
rewrite_call(context, &callee_str, &args[1..], span, shape)
246248
}
247249
}

tests/target/raw_identifiers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ fn main() {
1111
r#foo::r#bar();
1212

1313
let r#local = r#Struct { r#field: () };
14+
r#local.r#field = 1;
15+
r#foo.r#barr();
1416
let r#async = r#foo(r#local);
1517
r#macro!();
1618

0 commit comments

Comments
 (0)