Skip to content

Commit 676edac

Browse files
committed
some simple clippy things V2
1 parent 836fdac commit 676edac

25 files changed

+98
-97
lines changed

src/cargo/core/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ macro_rules! features {
9999
}
100100
static FEAT: Feature = Feature {
101101
name: stringify!($feature),
102-
get: get,
102+
get,
103103
};
104104
&FEAT
105105
}

src/cargo/core/registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ impl<'cfg> PackageRegistry<'cfg> {
187187
trace!("\t-> {}", dep);
188188
}
189189
let sub_map = self.locked.entry(id.source_id().clone())
190-
.or_insert(HashMap::new());
190+
.or_insert_with(HashMap::new);
191191
let sub_vec = sub_map.entry(id.name().to_string())
192-
.or_insert(Vec::new());
192+
.or_insert_with(Vec::new);
193193
sub_vec.push((id, deps));
194194
}
195195

src/cargo/core/resolver/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fn build_path_deps(ws: &Workspace) -> HashMap<String, SourceId> {
206206
for member in members.iter() {
207207
build_pkg(member, ws.config(), &mut ret, &mut visited);
208208
}
209-
for (_, deps) in ws.root_patch() {
209+
for deps in ws.root_patch().values() {
210210
for dep in deps {
211211
build_dep(dep, ws.config(), &mut ret, &mut visited);
212212
}

src/cargo/core/resolver/mod.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ enum ConflictReason {
540540

541541
impl ConflictReason {
542542
fn is_links(&self) -> bool {
543-
match self {
544-
&ConflictReason::Semver => false,
545-
&ConflictReason::Links(_) => true,
543+
match *self {
544+
ConflictReason::Semver => false,
545+
ConflictReason::Links(_) => true,
546546
}
547547
}
548548
}
@@ -739,7 +739,7 @@ fn activate_deps_loop<'a>(
739739
registry,
740740
&parent,
741741
&dep,
742-
conflicting,
742+
&conflicting,
743743
&candidates,
744744
config,
745745
)
@@ -780,8 +780,8 @@ fn activate_deps_loop<'a>(
780780
/// remaining candidates. For each one, also checks if rolling back
781781
/// could change the outcome of the failed resolution that caused backtracking
782782
/// in the first place. Namely, if we've backtracked past the parent of the
783-
/// failed dep, or any of the packages flagged as giving us trouble in conflicting_activations.
784-
/// Read https://github.com/rust-lang/cargo/pull/4834
783+
/// failed dep, or any of the packages flagged as giving us trouble in `conflicting_activations`.
784+
/// Read <https://github.com/rust-lang/cargo/pull/4834>
785785
/// For several more detailed explanations of the logic here.
786786
///
787787
/// If the outcome could differ, resets `cx` and `remaining_deps` to that
@@ -826,7 +826,7 @@ fn activation_error(cx: &Context,
826826
registry: &mut Registry,
827827
parent: &Summary,
828828
dep: &Dependency,
829-
conflicting_activations: HashMap<PackageId, ConflictReason>,
829+
conflicting_activations: &HashMap<PackageId, ConflictReason>,
830830
candidates: &[Candidate],
831831
config: Option<&Config>) -> CargoError {
832832
let graph = cx.graph();
@@ -860,17 +860,14 @@ fn activation_error(cx: &Context,
860860
let (links_errors, other_errors): (Vec<_>, Vec<_>) = conflicting_activations.drain(..).rev().partition(|&(_, r)| r.is_links());
861861

862862
for &(p, r) in &links_errors {
863-
match r {
864-
&ConflictReason::Links(ref link) => {
865-
msg.push_str("\n\nthe package `");
866-
msg.push_str(dep.name());
867-
msg.push_str("` links to the native library `");
868-
msg.push_str(&link);
869-
msg.push_str("`, but it conflicts with a previous package which links to `");
870-
msg.push_str(&link);
871-
msg.push_str("` as well:\n");
872-
},
873-
_ => (),
863+
if let ConflictReason::Links(ref link) = *r {
864+
msg.push_str("\n\nthe package `");
865+
msg.push_str(dep.name());
866+
msg.push_str("` links to the native library `");
867+
msg.push_str(link);
868+
msg.push_str("`, but it conflicts with a previous package which links to `");
869+
msg.push_str(link);
870+
msg.push_str("` as well:\n");
874871
}
875872
msg.push_str(&describe_path(p));
876873
}
@@ -1031,7 +1028,7 @@ impl<'r> Requirements<'r> {
10311028
return Ok(());
10321029
}
10331030
for f in self.summary.features().get(feat).expect("must be a valid feature") {
1034-
if f == &feat {
1031+
if f == feat {
10351032
bail!("Cyclic feature dependency: feature `{}` depends on itself", feat);
10361033
}
10371034
self.add_feature(f)?;
@@ -1095,7 +1092,7 @@ fn build_requirements<'a, 'b: 'a>(s: &'a Summary, method: &'b Method)
10951092
}
10961093
Method::Required { uses_default_features: false, .. } => {}
10971094
}
1098-
return Ok(reqs);
1095+
Ok(reqs)
10991096
}
11001097

11011098
impl<'a> Context<'a> {
@@ -1110,7 +1107,7 @@ impl<'a> Context<'a> {
11101107
.entry(id.name().to_string())
11111108
.or_insert_with(HashMap::new)
11121109
.entry(id.source_id().clone())
1113-
.or_insert(Vec::new());
1110+
.or_insert_with(Vec::new);
11141111
if !prev.iter().any(|c| c == summary) {
11151112
self.resolve_graph.push(GraphNode::Add(id.clone()));
11161113
if let Some(link) = summary.links() {
@@ -1294,7 +1291,7 @@ impl<'a> Context<'a> {
12941291
let mut base = base.1;
12951292
base.extend(dep.features().iter().cloned());
12961293
for feature in base.iter() {
1297-
if feature.contains("/") {
1294+
if feature.contains('/') {
12981295
bail!("feature names may not contain slashes: `{}`", feature);
12991296
}
13001297
}

src/cargo/core/shell.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ pub struct Shell {
2727

2828
impl fmt::Debug for Shell {
2929
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30-
match &self.err {
31-
&ShellOut::Write(_) => {
30+
match self.err {
31+
ShellOut::Write(_) => {
3232
f.debug_struct("Shell")
3333
.field("verbosity", &self.verbosity)
3434
.finish()
3535
}
36-
&ShellOut::Stream { color_choice, .. } => {
36+
ShellOut::Stream { color_choice, .. } => {
3737
f.debug_struct("Shell")
3838
.field("verbosity", &self.verbosity)
3939
.field("color_choice", &color_choice)
@@ -221,6 +221,12 @@ impl Shell {
221221
}
222222
}
223223

224+
impl Default for Shell {
225+
fn default() -> Self {
226+
Self::new()
227+
}
228+
}
229+
224230
impl ShellOut {
225231
/// Print out a message with a status. The status comes first and is bold + the given color.
226232
/// The status can be justified, in which case the max width that will right align is 12 chars.

src/cargo/core/source/source_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl Hash for SourceId {
444444
}
445445
}
446446

447-
/// A `Display`able view into a SourceId that will write it as a url
447+
/// A `Display`able view into a `SourceId` that will write it as a url
448448
pub struct SourceIdToUrl<'a> {
449449
inner: &'a SourceIdInner,
450450
}

src/cargo/core/workspace.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'cfg> Workspace<'cfg> {
340340
match *self.packages.load(&ances_manifest_path)?.workspace_config() {
341341
WorkspaceConfig::Root(ref ances_root_config) => {
342342
debug!("find_root - found a root checking exclusion");
343-
if !ances_root_config.is_excluded(&manifest_path) {
343+
if !ances_root_config.is_excluded(manifest_path) {
344344
debug!("find_root - found!");
345345
return Ok(Some(ances_manifest_path))
346346
}
@@ -443,13 +443,10 @@ impl<'cfg> Workspace<'cfg> {
443443
return Ok(())
444444
}
445445

446-
match *self.packages.load(root_manifest)?.workspace_config() {
447-
WorkspaceConfig::Root(ref root_config) => {
448-
if root_config.is_excluded(&manifest_path) {
449-
return Ok(())
450-
}
446+
if let WorkspaceConfig::Root(ref root_config) = *self.packages.load(root_manifest)?.workspace_config() {
447+
if root_config.is_excluded(&manifest_path) {
448+
return Ok(())
451449
}
452-
_ => {}
453450
}
454451

455452
debug!("find_members - {}", manifest_path.display());

src/cargo/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#![cfg_attr(test, deny(warnings))]
33
#![recursion_limit="128"]
44

5+
// Currently, Cargo does not use clippy for its source code.
6+
// But if someone runs it they should know that
7+
// @alexcrichton disagree with clippy on some style things
8+
#![cfg_attr(feature = "cargo-clippy", allow(explicit_iter_loop))]
9+
510
#[macro_use] extern crate failure;
611
#[macro_use] extern crate log;
712
#[macro_use] extern crate scoped_tls;
@@ -51,7 +56,7 @@ use core::shell::Verbosity::Verbose;
5156
pub use util::{CargoError, CargoResult, CliError, CliResult, Config};
5257
pub use util::errors::Internal;
5358

54-
pub const CARGO_ENV: &'static str = "CARGO";
59+
pub const CARGO_ENV: &str = "CARGO";
5560

5661
pub mod core;
5762
pub mod ops;

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
321321
config,
322322
build_config,
323323
profiles,
324-
exec)?
324+
&exec)?
325325
};
326326

327327
ret.to_doc_test = to_builds.into_iter().cloned().collect();

src/cargo/ops/cargo_doc.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
4444
or marking one of the targets as `doc = false`.",
4545
target.crate_name(), prev, package);
4646
}
47-
} else {
48-
if let Some(prev) = bin_names.insert(target.crate_name(), package) {
49-
bail!("The binary `{}` is specified by packages `{}` and \
50-
`{}` but can be documented only once. Consider renaming \
51-
or marking one of the targets as `doc = false`.",
52-
target.crate_name(), prev, package);
53-
}
47+
} else if let Some(prev) = bin_names.insert(target.crate_name(), package) {
48+
bail!("The binary `{}` is specified by packages `{}` and \
49+
`{}` but can be documented only once. Consider renaming \
50+
or marking one of the targets as `doc = false`.",
51+
target.crate_name(), prev, package);
5452
}
5553
}
5654
}

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions)
174174
let mut changes = BTreeMap::new();
175175
let empty = (Vec::new(), Vec::new());
176176
for dep in previous_resolve.iter() {
177-
changes.entry(key(dep)).or_insert(empty.clone()).0.push(dep);
177+
changes.entry(key(dep)).or_insert_with(||empty.clone()).0.push(dep);
178178
}
179179
for dep in resolve.iter() {
180-
changes.entry(key(dep)).or_insert(empty.clone()).1.push(dep);
180+
changes.entry(key(dep)).or_insert_with(||empty.clone()).1.push(dep);
181181
}
182182

183183
for v in changes.values_mut() {

src/cargo/ops/cargo_install.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn install_one(root: &Filesystem,
286286
}
287287
}
288288
list.v1.entry(pkg.package_id().clone())
289-
.or_insert_with(|| BTreeSet::new())
289+
.or_insert_with(BTreeSet::new)
290290
.insert(bin.to_string());
291291
}
292292

@@ -301,7 +301,7 @@ fn install_one(root: &Filesystem,
301301
// If installation was successful record newly installed binaries.
302302
if result.is_ok() {
303303
list.v1.entry(pkg.package_id().clone())
304-
.or_insert_with(|| BTreeSet::new())
304+
.or_insert_with(BTreeSet::new)
305305
.extend(to_install.iter().map(|s| s.to_string()));
306306
}
307307

@@ -347,7 +347,7 @@ fn select_pkg<'a, T>(mut source: T,
347347
// version range, otherwise parse it as a specific version
348348
let first = v.chars()
349349
.nth(0)
350-
.ok_or(format_err!("no version provided for the `--vers` flag"))?;
350+
.ok_or_else(||format_err!("no version provided for the `--vers` flag"))?;
351351

352352
match first {
353353
'<' | '>' | '=' | '^' | '~' => match v.parse::<VersionReq>() {
@@ -570,20 +570,20 @@ pub fn uninstall(root: Option<&str>,
570570
specs: Vec<&str>,
571571
bins: &[String],
572572
config: &Config) -> CargoResult<()> {
573-
if specs.len() > 1 && bins.len() > 0 {
573+
if specs.len() > 1 && !bins.is_empty() {
574574
bail!("A binary can only be associated with a single installed package, specifying multiple specs with --bin is redundant.");
575575
}
576576

577577
let root = resolve_root(root, config)?;
578578
let scheduled_error = if specs.len() == 1 {
579-
uninstall_one(root, specs[0], bins, config)?;
579+
uninstall_one(&root, specs[0], bins, config)?;
580580
false
581581
} else {
582582
let mut succeeded = vec![];
583583
let mut failed = vec![];
584584
for spec in specs {
585585
let root = root.clone();
586-
match uninstall_one(root, spec, bins, config) {
586+
match uninstall_one(&root, spec, bins, config) {
587587
Ok(()) => succeeded.push(spec),
588588
Err(e) => {
589589
::handle_error(e, &mut config.shell());
@@ -614,11 +614,11 @@ pub fn uninstall(root: Option<&str>,
614614
Ok(())
615615
}
616616

617-
pub fn uninstall_one(root: Filesystem,
617+
pub fn uninstall_one(root: &Filesystem,
618618
spec: &str,
619619
bins: &[String],
620620
config: &Config) -> CargoResult<()> {
621-
let crate_metadata = metadata(config, &root)?;
621+
let crate_metadata = metadata(config, root)?;
622622
let mut metadata = read_crate_list(&crate_metadata)?;
623623
let mut to_remove = Vec::new();
624624
{

src/cargo/ops/cargo_new.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ impl<'a> NewOptions<'a> {
9090

9191
let kind = match (bin, lib) {
9292
(true, true) => bail!("can't specify both lib and binary outputs"),
93-
(true, false) => NewProjectKind::Bin,
9493
(false, true) => NewProjectKind::Lib,
9594
// default to bin
96-
(false, false) => NewProjectKind::Bin,
95+
(_, false) => NewProjectKind::Bin,
9796
};
9897

9998
let opts = NewOptions { version_control, kind, path, name };

src/cargo/ops/cargo_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn run(ws: &Workspace,
3434
.map(|bin| bin.name())
3535
.collect();
3636

37-
if bins.len() == 0 {
37+
if bins.is_empty() {
3838
if !options.filter.is_specific() {
3939
bail!("a bin target must be available for `cargo run`")
4040
} else {

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
471471

472472
/// Return the target triple which this context is targeting.
473473
pub fn target_triple(&self) -> &str {
474-
self.requested_target().unwrap_or(self.host_triple())
474+
self.requested_target().unwrap_or_else(|| self.host_triple())
475475
}
476476

477477
/// Requested (not actual) target for the build
@@ -694,8 +694,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
694694
match *crate_type_info {
695695
Some((ref prefix, ref suffix)) => {
696696
let suffixes = add_target_specific_suffixes(
697-
&self.target_triple(),
698-
&crate_type,
697+
self.target_triple(),
698+
crate_type,
699699
unit.target.kind(),
700700
suffix,
701701
file_type,
@@ -1055,10 +1055,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
10551055
}
10561056

10571057
pub fn lib_or_check_profile(&self, unit: &Unit, target: &Target) -> &'a Profile {
1058-
if !target.is_custom_build() && !target.for_host() {
1059-
if unit.profile.check || (unit.profile.doc && !unit.profile.test) {
1058+
if !target.is_custom_build() && !target.for_host()
1059+
&& (unit.profile.check || (unit.profile.doc && !unit.profile.test)) {
10601060
return &self.profiles.check
1061-
}
10621061
}
10631062
self.lib_profile()
10641063
}

0 commit comments

Comments
 (0)