Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/builtin_fn_macro.rs')
-rw-r--r--crates/hir-expand/src/builtin_fn_macro.rs36
1 files changed, 15 insertions, 21 deletions
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index 8d2352f06e..687c549748 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -4,10 +4,7 @@ use base_db::{AnchoredPath, Edition, FileId};
use cfg::CfgExpr;
use either::Either;
use mbe::{parse_exprs_with_sep, parse_to_token_tree};
-use syntax::{
- ast::{self, AstToken},
- SmolStr,
-};
+use syntax::{ast, SmolStr};
use crate::{db::AstDatabase, name, quote, ExpandError, ExpandResult, MacroCallId, MacroCallLoc};
@@ -358,14 +355,7 @@ fn unreachable_expand(
}
fn unquote_str(lit: &tt::Literal) -> Option<String> {
- let lit = ast::make::tokens::literal(&lit.to_string());
- let token = ast::String::cast(lit)?;
- token.value().map(|it| it.into_owned())
-}
-
-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)?;
+ let token = ast::make::literal(&lit.to_string()).as_string()?;
token.value().map(|it| it.into_owned())
}
@@ -442,12 +432,16 @@ fn concat_bytes_expand(
for (i, t) in tt.token_trees.iter().enumerate() {
match t {
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
- let token = ast::make::tokens::literal(&lit.to_string());
- match token.kind() {
- syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
- syntax::SyntaxKind::BYTE_STRING => {
- let components = unquote_byte_string(lit).unwrap_or_else(Vec::new);
- components.into_iter().for_each(|x| bytes.push(x.to_string()));
+ let lit = ast::make::literal(&lit.to_string());
+ match lit.kind() {
+ ast::LiteralKind::ByteString(s) => {
+ s.value()
+ .unwrap_or_default()
+ .into_iter()
+ .for_each(|x| bytes.push(x.to_string()));
+ }
+ ast::LiteralKind::Byte(_) => {
+ bytes.push(lit.to_string());
}
_ => {
err.get_or_insert(mbe::ExpandError::UnexpectedToken.into());
@@ -481,10 +475,10 @@ fn concat_bytes_expand_subtree(
for (ti, tt) in tree.token_trees.iter().enumerate() {
match tt {
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
- let lit = ast::make::tokens::literal(&lit.to_string());
+ let lit = ast::make::literal(&lit.to_string());
match lit.kind() {
- syntax::SyntaxKind::BYTE | syntax::SyntaxKind::INT_NUMBER => {
- bytes.push(lit.text().to_string())
+ ast::LiteralKind::IntNumber(_) | ast::LiteralKind::Byte(_) => {
+ bytes.push(lit.to_string());
}
_ => {
return Err(mbe::ExpandError::UnexpectedToken.into());