8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use ast:: { Block , Crate , Ident , Mac_ , PatKind } ;
11
+ use ast:: { Block , Ident , Mac_ , PatKind } ;
12
12
use ast:: { Name , MacStmtStyle , StmtKind , ItemKind } ;
13
13
use ast;
14
14
use ext:: hygiene:: Mark ;
@@ -26,6 +26,7 @@ use parse::parser::Parser;
26
26
use parse:: token:: { self , intern, keywords} ;
27
27
use print:: pprust;
28
28
use ptr:: P ;
29
+ use std_inject;
29
30
use tokenstream:: { TokenTree , TokenStream } ;
30
31
use util:: small_vector:: SmallVector ;
31
32
use visit:: Visitor ;
@@ -186,8 +187,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
186
187
MacroExpander { cx : cx, monotonic : monotonic }
187
188
}
188
189
189
- fn expand_crate ( & mut self , mut krate : ast:: Crate ) -> ast:: Crate {
190
- let err_count = self . cx . parse_sess . span_diagnostic . err_count ( ) ;
190
+ pub fn expand_crate ( & mut self , mut krate : ast:: Crate ) -> ast:: Crate {
191
+ self . cx . crate_root = std_inject:: injected_crate_name ( & krate) ;
192
+ let mut module = ModuleData {
193
+ mod_path : vec ! [ token:: str_to_ident( & self . cx. ecfg. crate_name) ] ,
194
+ directory : PathBuf :: from ( self . cx . codemap ( ) . span_to_filename ( krate. span ) ) ,
195
+ } ;
196
+ module. directory . pop ( ) ;
197
+ self . cx . current_expansion . module = Rc :: new ( module) ;
191
198
192
199
let krate_item = Expansion :: Items ( SmallVector :: one ( P ( ast:: Item {
193
200
attrs : krate. attrs ,
@@ -206,10 +213,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
206
213
_ => unreachable ! ( ) ,
207
214
} ;
208
215
209
- if self . cx . parse_sess . span_diagnostic . err_count ( ) - self . cx . resolve_err_count > err_count {
210
- self . cx . parse_sess . span_diagnostic . abort_if_errors ( ) ;
211
- }
212
-
213
216
krate
214
217
}
215
218
@@ -866,18 +869,6 @@ impl<'feat> ExpansionConfig<'feat> {
866
869
}
867
870
}
868
871
869
- pub fn expand_crate ( cx : & mut ExtCtxt , c : Crate ) -> Crate {
870
- cx. initialize ( & c) ;
871
- cx. monotonic_expander ( ) . expand_crate ( c)
872
- }
873
-
874
- // Expands crate using supplied MacroExpander - allows for
875
- // non-standard expansion behaviour (e.g. step-wise).
876
- pub fn expand_crate_with_expander ( expander : & mut MacroExpander , c : Crate ) -> Crate {
877
- expander. cx . initialize ( & c) ;
878
- expander. expand_crate ( c)
879
- }
880
-
881
872
// A Marker adds the given mark to the syntax context and
882
873
// sets spans' `expn_id` to the given expn_id (unless it is `None`).
883
874
struct Marker { mark : Mark , expn_id : Option < ExpnId > }
0 commit comments