use std::ffi::OsString;
use std::fmt::{self, Display};
use std::io::{self, Read, Write};
-use std::iter::repeat;
use std::mem;
use std::panic;
use std::path::{PathBuf, Path};
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
-> Vec<(&'static str, Vec<lint::LintId>)> {
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
- lints.sort_by(|&(x, _): &(&'static str, Vec<lint::LintId>),
- &(y, _): &(&'static str, Vec<lint::LintId>)| {
- x.cmp(y)
- });
+ lints.sort_by_key(|l| l.0);
lints
}
.max()
.unwrap_or(0);
let padded = |x: &str| {
- let mut s = repeat(" ")
- .take(max_name_len - x.chars().count())
- .collect::<String>();
+ let mut s = " ".repeat(max_name_len - x.chars().count());
s.push_str(x);
s
};
.unwrap_or(0));
let padded = |x: &str| {
- let mut s = repeat(" ")
- .take(max_name_len - x.chars().count())
- .collect::<String>();
+ let mut s = " ".repeat(max_name_len - x.chars().count());
s.push_str(x);
s
};
}
}
-/// Runs `f` in a suitable thread for running `rustc`; returns a
-/// `Result` with either the return value of `f` or -- if a panic
-/// occurs -- the panic value.
-pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
+/// Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return
+/// value of `f` or -- if a panic occurs -- the panic value.
+///
+/// This version applies the given name to the thread. This is used by rustdoc to ensure consistent
+/// doctest output across platforms and executions.
+pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any + Send>>
where F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
// The or condition is added from backward compatibility.
if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() {
- let mut cfg = thread::Builder::new().name("rustc".to_string());
+ let mut cfg = thread::Builder::new().name(name);
// FIXME: Hacks on hacks. If the env is trying to override the stack size
// then *don't* set it explicitly.
}
}
+/// Runs `f` in a suitable thread for running `rustc`; returns a
+/// `Result` with either the return value of `f` or -- if a panic
+/// occurs -- the panic value.
+pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
+ where F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
+{
+ in_named_rustc_thread("rustc".to_string(), f)
+}
+
/// Get a list of extra command-line flags provided by the user, as strings.
///
/// This function is used during ICEs to show more information useful for