@@ -9,7 +9,7 @@ use std::{
99use base_db:: CrateId ;
1010use cfg:: { CfgExpr , CfgOptions } ;
1111use either:: Either ;
12- use hir_expand:: { hygiene:: Hygiene , name:: AsName , AstId , InFile } ;
12+ use hir_expand:: { hygiene:: Hygiene , name:: AsName , AstId , AttrId , InFile } ;
1313use itertools:: Itertools ;
1414use la_arena:: ArenaMap ;
1515use mbe:: ast_to_token_tree;
@@ -98,13 +98,16 @@ impl RawAttrs {
9898 pub ( crate ) fn new ( owner : & dyn ast:: AttrsOwner , hygiene : & Hygiene ) -> Self {
9999 let entries = collect_attrs ( owner)
100100 . 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+ }
108111 } )
109112 . collect :: < Arc < _ > > ( ) ;
110113
@@ -161,7 +164,7 @@ impl RawAttrs {
161164 let cfg = parts. next ( ) . unwrap ( ) ;
162165 let cfg = Subtree { delimiter : subtree. delimiter , token_trees : cfg. to_vec ( ) } ;
163166 let cfg = CfgExpr :: parse ( & cfg) ;
164- let index = attr. index ;
167+ let index = attr. id ;
165168 let attrs = parts. filter ( |a| !a. is_empty ( ) ) . filter_map ( |attr| {
166169 let tree = Subtree { delimiter : None , token_trees : attr. to_vec ( ) } ;
167170 let attr = ast:: Attr :: parse ( & format ! ( "#[{}]" , tree) ) . ok ( ) ?;
@@ -468,7 +471,7 @@ impl AttrsWithOwner {
468471 ) -> Option < ( Documentation , DocsRangeMap ) > {
469472 // FIXME: code duplication in `docs` above
470473 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 ) ) ,
472475 AttrInput :: TokenTree ( _) => None ,
473476 } ) ;
474477 let indent = docs
@@ -560,8 +563,8 @@ impl AttrSourceMap {
560563 /// the attribute represented by `Attr`.
561564 pub fn source_of ( & self , attr : & Attr ) -> InFile < & Either < ast:: Attr , ast:: Comment > > {
562565 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 ) )
565568 . as_ref ( )
566569 }
567570}
@@ -572,7 +575,7 @@ pub struct DocsRangeMap {
572575 // (docstring-line-range, attr_index, attr-string-range)
573576 // a mapping from the text range of a line of the [`Documentation`] to the attribute index and
574577 // the original (untrimmed) syntax doc line
575- mapping : Vec < ( TextRange , u32 , TextRange ) > ,
578+ mapping : Vec < ( TextRange , AttrId , TextRange ) > ,
576579}
577580
578581impl DocsRangeMap {
@@ -585,7 +588,7 @@ impl DocsRangeMap {
585588
586589 let relative_range = range - line_docs_range. start ( ) ;
587590
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 ] ;
589592 match source {
590593 Either :: Left ( _) => None , // FIXME, figure out a nice way to handle doc attributes here
591594 // as well as for whats done in syntax highlight doc injection
@@ -606,7 +609,7 @@ impl DocsRangeMap {
606609
607610#[ derive( Debug , Clone , PartialEq , Eq ) ]
608611pub struct Attr {
609- index : u32 ,
612+ pub ( crate ) id : AttrId ,
610613 pub ( crate ) path : Interned < ModPath > ,
611614 pub ( crate ) input : Option < AttrInput > ,
612615}
@@ -620,7 +623,7 @@ pub enum AttrInput {
620623}
621624
622625impl 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 > {
624627 let path = Interned :: new ( ModPath :: from_src ( ast. path ( ) ?, hygiene) ?) ;
625628 let input = if let Some ( ast:: Expr :: Literal ( lit) ) = ast. expr ( ) {
626629 let value = match lit. kind ( ) {
@@ -633,7 +636,7 @@ impl Attr {
633636 } else {
634637 None
635638 } ;
636- Some ( Attr { index , path, input } )
639+ Some ( Attr { id , path, input } )
637640 }
638641
639642 /// Parses this attribute as a `#[derive]`, returns an iterator that yields all contained paths
0 commit comments