Skip to content

Commit 7f548bc

Browse files
add --edition flag to rustdoc
1 parent 14ac1b5 commit 7f548bc

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/librustdoc/core.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_metadata::cstore::CStore;
2525

2626
use syntax::ast::NodeId;
2727
use syntax::codemap;
28+
use syntax::edition::Edition;
2829
use syntax::feature_gate::UnstableFeatures;
2930
use errors;
3031
use errors::emitter::ColorConfig;
@@ -120,7 +121,8 @@ pub fn run_core(search_paths: SearchPaths,
120121
maybe_sysroot: Option<PathBuf>,
121122
allow_warnings: bool,
122123
crate_name: Option<String>,
123-
force_unstable_if_unmarked: bool) -> (clean::Crate, RenderInfo)
124+
force_unstable_if_unmarked: bool,
125+
edition: Edition) -> (clean::Crate, RenderInfo)
124126
{
125127
// Parse, resolve, and typecheck the given crate.
126128

@@ -144,6 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
144146
actually_rustdoc: true,
145147
debugging_opts: config::DebuggingOptions {
146148
force_unstable_if_unmarked,
149+
edition,
147150
..config::basic_debugging_options()
148151
},
149152
..config::basic_options().clone()

src/librustdoc/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use std::path::{Path, PathBuf};
6161
use std::process;
6262
use std::sync::mpsc::channel;
6363

64+
use syntax::edition::Edition;
6465
use externalfiles::ExternalHtml;
6566
use rustc::session::search_paths::SearchPaths;
6667
use 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.
487502
fn acquire_input<R, F>(input: PathBuf,
488503
externs: Externs,
504+
edition: Edition,
489505
matches: &getopts::Matches,
490506
f: F)
491507
-> Result<R, String>
492508
where 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
523539
where 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

src/librustdoc/test.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_metadata::cstore::CStore;
3434
use rustc_resolve::MakeGlobMap;
3535
use syntax::ast;
3636
use syntax::codemap::CodeMap;
37+
use syntax::edition::Edition;
3738
use syntax::feature_gate::UnstableFeatures;
3839
use syntax::with_globals;
3940
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName};
@@ -57,7 +58,8 @@ pub fn run(input_path: &Path,
5758
crate_name: Option<String>,
5859
maybe_sysroot: Option<PathBuf>,
5960
display_warnings: bool,
60-
linker: Option<PathBuf>)
61+
linker: Option<PathBuf>,
62+
edition: Edition)
6163
-> isize {
6264
let input = config::Input::File(input_path.to_owned());
6365

@@ -70,6 +72,10 @@ pub fn run(input_path: &Path,
7072
unstable_features: UnstableFeatures::from_environment(),
7173
lint_cap: Some(::rustc::lint::Level::Allow),
7274
actually_rustdoc: true,
75+
debugging_opts: config::DebuggingOptions {
76+
edition,
77+
..config::basic_debugging_options()
78+
},
7379
..config::basic_options().clone()
7480
};
7581

0 commit comments

Comments
 (0)