mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
fix: make concat!
work with char
This commit is contained in:
parent
1c03f45c08
commit
859d467276
2 changed files with 14 additions and 4 deletions
|
@ -357,6 +357,12 @@ fn unquote_str(lit: &tt::Literal) -> Option<String> {
|
|||
token.value().map(|it| it.into_owned())
|
||||
}
|
||||
|
||||
fn unquote_char(lit: &tt::Literal) -> Option<char> {
|
||||
let lit = ast::make::tokens::literal(&lit.to_string());
|
||||
let token = ast::Char::cast(lit)?;
|
||||
token.value()
|
||||
}
|
||||
|
||||
fn unquote_byte_string(lit: &tt::Literal) -> Option<Vec<u8>> {
|
||||
let lit = ast::make::tokens::literal(&lit.to_string());
|
||||
let token = ast::ByteString::cast(lit)?;
|
||||
|
@ -408,8 +414,12 @@ fn concat_expand(
|
|||
// 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
|
||||
// as-is.
|
||||
let component = unquote_str(it).unwrap_or_else(|| it.text.to_string());
|
||||
text.push_str(&component);
|
||||
if let Some(c) = unquote_char(it) {
|
||||
text.push(c);
|
||||
} else {
|
||||
let component = unquote_str(it).unwrap_or_else(|| it.text.to_string());
|
||||
text.push_str(&component);
|
||||
}
|
||||
}
|
||||
// handle boolean literals
|
||||
tt::TokenTree::Leaf(tt::Leaf::Ident(id))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue