@@ -106,7 +106,9 @@ impl RawAttrs {
106
106
) -> Self {
107
107
let entries = collect_attrs ( owner)
108
108
. flat_map ( |( id, attr) | match attr {
109
- Either :: Left ( attr) => Attr :: from_src ( db, attr, hygiene, id) ,
109
+ Either :: Left ( attr) => {
110
+ attr. meta ( ) . and_then ( |meta| Attr :: from_src ( db, meta, hygiene, id) )
111
+ }
110
112
Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
111
113
id,
112
114
input : Some ( Interned :: new ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ) ,
@@ -172,10 +174,9 @@ impl RawAttrs {
172
174
let index = attr. id ;
173
175
let attrs = parts. filter ( |a| !a. is_empty ( ) ) . filter_map ( |attr| {
174
176
let tree = Subtree { delimiter : None , token_trees : attr. to_vec ( ) } ;
175
- let attr = ast:: Attr :: parse ( & format ! ( "#[{}]" , tree) ) . ok ( ) ?;
176
177
// FIXME hygiene
177
178
let hygiene = Hygiene :: new_unhygienic ( ) ;
178
- Attr :: from_src ( db, attr , & hygiene, index)
179
+ Attr :: from_tt ( db, & tree , & hygiene, index)
179
180
} ) ;
180
181
181
182
let cfg_options = & crate_graph[ krate] . cfg_options ;
@@ -664,7 +665,7 @@ impl fmt::Display for AttrInput {
664
665
impl Attr {
665
666
fn from_src (
666
667
db : & dyn DefDatabase ,
667
- ast : ast:: Attr ,
668
+ ast : ast:: Meta ,
668
669
hygiene : & Hygiene ,
669
670
id : AttrId ,
670
671
) -> Option < Attr > {
@@ -683,6 +684,19 @@ impl Attr {
683
684
Some ( Attr { id, path, input } )
684
685
}
685
686
687
+ fn from_tt (
688
+ db : & dyn DefDatabase ,
689
+ tt : & tt:: Subtree ,
690
+ hygiene : & Hygiene ,
691
+ id : AttrId ,
692
+ ) -> Option < Attr > {
693
+ let ( parse, _) =
694
+ mbe:: token_tree_to_syntax_node ( tt, hir_expand:: FragmentKind :: MetaItem ) . ok ( ) ?;
695
+ let ast = ast:: Meta :: cast ( parse. syntax_node ( ) ) ?;
696
+
697
+ Self :: from_src ( db, ast, hygiene, id)
698
+ }
699
+
686
700
/// Parses this attribute as a `#[derive]`, returns an iterator that yields all contained paths
687
701
/// to derive macros.
688
702
///
0 commit comments