Skip to content

Commit

Permalink
bootstrap: deny(rust_2018_idioms)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 25, 2019
1 parent 31eb0e2 commit 6343d6b
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 315 deletions.
24 changes: 12 additions & 12 deletions src/bootstrap/builder.rs
Expand Up @@ -62,21 +62,21 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {

/// Primary function to execute this rule. Can call `builder.ensure()`
/// with other steps to run those.
fn run(self, builder: &Builder) -> Self::Output;
fn run(self, builder: &Builder<'_>) -> Self::Output;

/// When bootstrap is passed a set of paths, this controls whether this rule
/// will execute. However, it does not get called in a "default" context
/// when we are not passed any paths; in that case, `make_run` is called
/// directly.
fn should_run(run: ShouldRun) -> ShouldRun;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_>;

/// Builds up a "root" rule, either as a default rule or from a path passed
/// to us.
///
/// When path is `None`, we are executing in a context where no paths were
/// passed. When `./x.py build` is run, for example, this rule could get
/// called if it is in the correct list below with a path of `None`.
fn make_run(_run: RunConfig) {
fn make_run(_run: RunConfig<'_>) {
// It is reasonable to not have an implementation of make_run for rules
// who do not want to get called from the root context. This means that
// they are likely dependencies (e.g., sysroot creation) or similar, and
Expand All @@ -95,8 +95,8 @@ pub struct RunConfig<'a> {
struct StepDescription {
default: bool,
only_hosts: bool,
should_run: fn(ShouldRun) -> ShouldRun,
make_run: fn(RunConfig),
should_run: fn(ShouldRun<'_>) -> ShouldRun<'_>,
make_run: fn(RunConfig<'_>),
name: &'static str,
}

Expand Down Expand Up @@ -124,7 +124,7 @@ impl PathSet {
}
}

fn path(&self, builder: &Builder) -> PathBuf {
fn path(&self, builder: &Builder<'_>) -> PathBuf {
match self {
PathSet::Set(set) => set
.iter()
Expand All @@ -147,7 +147,7 @@ impl StepDescription {
}
}

fn maybe_run(&self, builder: &Builder, pathset: &PathSet) {
fn maybe_run(&self, builder: &Builder<'_>, pathset: &PathSet) {
if builder.config.exclude.iter().any(|e| pathset.has(e)) {
eprintln!("Skipping {:?} because it is excluded", pathset);
return;
Expand Down Expand Up @@ -183,7 +183,7 @@ impl StepDescription {
}
}

fn run(v: &[StepDescription], builder: &Builder, paths: &[PathBuf]) {
fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) {
let should_runs = v
.iter()
.map(|desc| (desc.should_run)(ShouldRun::new(builder)))
Expand Down Expand Up @@ -245,7 +245,7 @@ pub struct ShouldRun<'a> {
}

impl<'a> ShouldRun<'a> {
fn new(builder: &'a Builder) -> ShouldRun<'a> {
fn new(builder: &'a Builder<'_>) -> ShouldRun<'a> {
ShouldRun {
builder,
paths: BTreeSet::new(),
Expand Down Expand Up @@ -511,7 +511,7 @@ impl<'a> Builder<'a> {
Some(help)
}

pub fn new(build: &Build) -> Builder {
pub fn new(build: &Build) -> Builder<'_> {
let (kind, paths) = match build.config.cmd {
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
Expand Down Expand Up @@ -591,11 +591,11 @@ impl<'a> Builder<'a> {
impl Step for Libdir {
type Output = Interned<PathBuf>;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.never()
}

fn run(self, builder: &Builder) -> Interned<PathBuf> {
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
let compiler = self.compiler;
let config = &builder.build.config;
let lib = if compiler.stage >= 1 && config.libdir_relative().is_some() {
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/cache.rs
Expand Up @@ -68,20 +68,20 @@ unsafe impl<T> Send for Interned<T> {}
unsafe impl<T> Sync for Interned<T> {}

impl fmt::Display for Interned<String> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: &str = &*self;
f.write_str(s)
}
}

impl fmt::Debug for Interned<String> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: &str = &*self;
f.write_fmt(format_args!("{:?}", s))
}
}
impl fmt::Debug for Interned<PathBuf> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: &Path = &*self;
f.write_fmt(format_args!("{:?}", s))
}
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/cc_detect.rs
Expand Up @@ -27,7 +27,6 @@ use std::path::{Path, PathBuf};
use std::process::Command;

use build_helper::output;
use cc;

use crate::{Build, GitRepo};
use crate::config::Target;
Expand Down Expand Up @@ -157,7 +156,7 @@ fn set_compiler(cfg: &mut cc::Build,
None => return,
};
match output[i + 3..].chars().next().unwrap() {
'0' ... '6' => {}
'0' ..= '6' => {}
_ => return,
}
let alternative = format!("e{}", gnu_compiler);
Expand Down
56 changes: 36 additions & 20 deletions src/bootstrap/check.rs
Expand Up @@ -17,17 +17,17 @@ impl Step for Std {
type Output = ();
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.all_krates("std")
}

fn make_run(run: RunConfig) {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Std {
target: run.target,
});
}

fn run(self, builder: &Builder) {
fn run(self, builder: &Builder<'_>) {
let target = self.target;
let compiler = builder.compiler(0, builder.config.build);

Expand Down Expand Up @@ -56,11 +56,11 @@ impl Step for Rustc {
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.all_krates("rustc-main")
}

fn make_run(run: RunConfig) {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Rustc {
target: run.target,
});
Expand All @@ -71,7 +71,7 @@ impl Step for Rustc {
/// This will build the compiler for a particular stage of the build using
/// the `compiler` targeting the `target` architecture. The artifacts
/// created will also be linked into the sysroot directory.
fn run(self, builder: &Builder) {
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let target = self.target;

Expand Down Expand Up @@ -103,11 +103,11 @@ impl Step for CodegenBackend {
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.all_krates("rustc_codegen_llvm")
}

fn make_run(run: RunConfig) {
fn make_run(run: RunConfig<'_>) {
let backend = run.builder.config.rust_codegen_backends.get(0);
let backend = backend.cloned().unwrap_or_else(|| {
INTERNER.intern_str("llvm")
Expand All @@ -118,7 +118,7 @@ impl Step for CodegenBackend {
});
}

fn run(self, builder: &Builder) {
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let target = self.target;
let backend = self.backend;
Expand Down Expand Up @@ -148,17 +148,17 @@ impl Step for Test {
type Output = ();
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.all_krates("test")
}

fn make_run(run: RunConfig) {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Test {
target: run.target,
});
}

fn run(self, builder: &Builder) {
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let target = self.target;

Expand Down Expand Up @@ -189,17 +189,17 @@ impl Step for Rustdoc {
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/rustdoc")
}

fn make_run(run: RunConfig) {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Rustdoc {
target: run.target,
});
}

fn run(self, builder: &Builder) {
fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let target = self.target;

Expand Down Expand Up @@ -229,25 +229,37 @@ impl Step for Rustdoc {

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
pub fn libstd_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
pub fn libstd_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
}

/// Cargo's output path for libtest in a given stage, compiled by a particular
/// compiler for the specified target.
pub fn libtest_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
pub fn libtest_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
) -> PathBuf {
builder.cargo_out(compiler, Mode::Test, target).join(".libtest-check.stamp")
}

/// Cargo's output path for librustc in a given stage, compiled by a particular
/// compiler for the specified target.
pub fn librustc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
pub fn librustc_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
) -> PathBuf {
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
}

/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
/// compiler for the specified target and backend.
fn codegen_backend_stamp(builder: &Builder,
fn codegen_backend_stamp(builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
backend: Interned<String>) -> PathBuf {
Expand All @@ -257,7 +269,11 @@ fn codegen_backend_stamp(builder: &Builder,

/// Cargo's output path for rustdoc in a given stage, compiled by a particular
/// compiler for the specified target.
pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
pub fn rustdoc_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
) -> PathBuf {
builder.cargo_out(compiler, Mode::ToolRustc, target)
.join(".rustdoc-check.stamp")
}

0 comments on commit 6343d6b

Please sign in to comment.