From 44533f09aaf0ed7c9dd146305dc8140476633124 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 21 Dec 2016 09:45:24 +0100 Subject: [PATCH] rustfmt round n --- clippy_lints/src/approx_const.rs | 4 ++- clippy_lints/src/loops.rs | 33 ++++++++++++------------ clippy_lints/src/methods.rs | 8 +++--- clippy_lints/src/misc.rs | 14 ++++++---- clippy_lints/src/non_expressive_names.rs | 4 +-- clippy_lints/src/regex.rs | 7 ++--- clippy_lints/src/transmute.rs | 29 +++++++++++---------- clippy_lints/src/types.rs | 10 ++----- clippy_lints/src/utils/mod.rs | 5 ++-- clippy_lints/src/utils/sugg.rs | 3 ++- 10 files changed, 59 insertions(+), 58 deletions(-) diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 3ccb5f6ef2a0..7131e609715b 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -85,7 +85,9 @@ fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &s APPROX_CONSTANT, e.span, &format!("approximate value of `{}::consts::{}` found. \ - Consider using it directly", module, &name)); + Consider using it directly", + module, + &name)); return; } } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 8fd694a1f630..e85d0f40c4b5 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -473,10 +473,10 @@ fn check_for_loop_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, ar expr.span, &format!("the loop variable `{}` is used to index `{}`", ident.node, indexed), |db| { - multispan_sugg(db, "consider using an iterator".to_string(), &[ - (pat.span, &format!("({}, )", ident.node)), - (arg.span, &format!("{}.iter().enumerate(){}{}", indexed, take, skip)), - ]); + multispan_sugg(db, + "consider using an iterator".to_string(), + &[(pat.span, &format!("({}, )", ident.node)), + (arg.span, &format!("{}.iter().enumerate(){}{}", indexed, take, skip))]); }); } else { let repl = if starts_at_zero && take.is_empty() { @@ -488,13 +488,14 @@ fn check_for_loop_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat, ar span_lint_and_then(cx, NEEDLESS_RANGE_LOOP, expr.span, - &format!("the loop variable `{}` is only used to index `{}`.", ident.node, indexed), + &format!("the loop variable `{}` is only used to index `{}`.", + ident.node, + indexed), |db| { - multispan_sugg(db, "consider using an iterator".to_string(), &[ - (pat.span, ""), - (arg.span, &repl), - ]); - }); + multispan_sugg(db, + "consider using an iterator".to_string(), + &[(pat.span, ""), (arg.span, &repl)]); + }); } } } @@ -551,9 +552,9 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) { "consider using the following if you are attempting to iterate over this \ range in reverse", format!("({end}{dots}{start}).rev()", - end=end_snippet, - dots=dots, - start=start_snippet)); + end = end_snippet, + dots = dots, + start = start_snippet)); }); } else if eq && limits != ast::RangeLimits::Closed { // if they are equal, it's also problematic - this loop @@ -597,9 +598,9 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) { EXPLICIT_INTO_ITER_LOOP, expr.span, &format!("it is more idiomatic to loop over `{}` instead of `{}.{}()`", - object, - object, - method_name)); + object, + object, + method_name)); } else if &*method_name.as_str() == "next" && match_trait_method(cx, arg, &paths::ITERATOR) { span_lint(cx, diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index d6f33cb1c855..5ecd1c06a5d8 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -776,10 +776,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir: span, &format!("use of `{}` followed by a function call", name), |db| { - db.span_suggestion(span, + db.span_suggestion(span, "try this", format!("{}.{}_{}({})", snippet(cx, self_expr.span, "_"), name, suffix, sugg)); - }); + }); } if args.len() == 2 { @@ -836,10 +836,10 @@ fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) { expr.span, "use of `extend` to extend a Vec by a slice", |db| { - db.span_suggestion(expr.span, + db.span_suggestion(expr.span, "try this", format!("{}.extend_from_slice({})", snippet(cx, args[0].span, "_"), slice)); - }); + }); } } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index f1bce029e395..f796207a2239 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -159,7 +159,12 @@ pub struct Pass; impl LintPass for Pass { fn get_lints(&self) -> LintArray { - lint_array!(TOPLEVEL_REF_ARG, CMP_NAN, FLOAT_CMP, CMP_OWNED, MODULO_ONE, REDUNDANT_PATTERN, + lint_array!(TOPLEVEL_REF_ARG, + CMP_NAN, + FLOAT_CMP, + CMP_OWNED, + MODULO_ONE, + REDUNDANT_PATTERN, USED_UNDERSCORE_BINDING) } } @@ -285,7 +290,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { USED_UNDERSCORE_BINDING, expr.span, &format!("used binding `{}` which is prefixed with an underscore. A leading \ - underscore signals that a binding will not be used.", binding)); + underscore signals that a binding will not be used.", + binding)); } } @@ -295,9 +301,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span_lint(cx, REDUNDANT_PATTERN, pat.span, - &format!("the `{} @ _` pattern can be written as just `{}`", - ident.node, - ident.node)); + &format!("the `{} @ _` pattern can be written as just `{}`", ident.node, ident.node)); } } } diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index f7005b6169b0..fd8ffb36d462 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -210,8 +210,8 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { diag.span_help(span, &format!("separate the discriminating character by an \ underscore like: `{}_{}`", - &interned_name[..split], - &interned_name[split..])); + &interned_name[..split], + &interned_name[split..])); } }); return; diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index a390a8ee47c4..31ac194ca7bf 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -219,8 +219,7 @@ fn check_regex(cx: &LateContext, expr: &Expr, utf8: bool) { span_lint(cx, INVALID_REGEX, str_span(expr.span, r, e.position()), - &format!("regex syntax error: {}", - e.description())); + &format!("regex syntax error: {}", e.description())); }, } } @@ -239,9 +238,7 @@ fn check_regex(cx: &LateContext, expr: &Expr, utf8: bool) { span_lint(cx, INVALID_REGEX, expr.span, - &format!("regex syntax error on position {}: {}", - e.position(), - e.description())); + &format!("regex syntax error on position {}: {}", e.position(), e.description())); }, } } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 7364e798ddba..5e01f891eb17 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -144,25 +144,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { CROSSPOINTER_TRANSMUTE, e.span, &format!("transmute from a type (`{}`) to the type that it points to (`{}`)", - from_ty, - to_ty)) + from_ty, + to_ty)) }, (_, &TyRawPtr(to_ptr)) if to_ptr.ty == from_ty => { span_lint(cx, CROSSPOINTER_TRANSMUTE, e.span, &format!("transmute from a type (`{}`) to a pointer to that type (`{}`)", - from_ty, - to_ty)) + from_ty, + to_ty)) }, - (&TyRawPtr(from_pty), &TyRef(_, to_rty)) => span_lint_and_then( - cx, - TRANSMUTE_PTR_TO_REF, - e.span, - &format!("transmute from a pointer type (`{}`) to a reference type (`{}`)", - from_ty, - to_ty), - |db| { + (&TyRawPtr(from_pty), &TyRef(_, to_rty)) => { + span_lint_and_then(cx, + TRANSMUTE_PTR_TO_REF, + e.span, + &format!("transmute from a pointer type (`{}`) to a reference type \ + (`{}`)", + from_ty, + to_ty), + |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); let (deref, cast) = if to_rty.mutbl == Mutability::MutMutable { ("&mut *", "*mut") @@ -177,8 +178,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { }; db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string()); - }, - ), + }) + }, _ => return, }; } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 50f3529d6787..2ef66cf76447 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -352,11 +352,7 @@ fn span_precision_loss_lint(cx: &LateContext, expr: &Expr, cast_from: &ty::TyS, &format!("casting {0} to {1} causes a loss of precision {2}({0} is {3} bits wide, but {1}'s mantissa \ is only {4} bits wide)", cast_from, - if cast_to_f64 { - "f64" - } else { - "f32" - }, + if cast_to_f64 { "f64" } else { "f32" }, if arch_dependent { arch_dependent_str } else { @@ -687,9 +683,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 { let msg = "casting character literal to u8. `char`s \ are 4 bytes wide in rust, so casting to u8 \ truncates them"; - let help = format!("Consider using a byte literal \ - instead:\nb{}", - snippet(cx, e.span, "'x'")); + let help = format!("Consider using a byte literal instead:\nb{}", snippet(cx, e.span, "'x'")); span_help_and_lint(cx, CHAR_LIT_AS_U8, expr.span, msg, &help); } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index ec98bfb3d680..e56574c9ba93 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -500,7 +500,7 @@ impl<'a> DiagnosticWrapper<'a> { fn wiki_link(&mut self, lint: &'static Lint) { if env::var("CLIPPY_DISABLE_WIKI_LINKS").is_err() { self.0.help(&format!("for further information visit https://github.com/Manishearth/rust-clippy/wiki#{}", - lint.name_lower())); + lint.name_lower())); } } } @@ -780,7 +780,8 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, env: Node /// Return whether a pattern is refutable. pub fn is_refutable(cx: &LateContext, pat: &Pat) -> bool { fn is_enum_variant(cx: &LateContext, qpath: &QPath, did: NodeId) -> bool { - matches!(cx.tcx.tables().qpath_def(qpath, did), def::Def::Variant(..) | def::Def::VariantCtor(..)) + matches!(cx.tcx.tables().qpath_def(qpath, did), + def::Def::Variant(..) | def::Def::VariantCtor(..)) } fn are_refutable<'a, I: Iterator>(cx: &LateContext, mut i: I) -> bool { diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 85f8623ab578..f3f0337a017d 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -249,7 +249,8 @@ pub fn make_assoc(op: AssocOp, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> { /// Whether the operator is a arithmetic operator (`+`, `-`, `*`, `/`, `%`). fn is_arith(op: &AssocOp) -> bool { - matches!(*op, AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus) + matches!(*op, + AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus) } /// Whether the operator `op` needs parenthesis with the operator `other` in the direction