Skip to content

Commit 55cb63a

Browse files
committed
Bump to 0.0.139
1 parent 4e151a4 commit 55cb63a

13 files changed

+67
-81
lines changed

clippy_lints/src/booleans.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,12 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
385385
e.span,
386386
"this boolean expression can be simplified",
387387
|db| {
388-
db.span_suggestions(e.span, "try", improvements.into_iter().map(|suggestion| {
389-
suggest(self.cx, suggestion, &h2q.terminals)
390-
}).collect());
391-
});
388+
db.span_suggestions(e.span,
389+
"try",
390+
improvements.into_iter()
391+
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals))
392+
.collect());
393+
});
392394
}
393395
}
394396
}

clippy_lints/src/copies.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
252252

253253
/// Return the list of bindings in a pattern.
254254
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<InternedString, Ty<'tcx>> {
255-
fn bindings_impl<'a, 'tcx>(
256-
cx: &LateContext<'a, 'tcx>,
257-
pat: &Pat,
258-
map: &mut HashMap<InternedString, Ty<'tcx>>
259-
) {
255+
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut HashMap<InternedString, Ty<'tcx>>) {
260256
match pat.node {
261257
PatKind::Box(ref pat) |
262258
PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),

clippy_lints/src/eq_op.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
9898
let rsnip = snippet(cx, r.span, "...").to_string();
9999
multispan_sugg(db,
100100
"use the values directly".to_string(),
101-
vec![(left.span, lsnip),
102-
(right.span, rsnip)]);
101+
vec![(left.span, lsnip), (right.span, rsnip)]);
103102
})
104-
} else if lcpy && !rcpy &&
105-
implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
103+
} else if lcpy && !rcpy && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
106104
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
107105
let lsnip = snippet(cx, l.span, "...").to_string();
108106
db.span_suggestion(left.span, "use the left value directly", lsnip);
109107
})
110-
} else if !lcpy && rcpy &&
111-
implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
108+
} else if !lcpy && rcpy && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
112109
span_lint_and_then(cx,
113110
OP_REF,
114111
e.span,
@@ -123,8 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
123120
(&ExprAddrOf(_, ref l), _) => {
124121
let lty = cx.tables.expr_ty(l);
125122
let lcpy = is_copy(cx, lty);
126-
if (requires_ref || lcpy) &&
127-
implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
123+
if (requires_ref || lcpy) && implements_trait(cx, lty, trait_id, &[cx.tables.expr_ty(right)]) {
128124
span_lint_and_then(cx, OP_REF, e.span, "needlessly taken reference of left operand", |db| {
129125
let lsnip = snippet(cx, l.span, "...").to_string();
130126
db.span_suggestion(left.span, "use the left value directly", lsnip);
@@ -135,8 +131,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
135131
(_, &ExprAddrOf(_, ref r)) => {
136132
let rty = cx.tables.expr_ty(r);
137133
let rcpy = is_copy(cx, rty);
138-
if (requires_ref || rcpy) &&
139-
implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
134+
if (requires_ref || rcpy) && implements_trait(cx, cx.tables.expr_ty(left), trait_id, &[rty]) {
140135
span_lint_and_then(cx, OP_REF, e.span, "taken reference of right operand", |db| {
141136
let rsnip = snippet(cx, r.span, "...").to_string();
142137
db.span_suggestion(right.span, "use the right value directly", rsnip);

clippy_lints/src/escape.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7171
};
7272

7373
let region_maps = &cx.tcx.region_maps(fn_def_id);
74-
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_maps, cx.tables)
75-
.consume_body(body);
74+
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_maps, cx.tables).consume_body(body);
7675

7776
for node in v.set {
7877
span_lint(cx,
@@ -134,15 +133,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
134133
}
135134

136135
}
137-
fn borrow(
138-
&mut self,
139-
_: NodeId,
140-
_: Span,
141-
cmt: cmt<'tcx>,
142-
_: ty::Region,
143-
_: ty::BorrowKind,
144-
loan_cause: LoanCause
145-
) {
136+
fn borrow(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, _: ty::Region, _: ty::BorrowKind, loan_cause: LoanCause) {
146137
if let Categorization::Local(lid) = cmt.cat {
147138
match loan_cause {
148139
// x.foo()

clippy_lints/src/identity_op.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
5858
}
5959
}
6060

61-
61+
#[allow(cast_possible_wrap)]
6262
fn check(cx: &LateContext, e: &Expr, m: i8, span: Span, arg: Span) {
6363
if let Some(Constant::Int(v)) = constant_simple(cx, e) {
6464
if match m {
6565
0 => v.to_u128_unchecked() == 0,
66-
-1 => match v.int_type() {
67-
SignedInt(_) => #[allow(cast_possible_wrap)] (v.to_u128_unchecked() as i128 == -1),
68-
UnsignedInt(_) => false
66+
-1 => {
67+
match v.int_type() {
68+
SignedInt(_) => (v.to_u128_unchecked() as i128 == -1),
69+
UnsignedInt(_) => false,
70+
}
6971
},
7072
1 => v.to_u128_unchecked() == 1,
7173
_ => unreachable!(),

clippy_lints/src/map_clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use rustc::lint::*;
22
use rustc::hir::*;
33
use rustc::ty;
44
use syntax::ast;
5-
use utils::{is_adjusted, match_path, match_trait_method, match_type, remove_blocks, paths, snippet, span_help_and_lint,
6-
walk_ptrs_ty, walk_ptrs_ty_depth, iter_input_pats};
5+
use utils::{is_adjusted, match_path, match_trait_method, match_type, remove_blocks, paths, snippet,
6+
span_help_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, iter_input_pats};
77

88
/// **What it does:** Checks for mapping `clone()` over an iterator.
99
///

clippy_lints/src/matches.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,7 @@ fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm],
226226
});
227227
}
228228

229-
fn check_single_match_opt_like(
230-
cx: &LateContext,
231-
ex: &Expr,
232-
arms: &[Arm],
233-
expr: &Expr,
234-
ty: Ty,
235-
els: Option<&Expr>
236-
) {
229+
fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, ty: Ty, els: Option<&Expr>) {
237230
// list of candidate Enums we know will never get any more members
238231
let candidates = &[(&paths::COW, "Borrowed"),
239232
(&paths::COW, "Cow::Borrowed"),

clippy_lints/src/methods.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,14 @@ enum SelfKind {
13511351
}
13521352

13531353
impl SelfKind {
1354-
fn matches(self, ty: &hir::Ty, arg: &hir::Arg, self_ty: &hir::Ty, allow_value_for_ref: bool, generics: &hir::Generics) -> bool {
1354+
fn matches(
1355+
self,
1356+
ty: &hir::Ty,
1357+
arg: &hir::Arg,
1358+
self_ty: &hir::Ty,
1359+
allow_value_for_ref: bool,
1360+
generics: &hir::Generics
1361+
) -> bool {
13551362
// Self types in the HIR are desugared to explicit self types. So it will always be `self:
13561363
// SomeType`,
13571364
// 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 {
13861393
SelfKind::Value => false,
13871394
SelfKind::Ref => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASREF_TRAIT),
13881395
SelfKind::RefMut => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASMUT_TRAIT),
1389-
SelfKind::No => true
1396+
SelfKind::No => true,
13901397
}
13911398
}
13921399
}
@@ -1404,19 +1411,18 @@ impl SelfKind {
14041411
fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Generics, name: &[&str]) -> bool {
14051412
single_segment_ty(ty).map_or(false, |seg| {
14061413
generics.ty_params.iter().any(|param| {
1407-
param.name == seg.name && param.bounds.iter().any(|bound| {
1408-
if let hir::TyParamBound::TraitTyParamBound(ref ptr, ..) = *bound {
1409-
let path = &ptr.trait_ref.path;
1410-
match_path_old(path, name) && path.segments.last().map_or(false, |s| {
1411-
if let hir::PathParameters::AngleBracketedParameters(ref data) = s.parameters {
1412-
data.types.len() == 1 && (is_self_ty(&data.types[0]) || is_ty(&*data.types[0], self_ty))
1413-
} else {
1414-
false
1415-
}
1416-
})
1414+
param.name == seg.name &&
1415+
param.bounds.iter().any(|bound| if let hir::TyParamBound::TraitTyParamBound(ref ptr, ..) = *bound {
1416+
let path = &ptr.trait_ref.path;
1417+
match_path_old(path, name) &&
1418+
path.segments.last().map_or(false, |s| if let hir::PathParameters::AngleBracketedParameters(ref data) =
1419+
s.parameters {
1420+
data.types.len() == 1 && (is_self_ty(&data.types[0]) || is_ty(&*data.types[0], self_ty))
14171421
} else {
14181422
false
1419-
}
1423+
})
1424+
} else {
1425+
false
14201426
})
14211427
})
14221428
})
@@ -1426,10 +1432,9 @@ fn is_ty(ty: &hir::Ty, self_ty: &hir::Ty) -> bool {
14261432
match (&ty.node, &self_ty.node) {
14271433
(&hir::TyPath(hir::QPath::Resolved(_, ref ty_path)),
14281434
&hir::TyPath(hir::QPath::Resolved(_, ref self_ty_path))) => {
1429-
ty_path.segments.iter().map(|seg| seg.name).eq(
1430-
self_ty_path.segments.iter().map(|seg| seg.name))
1431-
}
1432-
_ => false
1435+
ty_path.segments.iter().map(|seg| seg.name).eq(self_ty_path.segments.iter().map(|seg| seg.name))
1436+
},
1437+
_ => false,
14331438
}
14341439
}
14351440

clippy_lints/src/misc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool {
516516
match *def {
517517
def::Def::Local(def_id) |
518518
def::Def::Upvar(def_id, _, _) => {
519-
let id = cx.tcx.hir.as_local_node_id(def_id)
519+
let id = cx.tcx
520+
.hir
521+
.as_local_node_id(def_id)
520522
.expect("local variables should be found in the same crate");
521523
!in_macro(cx.tcx.hir.span(id))
522524
},

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
9191
let MovedVariablesCtxt { moved_vars, spans_need_deref, .. } = {
9292
let mut ctx = MovedVariablesCtxt::new(cx);
9393
let region_maps = &cx.tcx.region_maps(fn_def_id);
94-
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_maps, cx.tables)
95-
.consume_body(body);
94+
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_maps, cx.tables).consume_body(body);
9695
ctx
9796
};
9897

clippy_lints/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
11071107
}
11081108
}
11091109

1110+
#[allow(cast_possible_wrap)]
11101111
fn node_as_const_fullint(cx: &LateContext, expr: &Expr) -> Option<FullInt> {
11111112
use rustc::middle::const_val::ConstVal::*;
11121113
use rustc_const_eval::ConstContext;
@@ -1115,7 +1116,7 @@ fn node_as_const_fullint(cx: &LateContext, expr: &Expr) -> Option<FullInt> {
11151116
Ok(val) => {
11161117
if let Integral(const_int) = val {
11171118
match const_int.int_type() {
1118-
IntType::SignedInt(_) => #[allow(cast_possible_wrap)] Some(FullInt::S(const_int.to_u128_unchecked() as i128)),
1119+
IntType::SignedInt(_) => Some(FullInt::S(const_int.to_u128_unchecked() as i128)),
11191120
IntType::UnsignedInt(_) => Some(FullInt::U(const_int.to_u128_unchecked())),
11201121
}
11211122
} else {

clippy_lints/src/utils/higher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
7676
end: None,
7777
limits: ast::RangeLimits::HalfOpen,
7878
})
79-
} else if match_path(path, &paths::RANGE_INCLUSIVE_STD) ||
80-
match_path(path, &paths::RANGE_INCLUSIVE) {
79+
} else if match_path(path, &paths::RANGE_INCLUSIVE_STD) || match_path(path, &paths::RANGE_INCLUSIVE) {
8180
Some(Range {
8281
start: get_field("start", fields),
8382
end: get_field("end", fields),

clippy_lints/src/utils/mod.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ pub fn implements_trait<'a, 'tcx>(
314314
ty_params: &[Ty<'tcx>]
315315
) -> bool {
316316
let ty = cx.tcx.erase_regions(&ty);
317-
let obligation = cx.tcx.predicate_for_trait_def(
318-
cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
319-
cx.tcx.infer_ctxt().enter(|infcx| {
320-
traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation)
321-
})
317+
let obligation = cx.tcx
318+
.predicate_for_trait_def(cx.param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
319+
cx.tcx
320+
.infer_ctxt()
321+
.enter(|infcx| traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation))
322322
}
323323

324324
/// 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>>(
575575
/// replacement. In human-readable format though, it only appears once before the whole suggestion.
576576
pub fn multispan_sugg(db: &mut DiagnosticBuilder, help_msg: String, sugg: Vec<(Span, String)>) {
577577
let sugg = rustc_errors::CodeSuggestion {
578-
substitution_parts: sugg.into_iter().map(|(span, sub)| rustc_errors::Substitution { span, substitutions: vec![sub] }).collect(),
578+
substitution_parts: sugg.into_iter()
579+
.map(|(span, sub)| {
580+
rustc_errors::Substitution {
581+
span: span,
582+
substitutions: vec![sub],
583+
}
584+
})
585+
.collect(),
579586
msg: help_msg,
580587
};
581588
db.suggestions.push(sugg);
@@ -764,14 +771,8 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'t
764771
/// Check if two types are the same.
765772
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for <'b> Foo<'b>` but
766773
// not for type parameters.
767-
pub fn same_tys<'a, 'tcx>(
768-
cx: &LateContext<'a, 'tcx>,
769-
a: Ty<'tcx>,
770-
b: Ty<'tcx>
771-
) -> bool {
772-
cx.tcx.infer_ctxt().enter(|infcx| {
773-
infcx.can_eq(cx.param_env, a, b).is_ok()
774-
})
774+
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
775+
cx.tcx.infer_ctxt().enter(|infcx| infcx.can_eq(cx.param_env, a, b).is_ok())
775776
}
776777

777778
/// Return whether the given type is an `unsafe` function.

0 commit comments

Comments
 (0)