Skip to content

Commit 72eee12

Browse files
committed
Auto merge of #5835 - dwijnand:clippy, r=alexcrichton
Resolve some Clippy warnings I'm not sure how these popped up since my PR 8 days ago. My current hypotheses: * changes in latest nightly rust/clippy * new or changed cargo code * I missed these as I was only touching `src/bin/cargo/main.rs` For future reference I now iterate with: touch src/bin/cargo/main.rs src/cargo/lib.rs && cargo +nightly clippy
2 parents 9bbab73 + 0807730 commit 72eee12

22 files changed

+56
-73
lines changed

src/bin/cargo/commands/fix.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,15 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
110110
// Unlike other commands default `cargo fix` to all targets to fix as much
111111
// code as we can.
112112
let mut opts = args.compile_options(config, mode)?;
113-
match opts.filter {
114-
CompileFilter::Default { .. } => {
115-
opts.filter = CompileFilter::Only {
116-
all_targets: true,
117-
lib: true,
118-
bins: FilterRule::All,
119-
examples: FilterRule::All,
120-
benches: FilterRule::All,
121-
tests: FilterRule::All,
122-
};
113+
if let CompileFilter::Default { .. } = opts.filter {
114+
opts.filter = CompileFilter::Only {
115+
all_targets: true,
116+
lib: true,
117+
bins: FilterRule::All,
118+
examples: FilterRule::All,
119+
benches: FilterRule::All,
120+
tests: FilterRule::All,
123121
}
124-
_ => {}
125122
}
126123
ops::fix(&ws, &mut ops::FixOptions {
127124
edition: args.value_of("edition"),

src/bin/cargo/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// we have lots of arguments, cleaning this up would be a large project
2-
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
1+
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // large project
2+
#![cfg_attr(feature = "cargo-clippy", allow(redundant_closure))] // there's a false positive
33

44
extern crate cargo;
55
extern crate clap;
@@ -135,7 +135,6 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
135135

136136
fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
137137
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
138-
#[cfg_attr(feature = "cargo-clippy", allow(redundant_closure))] // false positive
139138
let path = search_directories(config)
140139
.iter()
141140
.map(|dir| dir.join(&command_exe))

src/cargo/core/compiler/job.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ trait FnBox<A, R> {
1919
}
2020

2121
impl<A, R, F: FnOnce(A) -> R> FnBox<A, R> for F {
22-
// False positive: https://github.com/rust-lang-nursery/rust-clippy/issues/1123
23-
#[cfg_attr(feature = "cargo-clippy", allow(boxed_local))]
2422
fn call_box(self: Box<F>, a: A) -> R {
2523
(*self)(a)
2624
}

src/cargo/core/manifest.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use util::errors::*;
1717
use util::toml::TomlManifest;
1818
use util::Config;
1919

20-
// While unfortunate, resolving the size difference with Box would be a large project
21-
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
2220
pub enum EitherManifest {
2321
Real(Manifest),
2422
Virtual(VirtualManifest),
@@ -208,7 +206,6 @@ struct NonHashedPathBuf {
208206
path: PathBuf,
209207
}
210208

211-
#[cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))] // current intentional incoherence
212209
impl Hash for NonHashedPathBuf {
213210
fn hash<H: Hasher>(&self, _: &mut H) {
214211
// ...

src/cargo/core/profiles.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,6 @@ impl Profile {
495495
/// Compare all fields except `name`, which doesn't affect compilation.
496496
/// This is necessary for `Unit` deduplication for things like "test" and
497497
/// "dev" which are essentially the same.
498-
// The complexity of the result type is exempted because it's limited in scope.
499-
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
500498
fn comparable(
501499
&self,
502500
) -> (

src/cargo/core/resolver/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ mod types;
106106
///
107107
/// * `print_warnings` - whether or not to print backwards-compatibility
108108
/// warnings and such
109-
// While unfortunate, generalising this over different hashers would be a large project
110-
#[cfg_attr(feature = "cargo-clippy", allow(implicit_hasher))]
111109
pub fn resolve(
112110
summaries: &[(Summary, Method)],
113111
replacements: &[(PackageIdSpec, Dependency)],

src/cargo/core/summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Summary {
3535
pub fn new<K>(
3636
pkg_id: PackageId,
3737
dependencies: Vec<Dependency>,
38-
features: BTreeMap<K, Vec<impl AsRef<str>>>,
38+
features: &BTreeMap<K, Vec<impl AsRef<str>>>,
3939
links: Option<impl AsRef<str>>,
4040
namespaced_features: bool,
4141
) -> CargoResult<Summary>

src/cargo/core/workspace.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ struct Packages<'cfg> {
8787
}
8888

8989
#[derive(Debug)]
90-
// While unfortunate, resolving the size difference with Box would be a large project
91-
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
9290
enum MaybePackage {
9391
Package(Package),
9492
Virtual(VirtualManifest),
@@ -777,12 +775,6 @@ impl<'cfg> Packages<'cfg> {
777775
}
778776
}
779777

780-
impl<'a, 'cfg> Members<'a, 'cfg> {
781-
pub fn is_empty(self) -> bool {
782-
self.count() == 0
783-
}
784-
}
785-
786778
impl<'a, 'cfg> Iterator for Members<'a, 'cfg> {
787779
type Item = &'a Package;
788780

src/cargo/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#![cfg_attr(test, deny(warnings))]
2-
// Currently, Cargo does not use clippy for its source code.
3-
// But if someone runs it they should know that
4-
// @alexcrichton disagree with clippy on some style things
5-
#![cfg_attr(feature = "cargo-clippy", allow(explicit_iter_loop))]
6-
#![cfg_attr(feature = "cargo-clippy", allow(explicit_into_iter_loop))]
7-
// also we use closures as an alternative to try catch blocks
8-
#![cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))]
9-
10-
// we have some complicated functions, cleaning this up would be a large project
11-
#![cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
2+
3+
// Clippy isn't enforced by CI, and know that @alexcrichton isn't a fan :)
4+
#![cfg_attr(feature = "cargo-clippy", allow(boxed_local))] // bug rust-lang-nursery/rust-clippy#1123
5+
#![cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // large project
6+
#![cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))] // there's an intentional incoherence
7+
#![cfg_attr(feature = "cargo-clippy", allow(explicit_into_iter_loop))] // (unclear why)
8+
#![cfg_attr(feature = "cargo-clippy", allow(explicit_iter_loop))] // (unclear why)
9+
#![cfg_attr(feature = "cargo-clippy", allow(identity_op))] // used for vertical alignment
10+
#![cfg_attr(feature = "cargo-clippy", allow(implicit_hasher))] // large project
11+
#![cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))] // large project
12+
#![cfg_attr(feature = "cargo-clippy", allow(redundant_closure_call))] // closures over try catch blocks
13+
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // large project
14+
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))] // there's an exceptionally complex type
15+
#![cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] // perhaps Rc should be special cased in Clippy?
1216

1317
extern crate atty;
1418
extern crate clap;

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Packages {
122122
})
123123
}
124124

125-
pub fn into_package_id_specs(&self, ws: &Workspace) -> CargoResult<Vec<PackageIdSpec>> {
125+
pub fn to_package_id_specs(&self, ws: &Workspace) -> CargoResult<Vec<PackageIdSpec>> {
126126
let specs = match *self {
127127
Packages::All => ws.members()
128128
.map(Package::package_id)
@@ -185,15 +185,16 @@ pub fn compile<'a>(
185185
ws: &Workspace<'a>,
186186
options: &CompileOptions<'a>,
187187
) -> CargoResult<Compilation<'a>> {
188-
compile_with_exec(ws, options, Arc::new(DefaultExecutor))
188+
let exec: Arc<Executor> = Arc::new(DefaultExecutor);
189+
compile_with_exec(ws, options, &exec)
189190
}
190191

191192
/// Like `compile` but allows specifying a custom `Executor` that will be able to intercept build
192193
/// calls and add custom logic. `compile` uses `DefaultExecutor` which just passes calls through.
193194
pub fn compile_with_exec<'a>(
194195
ws: &Workspace<'a>,
195196
options: &CompileOptions<'a>,
196-
exec: Arc<Executor>,
197+
exec: &Arc<Executor>,
197198
) -> CargoResult<Compilation<'a>> {
198199
ws.emit_warnings()?;
199200
compile_ws(ws, None, options, exec)
@@ -203,7 +204,7 @@ pub fn compile_ws<'a>(
203204
ws: &Workspace<'a>,
204205
source: Option<Box<Source + 'a>>,
205206
options: &CompileOptions<'a>,
206-
exec: Arc<Executor>,
207+
exec: &Arc<Executor>,
207208
) -> CargoResult<Compilation<'a>> {
208209
let CompileOptions {
209210
config,
@@ -224,7 +225,7 @@ pub fn compile_ws<'a>(
224225
Kind::Host
225226
};
226227

227-
let specs = spec.into_package_id_specs(ws)?;
228+
let specs = spec.to_package_id_specs(ws)?;
228229
let features = Method::split_features(features);
229230
let method = Method::Required {
230231
dev_deps: ws.require_optional_deps() || filter.need_dev_deps(build_config.mode),

src/cargo/ops/cargo_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct DocOptions<'a> {
1818

1919
/// Main method for `cargo doc`.
2020
pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
21-
let specs = options.compile_opts.spec.into_package_id_specs(ws)?;
21+
let specs = options.compile_opts.spec.to_package_id_specs(ws)?;
2222
let resolve = ops::resolve_ws_precisely(
2323
ws,
2424
None,

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions) -> CargoResult<()>
3838
bail!("cannot specify both aggressive and precise simultaneously")
3939
}
4040

41-
if ws.members().is_empty() {
41+
if ws.members().count() == 0 {
4242
bail!("you can't generate a lockfile for an empty workspace.")
4343
}
4444

src/cargo/ops/cargo_install.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use toml;
1212

1313
use core::{Dependency, Edition, Package, PackageIdSpec, Source, SourceId};
1414
use core::{PackageId, Workspace};
15-
use core::compiler::DefaultExecutor;
15+
use core::compiler::{DefaultExecutor, Executor};
1616
use ops::{self, CompileFilter};
1717
use sources::{GitSource, PathSource, SourceConfigMap};
1818
use util::{internal, Config};
@@ -262,8 +262,9 @@ fn install_one(
262262
check_overwrites(&dst, pkg, &opts.filter, &list, force)?;
263263
}
264264

265+
let exec: Arc<Executor> = Arc::new(DefaultExecutor);
265266
let compile =
266-
ops::compile_ws(&ws, Some(source), opts, Arc::new(DefaultExecutor)).chain_err(|| {
267+
ops::compile_ws(&ws, Some(source), opts, &exec).chain_err(|| {
267268
if let Some(td) = td_opt.take() {
268269
// preserve the temporary directory, so the user can inspect it
269270
td.into_path();

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn metadata_no_deps(ws: &Workspace, _opt: &OutputMetadataOptions) -> CargoResult
4545
}
4646

4747
fn metadata_full(ws: &Workspace, opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {
48-
let specs = Packages::All.into_package_id_specs(ws)?;
48+
let specs = Packages::All.to_package_id_specs(ws)?;
4949
let deps = ops::resolve_ws_precisely(
5050
ws,
5151
None,

src/cargo/ops/cargo_package.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use git2;
1010
use tar::{Archive, Builder, EntryType, Header};
1111

1212
use core::{Package, Source, SourceId, Workspace};
13-
use core::compiler::{BuildConfig, CompileMode, DefaultExecutor};
13+
use core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor};
1414
use sources::PathSource;
1515
use util::{self, internal, Config, FileLock};
1616
use util::paths;
@@ -333,6 +333,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
333333
let pkg_fingerprint = src.last_modified_file(&new_pkg)?;
334334
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;
335335

336+
let exec: Arc<Executor> = Arc::new(DefaultExecutor);
336337
ops::compile_ws(
337338
&ws,
338339
None,
@@ -350,7 +351,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
350351
target_rustc_args: None,
351352
export_dir: None,
352353
},
353-
Arc::new(DefaultExecutor),
354+
&exec,
354355
)?;
355356

356357
// Check that build.rs didn't modify any files in the src directory.

src/cargo/ops/resolve.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ fn resolve_with_registry<'cfg>(
133133
///
134134
/// The previous resolve normally comes from a lockfile. This function does not
135135
/// read or write lockfiles from the filesystem.
136-
// While unfortunate, generalising this over different hashers would be a large project
137-
#[cfg_attr(feature = "cargo-clippy", allow(implicit_hasher))]
138136
pub fn resolve_with_previous<'a, 'cfg>(
139137
registry: &mut PackageRegistry<'cfg>,
140138
ws: &Workspace<'cfg>,

src/cargo/sources/registry/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'cfg> RegistryIndex<'cfg> {
253253
.into_iter()
254254
.map(|dep| dep.into_dep(&self.source_id))
255255
.collect::<CargoResult<Vec<_>>>()?;
256-
let summary = Summary::new(pkgid, deps, features, links, false)?;
256+
let summary = Summary::new(pkgid, deps, &features, links, false)?;
257257
let summary = summary.set_checksum(cksum.clone());
258258
self.hashes
259259
.entry(name.as_str())

src/cargo/util/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl From<clap::Error> for CliError {
209209

210210
pub fn process_error(
211211
msg: &str,
212-
status: Option<&ExitStatus>,
212+
status: Option<ExitStatus>,
213213
output: Option<&Output>,
214214
) -> ProcessError {
215215
let exit = match status {
@@ -237,12 +237,12 @@ pub fn process_error(
237237

238238
return ProcessError {
239239
desc,
240-
exit: status.cloned(),
240+
exit: status,
241241
output: output.cloned(),
242242
};
243243

244244
#[cfg(unix)]
245-
fn status_to_string(status: &ExitStatus) -> String {
245+
fn status_to_string(status: ExitStatus) -> String {
246246
use std::os::unix::process::*;
247247
use libc;
248248

@@ -272,7 +272,7 @@ pub fn process_error(
272272
}
273273

274274
#[cfg(windows)]
275-
fn status_to_string(status: &ExitStatus) -> String {
275+
fn status_to_string(status: ExitStatus) -> String {
276276
status.to_string()
277277
}
278278
}

src/cargo/util/process_builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl ProcessBuilder {
144144
} else {
145145
Err(process_error(
146146
&format!("process didn't exit successfully: {}", self),
147-
Some(&exit),
147+
Some(exit),
148148
None,
149149
).into())
150150
}
@@ -193,7 +193,7 @@ impl ProcessBuilder {
193193
} else {
194194
Err(process_error(
195195
&format!("process didn't exit successfully: {}", self),
196-
Some(&output.status),
196+
Some(output.status),
197197
Some(&output),
198198
).into())
199199
}
@@ -271,13 +271,13 @@ impl ProcessBuilder {
271271
if !output.status.success() {
272272
return Err(process_error(
273273
&format!("process didn't exit successfully: {}", self),
274-
Some(&output.status),
274+
Some(output.status),
275275
to_print,
276276
).into());
277277
} else if let Some(e) = callback_error {
278278
let cx = process_error(
279279
&format!("failed to parse process output: {}", self),
280-
Some(&output.status),
280+
Some(output.status),
281281
to_print,
282282
);
283283
return Err(e.context(cx).into());

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ type TomlBenchTarget = TomlTarget;
151151

152152
#[derive(Debug, Serialize)]
153153
#[serde(untagged)]
154-
// While unfortunate, resolving the size difference with Box would be a large project
155-
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
156154
pub enum TomlDependency {
157155
Simple(String),
158156
Detailed(DetailedTomlDependency),
@@ -894,7 +892,7 @@ impl TomlManifest {
894892
let summary = Summary::new(
895893
pkgid,
896894
deps,
897-
me.features
895+
&me.features
898896
.as_ref()
899897
.map(|x| {
900898
x.iter()

src/crates-io/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(unknown_lints)]
2+
#![cfg_attr(feature = "cargo-clippy", allow(identity_op))] // used for vertical alignment
23

34
extern crate curl;
45
#[macro_use]

0 commit comments

Comments
 (0)