Skip to content

Commit 75e3172

Browse files
authored
fix a couply of clippy findings (#6007)
* clippy: autofix some lint warnings * fix a couple more clippy warnings
1 parent 85e21fa commit 75e3172

File tree

12 files changed

+48
-53
lines changed

12 files changed

+48
-53
lines changed

build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ fn channel() -> String {
4040

4141
fn commit_hash() -> Option<String> {
4242
Command::new("git")
43-
.args(&["rev-parse", "--short", "HEAD"])
43+
.args(["rev-parse", "--short", "HEAD"])
4444
.output()
4545
.ok()
4646
.and_then(|r| String::from_utf8(r.stdout).ok())
4747
}
4848

4949
fn commit_date() -> Option<String> {
5050
Command::new("git")
51-
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
51+
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
5252
.output()
5353
.ok()
5454
.and_then(|r| String::from_utf8(r.stdout).ok())

src/bin/main.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,11 @@ fn format_and_emit_report<T: Write>(session: &mut Session<'_, T>, input: Input)
387387
}
388388

389389
fn should_print_with_colors<T: Write>(session: &mut Session<'_, T>) -> bool {
390-
match term::stderr() {
391-
Some(ref t)
392-
if session.config.color().use_colored_tty()
393-
&& t.supports_color()
394-
&& t.supports_attr(term::Attr::Bold) =>
395-
{
396-
true
397-
}
398-
_ => false,
399-
}
390+
term::stderr().is_some_and(|t| {
391+
session.config.color().use_colored_tty()
392+
&& t.supports_color()
393+
&& t.supports_attr(term::Attr::Bold)
394+
})
400395
}
401396

402397
fn print_usage_to_stdout(opts: &Options, reason: &str) {
@@ -445,7 +440,7 @@ fn print_version() {
445440
fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> {
446441
if matches.opt_present("h") {
447442
let topic = matches.opt_str("h");
448-
if topic == None {
443+
if topic.is_none() {
449444
return Ok(Operation::Help(HelpOp::None));
450445
} else if topic == Some("config".to_owned()) {
451446
return Ok(Operation::Help(HelpOp::Config));

src/cargo-fmt/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn run_rustfmt(
507507
let mut command = rustfmt_command()
508508
.stdout(stdout)
509509
.args(files)
510-
.args(&["--edition", edition.as_str()])
510+
.args(["--edition", edition.as_str()])
511511
.args(fmt_args)
512512
.spawn()
513513
.map_err(|e| match e.kind() {

src/cargo-fmt/test/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn default_options() {
2020

2121
#[test]
2222
fn good_options() {
23-
let o = Opts::parse_from(&[
23+
let o = Opts::parse_from([
2424
"test",
2525
"-q",
2626
"-p",
@@ -48,7 +48,7 @@ fn good_options() {
4848
fn unexpected_option() {
4949
assert!(
5050
Opts::command()
51-
.try_get_matches_from(&["test", "unexpected"])
51+
.try_get_matches_from(["test", "unexpected"])
5252
.is_err()
5353
);
5454
}
@@ -57,7 +57,7 @@ fn unexpected_option() {
5757
fn unexpected_flag() {
5858
assert!(
5959
Opts::command()
60-
.try_get_matches_from(&["test", "--flag"])
60+
.try_get_matches_from(["test", "--flag"])
6161
.is_err()
6262
);
6363
}
@@ -66,19 +66,19 @@ fn unexpected_flag() {
6666
fn mandatory_separator() {
6767
assert!(
6868
Opts::command()
69-
.try_get_matches_from(&["test", "--emit"])
69+
.try_get_matches_from(["test", "--emit"])
7070
.is_err()
7171
);
7272
assert!(
7373
Opts::command()
74-
.try_get_matches_from(&["test", "--", "--emit"])
74+
.try_get_matches_from(["test", "--", "--emit"])
7575
.is_ok()
7676
);
7777
}
7878

7979
#[test]
8080
fn multiple_packages_one_by_one() {
81-
let o = Opts::parse_from(&[
81+
let o = Opts::parse_from([
8282
"test",
8383
"-p",
8484
"package1",
@@ -92,7 +92,7 @@ fn multiple_packages_one_by_one() {
9292

9393
#[test]
9494
fn multiple_packages_grouped() {
95-
let o = Opts::parse_from(&[
95+
let o = Opts::parse_from([
9696
"test",
9797
"--package",
9898
"package1",
@@ -108,7 +108,7 @@ fn multiple_packages_grouped() {
108108
fn empty_packages_1() {
109109
assert!(
110110
Opts::command()
111-
.try_get_matches_from(&["test", "-p"])
111+
.try_get_matches_from(["test", "-p"])
112112
.is_err()
113113
);
114114
}
@@ -117,7 +117,7 @@ fn empty_packages_1() {
117117
fn empty_packages_2() {
118118
assert!(
119119
Opts::command()
120-
.try_get_matches_from(&["test", "-p", "--", "--check"])
120+
.try_get_matches_from(["test", "-p", "--", "--check"])
121121
.is_err()
122122
);
123123
}
@@ -126,7 +126,7 @@ fn empty_packages_2() {
126126
fn empty_packages_3() {
127127
assert!(
128128
Opts::command()
129-
.try_get_matches_from(&["test", "-p", "--verbose"])
129+
.try_get_matches_from(["test", "-p", "--verbose"])
130130
.is_err()
131131
);
132132
}
@@ -135,7 +135,7 @@ fn empty_packages_3() {
135135
fn empty_packages_4() {
136136
assert!(
137137
Opts::command()
138-
.try_get_matches_from(&["test", "-p", "--check"])
138+
.try_get_matches_from(["test", "-p", "--check"])
139139
.is_err()
140140
);
141141
}

src/comment.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl ItemizedBlock {
503503
let mut line_start = " ".repeat(indent);
504504

505505
// Markdown blockquote start with a "> "
506-
if line.trim_start().starts_with(">") {
506+
if line.trim_start().starts_with('>') {
507507
// remove the original +2 indent because there might be multiple nested block quotes
508508
// and it's easier to reason about the final indent by just taking the length
509509
// of the new line_start. We update the indent because it effects the max width
@@ -654,7 +654,7 @@ impl<'a> CommentRewrite<'a> {
654654
while let Some(line) = iter.next() {
655655
result.push_str(line);
656656
result.push_str(match iter.peek() {
657-
Some(next_line) if next_line.is_empty() => sep.trim_end(),
657+
Some(&"") => sep.trim_end(),
658658
Some(..) => sep,
659659
None => "",
660660
});
@@ -836,7 +836,7 @@ impl<'a> CommentRewrite<'a> {
836836
}
837837
}
838838

839-
let is_markdown_header_doc_comment = is_doc_comment && line.starts_with("#");
839+
let is_markdown_header_doc_comment = is_doc_comment && line.starts_with('#');
840840

841841
// We only want to wrap the comment if:
842842
// 1) wrap_comments = true is configured
@@ -1761,7 +1761,7 @@ fn changed_comment_content(orig: &str, new: &str) -> bool {
17611761
let code_comment_content = |code| {
17621762
let slices = UngroupedCommentCodeSlices::new(code);
17631763
slices
1764-
.filter(|&(ref kind, _, _)| *kind == CodeCharKind::Comment)
1764+
.filter(|(kind, _, _)| *kind == CodeCharKind::Comment)
17651765
.flat_map(|(_, _, s)| CommentReducer::new(s))
17661766
};
17671767
let res = code_comment_content(orig).ne(code_comment_content(new));

src/emitter/checkstyle.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ mod tests {
8989
#[test]
9090
fn emits_single_xml_tree_containing_all_files() {
9191
let bin_file = "src/bin.rs";
92-
let bin_original = vec!["fn main() {", "println!(\"Hello, world!\");", "}"];
93-
let bin_formatted = vec!["fn main() {", " println!(\"Hello, world!\");", "}"];
92+
let bin_original = ["fn main() {", "println!(\"Hello, world!\");", "}"];
93+
let bin_formatted = ["fn main() {", " println!(\"Hello, world!\");", "}"];
9494
let lib_file = "src/lib.rs";
95-
let lib_original = vec!["fn greet() {", "println!(\"Greetings!\");", "}"];
96-
let lib_formatted = vec!["fn greet() {", " println!(\"Greetings!\");", "}"];
95+
let lib_original = ["fn greet() {", "println!(\"Greetings!\");", "}"];
96+
let lib_formatted = ["fn greet() {", " println!(\"Greetings!\");", "}"];
9797
let mut writer = Vec::new();
9898
let mut emitter = CheckstyleEmitter::default();
9999
let _ = emitter.emit_header(&mut writer);
@@ -118,15 +118,15 @@ mod tests {
118118
)
119119
.unwrap();
120120
let _ = emitter.emit_footer(&mut writer);
121-
let exp_bin_xml = vec![
121+
let exp_bin_xml = [
122122
format!(r#"<file name="{}">"#, bin_file),
123123
format!(
124124
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
125125
XmlEscaped(r#" println!("Hello, world!");"#),
126126
),
127127
String::from("</file>"),
128128
];
129-
let exp_lib_xml = vec![
129+
let exp_lib_xml = [
130130
format!(r#"<file name="{}">"#, lib_file),
131131
format!(
132132
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
@@ -136,7 +136,7 @@ mod tests {
136136
];
137137
assert_eq!(
138138
String::from_utf8(writer).unwrap(),
139-
vec![
139+
[
140140
r#"<?xml version="1.0" encoding="utf-8"?>"#,
141141
"\n",
142142
r#"<checkstyle version="4.3">"#,

src/emitter/json.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ mod tests {
212212
#[test]
213213
fn emits_array_with_files_with_diffs() {
214214
let file_name = "src/bin.rs";
215-
let original = vec![
215+
let original = [
216216
"fn main() {",
217217
"println!(\"Hello, world!\");",
218218
"}",
@@ -225,7 +225,7 @@ mod tests {
225225
"}",
226226
"}",
227227
];
228-
let formatted = vec![
228+
let formatted = [
229229
"fn main() {",
230230
" println!(\"Hello, world!\");",
231231
"}",
@@ -285,11 +285,11 @@ mod tests {
285285
#[test]
286286
fn emits_valid_json_with_multiple_files() {
287287
let bin_file = "src/bin.rs";
288-
let bin_original = vec!["fn main() {", "println!(\"Hello, world!\");", "}"];
289-
let bin_formatted = vec!["fn main() {", " println!(\"Hello, world!\");", "}"];
288+
let bin_original = ["fn main() {", "println!(\"Hello, world!\");", "}"];
289+
let bin_formatted = ["fn main() {", " println!(\"Hello, world!\");", "}"];
290290
let lib_file = "src/lib.rs";
291-
let lib_original = vec!["fn greet() {", "println!(\"Greetings!\");", "}"];
292-
let lib_formatted = vec!["fn greet() {", " println!(\"Greetings!\");", "}"];
291+
let lib_original = ["fn greet() {", "println!(\"Greetings!\");", "}"];
292+
let lib_formatted = ["fn greet() {", " println!(\"Greetings!\");", "}"];
293293
let mut writer = Vec::new();
294294
let mut emitter = JsonEmitter::default();
295295
let _ = emitter.emit_header(&mut writer);

src/format-diff/main.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ mod cmd_line_tests {
234234
#[test]
235235
fn default_options() {
236236
let empty: Vec<String> = vec![];
237-
let o = Opts::parse_from(&empty);
237+
let o = Opts::parse_from(empty);
238238
assert_eq!(DEFAULT_PATTERN, o.filter);
239239
assert_eq!(0, o.skip_prefix);
240240
}
241241

242242
#[test]
243243
fn good_options() {
244-
let o = Opts::parse_from(&["test", "-p", "10", "-f", r".*\.hs"]);
244+
let o = Opts::parse_from(["test", "-p", "10", "-f", r".*\.hs"]);
245245
assert_eq!(r".*\.hs", o.filter);
246246
assert_eq!(10, o.skip_prefix);
247247
}
@@ -250,7 +250,7 @@ mod cmd_line_tests {
250250
fn unexpected_option() {
251251
assert!(
252252
Opts::command()
253-
.try_get_matches_from(&["test", "unexpected"])
253+
.try_get_matches_from(["test", "unexpected"])
254254
.is_err()
255255
);
256256
}
@@ -259,7 +259,7 @@ mod cmd_line_tests {
259259
fn unexpected_flag() {
260260
assert!(
261261
Opts::command()
262-
.try_get_matches_from(&["test", "--flag"])
262+
.try_get_matches_from(["test", "--flag"])
263263
.is_err()
264264
);
265265
}
@@ -268,7 +268,7 @@ mod cmd_line_tests {
268268
fn overridden_option() {
269269
assert!(
270270
Opts::command()
271-
.try_get_matches_from(&["test", "-p", "10", "-p", "20"])
271+
.try_get_matches_from(["test", "-p", "10", "-p", "20"])
272272
.is_err()
273273
);
274274
}
@@ -277,7 +277,7 @@ mod cmd_line_tests {
277277
fn negative_filter() {
278278
assert!(
279279
Opts::command()
280-
.try_get_matches_from(&["test", "-p", "-1"])
280+
.try_get_matches_from(["test", "-p", "-1"])
281281
.is_err()
282282
);
283283
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ impl FormatReport {
257257
self.internal
258258
.borrow()
259259
.0
260-
.iter()
261-
.map(|(_, errors)| errors.len())
260+
.values()
261+
.map(|errors| errors.len())
262262
.sum()
263263
}
264264

src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn rewrite_empty_macro_def_body(
389389
stmts: vec![].into(),
390390
id: rustc_ast::node_id::DUMMY_NODE_ID,
391391
rules: ast::BlockCheckMode::Default,
392-
span: span,
392+
span,
393393
tokens: None,
394394
could_be_bare_literal: false,
395395
};

src/source_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
let mut emitter = create_emitter(config);
3434

3535
emitter.emit_header(out)?;
36-
for &(ref filename, ref text) in source_file {
36+
for (filename, text) in source_file {
3737
write_file(
3838
None,
3939
filename,

src/test/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn assert_stdin_output(
332332
let mut session = Session::new(config, Some(&mut buf));
333333
session.format(input).unwrap();
334334
let errors = ReportedErrors {
335-
has_diff: has_diff,
335+
has_diff,
336336
..Default::default()
337337
};
338338
assert_eq!(session.errors, errors);

0 commit comments

Comments
 (0)