3131#![ feature( set_stdio) ]
3232#![ feature( staged_api) ]
3333#![ feature( question_mark) ]
34+ #![ feature( unboxed_closures) ]
3435
3536extern crate arena;
3637extern crate flate;
@@ -208,15 +209,8 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
208209
209210 do_or_return ! ( callbacks. late_callback( & matches, & sess, & input, & odir, & ofile) , Some ( sess) ) ;
210211
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-
218212 let plugins = sess. opts . debugging_opts . extra_plugins . clone ( ) ;
219- let control = callbacks. build_controller ( & sess) ;
213+ let control = callbacks. build_controller ( & sess, & matches ) ;
220214 ( driver:: compile_input ( & sess, & cstore, cfg, & input, & odir, & ofile,
221215 Some ( plugins) , & control) ,
222216 Some ( sess) )
@@ -247,6 +241,27 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> {
247241 }
248242}
249243
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+
250265// Whether to stop or continue compilation.
251266#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
252267pub enum Compilation {
@@ -316,29 +331,9 @@ pub trait CompilerCalls<'a> {
316331 None
317332 }
318333
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-
339334 // Create a CompilController struct for controlling the behaviour of
340335 // compilation.
341- fn build_controller ( & mut self , & Session ) -> CompileController < ' a > ;
336+ fn build_controller ( & mut self , & Session , & getopts :: Matches ) -> CompileController < ' a > ;
342337}
343338
344339// CompilerCalls instance for a regular rustc build.
@@ -441,28 +436,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
441436 None
442437 }
443438
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-
466439 fn late_callback ( & mut self ,
467440 matches : & getopts:: Matches ,
468441 sess : & Session ,
@@ -474,9 +447,22 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
474447 . and_then ( || RustcDefaultCalls :: list_metadata ( sess, matches, input) )
475448 }
476449
477- fn build_controller ( & mut self , sess : & Session ) -> CompileController < ' a > {
450+ fn build_controller ( & mut self , sess : & Session , matches : & getopts :: Matches ) -> CompileController < ' a > {
478451 let mut control = CompileController :: basic ( ) ;
479452
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+
480466 if sess. opts . parse_only || sess. opts . debugging_opts . show_span . is_some ( ) ||
481467 sess. opts . debugging_opts . ast_json_noexpand {
482468 control. after_parse . stop = Compilation :: Stop ;
@@ -498,7 +484,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
498484 control. after_analysis . callback = box |state| {
499485 time ( state. session . time_passes ( ) , "save analysis" , || {
500486 save:: process_crate ( state. tcx . unwrap ( ) ,
501- state. krate . unwrap ( ) ,
487+ state. expanded_crate . unwrap ( ) ,
502488 state. analysis . unwrap ( ) ,
503489 state. crate_name . unwrap ( ) ,
504490 state. out_dir ,
0 commit comments