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

clippy fixes, use matches! macro in more places #8575

Merged
merged 2 commits into from
Aug 4, 2020
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
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ impl Execs {
None => failures.push(e_line),
}
}
if failures.len() > 0 {
if !failures.is_empty() {
return Err(format!(
"Did not find expected line(s):\n{}\n\
Remaining available output:\n{}\n",
Expand Down
35 changes: 13 additions & 22 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ impl BuildConfig {
/// Whether or not the *user* wants JSON output. Whether or not rustc
/// actually uses JSON is decided in `add_error_format`.
pub fn emit_json(&self) -> bool {
match self.message_format {
MessageFormat::Json { .. } => true,
_ => false,
}
matches!(self.message_format, MessageFormat::Json { .. })
}

pub fn test(&self) -> bool {
Expand Down Expand Up @@ -171,18 +168,12 @@ impl ser::Serialize for CompileMode {
impl CompileMode {
/// Returns `true` if the unit is being checked.
pub fn is_check(self) -> bool {
match self {
CompileMode::Check { .. } => true,
_ => false,
}
matches!(self, CompileMode::Check { .. })
}

/// Returns `true` if this is generating documentation.
pub fn is_doc(self) -> bool {
match self {
CompileMode::Doc { .. } => true,
_ => false,
}
matches!(self, CompileMode::Doc { .. })
}

/// Returns `true` if this a doc test.
Expand All @@ -193,21 +184,21 @@ impl CompileMode {
/// Returns `true` if this is any type of test (test, benchmark, doc test, or
/// check test).
pub fn is_any_test(self) -> bool {
match self {
matches!(
self,
CompileMode::Test
| CompileMode::Bench
| CompileMode::Check { test: true }
| CompileMode::Doctest => true,
_ => false,
}
| CompileMode::Bench
| CompileMode::Check { test: true }
| CompileMode::Doctest
)
}

/// Returns `true` if this is something that passes `--test` to rustc.
pub fn is_rustc_test(self) -> bool {
match self {
CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true } => true,
_ => false,
}
matches!(
self,
CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true }
)
}

/// Returns `true` if this is the *execution* of a `build.rs` script.
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/compiler/compile_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ pub enum CompileKind {

impl CompileKind {
pub fn is_host(&self) -> bool {
match self {
CompileKind::Host => true,
_ => false,
}
matches!(self, CompileKind::Host)
}

pub fn for_target(self, target: &Target) -> CompileKind {
Expand Down
15 changes: 6 additions & 9 deletions src/cargo/core/compiler/crate_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@ impl CrateType {
}

pub fn requires_upstream_objects(&self) -> bool {
match self {
// "lib" == "rlib" and is a compilation that doesn't actually
// require upstream object files to exist, only upstream metadata
// files. As a result, it doesn't require upstream artifacts
CrateType::Lib | CrateType::Rlib => false,
// "lib" == "rlib" and is a compilation that doesn't actually
// require upstream object files to exist, only upstream metadata
// files. As a result, it doesn't require upstream artifacts

// Everything else, however, is some form of "linkable output" or
// something that requires upstream object files.
_ => true,
}
!matches!(self, CrateType::Lib | CrateType::Rlib)
// Everything else, however, is some form of "linkable output" or
// something that requires upstream object files.
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ impl Dependency {
}

pub fn is_build(&self) -> bool {
match self.inner.kind {
DepKind::Build => true,
_ => false,
}
matches!(self.inner.kind, DepKind::Build)
}

pub fn is_optional(&self) -> bool {
Expand Down
23 changes: 7 additions & 16 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ impl TargetSourcePath {
}

pub fn is_path(&self) -> bool {
match self {
TargetSourcePath::Path(_) => true,
_ => false,
}
matches!(self, TargetSourcePath::Path(_))
}
}

Expand Down Expand Up @@ -777,10 +774,7 @@ impl Target {
}

pub fn is_lib(&self) -> bool {
match self.kind() {
TargetKind::Lib(_) => true,
_ => false,
}
matches!(self.kind(), TargetKind::Lib(_))
}

pub fn is_dylib(&self) -> bool {
Expand Down Expand Up @@ -813,10 +807,10 @@ impl Target {
}

pub fn is_example(&self) -> bool {
match self.kind() {
TargetKind::ExampleBin | TargetKind::ExampleLib(..) => true,
_ => false,
}
matches!(
self.kind(),
TargetKind::ExampleBin | TargetKind::ExampleLib(..)
)
}

/// Returns `true` if it is a binary or executable example.
Expand All @@ -828,10 +822,7 @@ impl Target {
/// Returns `true` if it is an executable example.
pub fn is_exe_example(&self) -> bool {
// Needed for --all-examples in contexts where only runnable examples make sense
match self.kind() {
TargetKind::ExampleBin => true,
_ => false,
}
matches!(self.kind(), TargetKind::ExampleBin)
}

pub fn is_test(&self) -> bool {
Expand Down
5 changes: 1 addition & 4 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ impl Profiles {
// `--release` and `--debug` predicates, and convert back from
// ProfileKind::Custom instantiation.

let release = match self.requested_profile.as_str() {
"release" | "bench" => true,
_ => false,
};
let release = matches!(self.requested_profile.as_str(), "release" | "bench");

match mode {
CompileMode::Test | CompileMode::Bench => {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub(super) fn activation_error(
if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s), true) {
return to_resolve_err(e);
};
candidates.sort_unstable_by(|a, b| a.name().cmp(&b.name()));
candidates.sort_unstable_by_key(|a| a.name());
candidates.dedup_by(|a, b| a.name() == b.name());
let mut candidates: Vec<_> = candidates
.iter()
Expand Down
18 changes: 6 additions & 12 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,23 @@ impl SourceId {

/// Returns `true` if this source is from a registry (either local or not).
pub fn is_registry(self) -> bool {
match self.inner.kind {
SourceKind::Registry | SourceKind::LocalRegistry => true,
_ => false,
}
matches!(
self.inner.kind,
SourceKind::Registry | SourceKind::LocalRegistry
)
}

/// Returns `true` if this source is a "remote" registry.
///
/// "remote" may also mean a file URL to a git index, so it is not
/// necessarily "remote". This just means it is not `local-registry`.
pub fn is_remote_registry(self) -> bool {
match self.inner.kind {
SourceKind::Registry => true,
_ => false,
}
matches!(self.inner.kind, SourceKind::Registry)
}

/// Returns `true` if this source from a Git repository.
pub fn is_git(self) -> bool {
match self.inner.kind {
SourceKind::Git(_) => true,
_ => false,
}
matches!(self.inner.kind, SourceKind::Git(_))
}

/// Creates an implementation of `Source` corresponding to this ID.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ pub fn fetch(

GitReference::DefaultBranch => {
// See the module docs for why we're fetching `master` here.
refspecs.push(format!("refs/heads/master:refs/remotes/origin/master"));
refspecs.push(String::from("refs/heads/master:refs/remotes/origin/master"));
refspecs.push(String::from("HEAD:refs/remotes/origin/HEAD"));
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,8 @@ fn long_file_names() {
test_path.mkdir_p();
let test_path = test_path.join(long_name);
if let Err(e) = File::create(&test_path) {
// write to stderr directly to avoid output from being captured
// and always display text, even without --nocapture
use std::io::Write;
writeln!(
std::io::stderr(),
Expand Down