@@ -9,7 +9,7 @@ use std::{
9
9
use base_db:: CrateId ;
10
10
use cfg:: { CfgExpr , CfgOptions } ;
11
11
use either:: Either ;
12
- use hir_expand:: { hygiene:: Hygiene , name:: AsName , AstId , InFile } ;
12
+ use hir_expand:: { hygiene:: Hygiene , name:: AsName , AstId , AttrId , InFile } ;
13
13
use itertools:: Itertools ;
14
14
use la_arena:: ArenaMap ;
15
15
use mbe:: ast_to_token_tree;
@@ -98,13 +98,16 @@ impl RawAttrs {
98
98
pub ( crate ) fn new ( owner : & dyn ast:: AttrsOwner , hygiene : & Hygiene ) -> Self {
99
99
let entries = collect_attrs ( owner)
100
100
. enumerate ( )
101
- . flat_map ( |( i, attr) | match attr {
102
- Either :: Left ( attr) => Attr :: from_src ( attr, hygiene, i as u32 ) ,
103
- Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
104
- index : i as u32 ,
105
- input : Some ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ,
106
- path : Interned :: new ( ModPath :: from ( hir_expand:: name!( doc) ) ) ,
107
- } ) ,
101
+ . flat_map ( |( i, attr) | {
102
+ let index = AttrId ( i as u32 ) ;
103
+ match attr {
104
+ Either :: Left ( attr) => Attr :: from_src ( attr, hygiene, index) ,
105
+ Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
106
+ id : index,
107
+ input : Some ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ,
108
+ path : Interned :: new ( ModPath :: from ( hir_expand:: name!( doc) ) ) ,
109
+ } ) ,
110
+ }
108
111
} )
109
112
. collect :: < Arc < _ > > ( ) ;
110
113
@@ -161,7 +164,7 @@ impl RawAttrs {
161
164
let cfg = parts. next ( ) . unwrap ( ) ;
162
165
let cfg = Subtree { delimiter : subtree. delimiter , token_trees : cfg. to_vec ( ) } ;
163
166
let cfg = CfgExpr :: parse ( & cfg) ;
164
- let index = attr. index ;
167
+ let index = attr. id ;
165
168
let attrs = parts. filter ( |a| !a. is_empty ( ) ) . filter_map ( |attr| {
166
169
let tree = Subtree { delimiter : None , token_trees : attr. to_vec ( ) } ;
167
170
let attr = ast:: Attr :: parse ( & format ! ( "#[{}]" , tree) ) . ok ( ) ?;
@@ -468,7 +471,7 @@ impl AttrsWithOwner {
468
471
) -> Option < ( Documentation , DocsRangeMap ) > {
469
472
// FIXME: code duplication in `docs` above
470
473
let docs = self . by_key ( "doc" ) . attrs ( ) . flat_map ( |attr| match attr. input . as_ref ( ) ? {
471
- AttrInput :: Literal ( s) => Some ( ( s, attr. index ) ) ,
474
+ AttrInput :: Literal ( s) => Some ( ( s, attr. id ) ) ,
472
475
AttrInput :: TokenTree ( _) => None ,
473
476
} ) ;
474
477
let indent = docs
@@ -560,8 +563,8 @@ impl AttrSourceMap {
560
563
/// the attribute represented by `Attr`.
561
564
pub fn source_of ( & self , attr : & Attr ) -> InFile < & Either < ast:: Attr , ast:: Comment > > {
562
565
self . attrs
563
- . get ( attr. index as usize )
564
- . unwrap_or_else ( || panic ! ( "cannot find `Attr` at index {}" , attr. index ) )
566
+ . get ( attr. id . 0 as usize )
567
+ . unwrap_or_else ( || panic ! ( "cannot find `Attr` at index {:? }" , attr. id ) )
565
568
. as_ref ( )
566
569
}
567
570
}
@@ -572,7 +575,7 @@ pub struct DocsRangeMap {
572
575
// (docstring-line-range, attr_index, attr-string-range)
573
576
// a mapping from the text range of a line of the [`Documentation`] to the attribute index and
574
577
// the original (untrimmed) syntax doc line
575
- mapping : Vec < ( TextRange , u32 , TextRange ) > ,
578
+ mapping : Vec < ( TextRange , AttrId , TextRange ) > ,
576
579
}
577
580
578
581
impl DocsRangeMap {
@@ -585,7 +588,7 @@ impl DocsRangeMap {
585
588
586
589
let relative_range = range - line_docs_range. start ( ) ;
587
590
588
- let & InFile { file_id, value : ref source } = & self . source [ idx as usize ] ;
591
+ let & InFile { file_id, value : ref source } = & self . source [ idx. 0 as usize ] ;
589
592
match source {
590
593
Either :: Left ( _) => None , // FIXME, figure out a nice way to handle doc attributes here
591
594
// as well as for whats done in syntax highlight doc injection
@@ -606,7 +609,7 @@ impl DocsRangeMap {
606
609
607
610
#[ derive( Debug , Clone , PartialEq , Eq ) ]
608
611
pub struct Attr {
609
- index : u32 ,
612
+ pub ( crate ) id : AttrId ,
610
613
pub ( crate ) path : Interned < ModPath > ,
611
614
pub ( crate ) input : Option < AttrInput > ,
612
615
}
@@ -620,7 +623,7 @@ pub enum AttrInput {
620
623
}
621
624
622
625
impl Attr {
623
- fn from_src ( ast : ast:: Attr , hygiene : & Hygiene , index : u32 ) -> Option < Attr > {
626
+ fn from_src ( ast : ast:: Attr , hygiene : & Hygiene , id : AttrId ) -> Option < Attr > {
624
627
let path = Interned :: new ( ModPath :: from_src ( ast. path ( ) ?, hygiene) ?) ;
625
628
let input = if let Some ( ast:: Expr :: Literal ( lit) ) = ast. expr ( ) {
626
629
let value = match lit. kind ( ) {
@@ -633,7 +636,7 @@ impl Attr {
633
636
} else {
634
637
None
635
638
} ;
636
- Some ( Attr { index , path, input } )
639
+ Some ( Attr { id , path, input } )
637
640
}
638
641
639
642
/// Parses this attribute as a `#[derive]`, returns an iterator that yields all contained paths
0 commit comments