@@ -15,7 +15,6 @@ use rustc_target::spec::abi::Abi;
1515
1616use std:: borrow:: Cow ;
1717use std:: cell:: Cell ;
18- use std:: collections:: BTreeMap ;
1918use std:: vec;
2019
2120pub 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<'_> {
6968pub struct State < ' a > {
7069 pub s : pp:: Printer ,
7170 comments : Option < Comments < ' a > > ,
72- attrs : & ' a BTreeMap < hir:: HirId , & ' a [ ast:: Attribute ] > ,
71+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
7372 ann : & ' a ( dyn PpAnn + ' a ) ,
7473}
7574
@@ -146,17 +145,18 @@ pub const INDENT_UNIT: usize = 4;
146145/// it can scan the input text for comments to copy forward.
147146pub fn print_crate < ' a > (
148147 sm : & ' a SourceMap ,
149- krate : & hir:: Crate < ' _ > ,
148+ krate : & hir:: Mod < ' _ > ,
150149 filename : FileName ,
151150 input : String ,
151+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
152152 ann : & ' a dyn PpAnn ,
153153) -> 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) ;
155155
156156 // When printing the AST, we sometimes need to inject `#[no_std]` here.
157157 // Since you can't compile the HIR, it's not necessary.
158158
159- s. print_mod ( & krate. module ( ) , s . attrs ( hir:: CRATE_HIR_ID ) ) ;
159+ s. print_mod ( krate, ( * attrs) ( hir:: CRATE_HIR_ID ) ) ;
160160 s. print_remaining_comments ( ) ;
161161 s. s . eof ( )
162162}
@@ -166,7 +166,7 @@ impl<'a> State<'a> {
166166 sm : & ' a SourceMap ,
167167 filename : FileName ,
168168 input : String ,
169- attrs : & ' a BTreeMap < hir:: HirId , & [ ast:: Attribute ] > ,
169+ attrs : & ' a dyn Fn ( hir:: HirId ) -> & ' a [ ast:: Attribute ] ,
170170 ann : & ' a dyn PpAnn ,
171171 ) -> State < ' a > {
172172 State {
@@ -178,16 +178,15 @@ impl<'a> State<'a> {
178178 }
179179
180180 fn attrs ( & self , id : hir:: HirId ) -> & ' a [ ast:: Attribute ] {
181- self . attrs . get ( & id ) . map_or ( & [ ] , |la| * la )
181+ ( self . attrs ) ( id )
182182 }
183183}
184184
185185pub fn to_string < F > ( ann : & dyn PpAnn , f : F ) -> String
186186where
187187 F : FnOnce ( & mut State < ' _ > ) ,
188188{
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 } ;
191190 f ( & mut printer) ;
192191 printer. s . eof ( )
193192}
0 commit comments