diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index e0418be7a..c338189ce 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -385,10 +385,12 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> { e.span, "this boolean expression can be simplified", |db| { - db.span_suggestions(e.span, "try", improvements.into_iter().map(|suggestion| { - suggest(self.cx, suggestion, &h2q.terminals) - }).collect()); - }); + db.span_suggestions(e.span, + "try", + improvements.into_iter() + .map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals)) + .collect()); + }); } } } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 8764bbfa1..8f8bdf472 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -252,11 +252,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) { /// Return the list of bindings in a pattern. fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap> { - fn bindings_impl<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - pat: &Pat, - map: &mut HashMap> - ) { + fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut HashMap>) { match pat.node { PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map), diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 9eab6352c..10e5f2ba7 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -98,17 +98,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { let rsnip = snippet(cx, r.span, "...").to_string(); multispan_sugg(db, "use the values directly".to_string(), - vec![(left.span, lsnip), - (right.span, rsnip)]); + vec![(left.span, lsnip), (right.span, rsnip)]); }) - } else if lcpy && !rcpy && - implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) { + } else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); db.span_suggestion(left.span, "use the left value directly", lsnip); }) - } else if !lcpy && rcpy && - implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) { + } else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) { span_lint_and_then(cx, OP_REF, e.span, @@ -123,8 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { (&ExprAddrOf(_, ref l), _) => { let lty = cx.tables.expr_ty(l); let lcpy = is_copy(cx, lty); - if (requires_ref || lcpy) && - implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) { + if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) { span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| { let lsnip = snippet(cx, l.span, "...").to_string(); db.span_suggestion(left.span, "use the left value directly", lsnip); @@ -135,8 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp { (_, &ExprAddrOf(_, ref r)) => { let rty = cx.tables.expr_ty(r); let rcpy = is_copy(cx, rty); - if (requires_ref || rcpy) && - implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) { + if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) { span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| { let rsnip = snippet(cx, r.span, "...").to_string(); db.span_suggestion(right.span, "use the right value directly", rsnip); diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 9f32204c4..c3a3f37fa 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -71,8 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { }; let region_maps = &cx.tcx.region_maps(fn_def_id); - ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_maps, cx.tables) - .consume_body(body); + ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_maps, cx.tables).consume_body(body); for node in v.set { span_lint(cx, @@ -134,15 +133,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } - fn borrow( - &mut self, - _: NodeId, - _: Span, - cmt: cmt<'tcx>, - _: ty::Region, - _: ty::BorrowKind, - loan_cause: LoanCause - ) { + fn borrow(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, _: ty::Region, _: ty::BorrowKind, loan_cause: LoanCause) { if let Categorization::Local(lid) = cmt.cat { match loan_cause { // x.foo() diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index e57feaa59..7bac29f68 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -58,14 +58,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp { } } - +#[allow(cast_possible_wrap)] fn check(cx: &LateContext, e: &Expr, m: i8, span: Span, arg: Span) { if let Some(Constant::Int(v)) = constant_simple(cx, e) { if match m { 0 => v.to_u128_unchecked() == 0, - -1 => match v.int_type() { - SignedInt(_) => #[allow(cast_possible_wrap)] (v.to_u128_unchecked() as i128 == -1), - UnsignedInt(_) => false + -1 => { + match v.int_type() { + SignedInt(_) => (v.to_u128_unchecked() as i128 == -1), + UnsignedInt(_) => false, + } }, 1 => v.to_u128_unchecked() == 1, _ => unreachable!(), diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 6b721a970..ba4d24b1d 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -2,8 +2,8 @@ use rustc::lint::*; use rustc::hir::*; use rustc::ty; use syntax::ast; -use utils::{is_adjusted, match_path, match_trait_method, match_type, remove_blocks, paths, snippet, span_help_and_lint, - walk_ptrs_ty, walk_ptrs_ty_depth, iter_input_pats}; +use utils::{is_adjusted, match_path, match_trait_method, match_type, remove_blocks, paths, snippet, + span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, iter_input_pats}; /// **What it does:** Checks for mapping `clone()` over an iterator. /// diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 4ff1b5d06..3e9e2d06d 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -226,14 +226,7 @@ fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], }); } -fn check_single_match_opt_like( - cx: &LateContext, - ex: &Expr, - arms: &[Arm], - expr: &Expr, - ty: Ty, - els: Option<&Expr> -) { +fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, ty: Ty, els: Option<&Expr>) { // list of candidate Enums we know will never get any more members let candidates = &[(&paths::COW, "Borrowed"), (&paths::COW, "Cow::Borrowed"), diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 9f662d573..08400600b 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1351,7 +1351,14 @@ enum SelfKind { } impl SelfKind { - fn matches(self, ty: &hir::Ty, arg: &hir::Arg, self_ty: &hir::Ty, allow_value_for_ref: bool, generics: &hir::Generics) -> bool { + fn matches( + self, + ty: &hir::Ty, + arg: &hir::Arg, + self_ty: &hir::Ty, + allow_value_for_ref: bool, + generics: &hir::Generics + ) -> bool { // Self types in the HIR are desugared to explicit self types. So it will always be `self: // SomeType`, // where SomeType can be `Self` or an explicit impl self type (e.g. `Foo` if the impl is on `Foo`) @@ -1386,7 +1393,7 @@ impl SelfKind { SelfKind::Value => false, SelfKind::Ref => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASREF_TRAIT), SelfKind::RefMut => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASMUT_TRAIT), - SelfKind::No => true + SelfKind::No => true, } } } @@ -1404,19 +1411,18 @@ impl SelfKind { fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Generics, name: &[&str]) -> bool { single_segment_ty(ty).map_or(false, |seg| { generics.ty_params.iter().any(|param| { - param.name == seg.name && param.bounds.iter().any(|bound| { - if let hir::TyParamBound::TraitTyParamBound(ref ptr, ..) = *bound { - let path = &ptr.trait_ref.path; - match_path_old(path, name) && path.segments.last().map_or(false, |s| { - if let hir::PathParameters::AngleBracketedParameters(ref data) = s.parameters { - data.types.len() == 1 && (is_self_ty(&data.types[0]) || is_ty(&*data.types[0], self_ty)) - } else { - false - } - }) + param.name == seg.name && + param.bounds.iter().any(|bound| if let hir::TyParamBound::TraitTyParamBound(ref ptr, ..) = *bound { + let path = &ptr.trait_ref.path; + match_path_old(path, name) && + path.segments.last().map_or(false, |s| if let hir::PathParameters::AngleBracketedParameters(ref data) = + s.parameters { + data.types.len() == 1 && (is_self_ty(&data.types[0]) || is_ty(&*data.types[0], self_ty)) } else { false - } + }) + } else { + false }) }) }) @@ -1426,10 +1432,9 @@ fn is_ty(ty: &hir::Ty, self_ty: &hir::Ty) -> bool { match (&ty.node, &self_ty.node) { (&hir::TyPath(hir::QPath::Resolved(_, ref ty_path)), &hir::TyPath(hir::QPath::Resolved(_, ref self_ty_path))) => { - ty_path.segments.iter().map(|seg| seg.name).eq( - self_ty_path.segments.iter().map(|seg| seg.name)) - } - _ => false + ty_path.segments.iter().map(|seg| seg.name).eq(self_ty_path.segments.iter().map(|seg| seg.name)) + }, + _ => false, } } diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index fe19a82a1..02ccdb2d7 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -516,7 +516,9 @@ fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool { match *def { def::Def::Local(def_id) | def::Def::Upvar(def_id, _, _) => { - let id = cx.tcx.hir.as_local_node_id(def_id) + let id = cx.tcx + .hir + .as_local_node_id(def_id) .expect("local variables should be found in the same crate"); !in_macro(cx.tcx.hir.span(id)) }, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index fda67f320..b8aacb3b4 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -91,8 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let MovedVariablesCtxt { moved_vars, spans_need_deref, .. } = { let mut ctx = MovedVariablesCtxt::new(cx); let region_maps = &cx.tcx.region_maps(fn_def_id); - euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_maps, cx.tables) - .consume_body(body); + euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_maps, cx.tables).consume_body(body); ctx }; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index ce8b8c405..f608c7808 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -1107,6 +1107,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<( } } +#[allow(cast_possible_wrap)] fn node_as_const_fullint(cx: &LateContext, expr: &Expr) -> Option { use rustc::middle::const_val::ConstVal::*; use rustc_const_eval::ConstContext; @@ -1115,7 +1116,7 @@ fn node_as_const_fullint(cx: &LateContext, expr: &Expr) -> Option { Ok(val) => { if let Integral(const_int) = val { match const_int.int_type() { - IntType::SignedInt(_) => #[allow(cast_possible_wrap)] Some(FullInt::S(const_int.to_u128_unchecked() as i128)), + IntType::SignedInt(_) => Some(FullInt::S(const_int.to_u128_unchecked() as i128)), IntType::UnsignedInt(_) => Some(FullInt::U(const_int.to_u128_unchecked())), } } else { diff --git a/clippy_lints/src/utils/higher.rs b/clippy_lints/src/utils/higher.rs index e736f2eae..7c7b3b57a 100644 --- a/clippy_lints/src/utils/higher.rs +++ b/clippy_lints/src/utils/higher.rs @@ -76,8 +76,7 @@ pub fn range(expr: &hir::Expr) -> Option { end: None, limits: ast::RangeLimits::HalfOpen, }) - } else if match_path(path, &paths::RANGE_INCLUSIVE_STD) || - match_path(path, &paths::RANGE_INCLUSIVE) { + } else if match_path(path, &paths::RANGE_INCLUSIVE_STD) || match_path(path, &paths::RANGE_INCLUSIVE) { Some(Range { start: get_field("start", fields), end: get_field("end", fields), diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 34c514360..c2cbd4d4c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -314,11 +314,11 @@ pub fn implements_trait<'a, 'tcx>( ty_params: &[Ty<'tcx>] ) -> bool { let ty = cx.tcx.erase_regions(&ty); - let obligation = cx.tcx.predicate_for_trait_def( - cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params); - cx.tcx.infer_ctxt().enter(|infcx| { - traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation) - }) + let obligation = cx.tcx + .predicate_for_trait_def(cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params); + cx.tcx + .infer_ctxt() + .enter(|infcx| traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation)) } /// Resolve the definition of a node from its `NodeId`. @@ -575,7 +575,14 @@ pub fn span_lint_and_sugg<'a, 'tcx: 'a, T: LintContext<'tcx>>( /// replacement. In human-readable format though, it only appears once before the whole suggestion. pub fn multispan_sugg(db: &mut DiagnosticBuilder, help_msg: String, sugg: Vec<(Span, String)>) { let sugg = rustc_errors::CodeSuggestion { - substitution_parts: sugg.into_iter().map(|(span, sub)| rustc_errors::Substitution { span, substitutions: vec![sub] }).collect(), + substitution_parts: sugg.into_iter() + .map(|(span, sub)| { + rustc_errors::Substitution { + span: span, + substitutions: vec![sub], + } + }) + .collect(), msg: help_msg, }; db.suggestions.push(sugg); @@ -764,14 +771,8 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'t /// Check if two types are the same. // FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for <'b> Foo<'b>` but // not for type parameters. -pub fn same_tys<'a, 'tcx>( - cx: &LateContext<'a, 'tcx>, - a: Ty<'tcx>, - b: Ty<'tcx> -) -> bool { - cx.tcx.infer_ctxt().enter(|infcx| { - infcx.can_eq(cx.param_env, a, b).is_ok() - }) +pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool { + cx.tcx.infer_ctxt().enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok()) } /// Return whether the given type is an `unsafe` function.