Skip to content

Commit 4780ac0

Browse files
committed
Auto merge of #4857 - rust-lang:rustup, r=matthewjasper,oli-obk
Rustup From rust-lang/rust#66246 changelog: none
2 parents b5a6714 + 604e6ba commit 4780ac0

File tree

4 files changed

+67
-96
lines changed

4 files changed

+67
-96
lines changed

clippy_lints/src/escape.rs

+36-32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use rustc::hir::intravisit as visit;
22
use rustc::hir::{self, *};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::middle::expr_use_visitor::*;
5-
use rustc::middle::mem_categorization::{cmt_, Categorization};
64
use rustc::ty::layout::LayoutOf;
75
use rustc::ty::{self, Ty};
86
use rustc::util::nodemap::HirIdSet;
97
use rustc::{declare_tool_lint, impl_lint_pass};
8+
use rustc_typeck::expr_use_visitor::*;
109
use syntax::source_map::Span;
1110

1211
use crate::utils::span_lint;
@@ -77,8 +76,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
7776
};
7877

7978
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
80-
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
81-
ExprUseVisitor::new(&mut v, cx.tcx, fn_def_id, cx.param_env, region_scope_tree, cx.tables).consume_body(body);
79+
cx.tcx.infer_ctxt().enter(|infcx| {
80+
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body);
81+
});
8282

8383
for node in v.set {
8484
span_lint(
@@ -105,45 +105,49 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
105105
}
106106

107107
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
108-
fn consume(&mut self, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
109-
if let Categorization::Local(lid) = cmt.cat {
110-
if let ConsumeMode::Move = mode {
111-
// moved out or in. clearly can't be localized
112-
self.set.remove(&lid);
113-
}
114-
}
115-
let map = &self.cx.tcx.hir();
116-
if let Categorization::Local(lid) = cmt.cat {
117-
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
118-
if self.set.contains(&lid) {
119-
// let y = x where x is known
120-
// remove x, insert y
121-
self.set.insert(cmt.hir_id);
108+
fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) {
109+
if cmt.projections.is_empty() {
110+
if let PlaceBase::Local(lid) = cmt.base {
111+
if let ConsumeMode::Move = mode {
112+
// moved out or in. clearly can't be localized
122113
self.set.remove(&lid);
123114
}
115+
let map = &self.cx.tcx.hir();
116+
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
117+
if self.set.contains(&lid) {
118+
// let y = x where x is known
119+
// remove x, insert y
120+
self.set.insert(cmt.hir_id);
121+
self.set.remove(&lid);
122+
}
123+
}
124124
}
125125
}
126126
}
127127

128-
fn borrow(&mut self, cmt: &cmt_<'tcx>, _: ty::BorrowKind) {
129-
if let Categorization::Local(lid) = cmt.cat {
130-
self.set.remove(&lid);
128+
fn borrow(&mut self, cmt: &Place<'tcx>, _: ty::BorrowKind) {
129+
if cmt.projections.is_empty() {
130+
if let PlaceBase::Local(lid) = cmt.base {
131+
self.set.remove(&lid);
132+
}
131133
}
132134
}
133135

134-
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
135-
let map = &self.cx.tcx.hir();
136-
if is_argument(map, cmt.hir_id) {
137-
// Skip closure arguments
138-
let parent_id = map.get_parent_node(cmt.hir_id);
139-
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) {
140-
return;
141-
}
136+
fn mutate(&mut self, cmt: &Place<'tcx>) {
137+
if cmt.projections.is_empty() {
138+
let map = &self.cx.tcx.hir();
139+
if is_argument(map, cmt.hir_id) {
140+
// Skip closure arguments
141+
let parent_id = map.get_parent_node(cmt.hir_id);
142+
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(parent_id)) {
143+
return;
144+
}
142145

143-
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
144-
self.set.insert(cmt.hir_id);
146+
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
147+
self.set.insert(cmt.hir_id);
148+
}
149+
return;
145150
}
146-
return;
147151
}
148152
}
149153
}

clippy_lints/src/loops.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1212
use crate::consts::{constant, Constant};
1313
use crate::utils::usage::mutated_variables;
1414
use crate::utils::{is_type_diagnostic_item, qpath_res, sext, sugg};
15-
use rustc::middle::expr_use_visitor::*;
16-
use rustc::middle::mem_categorization::cmt_;
17-
use rustc::middle::mem_categorization::Categorization;
1815
use rustc::ty::subst::Subst;
1916
use rustc::ty::{self, Ty};
2017
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2118
use rustc_errors::Applicability;
19+
use rustc_typeck::expr_use_visitor::*;
2220
use std::iter::{once, Iterator};
2321
use std::mem;
2422
use syntax::ast;
@@ -1586,11 +1584,11 @@ struct MutatePairDelegate {
15861584
}
15871585

15881586
impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
1589-
fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
1587+
fn consume(&mut self, _: &Place<'tcx>, _: ConsumeMode) {}
15901588

1591-
fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
1589+
fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) {
15921590
if let ty::BorrowKind::MutBorrow = bk {
1593-
if let Categorization::Local(id) = cmt.cat {
1591+
if let PlaceBase::Local(id) = cmt.base {
15941592
if Some(id) == self.hir_id_low {
15951593
self.span_low = Some(cmt.span)
15961594
}
@@ -1601,8 +1599,8 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
16011599
}
16021600
}
16031601

1604-
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
1605-
if let Categorization::Local(id) = cmt.cat {
1602+
fn mutate(&mut self, cmt: &Place<'tcx>) {
1603+
if let PlaceBase::Local(id) = cmt.base {
16061604
if Some(id) == self.hir_id_low {
16071605
self.span_low = Some(cmt.span)
16081606
}
@@ -1680,16 +1678,9 @@ fn check_for_mutation(
16801678
span_high: None,
16811679
};
16821680
let def_id = def_id::DefId::local(body.hir_id.owner);
1683-
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
1684-
ExprUseVisitor::new(
1685-
&mut delegate,
1686-
cx.tcx,
1687-
def_id,
1688-
cx.param_env,
1689-
region_scope_tree,
1690-
cx.tables,
1691-
)
1692-
.walk_expr(body);
1681+
cx.tcx.infer_ctxt().enter(|infcx| {
1682+
ExprUseVisitor::new(&mut delegate, &infcx, def_id, cx.param_env, cx.tables).walk_expr(body);
1683+
});
16931684
delegate.mutation_span()
16941685
}
16951686

clippy_lints/src/needless_pass_by_value.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use matches::matches;
88
use rustc::hir::intravisit::FnKind;
99
use rustc::hir::*;
1010
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
11-
use rustc::middle::expr_use_visitor as euv;
12-
use rustc::middle::mem_categorization as mc;
1311
use rustc::traits;
1412
use rustc::ty::{self, RegionKind, TypeFoldable};
1513
use rustc::{declare_lint_pass, declare_tool_lint};
1614
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1715
use rustc_errors::Applicability;
1816
use rustc_target::spec::abi::Abi;
17+
use rustc_typeck::expr_use_visitor as euv;
1918
use std::borrow::Cow;
2019
use syntax::ast::Attribute;
2120
use syntax::errors::DiagnosticBuilder;
@@ -135,9 +134,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
135134
..
136135
} = {
137136
let mut ctx = MovedVariablesCtxt::default();
138-
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
139-
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, fn_def_id, cx.param_env, region_scope_tree, cx.tables)
140-
.consume_body(body);
137+
cx.tcx.infer_ctxt().enter(|infcx| {
138+
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.tables).consume_body(body);
139+
});
141140
ctx
142141
};
143142

@@ -326,34 +325,21 @@ struct MovedVariablesCtxt {
326325
}
327326

328327
impl MovedVariablesCtxt {
329-
fn move_common(&mut self, cmt: &mc::cmt_<'_>) {
330-
let cmt = unwrap_downcast_or_interior(cmt);
331-
332-
if let mc::Categorization::Local(vid) = cmt.cat {
328+
fn move_common(&mut self, cmt: &euv::Place<'_>) {
329+
if let euv::PlaceBase::Local(vid) = cmt.base {
333330
self.moved_vars.insert(vid);
334331
}
335332
}
336333
}
337334

338335
impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
339-
fn consume(&mut self, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
336+
fn consume(&mut self, cmt: &euv::Place<'tcx>, mode: euv::ConsumeMode) {
340337
if let euv::ConsumeMode::Move = mode {
341338
self.move_common(cmt);
342339
}
343340
}
344341

345-
fn borrow(&mut self, _: &mc::cmt_<'tcx>, _: ty::BorrowKind) {}
346-
347-
fn mutate(&mut self, _: &mc::cmt_<'tcx>) {}
348-
}
342+
fn borrow(&mut self, _: &euv::Place<'tcx>, _: ty::BorrowKind) {}
349343

350-
fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> {
351-
loop {
352-
match cmt.cat {
353-
mc::Categorization::Downcast(ref c, _) | mc::Categorization::Interior(ref c, _) => {
354-
cmt = c;
355-
},
356-
_ => return (*cmt).clone(),
357-
}
358-
}
344+
fn mutate(&mut self, _: &euv::Place<'tcx>) {}
359345
}

clippy_lints/src/utils/usage.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use rustc::hir::def::Res;
22
use rustc::hir::*;
33
use rustc::lint::LateContext;
4-
use rustc::middle::expr_use_visitor::*;
5-
use rustc::middle::mem_categorization::cmt_;
6-
use rustc::middle::mem_categorization::Categorization;
74
use rustc::ty;
85
use rustc_data_structures::fx::FxHashSet;
6+
use rustc_typeck::expr_use_visitor::*;
97

108
/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
119
pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> {
@@ -14,16 +12,9 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tc
1412
skip: false,
1513
};
1614
let def_id = def_id::DefId::local(expr.hir_id.owner);
17-
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
18-
ExprUseVisitor::new(
19-
&mut delegate,
20-
cx.tcx,
21-
def_id,
22-
cx.param_env,
23-
region_scope_tree,
24-
cx.tables,
25-
)
26-
.walk_expr(expr);
15+
cx.tcx.infer_ctxt().enter(|infcx| {
16+
ExprUseVisitor::new(&mut delegate, &infcx, def_id, cx.param_env, cx.tables).walk_expr(expr);
17+
});
2718

2819
if delegate.skip {
2920
return None;
@@ -46,33 +37,32 @@ struct MutVarsDelegate {
4637

4738
impl<'tcx> MutVarsDelegate {
4839
#[allow(clippy::similar_names)]
49-
fn update(&mut self, cat: &'tcx Categorization<'_>) {
50-
match *cat {
51-
Categorization::Local(id) => {
40+
fn update(&mut self, cat: &Place<'tcx>) {
41+
match cat.base {
42+
PlaceBase::Local(id) => {
5243
self.used_mutably.insert(id);
5344
},
54-
Categorization::Upvar(_) => {
45+
PlaceBase::Upvar(_) => {
5546
//FIXME: This causes false negatives. We can't get the `NodeId` from
5647
//`Categorization::Upvar(_)`. So we search for any `Upvar`s in the
5748
//`while`-body, not just the ones in the condition.
5849
self.skip = true
5950
},
60-
Categorization::Deref(ref cmt, _) | Categorization::Interior(ref cmt, _) => self.update(&cmt.cat),
6151
_ => {},
6252
}
6353
}
6454
}
6555

6656
impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
67-
fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
57+
fn consume(&mut self, _: &Place<'tcx>, _: ConsumeMode) {}
6858

69-
fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
59+
fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) {
7060
if let ty::BorrowKind::MutBorrow = bk {
71-
self.update(&cmt.cat)
61+
self.update(&cmt)
7262
}
7363
}
7464

75-
fn mutate(&mut self, cmt: &cmt_<'tcx>) {
76-
self.update(&cmt.cat)
65+
fn mutate(&mut self, cmt: &Place<'tcx>) {
66+
self.update(&cmt)
7767
}
7868
}

0 commit comments

Comments
 (0)