Skip to content

Commit d4af223

Browse files
committed
Auto merge of #6416 - alexcrichton:idioms, r=dwijnand
Migrate to some Rust 2018 idioms Run a few lints, hand-edit a few things, otherwise try to help push Cargo into the 2018 edition!
2 parents 2cf1f5d + 76ce4df commit d4af223

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+446
-460
lines changed

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ glob = "0.2.11"
3737
hex = "0.3"
3838
home = "0.3"
3939
ignore = "0.4"
40-
lazy_static = "1.0.0"
40+
lazy_static = "1.2.0"
4141
jobserver = "0.1.11"
4242
lazycell = "1.2.0"
4343
libc = "0.2"
44-
log = "0.4"
44+
log = "0.4.6"
4545
libgit2-sys = "0.7.9"
4646
num_cpus = "1.0"
4747
opener = "0.3.0"
4848
rustfix = "0.4.2"
4949
same-file = "1"
5050
semver = { version = "0.9.0", features = ["serde"] }
51-
serde = "1.0"
52-
serde_derive = "1.0"
51+
serde = { version = "1.0.82", features = ['derive'] }
5352
serde_ignored = "0.0.4"
5453
serde_json = { version = "1.0.30", features = ["raw_value"] }
5554
shell-escape = "0.1.4"

src/bin/cargo/commands/locate_project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::command_prelude::*;
22

33
use cargo::print_json;
4+
use serde::Serialize;
45

56
pub fn cli() -> App {
67
subcommand("locate-project")

src/bin/cargo/main.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))] // large project
2-
#![cfg_attr(feature = "cargo-clippy", allow(clippy::redundant_closure))] // there's a false positive
1+
#![warn(rust_2018_idioms)] // while we're getting used to 2018
2+
#![allow(clippy::too_many_arguments)] // large project
3+
#![allow(clippy::redundant_closure)] // there's a false positive
34

4-
use cargo;
5-
6-
#[cfg(not(feature = "pretty-env-logger"))]
7-
extern crate env_logger;
8-
#[cfg(feature = "pretty-env-logger")]
9-
extern crate pretty_env_logger;
105
#[macro_use]
116
extern crate failure;
12-
use git2_curl;
13-
14-
#[macro_use]
15-
extern crate serde_derive;
167

178
use std::collections::BTreeSet;
189
use std::env;

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::env;
33
use std::path::{Path, PathBuf};
44
use std::str;
55

6+
use log::debug;
7+
68
use crate::core::profiles::Profiles;
79
use crate::core::{Dependency, Workspace};
810
use crate::core::{PackageId, PackageSet, Resolve};
@@ -158,7 +160,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
158160
self.build_config.jobs
159161
}
160162

161-
pub fn rustflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
163+
pub fn rustflags_args(&self, unit: &Unit<'_>) -> CargoResult<Vec<String>> {
162164
env_args(
163165
self.config,
164166
&self.build_config.requested_target,
@@ -169,7 +171,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
169171
)
170172
}
171173

172-
pub fn rustdocflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
174+
pub fn rustdocflags_args(&self, unit: &Unit<'_>) -> CargoResult<Vec<String>> {
173175
env_args(
174176
self.config,
175177
&self.build_config.requested_target,

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl TargetInfo {
259259
fn parse_crate_type(
260260
crate_type: &str,
261261
error: &str,
262-
lines: &mut str::Lines,
262+
lines: &mut str::Lines<'_>,
263263
) -> CargoResult<Option<(String, String)>> {
264264
let not_supported = error.lines().any(|line| {
265265
(line.contains("unsupported crate type") || line.contains("unknown crate type"))

src/cargo/core/compiler/build_plan.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
//! dependencies on other Invocations.
88
99
use std::collections::BTreeMap;
10+
use std::path::PathBuf;
11+
12+
use serde::Serialize;
1013

1114
use super::context::OutputFile;
1215
use super::{CompileMode, Context, Kind, Unit};
1316
use crate::core::TargetKind;
1417
use crate::util::{internal, CargoResult, ProcessBuilder};
15-
use semver;
16-
use serde_json;
17-
use std::path::PathBuf;
1818

1919
#[derive(Debug, Serialize)]
2020
struct Invocation {
@@ -45,7 +45,7 @@ struct SerializedBuildPlan {
4545
}
4646

4747
impl Invocation {
48-
pub fn new(unit: &Unit, deps: Vec<usize>) -> Invocation {
48+
pub fn new(unit: &Unit<'_>, deps: Vec<usize>) -> Invocation {
4949
let id = unit.pkg.package_id();
5050
Invocation {
5151
package_name: id.name().to_string(),
@@ -109,7 +109,7 @@ impl BuildPlan {
109109
}
110110
}
111111

112-
pub fn add(&mut self, cx: &Context, unit: &Unit) -> CargoResult<()> {
112+
pub fn add(&mut self, cx: &Context<'_, '_>, unit: &Unit<'_>) -> CargoResult<()> {
113113
let id = self.plan.invocations.len();
114114
self.invocation_map.insert(unit.buildkey(), id);
115115
let deps = cx

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn pre_version_component(v: &Version) -> String {
256256
ret
257257
}
258258

259-
fn target_runner(bcx: &BuildContext) -> CargoResult<Option<(PathBuf, Vec<String>)>> {
259+
fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult<Option<(PathBuf, Vec<String>)>> {
260260
let target = bcx.target_triple();
261261

262262
// try target.{}.runner

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
66
use std::sync::Arc;
77

88
use lazycell::LazyCell;
9+
use log::info;
910

1011
use super::{BuildContext, Context, FileFlavor, Kind, Layout, Unit};
1112
use crate::core::{TargetKind, Workspace};
@@ -15,7 +16,7 @@ use crate::util::{self, CargoResult};
1516
pub struct Metadata(u64);
1617

1718
impl fmt::Display for Metadata {
18-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1920
write!(f, "{:016x}", self.0)
2021
}
2122
}
@@ -106,7 +107,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
106107

107108
/// Get the short hash based only on the PackageId
108109
/// Used for the metadata when target_metadata returns None
109-
pub fn target_short_hash(&self, unit: &Unit) -> String {
110+
pub fn target_short_hash(&self, unit: &Unit<'_>) -> String {
110111
let hashable = unit.pkg.package_id().stable_hash(self.ws.root());
111112
util::short_hash(&hashable)
112113
}
@@ -148,7 +149,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
148149

149150
/// Returns the directories where Rust crate dependencies are found for the
150151
/// specified unit.
151-
pub fn deps_dir(&self, unit: &Unit) -> &Path {
152+
pub fn deps_dir(&self, unit: &Unit<'_>) -> &Path {
152153
self.layout(unit.kind).deps()
153154
}
154155

@@ -192,7 +193,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
192193
}
193194

194195
/// Returns the bin stem for a given target (without metadata)
195-
fn bin_stem(&self, unit: &Unit) -> String {
196+
fn bin_stem(&self, unit: &Unit<'_>) -> String {
196197
if unit.target.allows_underscores() {
197198
unit.target.name().to_string()
198199
} else {

src/cargo/core/compiler/context/mod.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
129129
mut self,
130130
units: &[Unit<'a>],
131131
export_dir: Option<PathBuf>,
132-
exec: &Arc<Executor>,
132+
exec: &Arc<dyn Executor>,
133133
) -> CargoResult<Compilation<'cfg>> {
134134
let mut queue = JobQueue::new(self.bcx);
135135
let mut plan = BuildPlan::new();
@@ -386,7 +386,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
386386
deps
387387
}
388388

389-
pub fn incremental_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
389+
pub fn incremental_args(&self, unit: &Unit<'_>) -> CargoResult<Vec<String>> {
390390
// There's a number of ways to configure incremental compilation right
391391
// now. In order of descending priority (first is highest priority) we
392392
// have:
@@ -471,24 +471,25 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
471471

472472
fn check_collistions(&self) -> CargoResult<()> {
473473
let mut output_collisions = HashMap::new();
474-
let describe_collision = |unit: &Unit, other_unit: &Unit, path: &PathBuf| -> String {
475-
format!(
476-
"The {} target `{}` in package `{}` has the same output \
477-
filename as the {} target `{}` in package `{}`.\n\
478-
Colliding filename is: {}\n",
479-
unit.target.kind().description(),
480-
unit.target.name(),
481-
unit.pkg.package_id(),
482-
other_unit.target.kind().description(),
483-
other_unit.target.name(),
484-
other_unit.pkg.package_id(),
485-
path.display()
486-
)
487-
};
474+
let describe_collision =
475+
|unit: &Unit<'_>, other_unit: &Unit<'_>, path: &PathBuf| -> String {
476+
format!(
477+
"The {} target `{}` in package `{}` has the same output \
478+
filename as the {} target `{}` in package `{}`.\n\
479+
Colliding filename is: {}\n",
480+
unit.target.kind().description(),
481+
unit.target.name(),
482+
unit.pkg.package_id(),
483+
other_unit.target.kind().description(),
484+
other_unit.target.name(),
485+
other_unit.pkg.package_id(),
486+
path.display()
487+
)
488+
};
488489
let suggestion = "Consider changing their names to be unique or compiling them separately.\n\
489490
This may become a hard error in the future, see https://github.com/rust-lang/cargo/issues/6313";
490-
let report_collision = |unit: &Unit,
491-
other_unit: &Unit,
491+
let report_collision = |unit: &Unit<'_>,
492+
other_unit: &Unit<'_>,
492493
path: &PathBuf|
493494
-> CargoResult<()> {
494495
if unit.target.name() == other_unit.target.name() {
@@ -567,7 +568,7 @@ impl Links {
567568
}
568569
}
569570

570-
pub fn validate(&mut self, resolve: &Resolve, unit: &Unit) -> CargoResult<()> {
571+
pub fn validate(&mut self, resolve: &Resolve, unit: &Unit<'_>) -> CargoResult<()> {
571572
if !self.validated.insert(unit.pkg.package_id()) {
572573
return Ok(());
573574
}

src/cargo/core/compiler/context/unit_dependencies.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use std::cell::RefCell;
1919
use std::collections::{HashMap, HashSet};
2020

21+
use log::trace;
22+
2123
use super::{BuildContext, CompileMode, Kind, Unit};
2224
use crate::core::dependency::Kind as DepKind;
2325
use crate::core::package::Downloads;
@@ -328,7 +330,7 @@ fn compute_deps_doc<'a, 'cfg, 'tmp>(
328330

329331
fn maybe_lib<'a>(
330332
unit: &Unit<'a>,
331-
bcx: &BuildContext,
333+
bcx: &BuildContext<'_, '_>,
332334
unit_for: UnitFor,
333335
) -> Option<(Unit<'a>, UnitFor)> {
334336
unit.pkg.targets().iter().find(|t| t.linkable()).map(|t| {
@@ -345,7 +347,10 @@ fn maybe_lib<'a>(
345347
/// script itself doesn't have any dependencies, so even in that case a unit
346348
/// of work is still returned. `None` is only returned if the package has no
347349
/// build script.
348-
fn dep_build_script<'a>(unit: &Unit<'a>, bcx: &BuildContext) -> Option<(Unit<'a>, UnitFor)> {
350+
fn dep_build_script<'a>(
351+
unit: &Unit<'a>,
352+
bcx: &BuildContext<'_, '_>,
353+
) -> Option<(Unit<'a>, UnitFor)> {
349354
unit.pkg
350355
.targets()
351356
.iter()
@@ -385,7 +390,7 @@ fn check_or_build_mode(mode: CompileMode, target: &Target) -> CompileMode {
385390
}
386391

387392
fn new_unit<'a>(
388-
bcx: &BuildContext,
393+
bcx: &BuildContext<'_, '_>,
389394
pkg: &'a Package,
390395
target: &'a Target,
391396
unit_for: UnitFor,
@@ -418,7 +423,7 @@ fn new_unit<'a>(
418423
///
419424
/// Here we take the entire `deps` map and add more dependencies from execution
420425
/// of one build script to execution of another build script.
421-
fn connect_run_custom_build_deps(state: &mut State) {
426+
fn connect_run_custom_build_deps(state: &mut State<'_, '_, '_>) {
422427
let mut new_deps = Vec::new();
423428

424429
{

0 commit comments

Comments
 (0)