add --edition flag to rustdoc
This commit is contained in:
parent
14ac1b5faa
commit
7f548bc8c6
3 changed files with 33 additions and 8 deletions
|
|
@ -25,6 +25,7 @@ use rustc_metadata::cstore::CStore;
|
|||
|
||||
use syntax::ast::NodeId;
|
||||
use syntax::codemap;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use errors;
|
||||
use errors::emitter::ColorConfig;
|
||||
|
|
@ -120,7 +121,8 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
maybe_sysroot: Option<PathBuf>,
|
||||
allow_warnings: bool,
|
||||
crate_name: Option<String>,
|
||||
force_unstable_if_unmarked: bool) -> (clean::Crate, RenderInfo)
|
||||
force_unstable_if_unmarked: bool,
|
||||
edition: Edition) -> (clean::Crate, RenderInfo)
|
||||
{
|
||||
// Parse, resolve, and typecheck the given crate.
|
||||
|
||||
|
|
@ -144,6 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
|
|||
actually_rustdoc: true,
|
||||
debugging_opts: config::DebuggingOptions {
|
||||
force_unstable_if_unmarked,
|
||||
edition,
|
||||
..config::basic_debugging_options()
|
||||
},
|
||||
..config::basic_options().clone()
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::process;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
use syntax::edition::Edition;
|
||||
use externalfiles::ExternalHtml;
|
||||
use rustc::session::search_paths::SearchPaths;
|
||||
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options, Externs};
|
||||
|
|
@ -270,6 +271,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
|
|||
\"main-suffix.css\"",
|
||||
"PATH")
|
||||
}),
|
||||
unstable("edition", |o| {
|
||||
o.optopt("", "edition",
|
||||
"edition to use when compiling rust code (default: 2015)",
|
||||
"EDITION")
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -428,6 +434,15 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
|
||||
let resource_suffix = matches.opt_str("resource-suffix");
|
||||
|
||||
let edition = matches.opt_str("edition").unwrap_or("2015".to_string());
|
||||
let edition = match edition.parse() {
|
||||
Ok(e) => e,
|
||||
Err(_) => {
|
||||
print_error("could not parse edition");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
match (should_test, markdown_input) {
|
||||
(true, true) => {
|
||||
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
|
||||
|
|
@ -435,7 +450,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
}
|
||||
(true, false) => {
|
||||
return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,
|
||||
maybe_sysroot, display_warnings, linker)
|
||||
maybe_sysroot, display_warnings, linker, edition)
|
||||
}
|
||||
(false, true) => return markdown::render(Path::new(input),
|
||||
output.unwrap_or(PathBuf::from("doc")),
|
||||
|
|
@ -445,7 +460,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
}
|
||||
|
||||
let output_format = matches.opt_str("w");
|
||||
let res = acquire_input(PathBuf::from(input), externs, &matches, move |out| {
|
||||
let res = acquire_input(PathBuf::from(input), externs, edition, &matches, move |out| {
|
||||
let Output { krate, passes, renderinfo } = out;
|
||||
info!("going to format");
|
||||
match output_format.as_ref().map(|s| &**s) {
|
||||
|
|
@ -486,14 +501,15 @@ fn print_error<T>(error_message: T) where T: Display {
|
|||
/// and files and then generates the necessary rustdoc output for formatting.
|
||||
fn acquire_input<R, F>(input: PathBuf,
|
||||
externs: Externs,
|
||||
edition: Edition,
|
||||
matches: &getopts::Matches,
|
||||
f: F)
|
||||
-> Result<R, String>
|
||||
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
|
||||
match matches.opt_str("r").as_ref().map(|s| &**s) {
|
||||
Some("rust") => Ok(rust_input(input, externs, matches, f)),
|
||||
Some("rust") => Ok(rust_input(input, externs, edition, matches, f)),
|
||||
Some(s) => Err(format!("unknown input format: {}", s)),
|
||||
None => Ok(rust_input(input, externs, matches, f))
|
||||
None => Ok(rust_input(input, externs, edition, matches, f))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -519,7 +535,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
|
|||
/// generated from the cleaned AST of the crate.
|
||||
///
|
||||
/// This form of input will run all of the plug/cleaning passes
|
||||
fn rust_input<R, F>(cratefile: PathBuf, externs: Externs, matches: &getopts::Matches, f: F) -> R
|
||||
fn rust_input<R, F>(cratefile: PathBuf, externs: Externs, edition: Edition, matches: &getopts::Matches, f: F) -> R
|
||||
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
|
||||
let mut default_passes = !matches.opt_present("no-defaults");
|
||||
let mut passes = matches.opt_strs("passes");
|
||||
|
|
@ -563,7 +579,7 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
|
|||
let (mut krate, renderinfo) =
|
||||
core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
|
||||
display_warnings, crate_name.clone(),
|
||||
force_unstable_if_unmarked);
|
||||
force_unstable_if_unmarked, edition);
|
||||
|
||||
info!("finished with rustc");
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ use rustc_metadata::cstore::CStore;
|
|||
use rustc_resolve::MakeGlobMap;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::CodeMap;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use syntax::with_globals;
|
||||
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName};
|
||||
|
|
@ -57,7 +58,8 @@ pub fn run(input_path: &Path,
|
|||
crate_name: Option<String>,
|
||||
maybe_sysroot: Option<PathBuf>,
|
||||
display_warnings: bool,
|
||||
linker: Option<PathBuf>)
|
||||
linker: Option<PathBuf>,
|
||||
edition: Edition)
|
||||
-> isize {
|
||||
let input = config::Input::File(input_path.to_owned());
|
||||
|
||||
|
|
@ -70,6 +72,10 @@ pub fn run(input_path: &Path,
|
|||
unstable_features: UnstableFeatures::from_environment(),
|
||||
lint_cap: Some(::rustc::lint::Level::Allow),
|
||||
actually_rustdoc: true,
|
||||
debugging_opts: config::DebuggingOptions {
|
||||
edition,
|
||||
..config::basic_debugging_options()
|
||||
},
|
||||
..config::basic_options().clone()
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue