@@ -5,8 +5,6 @@ use std::sync::{Arc, OnceLock as OnceCell};
55use std:: { fmt, iter} ;
66
77use arrayvec:: ArrayVec ;
8- use rustc_ast:: MetaItemInner ;
9- use rustc_ast_pretty:: pprust;
108use rustc_attr:: { ConstStability , Deprecation , Stability , StableSince } ;
119use rustc_const_eval:: const_eval:: is_unstable_const_fn;
1210use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
@@ -47,6 +45,7 @@ use crate::formats::cache::Cache;
4745use crate :: formats:: item_type:: ItemType ;
4846use crate :: html:: render:: Context ;
4947use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
48+ use crate :: rustc_attr:: AttributeExt ;
5049
5150#[ cfg( test) ]
5251mod tests;
@@ -454,14 +453,14 @@ impl Item {
454453 kind : ItemKind ,
455454 cx : & mut DocContext < ' _ > ,
456455 ) -> Item {
457- let ast_attrs = cx. tcx . get_attrs_unchecked ( def_id) ;
456+ let hir_attrs = cx. tcx . get_attrs_unchecked ( def_id) ;
458457
459458 Self :: from_def_id_and_attrs_and_parts (
460459 def_id,
461460 name,
462461 kind,
463- Attributes :: from_ast ( ast_attrs ) ,
464- ast_attrs . cfg ( cx. tcx , & cx. cache . hidden_cfg ) ,
462+ Attributes :: from_hir ( hir_attrs ) ,
463+ hir_attrs . cfg ( cx. tcx , & cx. cache . hidden_cfg ) ,
465464 )
466465 }
467466
@@ -745,10 +744,10 @@ impl Item {
745744 . iter ( )
746745 . filter_map ( |attr| {
747746 if keep_as_is {
748- Some ( pprust :: attribute_to_string ( attr) )
747+ Some ( rustc_hir_pretty :: attribute_to_string ( & tcx , attr) )
749748 } else if ALLOWED_ATTRIBUTES . contains ( & attr. name_or_empty ( ) ) {
750749 Some (
751- pprust :: attribute_to_string ( attr)
750+ rustc_hir_pretty :: attribute_to_string ( & tcx , attr)
752751 . replace ( "\\ \n " , "" )
753752 . replace ( '\n' , "" )
754753 . replace ( " " , " " ) ,
@@ -956,7 +955,7 @@ pub(crate) trait AttributesExt {
956955 type AttributeIterator < ' a > : Iterator < Item = ast:: MetaItemInner >
957956 where
958957 Self : ' a ;
959- type Attributes < ' a > : Iterator < Item = & ' a ast :: Attribute >
958+ type Attributes < ' a > : Iterator < Item = & ' a hir :: Attribute >
960959 where
961960 Self : ' a ;
962961
@@ -1010,7 +1009,7 @@ pub(crate) trait AttributesExt {
10101009 // #[doc]
10111010 if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
10121011 // #[doc(...)]
1013- if let Some ( list) = attr. meta ( ) . as_ref ( ) . and_then ( |mi| mi . meta_item_list ( ) ) {
1012+ if let Some ( list) = attr. meta_item_list ( ) {
10141013 for item in list {
10151014 // #[doc(hidden)]
10161015 if !item. has_name ( sym:: cfg) {
@@ -1043,7 +1042,7 @@ pub(crate) trait AttributesExt {
10431042 let mut meta = attr. meta_item ( ) . unwrap ( ) . clone ( ) ;
10441043 meta. path = ast:: Path :: from_ident ( Ident :: with_dummy_span ( sym:: target_feature) ) ;
10451044
1046- if let Ok ( feat_cfg) = Cfg :: parse ( & MetaItemInner :: MetaItem ( meta) ) {
1045+ if let Ok ( feat_cfg) = Cfg :: parse ( & ast :: MetaItemInner :: MetaItem ( meta) ) {
10471046 cfg &= feat_cfg;
10481047 }
10491048 }
@@ -1054,14 +1053,14 @@ pub(crate) trait AttributesExt {
10541053 }
10551054}
10561055
1057- impl AttributesExt for [ ast :: Attribute ] {
1056+ impl AttributesExt for [ hir :: Attribute ] {
10581057 type AttributeIterator < ' a > = impl Iterator < Item = ast:: MetaItemInner > + ' a ;
1059- type Attributes < ' a > = impl Iterator < Item = & ' a ast :: Attribute > + ' a ;
1058+ type Attributes < ' a > = impl Iterator < Item = & ' a hir :: Attribute > + ' a ;
10601059
10611060 fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
10621061 self . iter ( )
10631062 . filter ( move |attr| attr. has_name ( name) )
1064- . filter_map ( ast:: Attribute :: meta_item_list)
1063+ . filter_map ( ast:: attr :: AttributeExt :: meta_item_list)
10651064 . flatten ( )
10661065 }
10671066
@@ -1070,20 +1069,20 @@ impl AttributesExt for [ast::Attribute] {
10701069 }
10711070}
10721071
1073- impl AttributesExt for [ ( Cow < ' _ , ast :: Attribute > , Option < DefId > ) ] {
1072+ impl AttributesExt for [ ( Cow < ' _ , hir :: Attribute > , Option < DefId > ) ] {
10741073 type AttributeIterator < ' a >
10751074 = impl Iterator < Item = ast:: MetaItemInner > + ' a
10761075 where
10771076 Self : ' a ;
10781077 type Attributes < ' a >
1079- = impl Iterator < Item = & ' a ast :: Attribute > + ' a
1078+ = impl Iterator < Item = & ' a hir :: Attribute > + ' a
10801079 where
10811080 Self : ' a ;
10821081
10831082 fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
10841083 AttributesExt :: iter ( self )
10851084 . filter ( move |attr| attr. has_name ( name) )
1086- . filter_map ( ast :: Attribute :: meta_item_list)
1085+ . filter_map ( hir :: Attribute :: meta_item_list)
10871086 . flatten ( )
10881087 }
10891088
@@ -1153,7 +1152,7 @@ pub struct RenderedLink {
11531152#[ derive( Clone , Debug , Default ) ]
11541153pub ( crate ) struct Attributes {
11551154 pub ( crate ) doc_strings : Vec < DocFragment > ,
1156- pub ( crate ) other_attrs : ast:: AttrVec ,
1155+ pub ( crate ) other_attrs : ast:: AttrVec < hir :: Attribute > ,
11571156}
11581157
11591158impl Attributes {
@@ -1181,22 +1180,22 @@ impl Attributes {
11811180 self . has_doc_flag ( sym:: hidden)
11821181 }
11831182
1184- pub ( crate ) fn from_ast ( attrs : & [ ast :: Attribute ] ) -> Attributes {
1185- Attributes :: from_ast_iter ( attrs. iter ( ) . map ( |attr| ( attr, None ) ) , false )
1183+ pub ( crate ) fn from_hir ( attrs : & [ hir :: Attribute ] ) -> Attributes {
1184+ Attributes :: from_hir_iter ( attrs. iter ( ) . map ( |attr| ( attr, None ) ) , false )
11861185 }
11871186
1188- pub ( crate ) fn from_ast_with_additional (
1189- attrs : & [ ast :: Attribute ] ,
1190- ( additional_attrs, def_id) : ( & [ ast :: Attribute ] , DefId ) ,
1187+ pub ( crate ) fn from_hir_with_additional (
1188+ attrs : & [ hir :: Attribute ] ,
1189+ ( additional_attrs, def_id) : ( & [ hir :: Attribute ] , DefId ) ,
11911190 ) -> Attributes {
11921191 // Additional documentation should be shown before the original documentation.
11931192 let attrs1 = additional_attrs. iter ( ) . map ( |attr| ( attr, Some ( def_id) ) ) ;
11941193 let attrs2 = attrs. iter ( ) . map ( |attr| ( attr, None ) ) ;
1195- Attributes :: from_ast_iter ( attrs1. chain ( attrs2) , false )
1194+ Attributes :: from_hir_iter ( attrs1. chain ( attrs2) , false )
11961195 }
11971196
1198- pub ( crate ) fn from_ast_iter < ' a > (
1199- attrs : impl Iterator < Item = ( & ' a ast :: Attribute , Option < DefId > ) > ,
1197+ pub ( crate ) fn from_hir_iter < ' a > (
1198+ attrs : impl Iterator < Item = ( & ' a hir :: Attribute , Option < DefId > ) > ,
12001199 doc_only : bool ,
12011200 ) -> Attributes {
12021201 let ( doc_strings, other_attrs) = attrs_to_doc_fragments ( attrs, doc_only) ;
0 commit comments