Skip to content

Commit 010974f

Browse files
committed
Finish rustup.
1 parent edef6c5 commit 010974f

File tree

12 files changed

+131
-111
lines changed

12 files changed

+131
-111
lines changed

clippy_lints/src/escape.rs

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc::lint::*;
55
use rustc::middle::expr_use_visitor::*;
66
use rustc::middle::mem_categorization::{cmt, Categorization};
77
use rustc::ty;
8-
use rustc::ty::layout::TargetDataLayout;
9-
use rustc::traits::Reveal;
108
use rustc::util::nodemap::NodeSet;
119
use syntax::ast::NodeId;
1210
use syntax::codemap::Span;
@@ -46,8 +44,7 @@ fn is_non_trait_box(ty: ty::Ty) -> bool {
4644
struct EscapeDelegate<'a, 'tcx: 'a> {
4745
set: NodeSet,
4846
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
49-
tables: &'a ty::TypeckTables<'tcx>,
50-
target: TargetDataLayout,
47+
param_env: ty::ParamEnv<'tcx>,
5148
too_large_for_stack: u64,
5249
}
5350

@@ -67,25 +64,20 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6764
_: Span,
6865
node_id: NodeId
6966
) {
70-
// we store the infcx because it is expensive to recreate
71-
// the context each time.
67+
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
68+
let param_env = cx.tcx.param_env(fn_def_id).reveal_all();
7269
let mut v = EscapeDelegate {
7370
set: NodeSet(),
7471
tcx: cx.tcx,
75-
tables: cx.tables,
76-
target: TargetDataLayout::parse(cx.sess()),
72+
param_env: param_env,
7773
too_large_for_stack: self.too_large_for_stack,
7874
};
7975

80-
let infcx = cx.tcx.borrowck_fake_infer_ctxt(body.id());
81-
let fn_def_id = cx.tcx.hir.local_def_id(node_id);
82-
let region_maps = &cx.tcx.region_maps(fn_def_id);
83-
{
84-
let def_id = cx.tcx.hir.body_owner_def_id(body.id());
85-
let param_env = cx.tcx.param_env(def_id);
76+
cx.tcx.infer_ctxt(body.id()).enter(|infcx| {
77+
let region_maps = &cx.tcx.region_maps(fn_def_id);
8678
let mut vis = ExprUseVisitor::new(&mut v, region_maps, &infcx, param_env);
8779
vis.consume_body(body);
88-
}
80+
});
8981

9082
for node in v.set {
9183
span_lint(cx,
@@ -96,14 +88,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9688
}
9789
}
9890

99-
impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
91+
impl<'a, 'gcx: 'tcx, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'gcx> {
10092
fn consume(&mut self, _: NodeId, _: Span, cmt: cmt<'tcx>, mode: ConsumeMode) {
10193
if let Categorization::Local(lid) = cmt.cat {
102-
if self.set.contains(&lid) {
103-
if let Move(DirectRefMove) = mode {
104-
// moved out or in. clearly can't be localized
105-
self.set.remove(&lid);
106-
}
94+
if let Move(DirectRefMove) = mode {
95+
// moved out or in. clearly can't be localized
96+
self.set.remove(&lid);
10797
}
10898
}
10999
}
@@ -151,49 +141,30 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
151141
}
152142
fn borrow(
153143
&mut self,
154-
borrow_id: NodeId,
144+
_: NodeId,
155145
_: Span,
156146
cmt: cmt<'tcx>,
157147
_: ty::Region,
158148
_: ty::BorrowKind,
159149
loan_cause: LoanCause
160150
) {
161-
use rustc::ty::adjustment::Adjust;
162-
163151
if let Categorization::Local(lid) = cmt.cat {
164-
if self.set.contains(&lid) {
165-
if let Some(&Adjust::Deref(ref overloaded)) =
166-
self.tables
167-
.adjustments
168-
.get(&borrow_id)
169-
.map(|a| &a.kind) {
170-
if LoanCause::AutoRef == loan_cause {
171-
// x.foo()
172-
if overloaded == 0 {
173-
self.set.remove(&lid); // Used without autodereffing (i.e. x.clone())
174-
}
175-
} else {
176-
span_bug!(cmt.span, "Unknown adjusted AutoRef");
177-
}
178-
} else if LoanCause::AddrOf == loan_cause {
179-
// &x
180-
if let Some(&Adjust::Deref(ref overloaded)) =
181-
self.tables
182-
.adjustments
183-
.get(&self.tcx
184-
.hir
185-
.get_parent_node(borrow_id))
186-
.map(|a| &a.kind) {
187-
if overloaded <= 1 {
188-
// foo(&x) where no extra autoreffing is happening
189-
self.set.remove(&lid);
190-
}
191-
}
152+
match loan_cause {
153+
// x.foo()
154+
// Used without autodereffing (i.e. x.clone())
155+
LoanCause::AutoRef |
192156

193-
} else if LoanCause::MatchDiscriminant == loan_cause {
194-
self.set.remove(&lid); // `match x` can move
157+
// &x
158+
// foo(&x) where no extra autoreffing is happening
159+
LoanCause::AddrOf |
160+
161+
// `match x` can move
162+
LoanCause::MatchDiscriminant => {
163+
self.set.remove(&lid);
195164
}
165+
196166
// do nothing for matches, etc. These can't escape
167+
_ => {}
197168
}
198169
}
199170
}
@@ -202,19 +173,17 @@ impl<'a, 'tcx: 'a> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
202173
}
203174

204175
impl<'a, 'tcx: 'a> EscapeDelegate<'a, 'tcx> {
205-
fn is_large_box(&self, ty: ty::Ty<'tcx>) -> bool {
176+
fn is_large_box(&self, ty: ty::Ty) -> bool {
206177
// Large types need to be boxed to avoid stack
207178
// overflows.
208179
if ty.is_box() {
209-
let inner = ty.boxed_ty();
210-
self.tcx.infer_ctxt(()).enter(|infcx| if let Ok(layout) = inner.layout(&infcx) {
211-
let size = layout.size(&self.target);
212-
size.bytes() > self.too_large_for_stack
213-
} else {
214-
false
215-
})
216-
} else {
217-
false
180+
if let Some(inner) = self.tcx.lift(&ty.boxed_ty()) {
181+
if let Ok(layout) = inner.layout(self.tcx, self.param_env) {
182+
return layout.size(self.tcx).bytes() > self.too_large_for_stack;
183+
}
184+
}
218185
}
186+
187+
false
219188
}
220189
}

clippy_lints/src/functions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc::hir::intravisit;
22
use rustc::hir;
3-
use rustc::ty;
43
use rustc::lint::*;
54
use std::collections::HashSet;
65
use syntax::ast;

clippy_lints/src/loops.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc::lint::*;
88
use rustc::middle::const_val::ConstVal;
99
use rustc::middle::region::CodeExtent;
1010
use rustc::ty;
11+
use rustc::ty::subst::Subst;
1112
use rustc_const_eval::ConstContext;
1213
use std::collections::HashMap;
1314
use syntax::ast;
@@ -676,8 +677,11 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
676677
lint_iter_method(cx, args, arg, &method_name);
677678
}
678679
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
679-
let fn_ty = cx.tables.expr_ty(arg);
680-
let fn_arg_tys = fn_ty.fn_sig().inputs();
680+
let def_id = cx.tables.type_dependent_defs[&arg.id].def_id();
681+
let substs = cx.tables.node_substs(arg.id);
682+
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
683+
684+
let fn_arg_tys = method_type.fn_sig().inputs();
681685
assert_eq!(fn_arg_tys.skip_binder().len(), 1);
682686
if fn_arg_tys.skip_binder()[0].is_region_ptr() {
683687
lint_iter_method(cx, args, arg, &method_name);

clippy_lints/src/mut_reference.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc::lint::*;
22
use rustc::ty::{TypeAndMut, TypeVariants, TyS};
3+
use rustc::ty::subst::Subst;
34
use rustc::hir::*;
45
use utils::span_lint;
56

@@ -34,23 +35,19 @@ impl LintPass for UnnecessaryMutPassed {
3435

3536
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
3637
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
37-
let borrowed_table = cx.tables;
3838
match e.node {
3939
ExprCall(ref fn_expr, ref arguments) => {
40-
let function_type = borrowed_table.node_types
41-
.get(&fn_expr.id)
42-
.expect("A function with an unknown type is called. If this happened, the compiler would have \
43-
aborted the compilation long ago");
4440
if let ExprPath(ref path) = fn_expr.node {
4541
check_arguments(cx,
4642
arguments,
47-
function_type,
43+
cx.tables.expr_ty(fn_expr),
4844
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)));
4945
}
5046
},
5147
ExprMethodCall(ref name, _, ref arguments) => {
52-
let def_id = borrowed_table.type_dependent_defs[&e.id].def_id();
53-
let method_type = cx.tcx.type_of(def_id);
48+
let def_id = cx.tables.type_dependent_defs[&e.id].def_id();
49+
let substs = cx.tables.node_substs(e.id);
50+
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
5451
check_arguments(cx, arguments, method_type, &name.node.as_str())
5552
},
5653
_ => (),

clippy_lints/src/needless_borrow.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use rustc::lint::*;
66
use rustc::hir::{ExprAddrOf, Expr, MutImmutable, Pat, PatKind, BindingMode};
77
use rustc::ty;
8+
use rustc::ty::adjustment::{Adjustment, Adjust};
89
use utils::{span_lint, in_macro};
910

1011
/// **What it does:** Checks for address of operations (`&`) that are going to
@@ -41,13 +42,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
4142
}
4243
if let ExprAddrOf(MutImmutable, ref inner) = e.node {
4344
if let ty::TyRef(..) = cx.tables.expr_ty(inner).sty {
44-
if let Some(&ty::adjustment::Adjust::Deref(Some(_))) =
45-
cx.tables.adjustments.get(&e.id).map(|a| &a.kind) {
46-
span_lint(cx,
47-
NEEDLESS_BORROW,
48-
e.span,
49-
"this expression borrows a reference that is immediately dereferenced by the \
50-
compiler");
45+
for adj3 in cx.tables.expr_adjustments(e).windows(3) {
46+
if let [
47+
Adjustment { kind: Adjust::Deref(_), .. },
48+
Adjustment { kind: Adjust::Deref(_), .. },
49+
Adjustment { kind: Adjust::Borrow(_), .. }
50+
] = *adj3 {
51+
span_lint(cx,
52+
NEEDLESS_BORROW,
53+
e.span,
54+
"this expression borrows a reference that is immediately dereferenced by the \
55+
compiler");
56+
}
5157
}
5258
}
5359
}

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
9191
// Collect moved variables and spans which will need dereferencings from the function body.
9292
let MovedVariablesCtxt { moved_vars, spans_need_deref, .. } = {
9393
let mut ctx = MovedVariablesCtxt::new(cx);
94-
let infcx = cx.tcx.borrowck_fake_infer_ctxt(body.id());
95-
let region_maps = &cx.tcx.region_maps(fn_def_id);
96-
{
97-
let mut v = euv::ExprUseVisitor::new(&mut ctx, region_maps, &infcx);
98-
v.consume_body(body);
99-
}
94+
cx.tcx.infer_ctxt(body.id()).enter(|infcx| {
95+
let param_env = cx.tcx.param_env(fn_def_id);
96+
let region_maps = &cx.tcx.region_maps(fn_def_id);
97+
euv::ExprUseVisitor::new(&mut ctx, region_maps, &infcx, param_env)
98+
.consume_body(body);
99+
});
100100
ctx
101101
};
102102

@@ -199,7 +199,7 @@ impl<'a, 'tcx: 'a> MovedVariablesCtxt<'a, 'tcx> {
199199
}
200200
}
201201

202-
fn move_common(&mut self, _consume_id: NodeId, _span: Span, cmt: mc::cmt<'tcx>) {
202+
fn move_common(&mut self, _consume_id: NodeId, _span: Span, cmt: mc::cmt) {
203203
let cmt = unwrap_downcast_or_interior(cmt);
204204

205205
if_let_chain! {[
@@ -210,7 +210,7 @@ impl<'a, 'tcx: 'a> MovedVariablesCtxt<'a, 'tcx> {
210210
}}
211211
}
212212

213-
fn non_moving_pat(&mut self, matched_pat: &Pat, cmt: mc::cmt<'tcx>) {
213+
fn non_moving_pat(&mut self, matched_pat: &Pat, cmt: mc::cmt) {
214214
let cmt = unwrap_downcast_or_interior(cmt);
215215

216216
if_let_chain! {[
@@ -262,7 +262,7 @@ impl<'a, 'tcx: 'a> MovedVariablesCtxt<'a, 'tcx> {
262262
}
263263
}
264264

265-
impl<'a, 'tcx: 'a> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
265+
impl<'a, 'gcx: 'tcx, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'gcx> {
266266
fn consume(&mut self, consume_id: NodeId, consume_span: Span, cmt: mc::cmt<'tcx>, mode: euv::ConsumeMode) {
267267
if let euv::ConsumeMode::Move(_) = mode {
268268
self.move_common(consume_id, consume_span, cmt);

clippy_lints/src/unused_io_amount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
4646
hir::ExprMatch(ref res, _, _) if is_try(expr).is_some() => {
4747
if let hir::ExprCall(ref func, ref args) = res.node {
4848
if let hir::ExprPath(ref path) = func.node {
49-
if match_path(path, &paths::CARRIER_TRANSLATE) && args.len() == 1 {
49+
if match_path(path, &paths::TRY_INTO_RESULT) && args.len() == 1 {
5050
check_method_call(cx, &args[0], expr);
5151
}
5252
}

clippy_lints/src/utils/mod.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc::traits::Reveal;
99
use rustc::traits;
1010
use rustc::ty::subst::{Subst, Substs};
1111
use rustc::ty;
12-
use rustc::ty::layout::TargetDataLayout;
1312
use rustc::mir::transform::MirSource;
1413
use rustc_errors;
1514
use std::borrow::Cow;
@@ -317,13 +316,15 @@ pub fn implements_trait<'a, 'tcx>(
317316
parent_node_id: Option<NodeId>
318317
) -> bool {
319318
let ty = cx.tcx.erase_regions(&ty);
320-
let mut b = if let Some(id) = parent_node_id {
321-
cx.tcx.infer_ctxt(BodyId { node_id: id })
319+
let param_env = if let Some(id) = parent_node_id {
320+
let def_id = cx.tcx.hir.body_owner_def_id(BodyId { node_id: id });
321+
cx.tcx.param_env(def_id).reveal_all()
322322
} else {
323-
cx.tcx.infer_ctxt(())
323+
ty::ParamEnv::empty(Reveal::All)
324324
};
325-
b.enter(|infcx| {
326-
let obligation = cx.tcx.predicate_for_trait_def(traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
325+
cx.tcx.infer_ctxt(()).enter(|infcx| {
326+
let obligation = cx.tcx.predicate_for_trait_def(
327+
param_env, traits::ObligationCause::dummy(), trait_id, 0, ty, ty_params);
327328

328329
traits::SelectionContext::new(&infcx).evaluate_obligation_conservatively(&obligation)
329330
})
@@ -778,12 +779,9 @@ pub fn same_tys<'a, 'tcx>(
778779
b: ty::Ty<'tcx>,
779780
parameter_item: DefId
780781
) -> bool {
781-
let parameter_env = cx.tcx.param_env(parameter_item);
782-
cx.tcx.infer_ctxt(parameter_env).enter(|infcx| {
783-
let substs = Substs::identity_for_item(cx.tcx, parameter_item);
784-
let new_a = a.subst(infcx.tcx, substs);
785-
let new_b = b.subst(infcx.tcx, substs);
786-
infcx.can_equate(&new_a, &new_b).is_ok()
782+
let param_env = cx.tcx.param_env(parameter_item).reveal_all();
783+
cx.tcx.infer_ctxt(()).enter(|infcx| {
784+
infcx.can_eq(param_env, a, b).is_ok()
787785
})
788786
}
789787

@@ -961,7 +959,6 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
961959
}
962960

963961
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Option<u64> {
964-
cx.tcx
965-
.infer_ctxt(())
966-
.enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()))
962+
ty.layout(cx.tcx, ty::ParamEnv::empty(Reveal::All))
963+
.ok().map(|layout| layout.size(cx.tcx).bytes())
967964
}

clippy_lints/src/utils/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub const BOX_NEW: [&'static str; 4] = ["std", "boxed", "Box", "new"];
99
pub const BTREEMAP: [&'static str; 4] = ["collections", "btree", "map", "BTreeMap"];
1010
pub const BTREEMAP_ENTRY: [&'static str; 4] = ["collections", "btree", "map", "Entry"];
1111
pub const BTREESET: [&'static str; 4] = ["collections", "btree", "set", "BTreeSet"];
12-
pub const CARRIER_TRANSLATE: [&'static str; 4] = ["std", "ops", "Carrier", "translate"];
1312
pub const CLONE: [&'static str; 4] = ["core", "clone", "Clone", "clone"];
1413
pub const CLONE_TRAIT: [&'static str; 3] = ["core", "clone", "Clone"];
1514
pub const CMP_MAX: [&'static str; 3] = ["core", "cmp", "max"];
@@ -72,6 +71,7 @@ pub const STRING: [&'static str; 3] = ["collections", "string", "String"];
7271
pub const TO_OWNED: [&'static str; 3] = ["collections", "borrow", "ToOwned"];
7372
pub const TO_STRING: [&'static str; 3] = ["collections", "string", "ToString"];
7473
pub const TRANSMUTE: [&'static str; 4] = ["core", "intrinsics", "", "transmute"];
74+
pub const TRY_INTO_RESULT: [&'static str; 4] = ["std", "ops", "Try", "into_result"];
7575
pub const VEC: [&'static str; 3] = ["collections", "vec", "Vec"];
7676
pub const VEC_DEQUE: [&'static str; 3] = ["collections", "vec_deque", "VecDeque"];
7777
pub const VEC_FROM_ELEM: [&'static str; 3] = ["collections", "vec", "from_elem"];

0 commit comments

Comments
 (0)