@@ -5,8 +5,6 @@ use std::sync::{Arc, OnceLock as OnceCell};
5
5
use std:: { fmt, iter} ;
6
6
7
7
use arrayvec:: ArrayVec ;
8
- use rustc_ast:: MetaItemInner ;
9
- use rustc_ast_pretty:: pprust;
10
8
use rustc_attr:: { ConstStability , Deprecation , Stability , StableSince } ;
11
9
use rustc_const_eval:: const_eval:: is_unstable_const_fn;
12
10
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
@@ -47,6 +45,7 @@ use crate::formats::cache::Cache;
47
45
use crate :: formats:: item_type:: ItemType ;
48
46
use crate :: html:: render:: Context ;
49
47
use crate :: passes:: collect_intra_doc_links:: UrlFragment ;
48
+ use crate :: rustc_attr:: AttributeExt ;
50
49
51
50
#[ cfg( test) ]
52
51
mod tests;
@@ -454,14 +453,14 @@ impl Item {
454
453
kind : ItemKind ,
455
454
cx : & mut DocContext < ' _ > ,
456
455
) -> Item {
457
- let ast_attrs = cx. tcx . get_attrs_unchecked ( def_id) ;
456
+ let hir_attrs = cx. tcx . get_attrs_unchecked ( def_id) ;
458
457
459
458
Self :: from_def_id_and_attrs_and_parts (
460
459
def_id,
461
460
name,
462
461
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 ) ,
465
464
)
466
465
}
467
466
@@ -745,10 +744,10 @@ impl Item {
745
744
. iter ( )
746
745
. filter_map ( |attr| {
747
746
if keep_as_is {
748
- Some ( pprust :: attribute_to_string ( attr) )
747
+ Some ( rustc_hir_pretty :: attribute_to_string ( & tcx , attr) )
749
748
} else if ALLOWED_ATTRIBUTES . contains ( & attr. name_or_empty ( ) ) {
750
749
Some (
751
- pprust :: attribute_to_string ( attr)
750
+ rustc_hir_pretty :: attribute_to_string ( & tcx , attr)
752
751
. replace ( "\\ \n " , "" )
753
752
. replace ( '\n' , "" )
754
753
. replace ( " " , " " ) ,
@@ -956,7 +955,7 @@ pub(crate) trait AttributesExt {
956
955
type AttributeIterator < ' a > : Iterator < Item = ast:: MetaItemInner >
957
956
where
958
957
Self : ' a ;
959
- type Attributes < ' a > : Iterator < Item = & ' a ast :: Attribute >
958
+ type Attributes < ' a > : Iterator < Item = & ' a hir :: Attribute >
960
959
where
961
960
Self : ' a ;
962
961
@@ -1010,7 +1009,7 @@ pub(crate) trait AttributesExt {
1010
1009
// #[doc]
1011
1010
if attr. doc_str ( ) . is_none ( ) && attr. has_name ( sym:: doc) {
1012
1011
// #[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 ( ) {
1014
1013
for item in list {
1015
1014
// #[doc(hidden)]
1016
1015
if !item. has_name ( sym:: cfg) {
@@ -1043,7 +1042,7 @@ pub(crate) trait AttributesExt {
1043
1042
let mut meta = attr. meta_item ( ) . unwrap ( ) . clone ( ) ;
1044
1043
meta. path = ast:: Path :: from_ident ( Ident :: with_dummy_span ( sym:: target_feature) ) ;
1045
1044
1046
- if let Ok ( feat_cfg) = Cfg :: parse ( & MetaItemInner :: MetaItem ( meta) ) {
1045
+ if let Ok ( feat_cfg) = Cfg :: parse ( & ast :: MetaItemInner :: MetaItem ( meta) ) {
1047
1046
cfg &= feat_cfg;
1048
1047
}
1049
1048
}
@@ -1054,14 +1053,14 @@ pub(crate) trait AttributesExt {
1054
1053
}
1055
1054
}
1056
1055
1057
- impl AttributesExt for [ ast :: Attribute ] {
1056
+ impl AttributesExt for [ hir :: Attribute ] {
1058
1057
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 ;
1060
1059
1061
1060
fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
1062
1061
self . iter ( )
1063
1062
. filter ( move |attr| attr. has_name ( name) )
1064
- . filter_map ( ast:: Attribute :: meta_item_list)
1063
+ . filter_map ( ast:: attr :: AttributeExt :: meta_item_list)
1065
1064
. flatten ( )
1066
1065
}
1067
1066
@@ -1070,20 +1069,20 @@ impl AttributesExt for [ast::Attribute] {
1070
1069
}
1071
1070
}
1072
1071
1073
- impl AttributesExt for [ ( Cow < ' _ , ast :: Attribute > , Option < DefId > ) ] {
1072
+ impl AttributesExt for [ ( Cow < ' _ , hir :: Attribute > , Option < DefId > ) ] {
1074
1073
type AttributeIterator < ' a >
1075
1074
= impl Iterator < Item = ast:: MetaItemInner > + ' a
1076
1075
where
1077
1076
Self : ' a ;
1078
1077
type Attributes < ' a >
1079
- = impl Iterator < Item = & ' a ast :: Attribute > + ' a
1078
+ = impl Iterator < Item = & ' a hir :: Attribute > + ' a
1080
1079
where
1081
1080
Self : ' a ;
1082
1081
1083
1082
fn lists ( & self , name : Symbol ) -> Self :: AttributeIterator < ' _ > {
1084
1083
AttributesExt :: iter ( self )
1085
1084
. filter ( move |attr| attr. has_name ( name) )
1086
- . filter_map ( ast :: Attribute :: meta_item_list)
1085
+ . filter_map ( hir :: Attribute :: meta_item_list)
1087
1086
. flatten ( )
1088
1087
}
1089
1088
@@ -1153,7 +1152,7 @@ pub struct RenderedLink {
1153
1152
#[ derive( Clone , Debug , Default ) ]
1154
1153
pub ( crate ) struct Attributes {
1155
1154
pub ( crate ) doc_strings : Vec < DocFragment > ,
1156
- pub ( crate ) other_attrs : ast:: AttrVec ,
1155
+ pub ( crate ) other_attrs : ast:: AttrVec < hir :: Attribute > ,
1157
1156
}
1158
1157
1159
1158
impl Attributes {
@@ -1181,22 +1180,22 @@ impl Attributes {
1181
1180
self . has_doc_flag ( sym:: hidden)
1182
1181
}
1183
1182
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 )
1186
1185
}
1187
1186
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 ) ,
1191
1190
) -> Attributes {
1192
1191
// Additional documentation should be shown before the original documentation.
1193
1192
let attrs1 = additional_attrs. iter ( ) . map ( |attr| ( attr, Some ( def_id) ) ) ;
1194
1193
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 )
1196
1195
}
1197
1196
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 > ) > ,
1200
1199
doc_only : bool ,
1201
1200
) -> Attributes {
1202
1201
let ( doc_strings, other_attrs) = attrs_to_doc_fragments ( attrs, doc_only) ;
0 commit comments