@@ -35,7 +35,8 @@ use arrayvec::ArrayVec;
3535use base_db:: Crate ;
3636use cfg:: { CfgExpr , CfgOptions } ;
3737use either:: Either ;
38- use intern:: { Interned , Symbol } ;
38+ use intern:: Interned ;
39+ use itertools:: Itertools ;
3940use mbe:: { DelimiterKind , Punct } ;
4041use parser:: T ;
4142use smallvec:: SmallVec ;
@@ -416,47 +417,42 @@ impl fmt::Display for AttrInput {
416417
417418impl Attr {
418419 /// #[path = "string"]
419- pub fn string_value ( & self ) -> Option < & Symbol > {
420+ pub fn string_value ( & self ) -> Option < & str > {
420421 match self . input . as_deref ( ) ? {
421- AttrInput :: Literal ( tt:: Literal {
422- symbol : text,
423- kind : tt:: LitKind :: Str | tt:: LitKind :: StrRaw ( _) ,
424- ..
425- } ) => Some ( text) ,
422+ AttrInput :: Literal (
423+ lit @ tt:: Literal { kind : tt:: LitKind :: Str | tt:: LitKind :: StrRaw ( _) , .. } ,
424+ ) => Some ( lit. text ( ) ) ,
426425 _ => None ,
427426 }
428427 }
429428
430429 /// #[path = "string"]
431- pub fn string_value_with_span ( & self ) -> Option < ( & Symbol , span:: Span ) > {
430+ pub fn string_value_with_span ( & self ) -> Option < ( & str , span:: Span ) > {
432431 match self . input . as_deref ( ) ? {
433- AttrInput :: Literal ( tt:: Literal {
434- symbol : text,
435- kind : tt:: LitKind :: Str | tt:: LitKind :: StrRaw ( _) ,
436- span,
437- suffix : _,
438- } ) => Some ( ( text, * span) ) ,
432+ AttrInput :: Literal (
433+ lit @ tt:: Literal { kind : tt:: LitKind :: Str | tt:: LitKind :: StrRaw ( _) , span, .. } ,
434+ ) => Some ( ( lit. text ( ) , * span) ) ,
439435 _ => None ,
440436 }
441437 }
442438
443439 pub fn string_value_unescape ( & self ) -> Option < Cow < ' _ , str > > {
444440 match self . input . as_deref ( ) ? {
445- AttrInput :: Literal ( tt:: Literal {
446- symbol : text , kind : tt :: LitKind :: StrRaw ( _ ) , ..
447- } ) => Some ( Cow :: Borrowed ( text . as_str ( ) ) ) ,
448- AttrInput :: Literal ( tt:: Literal { symbol : text , kind : tt:: LitKind :: Str , .. } ) => {
449- unescape ( text . as_str ( ) )
441+ AttrInput :: Literal ( lit @ tt:: Literal { kind : tt :: LitKind :: StrRaw ( _ ) , .. } ) => {
442+ Some ( Cow :: Borrowed ( lit . text ( ) ) )
443+ }
444+ AttrInput :: Literal ( lit @ tt:: Literal { kind : tt:: LitKind :: Str , .. } ) => {
445+ unescape ( lit . text ( ) )
450446 }
451447 _ => None ,
452448 }
453449 }
454450
455451 /// #[path(ident)]
456- pub fn single_ident_value ( & self ) -> Option < & tt:: Ident > {
452+ pub fn single_ident_value ( & self ) -> Option < tt:: Ident > {
457453 match self . input . as_deref ( ) ? {
458- AttrInput :: TokenTree ( tt) => match tt. token_trees ( ) . flat_tokens ( ) {
459- [ tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] => Some ( ident) ,
454+ AttrInput :: TokenTree ( tt) => match tt. token_trees ( ) . iter ( ) . collect_array ( ) {
455+ Some ( [ tt:: TtElement :: Leaf ( tt:: Leaf :: Ident ( ident) ) ] ) => Some ( ident) ,
460456 _ => None ,
461457 } ,
462458 _ => None ,
@@ -492,7 +488,7 @@ fn parse_path_comma_token_tree<'a>(
492488 args. token_trees ( )
493489 . split ( |tt| matches ! ( tt, tt:: TtElement :: Leaf ( tt:: Leaf :: Punct ( Punct { char : ',' , .. } ) ) ) )
494490 . filter_map ( move |tts| {
495- let span = tts. flat_tokens ( ) . first ( ) ? . first_span ( ) ;
491+ let span = tts. first_span ( ) ? ;
496492 Some ( ( ModPath :: from_tt ( db, tts) ?, span, tts) )
497493 } )
498494}
@@ -611,16 +607,12 @@ impl AttrId {
611607 else {
612608 return derive_attr_range;
613609 } ;
614- let ( Some ( first_tt) , Some ( last_tt) ) =
615- ( derive_tts. flat_tokens ( ) . first ( ) , derive_tts. flat_tokens ( ) . last ( ) )
610+ let ( Some ( first_span) , Some ( last_span) ) = ( derive_tts. first_span ( ) , derive_tts. last_span ( ) )
616611 else {
617612 return derive_attr_range;
618613 } ;
619- let start = first_tt. first_span ( ) . range . start ( ) ;
620- let end = match last_tt {
621- tt:: TokenTree :: Leaf ( it) => it. span ( ) . range . end ( ) ,
622- tt:: TokenTree :: Subtree ( it) => it. delimiter . close . range . end ( ) ,
623- } ;
614+ let start = first_span. range . start ( ) ;
615+ let end = last_span. range . end ( ) ;
624616 TextRange :: new ( start, end)
625617 }
626618}
0 commit comments