From 2a8fca599b22d02708b81c2e11a3075f195d0969 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sun, 5 Mar 2017 10:27:20 +0100 Subject: [PATCH] Mostly apply rustfmt --- clippy_lints/src/array_indexing.rs | 40 ++++++++++++++++-------------- clippy_lints/src/consts.rs | 18 ++++++-------- clippy_lints/src/eta_reduction.rs | 3 ++- clippy_lints/src/matches.rs | 14 +++++------ clippy_lints/src/misc.rs | 2 +- clippy_lints/src/utils/mod.rs | 6 ++--- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/clippy_lints/src/array_indexing.rs b/clippy_lints/src/array_indexing.rs index 1cd57e632ca..dd5baaadca6 100644 --- a/clippy_lints/src/array_indexing.rs +++ b/clippy_lints/src/array_indexing.rs @@ -2,7 +2,7 @@ use rustc::lint::*; use rustc::middle::const_val::ConstVal; use rustc::ty; use rustc_const_eval::ConstContext; -use rustc_const_math::{ConstUsize,ConstIsize,ConstInt}; +use rustc_const_math::{ConstUsize, ConstIsize, ConstInt}; use rustc::hir; use syntax::ast::RangeLimits; use utils::{self, higher}; @@ -60,7 +60,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing { // Array with known size can be checked statically let ty = cx.tables.expr_ty(array); if let ty::TyArray(_, size) = ty.sty { - let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type).expect("array size is invalid")); + let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type) + .expect("array size is invalid")); let constcx = ConstContext::with_tables(cx.tcx, cx.tables); // Index is a constant uint @@ -123,23 +124,24 @@ fn to_const_range( Some(Some(ConstVal::Integral(x))) => { if limits == RangeLimits::Closed { match x { - ConstInt::U8(_) => (x + ConstInt::U8(1)), - ConstInt::U16(_) => (x + ConstInt::U16(1)), - ConstInt::U32(_) => (x + ConstInt::U32(1)), - ConstInt::U64(_) => (x + ConstInt::U64(1)), - ConstInt::U128(_) => (x + ConstInt::U128(1)), - ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))), - ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))), - ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))), - ConstInt::I8(_) => (x + ConstInt::I8(1)), - ConstInt::I16(_) => (x + ConstInt::I16(1)), - ConstInt::I32(_) => (x + ConstInt::I32(1)), - ConstInt::I64(_) => (x + ConstInt::I64(1)), - ConstInt::I128(_) => (x + ConstInt::I128(1)), - ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))), - ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))), - ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))), - }.expect("such a big array is not realistic") + ConstInt::U8(_) => (x + ConstInt::U8(1)), + ConstInt::U16(_) => (x + ConstInt::U16(1)), + ConstInt::U32(_) => (x + ConstInt::U32(1)), + ConstInt::U64(_) => (x + ConstInt::U64(1)), + ConstInt::U128(_) => (x + ConstInt::U128(1)), + ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))), + ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))), + ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))), + ConstInt::I8(_) => (x + ConstInt::I8(1)), + ConstInt::I16(_) => (x + ConstInt::I16(1)), + ConstInt::I32(_) => (x + ConstInt::I32(1)), + ConstInt::I64(_) => (x + ConstInt::I64(1)), + ConstInt::I128(_) => (x + ConstInt::I128(1)), + ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))), + ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))), + ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))), + } + .expect("such a big array is not realistic") } else { x } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 3b624ff3d6c..7be6f6bf0d6 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -5,7 +5,7 @@ use rustc::hir::def::Def; use rustc_const_eval::lookup_const_by_id; use rustc_const_math::ConstInt; use rustc::hir::*; -use rustc::ty::{TyCtxt, self}; +use rustc::ty::{self, TyCtxt}; use std::cmp::Ordering::{self, Equal}; use std::cmp::PartialOrd; use std::hash::{Hash, Hasher}; @@ -179,17 +179,15 @@ pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut match (&ty.sty, hint) { (&ty::TyInt(ity), _) | (_, Signed(ity)) => { - Constant::Int(ConstInt::new_signed_truncating(n as i128, - ity, tcx.sess.target.int_type)) - } + Constant::Int(ConstInt::new_signed_truncating(n as i128, ity, tcx.sess.target.int_type)) + }, (&ty::TyUint(uty), _) | (_, Unsigned(uty)) => { - Constant::Int(ConstInt::new_unsigned_truncating(n as u128, - uty, tcx.sess.target.uint_type)) - } - _ => bug!() + Constant::Int(ConstInt::new_unsigned_truncating(n as u128, uty, tcx.sess.target.uint_type)) + }, + _ => bug!(), } - } + }, LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()), LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::Any), LitKind::Bool(b) => Constant::Bool(b), @@ -291,7 +289,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) { let mut cx = ConstEvalLateContext { tcx: self.tcx, - tables, + tables: tables, needed_resolution: false, }; let ret = cx.expr(const_expr); diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 8230fe73130..d2b07661d5b 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -66,7 +66,8 @@ fn check_closure(cx: &LateContext, expr: &Expr) { // Is it an unsafe function? They don't implement the closure traits ty::TyFnDef(_, _, fn_ty) | ty::TyFnPtr(fn_ty) => { - if fn_ty.skip_binder().unsafety == Unsafety::Unsafe || fn_ty.skip_binder().output().sty == ty::TyNever { + if fn_ty.skip_binder().unsafety == Unsafety::Unsafe || + fn_ty.skip_binder().output().sty == ty::TyNever { return; } }, diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 8729a39733a..90b616b20d4 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -211,14 +211,14 @@ fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], }; let els_str = els.map_or(String::new(), |els| format!(" else {}", expr_block(cx, els, None, ".."))); span_lint_and_then(cx, - lint, - expr.span, - "you seem to be trying to use match for destructuring a single pattern. \ - Consider using `if let`", - |db| { + lint, + expr.span, + "you seem to be trying to use match for destructuring a single pattern. Consider using `if \ + let`", + |db| { db.span_suggestion(expr.span, - "try this", - format!("if let {} = {} {}{}", + "try this", + format!("if let {} = {} {}{}", snippet(cx, arms[0].pats[0].span, ".."), snippet(cx, ex.span, ".."), expr_block(cx, &arms[0].body, None, ".."), diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 3fb9101076d..b4e79a1401d 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -382,7 +382,7 @@ fn is_allowed(cx: &LateContext, expr: &Expr) -> bool { val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) || val.try_cmp(neg_infinity) == Ok(Ordering::Equal) - } + }, } } else { false diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 32e8c90ad99..693b14d1b99 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -975,7 +975,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> { } pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Option { - cx.tcx.infer_ctxt((), Reveal::All).enter(|infcx| - ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()) - ) + cx.tcx + .infer_ctxt((), Reveal::All) + .enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes())) }