Skip to content

Commit 7862051

Browse files
authored
Merge pull request #3504 from matthiaskrgr/clippy_2
fix a bunch of clippy warnings
2 parents 896394a + 4352681 commit 7862051

19 files changed

+45
-45
lines changed

src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a> ChainFormatterShared<'a> {
550550
let almost_total = if extendable {
551551
prev_last_line_width
552552
} else {
553-
self.rewrites.iter().map(|a| a.len()).sum()
553+
self.rewrites.iter().map(String::len).sum()
554554
} + last.tries;
555555
let one_line_budget = if self.child_count == 1 {
556556
shape.width

src/closures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub fn rewrite_last_closure(
353353
/// Returns `true` if the given vector of arguments has more than one `ast::ExprKind::Closure`.
354354
pub fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
355355
args.iter()
356-
.filter_map(|arg| arg.to_expr())
356+
.filter_map(OverflowableItem::to_expr)
357357
.filter(|expr| match expr.node {
358358
ast::ExprKind::Closure(..) => true,
359359
_ => false,

src/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ where
12431243
},
12441244
CharClassesStatus::LitCharEscape => CharClassesStatus::LitChar,
12451245
CharClassesStatus::Normal => match chr {
1246-
'r' => match self.base.peek().map(|c| c.get_char()) {
1246+
'r' => match self.base.peek().map(RichChar::get_char) {
12471247
Some('#') | Some('"') => {
12481248
char_kind = FullCodeCharKind::InString;
12491249
CharClassesStatus::RawStringPrefix(0)

src/config/file_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl FileLines {
191191

192192
/// Returns an iterator over the files contained in `self`.
193193
pub fn files(&self) -> Files<'_> {
194-
Files(self.0.as_ref().map(|m| m.keys()))
194+
Files(self.0.as_ref().map(HashMap::keys))
195195
}
196196

197197
/// Returns JSON representation as accepted by the `--file-lines JSON` arg.

src/config/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Config {
244244
}
245245
}
246246

247-
return Ok(None);
247+
Ok(None)
248248
}
249249

250250
match resolve_project_file(dir)? {
@@ -260,7 +260,7 @@ impl Config {
260260
let mut err = String::new();
261261
let table = parsed
262262
.as_table()
263-
.ok_or(String::from("Parsed config was not table"))?;
263+
.ok_or_else(|| String::from("Parsed config was not table"))?;
264264
for key in table.keys() {
265265
if !Config::is_valid_name(key) {
266266
let msg = &format!("Warning: Unknown configuration option `{}`\n", key);
@@ -358,7 +358,7 @@ fn config_path(options: &dyn CliOptions) -> Result<Option<PathBuf>, Error> {
358358
config_path_not_found(path.to_str().unwrap())
359359
}
360360
}
361-
path => Ok(path.map(|p| p.to_owned())),
361+
path => Ok(path.map(ToOwned::to_owned)),
362362
}
363363
}
364364

src/formatting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl FormattingError {
263263
.and_then(|fl| {
264264
fl.file
265265
.get_line(fl.lines[0].line_index)
266-
.map(|l| l.into_owned())
266+
.map(std::borrow::Cow::into_owned)
267267
})
268268
.unwrap_or_else(String::new),
269269
}
@@ -653,7 +653,7 @@ fn parse_crate(
653653
return Ok(c);
654654
}
655655
}
656-
Ok(Err(mut diagnostics)) => diagnostics.iter_mut().for_each(|d| d.emit()),
656+
Ok(Err(mut diagnostics)) => diagnostics.iter_mut().for_each(DiagnosticBuilder::emit),
657657
Err(_) => {
658658
// Note that if you see this message and want more information,
659659
// then run the `parse_crate_mod` function above without

src/git-rustfmt/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn uncommitted_files() -> Vec<String> {
9898
stdout
9999
.lines()
100100
.filter(|s| s.ends_with(".rs"))
101-
.map(|s| s.to_owned())
101+
.map(std::borrow::ToOwned::to_owned)
102102
.collect()
103103
}
104104

src/imports.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,7 @@ impl UseTree {
492492

493493
// Recursively normalize elements of a list use (including sorting the list).
494494
if let UseSegment::List(list) = last {
495-
let mut list = list
496-
.into_iter()
497-
.map(|ut| ut.normalize())
498-
.collect::<Vec<_>>();
495+
let mut list = list.into_iter().map(UseTree::normalize).collect::<Vec<_>>();
499496
list.sort();
500497
last = UseSegment::List(list);
501498
}

src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ fn format_tuple_struct(
13581358
context
13591359
.snippet_provider
13601360
.opt_span_after(mk_sp(last_arg_span.hi(), span.hi()), ")")
1361-
.unwrap_or(last_arg_span.hi())
1361+
.unwrap_or_else(|| last_arg_span.hi())
13621362
};
13631363

13641364
let where_clause_str = match struct_parts.generics {
@@ -2143,7 +2143,7 @@ fn rewrite_fn_base(
21432143
indent
21442144
} else {
21452145
if context.config.version() == Version::Two {
2146-
if arg_str.len() != 0 || !no_args_and_over_max_width {
2146+
if !arg_str.is_empty() || !no_args_and_over_max_width {
21472147
result.push(' ');
21482148
}
21492149
} else {
@@ -2284,7 +2284,7 @@ fn rewrite_args(
22842284
span: Span,
22852285
variadic: bool,
22862286
) -> Option<String> {
2287-
if args.len() == 0 {
2287+
if args.is_empty() {
22882288
let comment = context
22892289
.snippet(mk_sp(
22902290
span.lo(),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn format_code_block(code_snippet: &str, config: &Config) -> Option<FormattedSni
445445
let block_len = formatted
446446
.snippet
447447
.rfind('}')
448-
.unwrap_or(formatted.snippet.len());
448+
.unwrap_or_else(|| formatted.snippet.len());
449449
let mut is_indented = true;
450450
for (kind, ref line) in LineClasses::new(&formatted.snippet[FN_MAIN_PREFIX.len()..block_len]) {
451451
if !is_first {

0 commit comments

Comments
 (0)