@@ -61,6 +61,7 @@ use std::path::{Path, PathBuf};
61
61
use std:: process;
62
62
use std:: sync:: mpsc:: channel;
63
63
64
+ use syntax:: edition:: Edition ;
64
65
use externalfiles:: ExternalHtml ;
65
66
use rustc:: session:: search_paths:: SearchPaths ;
66
67
use rustc:: session:: config:: { ErrorOutputType , RustcOptGroup , nightly_options, Externs } ;
@@ -270,6 +271,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
270
271
\" main-suffix.css\" ",
271
272
"PATH" )
272
273
} ) ,
274
+ unstable( "edition" , |o| {
275
+ o. optopt( "" , "edition" ,
276
+ "edition to use when compiling rust code (default: 2015)" ,
277
+ "EDITION" )
278
+ } ) ,
273
279
]
274
280
}
275
281
@@ -428,14 +434,23 @@ pub fn main_args(args: &[String]) -> isize {
428
434
let sort_modules_alphabetically = !matches. opt_present ( "sort-modules-by-appearance" ) ;
429
435
let resource_suffix = matches. opt_str ( "resource-suffix" ) ;
430
436
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
+
431
446
match ( should_test, markdown_input) {
432
447
( true , true ) => {
433
448
return markdown:: test ( input, cfgs, libs, externs, test_args, maybe_sysroot,
434
449
display_warnings, linker)
435
450
}
436
451
( true , false ) => {
437
452
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 )
439
454
}
440
455
( false , true ) => return markdown:: render ( Path :: new ( input) ,
441
456
output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
@@ -445,7 +460,7 @@ pub fn main_args(args: &[String]) -> isize {
445
460
}
446
461
447
462
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| {
449
464
let Output { krate, passes, renderinfo } = out;
450
465
info ! ( "going to format" ) ;
451
466
match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -486,14 +501,15 @@ fn print_error<T>(error_message: T) where T: Display {
486
501
/// and files and then generates the necessary rustdoc output for formatting.
487
502
fn acquire_input < R , F > ( input : PathBuf ,
488
503
externs : Externs ,
504
+ edition : Edition ,
489
505
matches : & getopts:: Matches ,
490
506
f : F )
491
507
-> Result < R , String >
492
508
where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
493
509
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) ) ,
495
511
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) )
497
513
}
498
514
}
499
515
@@ -519,7 +535,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
519
535
/// generated from the cleaned AST of the crate.
520
536
///
521
537
/// 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
523
539
where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
524
540
let mut default_passes = !matches. opt_present ( "no-defaults" ) ;
525
541
let mut passes = matches. opt_strs ( "passes" ) ;
@@ -563,7 +579,7 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
563
579
let ( mut krate, renderinfo) =
564
580
core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
565
581
display_warnings, crate_name. clone ( ) ,
566
- force_unstable_if_unmarked) ;
582
+ force_unstable_if_unmarked, edition ) ;
567
583
568
584
info ! ( "finished with rustc" ) ;
569
585
0 commit comments