Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some warnings from Clippy #2282

Merged
merged 9 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ impl PackageSet {
PackageSet { packages: packages.to_vec() }
}

pub fn is_empty(&self) -> bool {
self.packages.is_empty()
}

pub fn len(&self) -> usize {
self.packages.len()
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait Registry {
impl Registry for Vec<Summary> {
fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
Ok(self.iter().filter(|summary| dep.matches(*summary))
.map(|summary| summary.clone()).collect())
.cloned().collect())
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
let overrides = try!(self.query_overrides(dep));

let ret = if overrides.len() == 0 {
let ret = if overrides.is_empty() {
// Ensure the requested source_id is loaded
try!(self.ensure_loaded(dep.source_id(), Kind::Normal));
let mut ret = Vec::new();
Expand Down
14 changes: 7 additions & 7 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ fn find_candidate(backtrack_stack: &mut Vec<BacktrackFrame>,
return Some(candidate)
}
}
return None
None
}

#[allow(deprecated)] // connect => join in 1.3
Expand Down Expand Up @@ -453,7 +453,7 @@ fn activation_error(cx: &Context,
candidates.sort_by(|a, b| {
b.version().cmp(a.version())
});
if candidates.len() > 0 {
if !candidates.is_empty() {
msg.push_str("\nversions found: ");
for (i, c) in candidates.iter().take(3).enumerate() {
if i != 0 { msg.push_str(", "); }
Expand All @@ -469,7 +469,7 @@ fn activation_error(cx: &Context,
// update`. In this case try to print a helpful error!
if dep.source_id().is_path() &&
dep.version_req().to_string().starts_with("=") &&
candidates.len() > 0 {
!candidates.is_empty() {
msg.push_str("\nconsider running `cargo update` to update \
a path dependency's locked version");

Expand Down Expand Up @@ -607,7 +607,7 @@ impl Context {
(!use_default || prev.contains("default") ||
!has_default_feature)
}
None => features.len() == 0 && (!use_default || !has_default_feature)
None => features.is_empty() && (!use_default || !has_default_feature)
}
}

Expand Down Expand Up @@ -686,18 +686,18 @@ impl Context {
// they should have all been weeded out by the above iteration. Any
// remaining features are bugs in that the package does not actually
// have those features.
if feature_deps.len() > 0 {
if !feature_deps.is_empty() {
let unknown = feature_deps.keys().map(|s| &s[..])
.collect::<Vec<&str>>();
if unknown.len() > 0 {
if !unknown.is_empty() {
let features = unknown.connect(", ");
bail!("Package `{}` does not have these features: `{}`",
parent.package_id(), features)
}
}

// Record what list of features is active for this package.
if used_features.len() > 0 {
if !used_features.is_empty() {
let pkgid = parent.package_id();
self.resolve.features.entry(pkgid.clone())
.or_insert(HashSet::new())
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl MultiShell {
where F: FnMut(&mut MultiShell) -> io::Result<()>
{
match self.verbosity {
Verbose => return callback(self),
Verbose => callback(self),
_ => Ok(())
}
}
Expand All @@ -91,7 +91,7 @@ impl MultiShell {
{
match self.verbosity {
Verbose => Ok(()),
_ => return callback(self)
_ => callback(self)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/cargo/core/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ impl<'src> SourceMap<'src> {
self.map.insert(id.clone(), source);
}

pub fn is_empty(&self) -> bool {
self.map.is_empty()
}

pub fn len(&self) -> usize {
self.map.len()
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub fn version() -> String {
})
}

fn flags_from_args<'a, T>(usage: &str, args: &[String],
fn flags_from_args<T>(usage: &str, args: &[String],
options_first: bool) -> CliResult<T>
where T: Decodable
{
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {

// If we have a spec, then we need to delete some packages, otherwise, just
// remove the whole target directory and be done with it!
if opts.spec.len() == 0 {
if opts.spec.is_empty() {
return rm_rf(&target_dir);
}

Expand Down
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
vec![root_package.package_id()]
};

if spec.len() > 0 && invalid_spec.len() > 0 {
if !spec.is_empty() && !invalid_spec.is_empty() {
bail!("could not find package matching spec `{}`",
invalid_spec.connect(", "))
}
Expand Down Expand Up @@ -257,7 +257,7 @@ pub fn compile_pkg<'a>(root_package: &Package,

ret.to_doc_test = to_builds.iter().map(|&p| p.clone()).collect();

return Ok(ret);
Ok(ret)
}

impl<'a> CompileFilter<'a> {
Expand Down Expand Up @@ -311,7 +311,7 @@ fn generate_targets<'a>(pkg: &'a Package,
CompileMode::Build => build,
CompileMode::Doc { .. } => &profiles.doc,
};
return match *filter {
match *filter {
CompileFilter::Everything => {
match mode {
CompileMode::Bench => {
Expand Down Expand Up @@ -379,7 +379,7 @@ fn generate_targets<'a>(pkg: &'a Package,
}
Ok(targets)
}
};
}
}

/// Read the `paths` configuration variable to discover all path overrides that
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn doc(manifest_path: &Path,

let mut lib_names = HashSet::new();
let mut bin_names = HashSet::new();
if options.compile_opts.spec.len() == 0 {
if options.compile_opts.spec.is_empty() {
for target in package.targets().iter().filter(|t| t.documented()) {
if target.is_lib() {
assert!(lib_names.insert(target.crate_name()));
Expand All @@ -42,7 +42,7 @@ pub fn doc(manifest_path: &Path,
bail!("Passing multiple packages and `open` is not supported")
} else if options.compile_opts.spec.len() == 1 {
try!(PackageIdSpec::parse(&options.compile_opts.spec[0]))
.name().replace("-", "_").to_string()
.name().replace("-", "_")
} else {
match lib_names.iter().chain(bin_names.iter()).nth(0) {
Some(s) => s.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn update_lockfile(manifest_path: &Path,
let mut registry = PackageRegistry::new(opts.config);
let mut to_avoid = HashSet::new();

if opts.to_update.len() == 0 {
if opts.to_update.is_empty() {
to_avoid.extend(previous_resolve.iter());
} else {
let mut sources = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub fn uninstall(root: Option<&str>,
}
}

if bins.len() == 0 {
if bins.is_empty() {
to_remove.extend(installed.get().iter().map(|b| dst.join(b)));
installed.get_mut().clear();
} else {
Expand All @@ -321,7 +321,7 @@ pub fn uninstall(root: Option<&str>,
installed.get_mut().remove(bin);
}
}
if installed.get().len() == 0 {
if installed.get().is_empty() {
installed.remove();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ fn discover_author() -> CargoResult<(String, Option<String>)> {
let git_config = GitConfig::open_default().ok();
let git_config = git_config.as_ref();
let name = git_config.and_then(|g| g.get_string("user.name").ok())
.map(|s| s.to_string())
.or_else(|| env::var("USER").ok()) // unix
.or_else(|| env::var("USERNAME").ok()); // windows
let name = match name {
Expand Down
18 changes: 9 additions & 9 deletions src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
lines.next().unwrap().trim()
.split('_').skip(1).next().unwrap().to_string()
};
Ok((dylib, exe_suffix.to_string()))
Ok((dylib, exe_suffix))
}

/// Prepare this context, ensuring that all filesystem directories are in
Expand All @@ -159,7 +159,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
self.compilation.deps_output =
self.layout(root, Kind::Target).proxy().deps().to_path_buf();

return Ok(());
Ok(())
}

/// Returns the appropriate directory layout for either a plugin or not.
Expand Down Expand Up @@ -213,7 +213,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
if unit.target.is_lib() && unit.profile.test {
// Libs and their tests are built in parallel, so we need to make
// sure that their metadata is different.
metadata.map(|m| m.clone()).map(|mut m| {
metadata.cloned().map(|mut m| {
m.mix(&"test");
m
})
Expand All @@ -232,7 +232,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
// file names like `target/debug/libfoo.{a,so,rlib}` and such.
None
} else {
metadata.map(|m| m.clone())
metadata.cloned()
}
}

Expand All @@ -244,7 +244,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
None if unit.target.allows_underscores() => {
unit.target.name().to_string()
}
None => unit.target.crate_name().to_string(),
None => unit.target.crate_name(),
}
}

Expand Down Expand Up @@ -282,8 +282,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
}
}
}
assert!(ret.len() > 0);
return Ok(ret);
assert!(!ret.is_empty());
Ok(ret)
}

/// For a package, return all targets which are registered as dependencies
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
}
}));
}
return ret
ret
}

/// Returns the dependencies needed to run a build script.
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
if unit.target.is_bin() {
ret.extend(self.maybe_lib(unit));
}
return ret
ret
}

/// If a build script is scheduled to be run for the package specified by
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,6 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>,
let prev = out.entry(*unit).or_insert(BuildScripts::default());
prev.to_link.extend(to_link);
prev.plugins.extend(plugins);
return prev
prev
}
}
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_rustc/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Fingerprint {
}
let ret = util::hash_u64(self);
*self.memoized_hash.lock().unwrap() = Some(ret);
return ret
ret
}

fn compare(&self, old: &Fingerprint) -> CargoResult<()> {
Expand Down Expand Up @@ -398,7 +398,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
None => {
let &(ref output, ref deps) = &cx.build_explicit_deps[unit];

let local = if deps.len() == 0 {
let local = if deps.is_empty() {
let s = try!(pkg_fingerprint(cx, unit.pkg));
LocalFingerprint::Precalculated(s)
} else {
Expand Down Expand Up @@ -440,7 +440,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
let write_fingerprint = Work::new(move |_| {
if let Some(output_path) = output_path {
let outputs = state.outputs.lock().unwrap();
if outputs[&key].rerun_if_changed.len() > 0 {
if !outputs[&key].rerun_if_changed.is_empty() {
let slot = MtimeSlot(Mutex::new(None));
fingerprint.local = LocalFingerprint::MtimeBased(slot,
output_path);
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_rustc/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a> JobQueue<'a> {
// and then immediately return.
loop {
while self.active < self.jobs {
if queue.len() > 0 {
if !queue.is_empty() {
let (key, job, fresh) = queue.remove(0);
try!(self.run(key, fresh, job, config, scope));
} else if let Some((fresh, key, jobs)) = self.queue.dequeue() {
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<'a> JobQueue<'a> {
}
}

if self.queue.len() == 0 {
if self.queue.is_empty() {
Ok(())
} else {
debug!("queue: {:#?}", self.queue);
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_rustc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl Layout {
}
}

pub fn dest<'a>(&'a self) -> &'a Path { &self.root }
pub fn deps<'a>(&'a self) -> &'a Path { &self.deps }
pub fn examples<'a>(&'a self) -> &'a Path { &self.examples }
pub fn dest(&self) -> &Path { &self.root }
pub fn deps(&self) -> &Path { &self.deps }
pub fn examples(&self) -> &Path { &self.examples }

pub fn fingerprint(&self, package: &Package) -> PathBuf {
self.fingerprint.join(&self.pkg_dir(package))
Expand Down
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn run_tests(manifest_path: &Path,
let mut errors = try!(run_unit_tests(options, test_args, &compilation));

// If we have an error and want to fail fast, return
if errors.len() > 0 && !options.no_fail_fast {
if !errors.is_empty() && !options.no_fail_fast {
return Ok(Some(CargoTestError::new(errors)))
}

Expand All @@ -38,7 +38,7 @@ pub fn run_tests(manifest_path: &Path,
}

errors.extend(try!(run_doc_tests(options, test_args, &compilation)));
if errors.len() == 0 {
if errors.is_empty() {
Ok(None)
} else {
Ok(Some(CargoTestError::new(errors)))
Expand Down Expand Up @@ -93,7 +93,7 @@ fn run_unit_tests(options: &TestOptions,
shell.status("Running", cmd.to_string())
}));

if let Err(e) = ExecEngine::exec(&mut ProcessEngine, cmd) {
if let Err(e) = ExecEngine::exec(&ProcessEngine, cmd) {
errors.push(e);
if !options.no_fail_fast {
break
Expand Down Expand Up @@ -166,7 +166,7 @@ fn run_doc_tests(options: &TestOptions,
try!(config.shell().verbose(|shell| {
shell.status("Running", p.to_string())
}));
if let Err(e) = ExecEngine::exec(&mut ProcessEngine, p) {
if let Err(e) = ExecEngine::exec(&ProcessEngine, p) {
errors.push(e);
if !options.no_fail_fast {
return Ok(errors);
Expand Down
Loading