Skip to content

Rollup of 3 pull requests #49561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 1, 2018
30 changes: 24 additions & 6 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ pub fn run_cargo(build: &Build, cargo: &mut Command, stamp: &Path, is_check: boo
let max = max.unwrap();
let max_path = max_path.unwrap();
if stamp_contents == new_contents && max <= stamp_mtime {
build.verbose(&format!("not updating {:?}; contents equal and {} <= {}",
build.verbose(&format!("not updating {:?}; contents equal and {:?} <= {:?}",
stamp, max, stamp_mtime));
return deps
}
Expand Down
3 changes: 0 additions & 3 deletions src/build_helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ authors = ["The Rust Project Developers"]
[lib]
name = "build_helper"
path = "lib.rs"

[dependencies]
filetime = "0.1"
19 changes: 7 additions & 12 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

#![deny(warnings)]

extern crate filetime;

use std::fs::File;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::{fs, env};

use filetime::FileTime;
use std::time::{SystemTime, UNIX_EPOCH};

/// A helper macro to `unwrap` a result except also print out details like:
///
Expand Down Expand Up @@ -137,10 +134,8 @@ pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
}

/// Returns the last-modified time for `path`, or zero if it doesn't exist.
pub fn mtime(path: &Path) -> FileTime {
fs::metadata(path).map(|f| {
FileTime::from_last_modification_time(&f)
}).unwrap_or(FileTime::zero())
pub fn mtime(path: &Path) -> SystemTime {
fs::metadata(path).and_then(|f| f.modified()).unwrap_or(UNIX_EPOCH)
}

/// Returns whether `dst` is up to date given that the file or files in `src`
Expand All @@ -157,9 +152,9 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool {
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
};
if meta.is_dir() {
dir_up_to_date(src, &threshold)
dir_up_to_date(src, threshold)
} else {
FileTime::from_last_modification_time(&meta) <= threshold
meta.modified().unwrap_or(UNIX_EPOCH) <= threshold
}
}

Expand Down Expand Up @@ -226,13 +221,13 @@ pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result<NativeLibBoiler
search_path)
}

fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
let meta = t!(e.metadata());
if meta.is_dir() {
dir_up_to_date(&e.path(), threshold)
} else {
FileTime::from_last_modification_time(&meta) < *threshold
meta.modified().unwrap_or(UNIX_EPOCH) < threshold
}
})
}
Expand Down
13 changes: 13 additions & 0 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ details.

[issue-display-warnings]: https://github.com/rust-lang/rust/issues/41574

### `--edition`: control the edition of docs and doctests

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --edition 2018
$ rustdoc --test src/lib.rs -Z unstable-options --edition 2018
```

This flag allows rustdoc to treat your rust code as the given edition. It will compile doctests with
the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
(the first edition).

### `-Z force-unstable-if-unmarked`

Using this flag looks like this:
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use rustc_back::target::TargetTriple;

use syntax::ast::NodeId;
use syntax::codemap;
use syntax::edition::Edition;
use syntax::feature_gate::UnstableFeatures;
use errors;
use errors::emitter::ColorConfig;
Expand Down Expand Up @@ -123,7 +124,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.

Expand All @@ -148,6 +150,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()
Expand Down
38 changes: 30 additions & 8 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -271,6 +272,11 @@ pub fn opts() -> Vec<RustcOptGroup> {
\"light-suffix.css\"",
"PATH")
}),
unstable("edition", |o| {
o.optopt("", "edition",
"edition to use when compiling rust code (default: 2015)",
"EDITION")
}),
]
}

Expand Down Expand Up @@ -429,14 +435,23 @@ 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,
display_warnings, linker)
display_warnings, linker, edition)
}
(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")),
Expand All @@ -446,7 +461,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) {
Expand Down Expand Up @@ -487,14 +502,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))
}
}

Expand All @@ -520,8 +536,14 @@ 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
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> 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");
let mut plugins = matches.opt_strs("plugins");
Expand Down Expand Up @@ -570,7 +592,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");

Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use testing;
use rustc::session::search_paths::SearchPaths;
use rustc::session::config::Externs;
use syntax::codemap::DUMMY_SP;
use syntax::edition::Edition;

use externalfiles::{ExternalHtml, LoadStringError, load_string};

Expand Down Expand Up @@ -139,7 +140,7 @@ pub fn render(input: &Path, mut output: PathBuf, matches: &getopts::Matches,
/// Run any tests/code examples in the markdown file `input`.
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
mut test_args: Vec<String>, maybe_sysroot: Option<PathBuf>,
display_warnings: bool, linker: Option<PathBuf>) -> isize {
display_warnings: bool, linker: Option<PathBuf>, edition: Edition) -> isize {
let input_str = match load_string(input) {
Ok(s) => s,
Err(LoadStringError::ReadFail) => return 1,
Expand All @@ -151,7 +152,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
let mut collector = Collector::new(input.to_owned(), cfgs, libs, externs,
true, opts, maybe_sysroot, None,
Some(PathBuf::from(input)),
linker);
linker, edition);
find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&test_args, collector.tests,
Expand Down
Loading