@@ -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 } ;
@@ -270,6 +271,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
270271 \" main-suffix.css\" ",
271272 "PATH" )
272273 } ) ,
274+ unstable( "edition" , |o| {
275+ o. optopt( "" , "edition" ,
276+ "edition to use when compiling rust code (default: 2015)" ,
277+ "EDITION" )
278+ } ) ,
273279 ]
274280}
275281
@@ -428,14 +434,23 @@ pub fn main_args(args: &[String]) -> isize {
428434 let sort_modules_alphabetically = !matches. opt_present ( "sort-modules-by-appearance" ) ;
429435 let resource_suffix = matches. opt_str ( "resource-suffix" ) ;
430436
437+ let edition = matches. opt_str ( "edition" ) . unwrap_or ( "2015" . to_string ( ) ) ;
438+ let edition = match edition. parse ( ) {
439+ Ok ( e) => e,
440+ Err ( _) => {
441+ print_error ( "could not parse edition" ) ;
442+ return 1 ;
443+ }
444+ } ;
445+
431446 match ( should_test, markdown_input) {
432447 ( true , true ) => {
433448 return markdown:: test ( input, cfgs, libs, externs, test_args, maybe_sysroot,
434449 display_warnings, linker)
435450 }
436451 ( true , false ) => {
437452 return test:: run ( Path :: new ( input) , cfgs, libs, externs, test_args, crate_name,
438- maybe_sysroot, display_warnings, linker)
453+ maybe_sysroot, display_warnings, linker, edition )
439454 }
440455 ( false , true ) => return markdown:: render ( Path :: new ( input) ,
441456 output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
@@ -445,7 +460,7 @@ pub fn main_args(args: &[String]) -> isize {
445460 }
446461
447462 let output_format = matches. opt_str ( "w" ) ;
448- let res = acquire_input ( PathBuf :: from ( input) , externs, & matches, move |out| {
463+ let res = acquire_input ( PathBuf :: from ( input) , externs, edition , & matches, move |out| {
449464 let Output { krate, passes, renderinfo } = out;
450465 info ! ( "going to format" ) ;
451466 match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -486,14 +501,15 @@ fn print_error<T>(error_message: T) where T: Display {
486501/// and files and then generates the necessary rustdoc output for formatting.
487502fn acquire_input < R , F > ( input : PathBuf ,
488503 externs : Externs ,
504+ edition : Edition ,
489505 matches : & getopts:: Matches ,
490506 f : F )
491507 -> Result < R , String >
492508where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
493509 match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
494- Some ( "rust" ) => Ok ( rust_input ( input, externs, matches, f) ) ,
510+ Some ( "rust" ) => Ok ( rust_input ( input, externs, edition , matches, f) ) ,
495511 Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
496- None => Ok ( rust_input ( input, externs, matches, f) )
512+ None => Ok ( rust_input ( input, externs, edition , matches, f) )
497513 }
498514}
499515
@@ -519,7 +535,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
519535/// generated from the cleaned AST of the crate.
520536///
521537/// This form of input will run all of the plug/cleaning passes
522- fn rust_input < R , F > ( cratefile : PathBuf , externs : Externs , matches : & getopts:: Matches , f : F ) -> R
538+ fn rust_input < R , F > ( cratefile : PathBuf , externs : Externs , edition : Edition , matches : & getopts:: Matches , f : F ) -> R
523539where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
524540 let mut default_passes = !matches. opt_present ( "no-defaults" ) ;
525541 let mut passes = matches. opt_strs ( "passes" ) ;
@@ -563,7 +579,7 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
563579 let ( mut krate, renderinfo) =
564580 core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
565581 display_warnings, crate_name. clone ( ) ,
566- force_unstable_if_unmarked) ;
582+ force_unstable_if_unmarked, edition ) ;
567583
568584 info ! ( "finished with rustc" ) ;
569585
0 commit comments