Skip to content

Commit bc294a7

Browse files
authored
fix clippy warnings (#4061)
1 parent b676fd0 commit bc294a7

File tree

14 files changed

+41
-49
lines changed

14 files changed

+41
-49
lines changed

rustfmt-core/rustfmt-bin/src/bin/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl CliOptions for Opt {
340340
}
341341

342342
fn config_path(&self) -> Option<&Path> {
343-
self.config_path.as_ref().map(PathBuf::as_path)
343+
self.config_path.as_deref()
344344
}
345345
}
346346

@@ -372,10 +372,7 @@ fn print_default_config() -> Result<i32> {
372372
}
373373

374374
fn print_config(opt: &Opt, print_config: PrintConfig) -> Result<i32> {
375-
let (config, config_path) = load_config(
376-
env::current_dir().ok().as_ref().map(PathBuf::as_path),
377-
Some(opt),
378-
)?;
375+
let (config, config_path) = load_config(env::current_dir().ok().as_deref(), Some(opt))?;
379376
let actual_config =
380377
FileConfigPairIter::new(&opt, config_path.is_some()).find_map(|pair| match pair.config {
381378
FileConfig::Local(config, Some(_)) => Some(config),

rustfmt-core/rustfmt-bin/tests/cargo-fmt/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,8 @@ fn print_config() {
6969
fn rustfmt_help() {
7070
assert_that!(&["--", "--help"], contains("Format Rust code"));
7171
assert_that!(&["--", "-h"], contains("Format Rust code"));
72-
assert_that!(&["--", "--config", "help"], contains("Configuration Options:"));
72+
assert_that!(
73+
&["--", "--config", "help"],
74+
contains("Configuration Options:")
75+
);
7376
}

rustfmt-core/rustfmt-bin/tests/rustfmt/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ fn print_config() {
5454
);
5555
assert_that!(&["--print-config", "default"], contains("max_width = 100"));
5656
assert_that!(&["--print-config", "current"], contains("max_width = 100"));
57-
assert_that!(&["--config", "max_width=120", "--print-config", "current"], contains("max_width = 120"));
58-
assert_that!(&["--config", "max_width=120", "--print-config", "minimal"], contains("max_width = 120"));
59-
assert_that!(&["--config", "max_width=100", "--print-config", "minimal"], eq(""));
57+
assert_that!(
58+
&["--config", "max_width=120", "--print-config", "current"],
59+
contains("max_width = 120")
60+
);
61+
assert_that!(
62+
&["--config", "max_width=120", "--print-config", "minimal"],
63+
contains("max_width = 120")
64+
);
65+
assert_that!(
66+
&["--config", "max_width=100", "--print-config", "minimal"],
67+
eq("")
68+
);
6069
}
6170

6271
#[ignore]

rustfmt-core/rustfmt-config/src/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl fmt::Display for FileLines {
173173
Some(map) => {
174174
for (file_name, ranges) in map.iter() {
175175
write!(f, "{}: ", file_name)?;
176-
write!(f, "{}\n", ranges.iter().format(", "))?;
176+
writeln!(f, "{}", ranges.iter().format(", "))?;
177177
}
178178
}
179179
};

rustfmt-core/rustfmt-emitter/src/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Emitter for DiffEmitter {
4545
return Ok(EmitterResult { has_diff: true });
4646
}
4747

48-
return Ok(EmitterResult { has_diff });
48+
Ok(EmitterResult { has_diff })
4949
}
5050
}
5151

rustfmt-core/rustfmt-lib/src/closures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn is_block_closure_forced(
416416
} else {
417417
if let ast::ExprKind::Match(..) = expr.kind {
418418
let is_move_closure_without_brace = capture == ast::CaptureBy::Value
419-
&& !context.snippet(expr.span).trim().starts_with("{");
419+
&& !context.snippet(expr.span).trim().starts_with('{');
420420

421421
is_block_closure_forced_inner(expr) || is_move_closure_without_brace
422422
} else {

rustfmt-core/rustfmt-lib/src/imports.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,8 @@ impl UseTree {
442442

443443
// Normalise foo::self as bar -> foo as bar.
444444
if let UseSegment::Slf(_) = last {
445-
match self.path.last() {
446-
Some(UseSegment::Ident(_, None)) => {
447-
aliased_self = true;
448-
}
449-
_ => {}
445+
if let Some(UseSegment::Ident(_, None)) = self.path.last() {
446+
aliased_self = true;
450447
}
451448
}
452449

@@ -540,9 +537,8 @@ impl UseTree {
540537
match self.path.clone().last() {
541538
Some(UseSegment::List(list)) => {
542539
if list.len() == 1 && list[0].path.len() == 1 {
543-
match list[0].path[0] {
544-
UseSegment::Slf(..) => return vec![self],
545-
_ => (),
540+
if let UseSegment::Slf(..) = list[0].path[0] {
541+
return vec![self];
546542
};
547543
}
548544
let prefix = &self.path[..self.path.len() - 1];

rustfmt-core/rustfmt-lib/src/items.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'a> FnSig<'a> {
299299
result.push_str(&*format_visibility(context, &self.visibility));
300300
result.push_str(format_defaultness(self.defaultness));
301301
result.push_str(format_constness(self.constness));
302-
result.push_str(format_async(&self.is_async));
302+
result.push_str(format_async(*self.is_async));
303303
result.push_str(format_unsafety(self.unsafety));
304304
result.push_str(&format_extern(
305305
self.ext,
@@ -649,20 +649,14 @@ impl<'a> FmtVisitor<'a> {
649649
fn is_type(ty: &Option<syntax::ptr::P<ast::Ty>>) -> bool {
650650
match ty {
651651
None => true,
652-
Some(lty) => match lty.kind.opaque_top_hack() {
653-
None => true,
654-
Some(_) => false,
655-
},
652+
Some(lty) => lty.kind.opaque_top_hack().is_none(),
656653
}
657654
}
658655

659656
fn is_opaque(ty: &Option<syntax::ptr::P<ast::Ty>>) -> bool {
660657
match ty {
661658
None => false,
662-
Some(lty) => match lty.kind.opaque_top_hack() {
663-
None => false,
664-
Some(_) => true,
665-
},
659+
Some(lty) => lty.kind.opaque_top_hack().is_some(),
666660
}
667661
}
668662

rustfmt-core/rustfmt-lib/src/missed_spans.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ impl<'a> FmtVisitor<'a> {
240240
let last_char = big_snippet
241241
.chars()
242242
.rev()
243-
.skip_while(|rev_c| [' ', '\t'].contains(rev_c))
244-
.next();
243+
.find(|rev_c| ![' ', '\t'].contains(rev_c));
245244

246245
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
247246

@@ -276,8 +275,7 @@ impl<'a> FmtVisitor<'a> {
276275
match snippet[status.line_start..]
277276
.chars()
278277
// skip trailing whitespaces
279-
.skip_while(|c| *c == ' ' || *c == '\t')
280-
.next()
278+
.find(|c| !(*c == ' ' || *c == '\t'))
281279
{
282280
Some('\n') | Some('\r') => {
283281
if !is_last_comment_block(subslice) {

rustfmt-core/rustfmt-lib/src/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Rewrite for Pat {
238238
if let Some(rw) = p.rewrite(context, shape) {
239239
rw
240240
} else {
241-
format!("{}", context.snippet(p.span))
241+
context.snippet(p.span).to_string()
242242
}
243243
})
244244
.collect();

0 commit comments

Comments
 (0)