Skip to content

Commit 19c5f53

Browse files
committed
Rustup to rustc 1.15.0-nightly (0ed9519 2016-11-14)
1 parent bad26a5 commit 19c5f53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+237
-246
lines changed

clippy_lints/src/arithmetic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl LateLintPass for Arithmetic {
5959
hir::BiShr | hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => return,
6060
_ => (),
6161
}
62-
let (l_ty, r_ty) = (cx.tcx.expr_ty(l), cx.tcx.expr_ty(r));
62+
let (l_ty, r_ty) = (cx.tcx.tables().expr_ty(l), cx.tcx.tables().expr_ty(r));
6363
if l_ty.is_integral() && r_ty.is_integral() {
6464
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
6565
self.span = Some(expr.span);
@@ -69,7 +69,7 @@ impl LateLintPass for Arithmetic {
6969
}
7070
}
7171
hir::ExprUnary(hir::UnOp::UnNeg, ref arg) => {
72-
let ty = cx.tcx.expr_ty(arg);
72+
let ty = cx.tcx.tables().expr_ty(arg);
7373
if ty.is_integral() {
7474
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
7575
self.span = Some(expr.span);

clippy_lints/src/array_indexing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl LateLintPass for ArrayIndexing {
5959
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
6060
if let hir::ExprIndex(ref array, ref index) = e.node {
6161
// Array with known size can be checked statically
62-
let ty = cx.tcx.expr_ty(array);
62+
let ty = cx.tcx.tables().expr_ty(array);
6363
if let ty::TyArray(_, size) = ty.sty {
6464
let size = ConstInt::Infer(size as u64);
6565

clippy_lints/src/assign_ops.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ impl LateLintPass for AssignOps {
8181
if let hir::ExprBinary(binop, ref l, ref r) = rhs.node {
8282
if op.node == binop.node {
8383
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
84-
let ty = cx.tcx.expr_ty(assignee);
84+
let ty = cx.tcx.tables().expr_ty(assignee);
8585
if ty.walk_shallow().next().is_some() {
8686
return; // implements_trait does not work with generics
8787
}
88-
let rty = cx.tcx.expr_ty(rhs);
88+
let rty = cx.tcx.tables().expr_ty(rhs);
8989
if rty.walk_shallow().next().is_some() {
9090
return; // implements_trait does not work with generics
9191
}
@@ -116,11 +116,11 @@ impl LateLintPass for AssignOps {
116116
hir::ExprAssign(ref assignee, ref e) => {
117117
if let hir::ExprBinary(op, ref l, ref r) = e.node {
118118
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
119-
let ty = cx.tcx.expr_ty(assignee);
119+
let ty = cx.tcx.tables().expr_ty(assignee);
120120
if ty.walk_shallow().next().is_some() {
121121
return; // implements_trait does not work with generics
122122
}
123-
let rty = cx.tcx.expr_ty(rhs);
123+
let rty = cx.tcx.tables().expr_ty(rhs);
124124
if rty.walk_shallow().next().is_some() {
125125
return; // implements_trait does not work with generics
126126
}

clippy_lints/src/attrs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,24 @@ impl LateLintPass for AttrPass {
152152
}
153153

154154
fn is_relevant_item(cx: &LateContext, item: &Item) -> bool {
155-
if let ItemFn(_, _, _, _, _, ref block) = item.node {
156-
is_relevant_block(cx, block)
155+
if let ItemFn(_, _, _, _, _, ref expr) = item.node {
156+
is_relevant_expr(cx, expr)
157157
} else {
158158
false
159159
}
160160
}
161161

162162
fn is_relevant_impl(cx: &LateContext, item: &ImplItem) -> bool {
163163
match item.node {
164-
ImplItemKind::Method(_, ref block) => is_relevant_block(cx, block),
164+
ImplItemKind::Method(_, ref expr) => is_relevant_expr(cx, expr),
165165
_ => false,
166166
}
167167
}
168168

169169
fn is_relevant_trait(cx: &LateContext, item: &TraitItem) -> bool {
170170
match item.node {
171171
MethodTraitItem(_, None) => true,
172-
MethodTraitItem(_, Some(ref block)) => is_relevant_block(cx, block),
172+
MethodTraitItem(_, Some(ref expr)) => is_relevant_expr(cx, expr),
173173
_ => false,
174174
}
175175
}

clippy_lints/src/block_in_if_condition.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,9 @@ struct ExVisitor<'v> {
5555

5656
impl<'v> Visitor<'v> for ExVisitor<'v> {
5757
fn visit_expr(&mut self, expr: &'v Expr) {
58-
if let ExprClosure(_, _, ref block, _) = expr.node {
58+
if let ExprClosure(_, _, ref expr, _) = expr.node {
5959
let complex = {
60-
if block.stmts.is_empty() {
61-
if let Some(ref ex) = block.expr {
62-
matches!(ex.node, ExprBlock(_))
63-
} else {
64-
false
65-
}
66-
} else {
67-
true
68-
}
60+
matches!(expr.node, ExprBlock(_))
6961
};
7062
if complex {
7163
self.found_block = Some(expr);

clippy_lints/src/booleans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for NonminimalBoolVisitor<'a, 'tcx> {
392392
match e.node {
393393
ExprBinary(binop, _, _) if binop.node == BiOr || binop.node == BiAnd => self.bool_expr(e),
394394
ExprUnary(UnNot, ref inner) => {
395-
if self.0.tcx.node_types()[&inner.id].is_bool() {
395+
if self.0.tcx.tables.borrow().node_types[&inner.id].is_bool() {
396396
self.bool_expr(e);
397397
} else {
398398
walk_expr(self, e);

clippy_lints/src/copies.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl LateLintPass for CopyAndPaste {
120120
}
121121

122122
let (conds, blocks) = if_sequence(expr);
123-
lint_same_then_else(cx, blocks.as_slice());
124-
lint_same_cond(cx, conds.as_slice());
123+
lint_same_then_else(cx, &blocks);
124+
lint_same_cond(cx, &conds);
125125
lint_match_arms(cx, expr);
126126
}
127127
}
@@ -219,8 +219,8 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
219219
/// Eg. would return `([a, b], [c, d, e])` for the expression
220220
/// `if a { c } else if b { d } else { e }`.
221221
fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
222-
let mut conds = SmallVector::zero();
223-
let mut blocks = SmallVector::zero();
222+
let mut conds = SmallVector::new();
223+
let mut blocks = SmallVector::new();
224224

225225
while let ExprIf(ref cond, ref then_block, ref else_expr) = expr.node {
226226
conds.push(&**cond);
@@ -256,7 +256,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
256256
}
257257
PatKind::Binding(_, ref ident, ref as_pat) => {
258258
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) {
259-
v.insert(cx.tcx.pat_ty(pat));
259+
v.insert(cx.tcx.tables().pat_ty(pat));
260260
}
261261
if let Some(ref as_pat) = *as_pat {
262262
bindings_impl(cx, as_pat, map);

clippy_lints/src/cyclomatic_complexity.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ impl LintPass for CyclomaticComplexity {
4242
}
4343

4444
impl CyclomaticComplexity {
45-
fn check<'a, 'tcx>(&mut self, cx: &'a LateContext<'a, 'tcx>, block: &Block, span: Span) {
45+
fn check<'a, 'tcx>(&mut self, cx: &'a LateContext<'a, 'tcx>, expr: &Expr, span: Span) {
4646
if in_macro(cx, span) {
4747
return;
4848
}
4949

50-
let cfg = CFG::new(cx.tcx, block);
50+
let cfg = CFG::new(cx.tcx, expr);
5151
let n = cfg.graph.len_nodes() as u64;
5252
let e = cfg.graph.len_edges() as u64;
5353
if e + 2 < n {
@@ -62,9 +62,9 @@ impl CyclomaticComplexity {
6262
returns: 0,
6363
tcx: &cx.tcx,
6464
};
65-
helper.visit_block(block);
65+
helper.visit_expr(expr);
6666
let CCHelper { match_arms, divergence, short_circuits, returns, .. } = helper;
67-
let ret_ty = cx.tcx.node_id_to_type(block.id);
67+
let ret_ty = cx.tcx.tables().node_id_to_type(expr.id);
6868
let ret_adjust = if match_type(cx, ret_ty, &paths::RESULT) {
6969
returns
7070
} else {
@@ -92,22 +92,22 @@ impl CyclomaticComplexity {
9292

9393
impl LateLintPass for CyclomaticComplexity {
9494
fn check_item(&mut self, cx: &LateContext, item: &Item) {
95-
if let ItemFn(_, _, _, _, _, ref block) = item.node {
95+
if let ItemFn(_, _, _, _, _, ref expr) = item.node {
9696
if !attr::contains_name(&item.attrs, "test") {
97-
self.check(cx, block, item.span);
97+
self.check(cx, expr, item.span);
9898
}
9999
}
100100
}
101101

102102
fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
103-
if let ImplItemKind::Method(_, ref block) = item.node {
104-
self.check(cx, block, item.span);
103+
if let ImplItemKind::Method(_, ref expr) = item.node {
104+
self.check(cx, expr, item.span);
105105
}
106106
}
107107

108108
fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
109-
if let MethodTraitItem(_, Some(ref block)) = item.node {
110-
self.check(cx, block, item.span);
109+
if let MethodTraitItem(_, Some(ref expr)) = item.node {
110+
self.check(cx, expr, item.span);
111111
}
112112
}
113113

@@ -139,7 +139,7 @@ impl<'a, 'b, 'tcx, 'gcx> Visitor<'a> for CCHelper<'b, 'gcx, 'tcx> {
139139
}
140140
ExprCall(ref callee, _) => {
141141
walk_expr(self, e);
142-
let ty = self.tcx.node_id_to_type(callee.id);
142+
let ty = self.tcx.tables().node_id_to_type(callee.id);
143143
match ty.sty {
144144
ty::TyFnDef(_, _, ty) |
145145
ty::TyFnPtr(ty) if ty.sig.skip_binder().output.sty == ty::TyNever => {

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl LintPass for Derive {
7373
impl LateLintPass for Derive {
7474
fn check_item(&mut self, cx: &LateContext, item: &Item) {
7575
if let ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
76-
let ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(item.id)).ty;
76+
let ty = cx.tcx.item_type(cx.tcx.map.local_def_id(item.id));
7777
let is_automatically_derived = is_automatically_derived(&*item.attrs);
7878

7979
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/drop_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl LateLintPass for Pass {
5252
}
5353

5454
fn check_drop_arg(cx: &LateContext, call_span: Span, arg: &Expr) {
55-
let arg_ty = cx.tcx.expr_ty(arg);
55+
let arg_ty = cx.tcx.tables().expr_ty(arg);
5656
if let ty::TyRef(..) = arg_ty.sty {
5757
span_note_and_lint(cx,
5858
DROP_REF,

clippy_lints/src/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn check_cond<'a, 'tcx, 'b>(cx: &'a LateContext<'a, 'tcx>, check: &'b Expr) -> O
8686
let ExprAddrOf(_, ref key) = params[1].node
8787
], {
8888
let map = &params[0];
89-
let obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(map));
89+
let obj_ty = walk_ptrs_ty(cx.tcx.tables().expr_ty(map));
9090

9191
return if match_type(cx, obj_ty, &paths::BTREEMAP) {
9292
Some(("BTreeMap", map, key))

clippy_lints/src/escape.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::infer::InferCtxt;
55
use rustc::lint::*;
66
use rustc::middle::expr_use_visitor::*;
77
use rustc::middle::mem_categorization::{cmt, Categorization};
8-
use rustc::ty::adjustment::AutoAdjustment;
98
use rustc::ty;
109
use rustc::ty::layout::TargetDataLayout;
1110
use rustc::util::nodemap::NodeSet;
@@ -62,7 +61,7 @@ impl LintPass for Pass {
6261
}
6362

6463
impl LateLintPass for Pass {
65-
fn check_fn(&mut self, cx: &LateContext, _: visit::FnKind, decl: &FnDecl, body: &Block, _: Span, id: NodeId) {
64+
fn check_fn(&mut self, cx: &LateContext, _: visit::FnKind, decl: &FnDecl, body: &Expr, _: Span, id: NodeId) {
6665
let param_env = ty::ParameterEnvironment::for_item(cx.tcx, id);
6766

6867
let infcx = cx.tcx.borrowck_fake_infer_ctxt(param_env);
@@ -146,32 +145,35 @@ impl<'a, 'tcx: 'a+'gcx, 'gcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx, 'g
146145
}
147146
fn borrow(&mut self, borrow_id: NodeId, _: Span, cmt: cmt<'tcx>, _: &ty::Region, _: ty::BorrowKind,
148147
loan_cause: LoanCause) {
148+
use rustc::ty::adjustment::Adjust;
149149

150150
if let Categorization::Local(lid) = cmt.cat {
151151
if self.set.contains(&lid) {
152-
if let Some(&AutoAdjustment::AdjustDerefRef(adj)) = self.tcx
152+
if let Some(&Adjust::DerefRef { autoderefs, .. }) = self.tcx
153153
.tables
154154
.borrow()
155155
.adjustments
156-
.get(&borrow_id) {
156+
.get(&borrow_id)
157+
.map(|a| &a.kind) {
157158
if LoanCause::AutoRef == loan_cause {
158159
// x.foo()
159-
if adj.autoderefs == 0 {
160+
if autoderefs == 0 {
160161
self.set.remove(&lid); // Used without autodereffing (i.e. x.clone())
161162
}
162163
} else {
163164
span_bug!(cmt.span, "Unknown adjusted AutoRef");
164165
}
165166
} else if LoanCause::AddrOf == loan_cause {
166167
// &x
167-
if let Some(&AutoAdjustment::AdjustDerefRef(adj)) = self.tcx
168+
if let Some(&Adjust::DerefRef { autoderefs, .. }) = self.tcx
168169
.tables
169170
.borrow()
170171
.adjustments
171172
.get(&self.tcx
172-
.map
173-
.get_parent_node(borrow_id)) {
174-
if adj.autoderefs <= 1 {
173+
.map
174+
.get_parent_node(borrow_id))
175+
.map(|a| &a.kind) {
176+
if autoderefs <= 1 {
175177
// foo(&x) where no extra autoreffing is happening
176178
self.set.remove(&lid);
177179
}

clippy_lints/src/eta_reduction.rs

+37-44
Original file line numberDiff line numberDiff line change
@@ -48,60 +48,53 @@ impl LateLintPass for EtaPass {
4848
}
4949

5050
fn check_closure(cx: &LateContext, expr: &Expr) {
51-
if let ExprClosure(_, ref decl, ref blk, _) = expr.node {
52-
if !blk.stmts.is_empty() {
53-
// || {foo(); bar()}; can't be reduced here
54-
return;
55-
}
56-
57-
if let Some(ref ex) = blk.expr {
58-
if let ExprCall(ref caller, ref args) = ex.node {
59-
if args.len() != decl.inputs.len() {
60-
// Not the same number of arguments, there
61-
// is no way the closure is the same as the function
62-
return;
63-
}
64-
if is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)) {
65-
// Are the expression or the arguments type-adjusted? Then we need the closure
66-
return;
51+
if let ExprClosure(_, ref decl, ref ex, _) = expr.node {
52+
if let ExprCall(ref caller, ref args) = ex.node {
53+
if args.len() != decl.inputs.len() {
54+
// Not the same number of arguments, there
55+
// is no way the closure is the same as the function
56+
return;
57+
}
58+
if is_adjusted(cx, ex) || args.iter().any(|arg| is_adjusted(cx, arg)) {
59+
// Are the expression or the arguments type-adjusted? Then we need the closure
60+
return;
61+
}
62+
let fn_ty = cx.tcx.tables().expr_ty(caller);
63+
match fn_ty.sty {
64+
// Is it an unsafe function? They don't implement the closure traits
65+
ty::TyFnDef(_, _, fn_ty) |
66+
ty::TyFnPtr(fn_ty) => {
67+
if fn_ty.unsafety == Unsafety::Unsafe ||
68+
fn_ty.sig.skip_binder().output.sty == ty::TyNever {
69+
return;
70+
}
6771
}
68-
let fn_ty = cx.tcx.expr_ty(caller);
69-
match fn_ty.sty {
70-
// Is it an unsafe function? They don't implement the closure traits
71-
ty::TyFnDef(_, _, fn_ty) |
72-
ty::TyFnPtr(fn_ty) => {
73-
if fn_ty.unsafety == Unsafety::Unsafe ||
74-
fn_ty.sig.skip_binder().output.sty == ty::TyNever {
72+
_ => (),
73+
}
74+
for (a1, a2) in decl.inputs.iter().zip(args) {
75+
if let PatKind::Binding(_, ident, _) = a1.pat.node {
76+
// XXXManishearth Should I be checking the binding mode here?
77+
if let ExprPath(None, ref p) = a2.node {
78+
if p.segments.len() != 1 {
79+
// If it's a proper path, it can't be a local variable
7580
return;
7681
}
77-
}
78-
_ => (),
79-
}
80-
for (a1, a2) in decl.inputs.iter().zip(args) {
81-
if let PatKind::Binding(_, ident, _) = a1.pat.node {
82-
// XXXManishearth Should I be checking the binding mode here?
83-
if let ExprPath(None, ref p) = a2.node {
84-
if p.segments.len() != 1 {
85-
// If it's a proper path, it can't be a local variable
86-
return;
87-
}
88-
if p.segments[0].name != ident.node {
89-
// The two idents should be the same
90-
return;
91-
}
92-
} else {
82+
if p.segments[0].name != ident.node {
83+
// The two idents should be the same
9384
return;
9485
}
9586
} else {
9687
return;
9788
}
89+
} else {
90+
return;
9891
}
99-
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
100-
if let Some(snippet) = snippet_opt(cx, caller.span) {
101-
db.span_suggestion(expr.span, "remove closure as shown:", snippet);
102-
}
103-
});
10492
}
93+
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
94+
if let Some(snippet) = snippet_opt(cx, caller.span) {
95+
db.span_suggestion(expr.span, "remove closure as shown:", snippet);
96+
}
97+
});
10598
}
10699
}
107100
}

0 commit comments

Comments
 (0)