@@ -15,7 +15,6 @@ use rustc_target::spec::abi::Abi;
15
15
16
16
use std:: borrow:: Cow ;
17
17
use std:: cell:: Cell ;
18
- use std:: collections:: BTreeMap ;
19
18
use std:: vec;
20
19
21
20
pub fn id_to_string ( map : & dyn rustc_hir:: intravisit:: Map < ' _ > , hir_id : hir:: HirId ) -> String {
@@ -69,7 +68,7 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
69
68
pub struct State < ' a > {
70
69
pub s : pp:: Printer ,
71
70
comments : Option < Comments < ' a > > ,
72
- attrs : & ' a BTreeMap < hir:: HirId , & ' a [ ast:: Attribute ] > ,
71
+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
73
72
ann : & ' a ( dyn PpAnn + ' a ) ,
74
73
}
75
74
@@ -146,17 +145,18 @@ pub const INDENT_UNIT: usize = 4;
146
145
/// it can scan the input text for comments to copy forward.
147
146
pub fn print_crate < ' a > (
148
147
sm : & ' a SourceMap ,
149
- krate : & hir:: Crate < ' _ > ,
148
+ krate : & hir:: Mod < ' _ > ,
150
149
filename : FileName ,
151
150
input : String ,
151
+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
152
152
ann : & ' a dyn PpAnn ,
153
153
) -> String {
154
- let mut s = State :: new_from_input ( sm, filename, input, & krate . attrs , ann) ;
154
+ let mut s = State :: new_from_input ( sm, filename, input, attrs, ann) ;
155
155
156
156
// When printing the AST, we sometimes need to inject `#[no_std]` here.
157
157
// Since you can't compile the HIR, it's not necessary.
158
158
159
- s. print_mod ( & krate. module ( ) , s . attrs ( hir:: CRATE_HIR_ID ) ) ;
159
+ s. print_mod ( krate, ( * attrs) ( hir:: CRATE_HIR_ID ) ) ;
160
160
s. print_remaining_comments ( ) ;
161
161
s. s . eof ( )
162
162
}
@@ -166,7 +166,7 @@ impl<'a> State<'a> {
166
166
sm : & ' a SourceMap ,
167
167
filename : FileName ,
168
168
input : String ,
169
- attrs : & ' a BTreeMap < hir:: HirId , & [ ast:: Attribute ] > ,
169
+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
170
170
ann : & ' a dyn PpAnn ,
171
171
) -> State < ' a > {
172
172
State {
@@ -178,16 +178,15 @@ impl<'a> State<'a> {
178
178
}
179
179
180
180
fn attrs ( & self , id : hir:: HirId ) -> & ' a [ ast:: Attribute ] {
181
- self . attrs . get ( & id ) . map_or ( & [ ] , |la| * la )
181
+ ( self . attrs ) ( id )
182
182
}
183
183
}
184
184
185
185
pub fn to_string < F > ( ann : & dyn PpAnn , f : F ) -> String
186
186
where
187
187
F : FnOnce ( & mut State < ' _ > ) ,
188
188
{
189
- let mut printer =
190
- State { s : pp:: mk_printer ( ) , comments : None , attrs : & BTreeMap :: default ( ) , ann } ;
189
+ let mut printer = State { s : pp:: mk_printer ( ) , comments : None , attrs : & |_| & [ ] , ann } ;
191
190
f ( & mut printer) ;
192
191
printer. s . eof ( )
193
192
}
0 commit comments