Skip to content

Commit 964a16a

Browse files
committed
Auto merge of #8575 - matthiaskrgr:clippy_v16, r=ehuss
clippy fixes, use matches! macro in more places
2 parents 2732539 + f23b911 commit 964a16a

File tree

11 files changed

+40
-74
lines changed

11 files changed

+40
-74
lines changed

crates/cargo-test-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ impl Execs {
12331233
None => failures.push(e_line),
12341234
}
12351235
}
1236-
if failures.len() > 0 {
1236+
if !failures.is_empty() {
12371237
return Err(format!(
12381238
"Did not find expected line(s):\n{}\n\
12391239
Remaining available output:\n{}\n",

src/cargo/core/compiler/build_config.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ impl BuildConfig {
8686
/// Whether or not the *user* wants JSON output. Whether or not rustc
8787
/// actually uses JSON is decided in `add_error_format`.
8888
pub fn emit_json(&self) -> bool {
89-
match self.message_format {
90-
MessageFormat::Json { .. } => true,
91-
_ => false,
92-
}
89+
matches!(self.message_format, MessageFormat::Json { .. })
9390
}
9491

9592
pub fn test(&self) -> bool {
@@ -171,18 +168,12 @@ impl ser::Serialize for CompileMode {
171168
impl CompileMode {
172169
/// Returns `true` if the unit is being checked.
173170
pub fn is_check(self) -> bool {
174-
match self {
175-
CompileMode::Check { .. } => true,
176-
_ => false,
177-
}
171+
matches!(self, CompileMode::Check { .. })
178172
}
179173

180174
/// Returns `true` if this is generating documentation.
181175
pub fn is_doc(self) -> bool {
182-
match self {
183-
CompileMode::Doc { .. } => true,
184-
_ => false,
185-
}
176+
matches!(self, CompileMode::Doc { .. })
186177
}
187178

188179
/// Returns `true` if this a doc test.
@@ -193,21 +184,21 @@ impl CompileMode {
193184
/// Returns `true` if this is any type of test (test, benchmark, doc test, or
194185
/// check test).
195186
pub fn is_any_test(self) -> bool {
196-
match self {
187+
matches!(
188+
self,
197189
CompileMode::Test
198-
| CompileMode::Bench
199-
| CompileMode::Check { test: true }
200-
| CompileMode::Doctest => true,
201-
_ => false,
202-
}
190+
| CompileMode::Bench
191+
| CompileMode::Check { test: true }
192+
| CompileMode::Doctest
193+
)
203194
}
204195

205196
/// Returns `true` if this is something that passes `--test` to rustc.
206197
pub fn is_rustc_test(self) -> bool {
207-
match self {
208-
CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true } => true,
209-
_ => false,
210-
}
198+
matches!(
199+
self,
200+
CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true }
201+
)
211202
}
212203

213204
/// Returns `true` if this is the *execution* of a `build.rs` script.

src/cargo/core/compiler/compile_kind.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ pub enum CompileKind {
2727

2828
impl CompileKind {
2929
pub fn is_host(&self) -> bool {
30-
match self {
31-
CompileKind::Host => true,
32-
_ => false,
33-
}
30+
matches!(self, CompileKind::Host)
3431
}
3532

3633
pub fn for_target(self, target: &Target) -> CompileKind {

src/cargo/core/compiler/crate_type.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,13 @@ impl CrateType {
5858
}
5959

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

67-
// Everything else, however, is some form of "linkable output" or
68-
// something that requires upstream object files.
69-
_ => true,
70-
}
65+
!matches!(self, CrateType::Lib | CrateType::Rlib)
66+
// Everything else, however, is some form of "linkable output" or
67+
// something that requires upstream object files.
7168
}
7269
}
7370

src/cargo/core/dependency.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,7 @@ impl Dependency {
413413
}
414414

415415
pub fn is_build(&self) -> bool {
416-
match self.inner.kind {
417-
DepKind::Build => true,
418-
_ => false,
419-
}
416+
matches!(self.inner.kind, DepKind::Build)
420417
}
421418

422419
pub fn is_optional(&self) -> bool {

src/cargo/core/manifest.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ impl TargetSourcePath {
220220
}
221221

222222
pub fn is_path(&self) -> bool {
223-
match self {
224-
TargetSourcePath::Path(_) => true,
225-
_ => false,
226-
}
223+
matches!(self, TargetSourcePath::Path(_))
227224
}
228225
}
229226

@@ -777,10 +774,7 @@ impl Target {
777774
}
778775

779776
pub fn is_lib(&self) -> bool {
780-
match self.kind() {
781-
TargetKind::Lib(_) => true,
782-
_ => false,
783-
}
777+
matches!(self.kind(), TargetKind::Lib(_))
784778
}
785779

786780
pub fn is_dylib(&self) -> bool {
@@ -813,10 +807,10 @@ impl Target {
813807
}
814808

815809
pub fn is_example(&self) -> bool {
816-
match self.kind() {
817-
TargetKind::ExampleBin | TargetKind::ExampleLib(..) => true,
818-
_ => false,
819-
}
810+
matches!(
811+
self.kind(),
812+
TargetKind::ExampleBin | TargetKind::ExampleLib(..)
813+
)
820814
}
821815

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

837828
pub fn is_test(&self) -> bool {

src/cargo/core/profiles.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,7 @@ impl Profiles {
296296
// `--release` and `--debug` predicates, and convert back from
297297
// ProfileKind::Custom instantiation.
298298

299-
let release = match self.requested_profile.as_str() {
300-
"release" | "bench" => true,
301-
_ => false,
302-
};
299+
let release = matches!(self.requested_profile.as_str(), "release" | "bench");
303300

304301
match mode {
305302
CompileMode::Test | CompileMode::Bench => {

src/cargo/core/resolver/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub(super) fn activation_error(
254254
if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s), true) {
255255
return to_resolve_err(e);
256256
};
257-
candidates.sort_unstable_by(|a, b| a.name().cmp(&b.name()));
257+
candidates.sort_unstable_by_key(|a| a.name());
258258
candidates.dedup_by(|a, b| a.name() == b.name());
259259
let mut candidates: Vec<_> = candidates
260260
.iter()

src/cargo/core/source/source_id.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,23 @@ impl SourceId {
239239

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

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

259256
/// Returns `true` if this source from a Git repository.
260257
pub fn is_git(self) -> bool {
261-
match self.inner.kind {
262-
SourceKind::Git(_) => true,
263-
_ => false,
264-
}
258+
matches!(self.inner.kind, SourceKind::Git(_))
265259
}
266260

267261
/// Creates an implementation of `Source` corresponding to this ID.

src/cargo/sources/git/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ pub fn fetch(
901901

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

tests/testsuite/package.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,8 @@ fn long_file_names() {
18701870
test_path.mkdir_p();
18711871
let test_path = test_path.join(long_name);
18721872
if let Err(e) = File::create(&test_path) {
1873+
// write to stderr directly to avoid output from being captured
1874+
// and always display text, even without --nocapture
18731875
use std::io::Write;
18741876
writeln!(
18751877
std::io::stderr(),

0 commit comments

Comments
 (0)