@@ -4,7 +4,10 @@ use base_db::{AnchoredPath, Edition, FileId};
44use cfg:: CfgExpr ;
55use either:: Either ;
66use mbe:: { parse_exprs_with_sep, parse_to_token_tree} ;
7- use syntax:: { ast, SmolStr } ;
7+ use syntax:: {
8+ ast:: { self , AstToken } ,
9+ SmolStr ,
10+ } ;
811
912use crate :: { db:: AstDatabase , name, quote, ExpandError , ExpandResult , MacroCallId , MacroCallLoc } ;
1013
@@ -355,7 +358,14 @@ fn unreachable_expand(
355358}
356359
357360fn unquote_str ( lit : & tt:: Literal ) -> Option < String > {
358- let token = ast:: make:: literal ( & lit. to_string ( ) ) . as_string ( ) ?;
361+ let lit = ast:: make:: tokens:: literal ( & lit. to_string ( ) ) ;
362+ let token = ast:: String :: cast ( lit) ?;
363+ token. value ( ) . map ( |it| it. into_owned ( ) )
364+ }
365+
366+ fn unquote_byte_string ( lit : & tt:: Literal ) -> Option < Vec < u8 > > {
367+ let lit = ast:: make:: tokens:: literal ( & lit. to_string ( ) ) ;
368+ let token = ast:: ByteString :: cast ( lit) ?;
359369 token. value ( ) . map ( |it| it. into_owned ( ) )
360370}
361371
@@ -432,16 +442,12 @@ fn concat_bytes_expand(
432442 for ( i, t) in tt. token_trees . iter ( ) . enumerate ( ) {
433443 match t {
434444 tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( lit) ) => {
435- let lit = ast:: make:: literal ( & lit. to_string ( ) ) ;
436- match lit. kind ( ) {
437- ast:: LiteralKind :: ByteString ( s) => {
438- s. value ( )
439- . unwrap_or_default ( )
440- . into_iter ( )
441- . for_each ( |x| bytes. push ( x. to_string ( ) ) ) ;
442- }
443- ast:: LiteralKind :: Byte ( _) => {
444- bytes. push ( lit. to_string ( ) ) ;
445+ let token = ast:: make:: tokens:: literal ( & lit. to_string ( ) ) ;
446+ match token. kind ( ) {
447+ syntax:: SyntaxKind :: BYTE => bytes. push ( token. text ( ) . to_string ( ) ) ,
448+ syntax:: SyntaxKind :: BYTE_STRING => {
449+ let components = unquote_byte_string ( lit) . unwrap_or_else ( Vec :: new) ;
450+ components. into_iter ( ) . for_each ( |x| bytes. push ( x. to_string ( ) ) ) ;
445451 }
446452 _ => {
447453 err. get_or_insert ( mbe:: ExpandError :: UnexpectedToken . into ( ) ) ;
@@ -475,10 +481,10 @@ fn concat_bytes_expand_subtree(
475481 for ( ti, tt) in tree. token_trees . iter ( ) . enumerate ( ) {
476482 match tt {
477483 tt:: TokenTree :: Leaf ( tt:: Leaf :: Literal ( lit) ) => {
478- let lit = ast:: make:: literal ( & lit. to_string ( ) ) ;
484+ let lit = ast:: make:: tokens :: literal ( & lit. to_string ( ) ) ;
479485 match lit. kind ( ) {
480- ast :: LiteralKind :: IntNumber ( _ ) | ast :: LiteralKind :: Byte ( _ ) => {
481- bytes. push ( lit. to_string ( ) ) ;
486+ syntax :: SyntaxKind :: BYTE | syntax :: SyntaxKind :: INT_NUMBER => {
487+ bytes. push ( lit. text ( ) . to_string ( ) )
482488 }
483489 _ => {
484490 return Err ( mbe:: ExpandError :: UnexpectedToken . into ( ) ) ;
0 commit comments