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

Diff for: rustfmt-core/rustfmt-bin/src/bin/main.rs

+2-5
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),

Diff for: rustfmt-core/rustfmt-bin/tests/cargo-fmt/main.rs

+4-1
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
}

Diff for: rustfmt-core/rustfmt-bin/tests/rustfmt/main.rs

+12-3
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]

Diff for: rustfmt-core/rustfmt-config/src/file_lines.rs

+1-1
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
};

Diff for: rustfmt-core/rustfmt-emitter/src/diff.rs

+1-1
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

Diff for: rustfmt-core/rustfmt-lib/src/closures.rs

+1-1
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 {

Diff for: rustfmt-core/rustfmt-lib/src/imports.rs

+4-8
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];

Diff for: rustfmt-core/rustfmt-lib/src/items.rs

+3-9
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

Diff for: rustfmt-core/rustfmt-lib/src/missed_spans.rs

+2-4
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) {

Diff for: rustfmt-core/rustfmt-lib/src/patterns.rs

+1-1
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();

Diff for: rustfmt-core/rustfmt-lib/src/skip.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ impl SkipContext {
2929
}
3030
}
3131
for attr in attrs {
32-
match &attr.kind {
33-
syntax::ast::AttrKind::Normal(ref attr_item) => {
34-
if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) {
35-
get_skip_names(&mut self.macros, attr)
36-
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes)
37-
{
38-
get_skip_names(&mut self.attributes, attr)
39-
}
32+
if let syntax::ast::AttrKind::Normal(ref attr_item) = &attr.kind {
33+
if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) {
34+
get_skip_names(&mut self.macros, attr)
35+
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes) {
36+
get_skip_names(&mut self.attributes, attr)
4037
}
41-
_ => (),
4238
}
4339
}
4440
}

Diff for: rustfmt-core/rustfmt-lib/src/syntux/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'a> Parser<'a> {
286286
let token_stream = mac.args.inner_tokens();
287287
let mut parser = rustc_parse::stream_to_parser_with_base_dir(
288288
sess.inner(),
289-
token_stream.clone(),
289+
token_stream,
290290
base_dir.to_syntax_directory(),
291291
);
292292

Diff for: rustfmt-core/rustfmt-lib/src/utils.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub(crate) fn format_visibility(
8686
}
8787

8888
#[inline]
89-
pub(crate) fn format_async(is_async: &ast::IsAsync) -> &'static str {
89+
pub(crate) fn format_async(is_async: ast::IsAsync) -> &'static str {
9090
match is_async {
9191
ast::IsAsync::Async { .. } => "async ",
9292
ast::IsAsync::NotAsync => "",
@@ -255,8 +255,7 @@ fn is_skip(meta_item: &MetaItem) -> bool {
255255
match meta_item.kind {
256256
MetaItemKind::Word => {
257257
let path_str = pprust::path_to_string(&meta_item.path);
258-
path_str == &*skip_annotation().as_str()
259-
|| path_str == &*depr_skip_annotation().as_str()
258+
path_str == *skip_annotation().as_str() || path_str == *depr_skip_annotation().as_str()
260259
}
261260
MetaItemKind::List(ref l) => {
262261
meta_item.check_name(sym::cfg_attr) && l.len() == 2 && is_skip_nested(&l[1])

Diff for: rustfmt-core/rustfmt-lib/src/visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
177177
let missing_span = self.next_span(hi);
178178
let snippet = self.snippet(missing_span);
179179
let len = CommentCodeSlices::new(snippet)
180-
.nth(0)
180+
.next()
181181
.and_then(|(kind, _, s)| {
182182
if kind == CodeCharKind::Normal {
183183
s.rfind('\n')
@@ -690,7 +690,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
690690
let hi = self.snippet_provider.span_before(search_span, ";");
691691
let target_span = mk_sp(mac.span().lo(), hi + BytePos(1));
692692
let rewrite = rewrite.map(|rw| {
693-
if !rw.ends_with(";") {
693+
if !rw.ends_with(';') {
694694
format!("{};", rw)
695695
} else {
696696
rw

0 commit comments

Comments
 (0)