Skip to content

Commit b0ec33f

Browse files
committed
Auto merge of #4166 - mati865:rustup, r=Manishearth
Rustup for rust-lang/rust#61276 changelog: none
2 parents f5d6804 + a3ace5c commit b0ec33f

File tree

5 files changed

+57
-32
lines changed

5 files changed

+57
-32
lines changed

clippy_lints/src/escape.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
7979

8080
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
8181
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
82-
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
82+
ExprUseVisitor::new(
83+
&mut v,
84+
cx.tcx,
85+
fn_def_id,
86+
cx.param_env,
87+
region_scope_tree,
88+
cx.tables,
89+
None,
90+
)
91+
.consume_body(body);
8392

8493
for node in v.set {
8594
span_lint(

clippy_lints/src/loops.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,16 @@ fn check_for_mutation(
16621662
};
16631663
let def_id = def_id::DefId::local(body.hir_id.owner);
16641664
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
1665-
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(body);
1665+
ExprUseVisitor::new(
1666+
&mut delegate,
1667+
cx.tcx,
1668+
def_id,
1669+
cx.param_env,
1670+
region_scope_tree,
1671+
cx.tables,
1672+
None,
1673+
)
1674+
.walk_expr(body);
16661675
delegate.mutation_span()
16671676
}
16681677

@@ -1769,7 +1778,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17691778
}
17701779
let res = self.cx.tables.qpath_res(seqpath, seqexpr.hir_id);
17711780
match res {
1772-
Res::Local(hir_id) | Res::Upvar(hir_id, ..) => {
1781+
Res::Local(hir_id) => {
17731782
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
17741783
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
17751784
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
@@ -1829,24 +1838,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18291838
if let QPath::Resolved(None, ref path) = *qpath;
18301839
if path.segments.len() == 1;
18311840
then {
1832-
match self.cx.tables.qpath_res(qpath, expr.hir_id) {
1833-
Res::Upvar(local_id, ..) => {
1834-
if local_id == self.var {
1835-
// we are not indexing anything, record that
1836-
self.nonindex = true;
1837-
}
1838-
}
1839-
Res::Local(local_id) =>
1840-
{
1841-
1842-
if local_id == self.var {
1843-
self.nonindex = true;
1844-
} else {
1845-
// not the correct variable, but still a variable
1846-
self.referenced.insert(path.segments[0].ident.name);
1847-
}
1841+
if let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id) {
1842+
if local_id == self.var {
1843+
self.nonindex = true;
1844+
} else {
1845+
// not the correct variable, but still a variable
1846+
self.referenced.insert(path.segments[0].ident.name);
18481847
}
1849-
_ => {}
18501848
}
18511849
}
18521850
}
@@ -2378,7 +2376,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
23782376
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
23792377
then {
23802378
match res {
2381-
Res::Local(node_id) | Res::Upvar(node_id, ..) => {
2379+
Res::Local(node_id) => {
23822380
self.ids.insert(node_id);
23832381
},
23842382
Res::Def(DefKind::Static, def_id) => {

clippy_lints/src/misc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,10 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
600600

601601
/// Tests whether `res` is a variable defined outside a macro.
602602
fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
603-
match res {
604-
def::Res::Local(id) | def::Res::Upvar(id, ..) => !in_macro_or_desugar(cx.tcx.hir().span_by_hir_id(id)),
605-
_ => false,
603+
if let def::Res::Local(id) = res {
604+
!in_macro_or_desugar(cx.tcx.hir().span_by_hir_id(id))
605+
} else {
606+
false
606607
}
607608
}
608609

clippy_lints/src/needless_pass_by_value.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
137137
} = {
138138
let mut ctx = MovedVariablesCtxt::new(cx);
139139
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
140-
euv::ExprUseVisitor::new(&mut ctx, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None)
141-
.consume_body(body);
140+
euv::ExprUseVisitor::new(
141+
&mut ctx,
142+
cx.tcx,
143+
fn_def_id,
144+
cx.param_env,
145+
region_scope_tree,
146+
cx.tables,
147+
None,
148+
)
149+
.consume_body(body);
142150
ctx
143151
};
144152

clippy_lints/src/utils/usage.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a,
1616
};
1717
let def_id = def_id::DefId::local(expr.hir_id.owner);
1818
let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
19-
ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(expr);
19+
ExprUseVisitor::new(
20+
&mut delegate,
21+
cx.tcx,
22+
def_id,
23+
cx.param_env,
24+
region_scope_tree,
25+
cx.tables,
26+
None,
27+
)
28+
.walk_expr(expr);
2029

2130
if delegate.skip {
2231
return None;
@@ -29,11 +38,11 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
2938
expr: &'tcx Expr,
3039
cx: &'a LateContext<'a, 'tcx>,
3140
) -> bool {
32-
let id = match variable.res {
33-
Res::Local(id) | Res::Upvar(id, ..) => id,
34-
_ => return true,
35-
};
36-
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
41+
if let Res::Local(id) = variable.res {
42+
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
43+
} else {
44+
return true;
45+
}
3746
}
3847

3948
struct MutVarsDelegate {

0 commit comments

Comments
 (0)