summaryrefslogtreecommitdiff
path: root/src/fmt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fmt.rs')
-rw-r--r--src/fmt.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/fmt.rs b/src/fmt.rs
index ea1b518..e12e94b 100644
--- a/src/fmt.rs
+++ b/src/fmt.rs
@@ -54,8 +54,9 @@ impl Display<'_> {
member
}
'a'..='z' | 'A'..='Z' | '_' => {
- let ident = take_ident(&mut read);
- Member::Named(Ident::new(&ident, span))
+ let mut ident = take_ident(&mut read);
+ ident.set_span(span);
+ Member::Named(ident)
}
_ => continue,
};
@@ -64,6 +65,9 @@ impl Display<'_> {
Member::Named(ident) => ident.clone(),
};
let mut formatvar = local.clone();
+ if formatvar.to_string().starts_with("r#") {
+ formatvar = format_ident!("r_{}", formatvar);
+ }
if formatvar.to_string().starts_with('_') {
// Work around leading underscore being rejected by 1.40 and
// older compilers. https://github.com/rust-lang/rust/pull/66847
@@ -98,7 +102,7 @@ fn explicit_named_args(input: ParseStream) -> Result<Set<Ident>> {
while !input.is_empty() {
if input.peek(Token![,]) && input.peek2(Ident::peek_any) && input.peek3(Token![=]) {
input.parse::<Token![,]>()?;
- let ident: Ident = input.parse()?;
+ let ident = input.call(Ident::parse_any)?;
input.parse::<Token![=]>()?;
named_args.insert(ident);
} else {
@@ -123,8 +127,13 @@ fn take_int(read: &mut &str) -> String {
int
}
-fn take_ident(read: &mut &str) -> String {
+fn take_ident(read: &mut &str) -> Ident {
let mut ident = String::new();
+ let raw = read.starts_with("r#");
+ if raw {
+ ident.push_str("r#");
+ *read = &read[2..];
+ }
for (i, ch) in read.char_indices() {
match ch {
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => ident.push(ch),
@@ -134,5 +143,5 @@ fn take_ident(read: &mut &str) -> String {
}
}
}
- ident
+ Ident::parse_any.parse_str(&ident).unwrap()
}