@@ -61,6 +61,7 @@ use std::path::{Path, PathBuf};
6161use std:: process;
6262use std:: sync:: mpsc:: channel;
6363
64+ use syntax:: edition:: Edition ;
6465use externalfiles:: ExternalHtml ;
6566use rustc:: session:: search_paths:: SearchPaths ;
6667use rustc:: session:: config:: { ErrorOutputType , RustcOptGroup , nightly_options, Externs } ;
@@ -271,6 +272,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
271272 \" light-suffix.css\" ",
272273 "PATH" )
273274 } ) ,
275+ unstable( "edition" , |o| {
276+ o. optopt( "" , "edition" ,
277+ "edition to use when compiling rust code (default: 2015)" ,
278+ "EDITION" )
279+ } ) ,
274280 ]
275281}
276282
@@ -429,14 +435,23 @@ pub fn main_args(args: &[String]) -> isize {
429435 let sort_modules_alphabetically = !matches. opt_present ( "sort-modules-by-appearance" ) ;
430436 let resource_suffix = matches. opt_str ( "resource-suffix" ) ;
431437
438+ let edition = matches. opt_str ( "edition" ) . unwrap_or ( "2015" . to_string ( ) ) ;
439+ let edition = match edition. parse ( ) {
440+ Ok ( e) => e,
441+ Err ( _) => {
442+ print_error ( "could not parse edition" ) ;
443+ return 1 ;
444+ }
445+ } ;
446+
432447 match ( should_test, markdown_input) {
433448 ( true , true ) => {
434449 return markdown:: test ( input, cfgs, libs, externs, test_args, maybe_sysroot,
435- display_warnings, linker)
450+ display_warnings, linker, edition )
436451 }
437452 ( true , false ) => {
438453 return test:: run ( Path :: new ( input) , cfgs, libs, externs, test_args, crate_name,
439- maybe_sysroot, display_warnings, linker)
454+ maybe_sysroot, display_warnings, linker, edition )
440455 }
441456 ( false , true ) => return markdown:: render ( Path :: new ( input) ,
442457 output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
@@ -446,7 +461,7 @@ pub fn main_args(args: &[String]) -> isize {
446461 }
447462
448463 let output_format = matches. opt_str ( "w" ) ;
449- let res = acquire_input ( PathBuf :: from ( input) , externs, & matches, move |out| {
464+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition , & matches, move |out| {
450465 let Output { krate, passes, renderinfo } = out;
451466 info ! ( "going to format" ) ;
452467 match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -487,14 +502,15 @@ fn print_error<T>(error_message: T) where T: Display {
487502/// and files and then generates the necessary rustdoc output for formatting.
488503fn acquire_input < R , F > ( input : PathBuf ,
489504 externs : Externs ,
505+ edition : Edition ,
490506 matches : & getopts:: Matches ,
491507 f : F )
492508 -> Result < R , String >
493509where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
494510 match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
495- Some ( "rust" ) => Ok ( rust_input ( input, externs, matches, f) ) ,
511+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition , matches, f) ) ,
496512 Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
497- None => Ok ( rust_input ( input, externs, matches, f) )
513+ None => Ok ( rust_input ( input, externs, edition , matches, f) )
498514 }
499515}
500516
@@ -520,8 +536,14 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
520536/// generated from the cleaned AST of the crate.
521537///
522538/// This form of input will run all of the plug/cleaning passes
523- fn rust_input < R , F > ( cratefile : PathBuf , externs : Externs , matches : & getopts:: Matches , f : F ) -> R
524- where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
539+ fn rust_input < R , F > ( cratefile : PathBuf ,
540+ externs : Externs ,
541+ edition : Edition ,
542+ matches : & getopts:: Matches ,
543+ f : F ) -> R
544+ where R : ' static + Send ,
545+ F : ' static + Send + FnOnce ( Output ) -> R
546+ {
525547 let mut default_passes = !matches. opt_present ( "no-defaults" ) ;
526548 let mut passes = matches. opt_strs ( "passes" ) ;
527549 let mut plugins = matches. opt_strs ( "plugins" ) ;
@@ -570,7 +592,7 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
570592 let ( mut krate, renderinfo) =
571593 core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
572594 display_warnings, crate_name. clone ( ) ,
573- force_unstable_if_unmarked) ;
595+ force_unstable_if_unmarked, edition ) ;
574596
575597 info ! ( "finished with rustc" ) ;
576598
0 commit comments