31
31
#![ feature( set_stdio) ]
32
32
#![ feature( staged_api) ]
33
33
#![ feature( question_mark) ]
34
+ #![ feature( unboxed_closures) ]
34
35
35
36
extern crate arena;
36
37
extern crate flate;
@@ -208,15 +209,8 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
208
209
209
210
do_or_return ! ( callbacks. late_callback( & matches, & sess, & input, & odir, & ofile) , Some ( sess) ) ;
210
211
211
- // It is somewhat unfortunate that this is hardwired in.
212
- let pretty = callbacks. parse_pretty ( & sess, & matches) ;
213
- if let Some ( ( ppm, opt_uii) ) = pretty {
214
- pretty:: pretty_print_input ( & sess, & cstore, cfg, & input, ppm, opt_uii, ofile) ;
215
- return ( Ok ( ( ) ) , None ) ;
216
- }
217
-
218
212
let plugins = sess. opts . debugging_opts . extra_plugins . clone ( ) ;
219
- let control = callbacks. build_controller ( & sess) ;
213
+ let control = callbacks. build_controller ( & sess, & matches ) ;
220
214
( driver:: compile_input ( & sess, & cstore, cfg, & input, & odir, & ofile,
221
215
Some ( plugins) , & control) ,
222
216
Some ( sess) )
@@ -247,6 +241,27 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> {
247
241
}
248
242
}
249
243
244
+ fn parse_pretty ( sess : & Session ,
245
+ matches : & getopts:: Matches )
246
+ -> Option < ( PpMode , Option < UserIdentifiedItem > ) > {
247
+ let pretty = if sess. opts . debugging_opts . unstable_options {
248
+ matches. opt_default ( "pretty" , "normal" ) . map ( |a| {
249
+ // stable pretty-print variants only
250
+ pretty:: parse_pretty ( sess, & a, false )
251
+ } )
252
+ } else {
253
+ None
254
+ } ;
255
+ if pretty. is_none ( ) && sess. unstable_options ( ) {
256
+ matches. opt_str ( "unpretty" ) . map ( |a| {
257
+ // extended with unstable pretty-print variants
258
+ pretty:: parse_pretty ( sess, & a, true )
259
+ } )
260
+ } else {
261
+ pretty
262
+ }
263
+ }
264
+
250
265
// Whether to stop or continue compilation.
251
266
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
252
267
pub enum Compilation {
@@ -316,29 +331,9 @@ pub trait CompilerCalls<'a> {
316
331
None
317
332
}
318
333
319
- // Parse pretty printing information from the arguments. The implementer can
320
- // choose to ignore this (the default will return None) which will skip pretty
321
- // printing. If you do want to pretty print, it is recommended to use the
322
- // implementation of this method from RustcDefaultCalls.
323
- // FIXME, this is a terrible bit of API. Parsing of pretty printing stuff
324
- // should be done as part of the framework and the implementor should customise
325
- // handling of it. However, that is not possible atm because pretty printing
326
- // essentially goes off and takes another path through the compiler which
327
- // means the session is either moved or not depending on what parse_pretty
328
- // returns (we could fix this by cloning, but it's another hack). The proper
329
- // solution is to handle pretty printing as if it were a compiler extension,
330
- // extending CompileController to make this work (see for example the treatment
331
- // of save-analysis in RustcDefaultCalls::build_controller).
332
- fn parse_pretty ( & mut self ,
333
- _sess : & Session ,
334
- _matches : & getopts:: Matches )
335
- -> Option < ( PpMode , Option < UserIdentifiedItem > ) > {
336
- None
337
- }
338
-
339
334
// Create a CompilController struct for controlling the behaviour of
340
335
// compilation.
341
- fn build_controller ( & mut self , & Session ) -> CompileController < ' a > ;
336
+ fn build_controller ( & mut self , & Session , & getopts :: Matches ) -> CompileController < ' a > ;
342
337
}
343
338
344
339
// CompilerCalls instance for a regular rustc build.
@@ -441,28 +436,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
441
436
None
442
437
}
443
438
444
- fn parse_pretty ( & mut self ,
445
- sess : & Session ,
446
- matches : & getopts:: Matches )
447
- -> Option < ( PpMode , Option < UserIdentifiedItem > ) > {
448
- let pretty = if sess. opts . debugging_opts . unstable_options {
449
- matches. opt_default ( "pretty" , "normal" ) . map ( |a| {
450
- // stable pretty-print variants only
451
- pretty:: parse_pretty ( sess, & a, false )
452
- } )
453
- } else {
454
- None
455
- } ;
456
- if pretty. is_none ( ) && sess. unstable_options ( ) {
457
- matches. opt_str ( "unpretty" ) . map ( |a| {
458
- // extended with unstable pretty-print variants
459
- pretty:: parse_pretty ( sess, & a, true )
460
- } )
461
- } else {
462
- pretty
463
- }
464
- }
465
-
466
439
fn late_callback ( & mut self ,
467
440
matches : & getopts:: Matches ,
468
441
sess : & Session ,
@@ -474,9 +447,22 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
474
447
. and_then ( || RustcDefaultCalls :: list_metadata ( sess, matches, input) )
475
448
}
476
449
477
- fn build_controller ( & mut self , sess : & Session ) -> CompileController < ' a > {
450
+ fn build_controller ( & mut self , sess : & Session , matches : & getopts :: Matches ) -> CompileController < ' a > {
478
451
let mut control = CompileController :: basic ( ) ;
479
452
453
+ if let Some ( ( ppm, opt_uii) ) = parse_pretty ( & sess, & matches) {
454
+ control. after_parse . stop = Compilation :: Stop ;
455
+ control. after_parse . callback = box move |state| {
456
+ pretty:: pretty_print_input ( state. session ,
457
+ state. cstore . unwrap ( ) ,
458
+ state. input ,
459
+ state. krate . take ( ) . unwrap ( ) ,
460
+ ppm,
461
+ opt_uii. clone ( ) ,
462
+ state. out_file ) ;
463
+ } ;
464
+ }
465
+
480
466
if sess. opts . parse_only || sess. opts . debugging_opts . show_span . is_some ( ) ||
481
467
sess. opts . debugging_opts . ast_json_noexpand {
482
468
control. after_parse . stop = Compilation :: Stop ;
@@ -498,7 +484,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
498
484
control. after_analysis . callback = box |state| {
499
485
time ( state. session . time_passes ( ) , "save analysis" , || {
500
486
save:: process_crate ( state. tcx . unwrap ( ) ,
501
- state. krate . unwrap ( ) ,
487
+ state. expanded_crate . unwrap ( ) ,
502
488
state. analysis . unwrap ( ) ,
503
489
state. crate_name . unwrap ( ) ,
504
490
state. out_dir ,
0 commit comments