@@ -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 } ;
@@ -271,6 +272,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
271
272
\" light-suffix.css\" ",
272
273
"PATH" )
273
274
} ) ,
275
+ unstable( "edition" , |o| {
276
+ o. optopt( "" , "edition" ,
277
+ "edition to use when compiling rust code (default: 2015)" ,
278
+ "EDITION" )
279
+ } ) ,
274
280
]
275
281
}
276
282
@@ -429,14 +435,23 @@ pub fn main_args(args: &[String]) -> isize {
429
435
let sort_modules_alphabetically = !matches. opt_present ( "sort-modules-by-appearance" ) ;
430
436
let resource_suffix = matches. opt_str ( "resource-suffix" ) ;
431
437
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
+
432
447
match ( should_test, markdown_input) {
433
448
( true , true ) => {
434
449
return markdown:: test ( input, cfgs, libs, externs, test_args, maybe_sysroot,
435
- display_warnings, linker)
450
+ display_warnings, linker, edition )
436
451
}
437
452
( true , false ) => {
438
453
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 )
440
455
}
441
456
( false , true ) => return markdown:: render ( Path :: new ( input) ,
442
457
output. unwrap_or ( PathBuf :: from ( "doc" ) ) ,
@@ -446,7 +461,7 @@ pub fn main_args(args: &[String]) -> isize {
446
461
}
447
462
448
463
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| {
450
465
let Output { krate, passes, renderinfo } = out;
451
466
info ! ( "going to format" ) ;
452
467
match output_format. as_ref ( ) . map ( |s| & * * s) {
@@ -487,14 +502,15 @@ fn print_error<T>(error_message: T) where T: Display {
487
502
/// and files and then generates the necessary rustdoc output for formatting.
488
503
fn acquire_input < R , F > ( input : PathBuf ,
489
504
externs : Externs ,
505
+ edition : Edition ,
490
506
matches : & getopts:: Matches ,
491
507
f : F )
492
508
-> Result < R , String >
493
509
where R : ' static + Send , F : ' static + Send + FnOnce ( Output ) -> R {
494
510
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) ) ,
496
512
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) )
498
514
}
499
515
}
500
516
@@ -520,8 +536,14 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
520
536
/// generated from the cleaned AST of the crate.
521
537
///
522
538
/// 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
+ {
525
547
let mut default_passes = !matches. opt_present ( "no-defaults" ) ;
526
548
let mut passes = matches. opt_strs ( "passes" ) ;
527
549
let mut plugins = matches. opt_strs ( "plugins" ) ;
@@ -570,7 +592,7 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
570
592
let ( mut krate, renderinfo) =
571
593
core:: run_core ( paths, cfgs, externs, Input :: File ( cratefile) , triple, maybe_sysroot,
572
594
display_warnings, crate_name. clone ( ) ,
573
- force_unstable_if_unmarked) ;
595
+ force_unstable_if_unmarked, edition ) ;
574
596
575
597
info ! ( "finished with rustc" ) ;
576
598
0 commit comments