@@ -105,7 +105,7 @@ impl RawAttrs {
105
105
Either :: Left ( attr) => Attr :: from_src ( db, attr, hygiene, id) ,
106
106
Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
107
107
id,
108
- input : Some ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ,
108
+ input : Some ( Interned :: new ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ) ,
109
109
path : Interned :: new ( ModPath :: from ( hir_expand:: name!( doc) ) ) ,
110
110
} ) ,
111
111
} )
@@ -151,7 +151,7 @@ impl RawAttrs {
151
151
return smallvec ! [ attr. clone( ) ] ;
152
152
}
153
153
154
- let subtree = match & attr. input {
154
+ let subtree = match attr. input . as_deref ( ) {
155
155
Some ( AttrInput :: TokenTree ( it) ) => it,
156
156
_ => return smallvec ! [ attr. clone( ) ] ,
157
157
} ;
@@ -251,7 +251,7 @@ impl Attrs {
251
251
}
252
252
253
253
pub fn docs ( & self ) -> Option < Documentation > {
254
- let docs = self . by_key ( "doc" ) . attrs ( ) . flat_map ( |attr| match attr. input . as_ref ( ) ? {
254
+ let docs = self . by_key ( "doc" ) . attrs ( ) . flat_map ( |attr| match attr. input . as_deref ( ) ? {
255
255
AttrInput :: Literal ( s) => Some ( s) ,
256
256
AttrInput :: TokenTree ( _) => None ,
257
257
} ) ;
@@ -454,7 +454,7 @@ impl AttrsWithOwner {
454
454
db : & dyn DefDatabase ,
455
455
) -> Option < ( Documentation , DocsRangeMap ) > {
456
456
// FIXME: code duplication in `docs` above
457
- let docs = self . by_key ( "doc" ) . attrs ( ) . flat_map ( |attr| match attr. input . as_ref ( ) ? {
457
+ let docs = self . by_key ( "doc" ) . attrs ( ) . flat_map ( |attr| match attr. input . as_deref ( ) ? {
458
458
AttrInput :: Literal ( s) => Some ( ( s, attr. id ) ) ,
459
459
AttrInput :: TokenTree ( _) => None ,
460
460
} ) ;
@@ -637,10 +637,10 @@ pub(crate) struct AttrId {
637
637
pub struct Attr {
638
638
pub ( crate ) id : AttrId ,
639
639
pub ( crate ) path : Interned < ModPath > ,
640
- pub ( crate ) input : Option < AttrInput > ,
640
+ pub ( crate ) input : Option < Interned < AttrInput > > ,
641
641
}
642
642
643
- #[ derive( Debug , Clone , PartialEq , Eq ) ]
643
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
644
644
pub enum AttrInput {
645
645
/// `#[attr = "string"]`
646
646
Literal ( SmolStr ) ,
@@ -670,9 +670,9 @@ impl Attr {
670
670
ast:: LiteralKind :: String ( string) => string. value ( ) ?. into ( ) ,
671
671
_ => lit. syntax ( ) . first_token ( ) ?. text ( ) . trim_matches ( '"' ) . into ( ) ,
672
672
} ;
673
- Some ( AttrInput :: Literal ( value) )
673
+ Some ( Interned :: new ( AttrInput :: Literal ( value) ) )
674
674
} else if let Some ( tt) = ast. token_tree ( ) {
675
- Some ( AttrInput :: TokenTree ( ast_to_token_tree ( & tt) . 0 ) )
675
+ Some ( Interned :: new ( AttrInput :: TokenTree ( ast_to_token_tree ( & tt) . 0 ) ) )
676
676
} else {
677
677
None
678
678
} ;
@@ -688,7 +688,7 @@ impl Attr {
688
688
return None ;
689
689
}
690
690
691
- match & self . input {
691
+ match self . input . as_deref ( ) {
692
692
Some ( AttrInput :: TokenTree ( args) ) => {
693
693
let mut counter = 0 ;
694
694
let paths = args
@@ -720,7 +720,7 @@ impl Attr {
720
720
}
721
721
722
722
pub fn string_value ( & self ) -> Option < & SmolStr > {
723
- match self . input . as_ref ( ) ? {
723
+ match self . input . as_deref ( ) ? {
724
724
AttrInput :: Literal ( it) => Some ( it) ,
725
725
_ => None ,
726
726
}
@@ -735,14 +735,14 @@ pub struct AttrQuery<'a> {
735
735
736
736
impl < ' a > AttrQuery < ' a > {
737
737
pub fn tt_values ( self ) -> impl Iterator < Item = & ' a Subtree > {
738
- self . attrs ( ) . filter_map ( |attr| match attr. input . as_ref ( ) ? {
738
+ self . attrs ( ) . filter_map ( |attr| match attr. input . as_deref ( ) ? {
739
739
AttrInput :: TokenTree ( it) => Some ( it) ,
740
740
_ => None ,
741
741
} )
742
742
}
743
743
744
744
pub fn string_value ( self ) -> Option < & ' a SmolStr > {
745
- self . attrs ( ) . find_map ( |attr| match attr. input . as_ref ( ) ? {
745
+ self . attrs ( ) . find_map ( |attr| match attr. input . as_deref ( ) ? {
746
746
AttrInput :: Literal ( it) => Some ( it) ,
747
747
_ => None ,
748
748
} )
0 commit comments