Skip to content

Commit a1489e8

Browse files
committed
Auto merge of #4531 - lukaslueg:springclean, r=alexcrichton
Cleaning lints More fixes and cleanups. There will be at least two more commits to come.
2 parents c729a9a + 24ba7c8 commit a1489e8

Some content is hidden

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

47 files changed

+281
-319
lines changed

src/bin/cargo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ fn execute(flags: Flags, config: &Config) -> CliResult {
225225
}
226226
};
227227

228-
if let Some(r) = try_execute_builtin_command(&config, &args) {
228+
if let Some(r) = try_execute_builtin_command(config, &args) {
229229
return r;
230230
}
231231

232-
let alias_list = aliased_command(&config, &args[1])?;
232+
let alias_list = aliased_command(config, &args[1])?;
233233
let args = match alias_list {
234234
Some(alias_command) => {
235235
let chain = args.iter()
@@ -238,7 +238,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult {
238238
.chain(args.iter().skip(2))
239239
.map(|s| s.to_string())
240240
.collect::<Vec<_>>();
241-
if let Some(r) = try_execute_builtin_command(&config, &chain) {
241+
if let Some(r) = try_execute_builtin_command(config, &chain) {
242242
return r;
243243
} else {
244244
chain
@@ -266,7 +266,7 @@ fn try_execute_builtin_command(config: &Config, args: &[String]) -> Option<CliRe
266266
None
267267
}
268268

269-
fn aliased_command(config: &Config, command: &String) -> CargoResult<Option<Vec<String>>> {
269+
fn aliased_command(config: &Config, command: &str) -> CargoResult<Option<Vec<String>>> {
270270
let alias_name = format!("alias.{}", command);
271271
let mut result = Ok(None);
272272
match config.get_string(&alias_name) {
@@ -298,7 +298,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
298298
// Only consider candidates with a lev_distance of 3 or less so we don't
299299
// suggest out-of-the-blue options.
300300
let mut filtered = cmds.iter()
301-
.map(|c| (lev_distance(&c, cmd), c))
301+
.map(|c| (lev_distance(c, cmd), c))
302302
.filter(|&(d, _)| d < 4)
303303
.collect::<Vec<_>>();
304304
filtered.sort_by(|a, b| a.0.cmp(&b.0));

src/bin/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
5454

5555
let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;
5656

57-
let path = &arg_path.unwrap_or(format!("."));
57+
let path = &arg_path.unwrap_or_else(|| String::from("."));
5858
let opts = ops::NewOptions::new(flag_vcs,
5959
flag_bin,
6060
flag_lib,
6161
path,
6262
flag_name.as_ref().map(|s| s.as_ref()));
6363

6464
let opts_lib = opts.lib;
65-
ops::init(opts, config)?;
65+
ops::init(&opts, config)?;
6666

6767
config.shell().status("Created", format!("{} project",
6868
if opts_lib { "library" }

src/bin/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
145145
} else if let Some(path) = options.flag_path {
146146
SourceId::for_path(&config.cwd().join(path))?
147147
} else if options.arg_crate.is_empty() {
148-
SourceId::for_path(&config.cwd())?
148+
SourceId::for_path(config.cwd())?
149149
} else {
150150
SourceId::crates_io(config)?
151151
};

src/bin/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
6161
flag_name.as_ref().map(|s| s.as_ref()));
6262

6363
let opts_lib = opts.lib;
64-
ops::new(opts, config)?;
64+
ops::new(&opts, config)?;
6565

6666
config.shell().status("Created", format!("{} `{}` project",
6767
if opts_lib { "library" }

src/bin/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
116116
Some(err) => {
117117
// If we never actually spawned the process then that sounds pretty
118118
// bad and we always want to forward that up.
119-
let exit = match err.exit.clone() {
119+
let exit = match err.exit {
120120
Some(exit) => exit,
121121
None => return Err(
122122
CliError::new(CargoErrorKind::ProcessErrorKind(err).into(), 101)),

src/bin/verify_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn execute(args: Flags, config: &Config) -> CliResult {
4848
&args.flag_z)?;
4949

5050
let mut contents = String::new();
51-
let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into());
51+
let filename = args.flag_manifest_path.unwrap_or_else(|| "Cargo.toml".into());
5252
let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) {
5353
Ok(manifest_path) => manifest_path,
5454
Err(e) => fail("invalid", &e.to_string()),

src/cargo/core/dependency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl ser::Serialize for Dependency {
6161
{
6262
SerializedDependency {
6363
name: self.name(),
64-
source: &self.source_id(),
64+
source: self.source_id(),
6565
req: self.version_req().to_string(),
6666
kind: self.kind(),
6767
optional: self.is_optional(),
@@ -262,7 +262,7 @@ impl Dependency {
262262
/// an exact version req.
263263
pub fn is_locked(&self) -> bool {
264264
// Kind of a hack to figure this out, but it works!
265-
self.inner.req.to_string().starts_with("=")
265+
self.inner.req.to_string().starts_with('=')
266266
}
267267

268268
/// Returns false if the dependency is only used to build the local package.
@@ -348,7 +348,7 @@ impl FromStr for Platform {
348348
type Err = CargoError;
349349

350350
fn from_str(s: &str) -> CargoResult<Platform> {
351-
if s.starts_with("cfg(") && s.ends_with(")") {
351+
if s.starts_with("cfg(") && s.ends_with(')') {
352352
let s = &s[4..s.len()-1];
353353
s.parse().map(Platform::Cfg).chain_err(|| {
354354
format!("failed to parse `{}` as a cfg expression", s)

src/cargo/core/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub struct CliUnstable {
232232

233233
impl CliUnstable {
234234
pub fn parse(&mut self, flags: &[String]) -> CargoResult<()> {
235-
if flags.len() > 0 && !nightly_features_allowed() {
235+
if !flags.is_empty() && !nightly_features_allowed() {
236236
bail!("the `-Z` flag is only accepted on the nightly channel of Cargo")
237237
}
238238
for flag in flags {
@@ -267,7 +267,7 @@ impl CliUnstable {
267267
fn channel() -> String {
268268
env::var("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS").unwrap_or_else(|_| {
269269
::version().cfg_info.map(|c| c.release_channel)
270-
.unwrap_or(String::from("dev"))
270+
.unwrap_or_else(|| String::from("dev"))
271271
})
272272
}
273273

src/cargo/core/manifest.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,11 @@ impl Target {
470470
pub fn doctested(&self) -> bool {
471471
self.doctest && match self.kind {
472472
TargetKind::Lib(ref kinds) => {
473-
kinds.iter().find(|k| {
474-
*k == &LibKind::Rlib ||
475-
*k == &LibKind::Lib ||
476-
*k == &LibKind::ProcMacro
477-
}).is_some()
473+
kinds.iter().any(|k| {
474+
*k == LibKind::Rlib ||
475+
*k == LibKind::Lib ||
476+
*k == LibKind::ProcMacro
477+
})
478478
}
479479
_ => false,
480480
}

src/cargo/core/package.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ impl ser::Serialize for Package {
5353
let description = manmeta.description.as_ref().map(String::as_ref);
5454

5555
SerializedPackage {
56-
name: &package_id.name(),
56+
name: package_id.name(),
5757
version: &package_id.version().to_string(),
5858
id: package_id,
5959
license: license,
6060
license_file: license_file,
6161
description: description,
6262
source: summary.source_id(),
6363
dependencies: summary.dependencies(),
64-
targets: &self.manifest.targets(),
64+
targets: self.manifest.targets(),
6565
features: summary.features(),
6666
manifest_path: &self.manifest_path.display().to_string(),
6767
}.serialize(s)
@@ -80,8 +80,7 @@ impl Package {
8080
pub fn for_path(manifest_path: &Path, config: &Config) -> CargoResult<Package> {
8181
let path = manifest_path.parent().unwrap();
8282
let source_id = SourceId::for_path(path)?;
83-
let (pkg, _) = ops::read_package(&manifest_path, &source_id,
84-
config)?;
83+
let (pkg, _) = ops::read_package(manifest_path, &source_id, config)?;
8584
Ok(pkg)
8685
}
8786

src/cargo/core/package_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'de> de::Deserialize<'de> for PackageId {
5353
Some(s) => s,
5454
None => return Err(de::Error::custom("invalid serialized PackageId")),
5555
};
56-
let url = if url.starts_with("(") && url.ends_with(")") {
56+
let url = if url.starts_with('(') && url.ends_with(')') {
5757
&url[1..url.len() - 1]
5858
} else {
5959
return Err(de::Error::custom("invalid serialized PackageId"))
@@ -134,7 +134,7 @@ impl PackageId {
134134
}
135135

136136
pub fn stable_hash<'a>(&'a self, workspace: &'a Path) -> PackageIdStableHash<'a> {
137-
PackageIdStableHash(&self, workspace)
137+
PackageIdStableHash(self, workspace)
138138
}
139139
}
140140

src/cargo/core/package_id_spec.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct PackageIdSpec {
1717

1818
impl PackageIdSpec {
1919
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
20-
if spec.contains("/") {
20+
if spec.contains('/') {
2121
if let Ok(url) = spec.to_url() {
2222
return PackageIdSpec::from_url(url);
2323
}
@@ -117,9 +117,10 @@ impl PackageIdSpec {
117117
pub fn matches(&self, package_id: &PackageId) -> bool {
118118
if self.name() != package_id.name() { return false }
119119

120-
match self.version {
121-
Some(ref v) => if v != package_id.version() { return false },
122-
None => {}
120+
if let Some(ref v) = self.version {
121+
if v != package_id.version() {
122+
return false;
123+
}
123124
}
124125

125126
match self.url {
@@ -148,20 +149,20 @@ impl PackageIdSpec {
148149
self.name(), self);
149150
let mut vec = vec![ret, other];
150151
vec.extend(ids);
151-
minimize(&mut msg, vec, self);
152+
minimize(&mut msg, &vec, self);
152153
Err(msg.into())
153154
}
154155
None => Ok(ret)
155156
};
156157

157158
fn minimize(msg: &mut String,
158-
ids: Vec<&PackageId>,
159+
ids: &[&PackageId],
159160
spec: &PackageIdSpec) {
160161
let mut version_cnt = HashMap::new();
161-
for id in ids.iter() {
162+
for id in ids {
162163
*version_cnt.entry(id.version()).or_insert(0) += 1;
163164
}
164-
for id in ids.iter() {
165+
for id in ids {
165166
if version_cnt[id.version()] == 1 {
166167
msg.push_str(&format!("\n {}:{}", spec.name(),
167168
id.version()));
@@ -184,18 +185,15 @@ impl fmt::Display for PackageIdSpec {
184185
} else {
185186
write!(f, "{}", url)?;
186187
}
187-
if url.path_segments().unwrap().next_back().unwrap() != &self.name {
188+
if url.path_segments().unwrap().next_back().unwrap() != self.name {
188189
printed_name = true;
189190
write!(f, "#{}", self.name)?;
190191
}
191192
}
192193
None => { printed_name = true; write!(f, "{}", self.name)? }
193194
}
194-
match self.version {
195-
Some(ref v) => {
196-
write!(f, "{}{}", if printed_name {":"} else {"#"}, v)?;
197-
}
198-
None => {}
195+
if let Some(ref v) = self.version {
196+
write!(f, "{}{}", if printed_name {":"} else {"#"}, v)?;
199197
}
200198
Ok(())
201199
}

src/cargo/core/registry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'cfg> PackageRegistry<'cfg> {
243243
let src = self.sources.get_mut(s).unwrap();
244244
let dep = Dependency::new_override(dep.name(), s);
245245
let mut results = src.query_vec(&dep)?;
246-
if results.len() > 0 {
246+
if !results.is_empty() {
247247
return Ok(Some(results.remove(0)))
248248
}
249249
}
@@ -303,7 +303,7 @@ http://doc.crates.io/specifying-dependencies.html#overriding-dependencies
303303
return Ok(())
304304
}
305305

306-
for id in real_deps {
306+
if let Some(id) = real_deps.get(0) {
307307
let msg = format!("\
308308
path override for crate `{}` has altered the original list of
309309
dependencies; the dependency on `{}` was removed\n\n
@@ -322,7 +322,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
322322
f: &mut FnMut(Summary)) -> CargoResult<()> {
323323
let (override_summary, n, to_warn) = {
324324
// Look for an override and get ready to query the real source.
325-
let override_summary = self.query_overrides(&dep)?;
325+
let override_summary = self.query_overrides(dep)?;
326326

327327
// Next up on our list of candidates is to check the `[patch]`
328328
// section of the manifest. Here we look through all patches
@@ -353,7 +353,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
353353
}
354354
}
355355
} else {
356-
if patches.len() > 0 {
356+
if !patches.is_empty() {
357357
debug!("found {} patches with an unlocked dep, \
358358
looking at sources", patches.len());
359359
}
@@ -400,7 +400,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
400400
// to sanity check its results. We don't actually use any of
401401
// the summaries it gives us though.
402402
(Some(override_summary), Some(source)) => {
403-
if patches.len() > 0 {
403+
if !patches.is_empty() {
404404
bail!("found patches and a path override")
405405
}
406406
let mut n = 0;
@@ -526,7 +526,7 @@ fn lock(locked: &LockedMap,
526526
}
527527

528528
trace!("\tnope, unlocked");
529-
return dep
529+
dep
530530
})
531531
}
532532

0 commit comments

Comments
 (0)