mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Merge #7419
7419: Unquote strings when expanding concat! r=matklad a=lnicola Fixes #7417. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
6362b399ad
1 changed files with 8 additions and 16 deletions
|
@ -327,17 +327,12 @@ fn concat_expand(
|
||||||
// concat works with string and char literals, so remove any quotes.
|
// concat works with string and char literals, so remove any quotes.
|
||||||
// It also works with integer, float and boolean literals, so just use the rest
|
// It also works with integer, float and boolean literals, so just use the rest
|
||||||
// as-is.
|
// as-is.
|
||||||
|
let component = unquote_str(&it).unwrap_or_else(|| it.text.to_string());
|
||||||
text += it
|
text.push_str(&component);
|
||||||
.text
|
}
|
||||||
.trim_start_matches(|c| match c {
|
// handle boolean literals
|
||||||
'r' | '#' | '\'' | '"' => true,
|
tt::TokenTree::Leaf(tt::Leaf::Ident(id)) if i % 2 == 0 => {
|
||||||
_ => false,
|
text.push_str(id.text.as_str());
|
||||||
})
|
|
||||||
.trim_end_matches(|c| match c {
|
|
||||||
'#' | '\'' | '"' => true,
|
|
||||||
_ => false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
|
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -345,7 +340,6 @@ fn concat_expand(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpandResult { value: Some((quote!(#text), FragmentKind::Expr)), err }
|
ExpandResult { value: Some((quote!(#text), FragmentKind::Expr)), err }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,12 +739,10 @@ mod tests {
|
||||||
r##"
|
r##"
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
macro_rules! concat {}
|
macro_rules! concat {}
|
||||||
concat!("foo", 0, r#"bar"#);
|
concat!("foo", r, 0, r#"bar"#, false);
|
||||||
"##,
|
"##,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(expanded, r#""foo0bar""#);
|
assert_eq!(expanded, r#""foor0barfalse""#);
|
||||||
|
|
||||||
// FIXME: `true`/`false` literals don't work.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue