Skip to content

Commit f51f017

Browse files
author
Michael Wright
committed
Fixed breakage due to #57489
1 parent 77b71a1 commit f51f017

24 files changed

+141
-199
lines changed

clippy_lints/src/attrs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
376376
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
377377
if let Some(stmt) = block.stmts.first() {
378378
match &stmt.node {
379-
StmtKind::Decl(_, _) => true,
380-
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
379+
StmtKind::Local(_) => true,
380+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
381+
_ => false,
381382
}
382383
} else {
383384
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))

clippy_lints/src/escape.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
120120
if let Categorization::Rvalue(..) = cmt.cat {
121121
let id = map.hir_to_node_id(cmt.hir_id);
122122
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(id)) {
123-
if let StmtKind::Decl(ref decl, _) = st.node {
124-
if let DeclKind::Local(ref loc) = decl.node {
123+
if let StmtKind::Local(ref loc) = st.node {
125124
if let Some(ref ex) = loc.init {
126125
if let ExprKind::Box(..) = ex.node {
127126
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
@@ -136,7 +135,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
136135
}
137136
}
138137
}
139-
}
140138
if let Categorization::Local(lid) = cmt.cat {
141139
if self.set.contains(&lid) {
142140
// let y = x where x is known

clippy_lints/src/eval_order_dependence.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
8989
}
9090
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
9191
match stmt.node {
92-
StmtKind::Expr(ref e, _) | StmtKind::Semi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
93-
StmtKind::Decl(ref d, _) => {
94-
if let DeclKind::Local(ref local) = d.node {
92+
StmtKind::Local(ref local) => {
9593
if let Local { init: Some(ref e), .. } = **local {
9694
DivergenceVisitor { cx }.visit_expr(e);
9795
}
98-
}
9996
},
97+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
98+
StmtKind::Item(..) => {},
10099
}
101100
}
102101
}
@@ -269,18 +268,13 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
269268

270269
fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly {
271270
match stmt.node {
272-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => check_expr(vis, expr),
273-
StmtKind::Decl(ref decl, _) => {
274-
// If the declaration is of a local variable, check its initializer
275-
// expression if it has one. Otherwise, keep going.
276-
let local = match decl.node {
277-
DeclKind::Local(ref local) => Some(local),
278-
_ => None,
279-
};
280-
local
281-
.and_then(|local| local.init.as_ref())
282-
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr))
271+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
272+
// If the declaration is of a local variable, check its initializer
273+
// expression if it has one. Otherwise, keep going.
274+
StmtKind::Local(ref local) => {
275+
local.init.as_ref().map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr))
283276
},
277+
_ => StopEarly::KeepGoing,
284278
}
285279
}
286280

clippy_lints/src/let_if_seq.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
6868
while let Some(stmt) = it.next() {
6969
if_chain! {
7070
if let Some(expr) = it.peek();
71-
if let hir::StmtKind::Decl(ref decl, _) = stmt.node;
72-
if let hir::DeclKind::Local(ref decl) = decl.node;
73-
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = decl.pat.node;
74-
if let hir::StmtKind::Expr(ref if_, _) = expr.node;
71+
if let hir::StmtKind::Local(ref local) = stmt.node;
72+
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
73+
if let hir::StmtKind::Expr(ref if_) = expr.node;
7574
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
7675
if !used_in_expr(cx, canonical_id, cond);
7776
if let hir::ExprKind::Block(ref then, _) = then.node;
@@ -84,15 +83,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
8483
if let hir::ExprKind::Block(ref else_, _) = else_.node {
8584
if let Some(default) = check_assign(cx, canonical_id, else_) {
8685
(else_.stmts.len() > 1, default)
87-
} else if let Some(ref default) = decl.init {
86+
} else if let Some(ref default) = local.init {
8887
(true, &**default)
8988
} else {
9089
continue;
9190
}
9291
} else {
9392
continue;
9493
}
95-
} else if let Some(ref default) = decl.init {
94+
} else if let Some(ref default) = local.init {
9695
(false, &**default)
9796
} else {
9897
continue;
@@ -169,7 +168,7 @@ fn check_assign<'a, 'tcx>(
169168
if_chain! {
170169
if block.expr.is_none();
171170
if let Some(expr) = block.stmts.iter().last();
172-
if let hir::StmtKind::Semi(ref expr, _) = expr.node;
171+
if let hir::StmtKind::Semi(ref expr) = expr.node;
173172
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
174173
if let hir::ExprKind::Path(ref qpath) = var.node;
175174
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);

clippy_lints/src/loops.rs

+12-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use if_chain::if_chain;
33
use itertools::Itertools;
44
use rustc::hir::def::Def;
55
use rustc::hir::def_id;
6-
use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
6+
use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
77
use rustc::hir::*;
88
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
99
use rustc::middle::region;
@@ -597,7 +597,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
597597
}
598598

599599
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
600-
if let StmtKind::Semi(ref expr, _) = stmt.node {
600+
if let StmtKind::Semi(ref expr) = stmt.node {
601601
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node {
602602
if args.len() == 1 && method.ident.name == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
603603
span_lint(
@@ -668,13 +668,7 @@ fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult {
668668
fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
669669
match stmt.node {
670670
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
671-
StmtKind::Decl(ref d, ..) => decl_to_expr(d),
672-
}
673-
}
674-
675-
fn decl_to_expr(decl: &Decl) -> Option<&Expr> {
676-
match decl.node {
677-
DeclKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
671+
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
678672
_ => None,
679673
}
680674
}
@@ -942,8 +936,8 @@ fn get_indexed_assignments<'a, 'tcx>(
942936
stmts
943937
.iter()
944938
.map(|stmt| match stmt.node {
945-
StmtKind::Decl(..) => None,
946-
StmtKind::Expr(ref e, _node_id) | StmtKind::Semi(ref e, _node_id) => Some(get_assignment(cx, e, var)),
939+
StmtKind::Local(..) | StmtKind::Item(..) => None,
940+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => Some(get_assignment(cx, e, var)),
947941
})
948942
.chain(expr.as_ref().into_iter().map(|e| Some(get_assignment(cx, &*e, var))))
949943
.filter_map(|op| op)
@@ -1976,16 +1970,12 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
19761970
if block.stmts.is_empty() {
19771971
return None;
19781972
}
1979-
if let StmtKind::Decl(ref decl, _) = block.stmts[0].node {
1980-
if let DeclKind::Local(ref local) = decl.node {
1973+
if let StmtKind::Local(ref local) = block.stmts[0].node {
19811974
if let Some(ref expr) = local.init {
19821975
Some(expr)
19831976
} else {
19841977
None
19851978
}
1986-
} else {
1987-
None
1988-
}
19891979
} else {
19901980
None
19911981
}
@@ -1996,8 +1986,8 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> {
19961986
match block.expr {
19971987
Some(ref expr) if block.stmts.is_empty() => Some(expr),
19981988
None if !block.stmts.is_empty() => match block.stmts[0].node {
1999-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => Some(expr),
2000-
StmtKind::Decl(..) => None,
1989+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr),
1990+
StmtKind::Local(..) | StmtKind::Item(..) => None,
20011991
},
20021992
_ => None,
20031993
}
@@ -2095,9 +2085,9 @@ struct InitializeVisitor<'a, 'tcx: 'a> {
20952085
}
20962086

20972087
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
2098-
fn visit_decl(&mut self, decl: &'tcx Decl) {
2088+
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
20992089
// Look for declarations of the variable
2100-
if let DeclKind::Local(ref local) = decl.node {
2090+
if let StmtKind::Local(ref local) = stmt.node {
21012091
if local.pat.id == self.var_id {
21022092
if let PatKind::Binding(_, _, ident, _) = local.pat.node {
21032093
self.name = Some(ident.name);
@@ -2114,7 +2104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21142104
}
21152105
}
21162106
}
2117-
walk_decl(self, decl);
2107+
walk_stmt(self, stmt);
21182108
}
21192109

21202110
fn visit_expr(&mut self, expr: &'tcx Expr) {
@@ -2261,7 +2251,7 @@ struct LoopNestVisitor {
22612251

22622252
impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
22632253
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
2264-
if stmt.node.id() == self.id {
2254+
if stmt.id == self.id {
22652255
self.nesting = LookFurther;
22662256
} else if self.nesting == Unknown {
22672257
walk_stmt(self, stmt);

clippy_lints/src/map_unit_fn.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
131131
// If block only contains statements,
132132
// reduce `{ X; }` to `X` or `X;`
133133
match inner_stmt.node {
134-
hir::StmtKind::Decl(ref d, _) => Some(d.span),
135-
hir::StmtKind::Expr(ref e, _) => Some(e.span),
136-
hir::StmtKind::Semi(_, _) => Some(inner_stmt.span),
134+
hir::StmtKind::Local(ref local) => Some(local.span),
135+
hir::StmtKind::Expr(ref e) => Some(e.span),
136+
hir::StmtKind::Semi(..) => Some(inner_stmt.span),
137+
hir::StmtKind::Item(..) => None,
137138
}
138139
},
139140
_ => {
@@ -250,7 +251,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
250251
return;
251252
}
252253

253-
if let hir::StmtKind::Semi(ref expr, _) = stmt.node {
254+
if let hir::StmtKind::Semi(ref expr) = stmt.node {
254255
if let Some(arglists) = method_chain_args(expr, &["map"]) {
255256
lint_map_unit_fn(cx, stmt, expr, arglists[0]);
256257
}

clippy_lints/src/methods/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1336,13 +1336,11 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
13361336
_ => {},
13371337
},
13381338
hir::Node::Stmt(stmt) => {
1339-
if let hir::StmtKind::Decl(ref decl, _) = stmt.node {
1340-
if let hir::DeclKind::Local(ref loc) = decl.node {
1339+
if let hir::StmtKind::Local(ref loc) = stmt.node {
13411340
if let hir::PatKind::Ref(..) = loc.pat.node {
13421341
// let ref y = *x borrows x, let ref y = x.clone() does not
13431342
return;
13441343
}
1345-
}
13461344
}
13471345
},
13481346
_ => {},

clippy_lints/src/misc.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
277277

278278
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
279279
if_chain! {
280-
if let StmtKind::Decl(ref d, _) = s.node;
281-
if let DeclKind::Local(ref l) = d.node;
280+
if let StmtKind::Local(ref l) = s.node;
282281
if let PatKind::Binding(an, _, i, None) = l.pat.node;
283282
if let Some(ref init) = l.init;
284283
then {
@@ -316,7 +315,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
316315
}
317316
};
318317
if_chain! {
319-
if let StmtKind::Semi(ref expr, _) = s.node;
318+
if let StmtKind::Semi(ref expr) = s.node;
320319
if let ExprKind::Binary(ref binop, ref a, ref b) = expr.node;
321320
if binop.node == BinOpKind::And || binop.node == BinOpKind::Or;
322321
if let Some(sugg) = Sugg::hir_opt(cx, a);

clippy_lints/src/needless_bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn fetch_bool_block(block: &Block) -> Expression {
267267
match (&*block.stmts, block.expr.as_ref()) {
268268
(&[], Some(e)) => fetch_bool_expr(&**e),
269269
(&[ref e], None) => {
270-
if let StmtKind::Semi(ref e, _) = e.node {
270+
if let StmtKind::Semi(ref e) = e.node {
271271
if let ExprKind::Ret(_) = e.node {
272272
fetch_bool_expr(&**e)
273273
} else {

clippy_lints/src/needless_pass_by_value.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
368368
Node::Stmt(s) => {
369369
// `let <pat> = x;`
370370
if_chain! {
371-
if let StmtKind::Decl(ref decl, _) = s.node;
372-
if let DeclKind::Local(ref local) = decl.node;
371+
if let StmtKind::Local(ref local) = s.node;
373372
then {
374373
self.spans_need_deref
375374
.entry(vid)

clippy_lints/src/no_effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl LintPass for Pass {
104104

105105
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
106106
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
107-
if let StmtKind::Semi(ref expr, _) = stmt.node {
107+
if let StmtKind::Semi(ref expr) = stmt.node {
108108
if has_no_effect(cx, expr) {
109109
span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect");
110110
} else if let Some(reduced) = reduce_expression(cx, expr) {

clippy_lints/src/question_mark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Pass {
139139
if_chain! {
140140
if block.stmts.len() == 1;
141141
if let Some(expr) = block.stmts.iter().last();
142-
if let StmtKind::Semi(ref expr, _) = expr.node;
142+
if let StmtKind::Semi(ref expr) = expr.node;
143143
if let ExprKind::Ret(ref ret_expr) = expr.node;
144144
if let &Some(ref ret_expr) = ret_expr;
145145

clippy_lints/src/shadow.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, binding
115115
let len = bindings.len();
116116
for stmt in &block.stmts {
117117
match stmt.node {
118-
StmtKind::Decl(ref decl, _) => check_decl(cx, decl, bindings),
119-
StmtKind::Expr(ref e, _) | StmtKind::Semi(ref e, _) => check_expr(cx, e, bindings),
118+
StmtKind::Local(ref local) => check_local(cx, local, bindings),
119+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => check_expr(cx, e, bindings),
120+
StmtKind::Item(..) => {},
120121
}
121122
}
122123
if let Some(ref o) = block.expr {
@@ -125,21 +126,20 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, binding
125126
bindings.truncate(len);
126127
}
127128

128-
fn check_decl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx Decl, bindings: &mut Vec<(Name, Span)>) {
129-
if in_external_macro(cx.sess(), decl.span) {
129+
fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local, bindings: &mut Vec<(Name, Span)>) {
130+
if in_external_macro(cx.sess(), local.span) {
130131
return;
131132
}
132-
if higher::is_from_for_desugar(decl) {
133+
if higher::is_from_for_desugar(local) {
133134
return;
134135
}
135-
if let DeclKind::Local(ref local) = decl.node {
136136
let Local {
137137
ref pat,
138138
ref ty,
139139
ref init,
140140
span,
141141
..
142-
} = **local;
142+
} = *local;
143143
if let Some(ref t) = *ty {
144144
check_ty(cx, t, bindings)
145145
}
@@ -149,7 +149,6 @@ fn check_decl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx Decl, bindings:
149149
} else {
150150
check_pat(cx, pat, None, span, bindings);
151151
}
152-
}
153152
}
154153

155154
fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool {

clippy_lints/src/slow_vector_initialization.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9191
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
9292
// Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)`
9393
if_chain! {
94-
if let StmtKind::Decl(ref decl, _) = stmt.node;
95-
if let DeclKind::Local(ref local) = decl.node;
94+
if let StmtKind::Local(ref local) = stmt.node;
9695
if let PatKind::Binding(BindingAnnotation::Mutable, _, variable_name, None) = local.pat.node;
9796
if let Some(ref init) = local.init;
9897
if let Some(ref len_arg) = Self::is_vec_with_capacity(init);
@@ -104,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
104103
len_expr: len_arg,
105104
};
106105

107-
Self::search_initialization(cx, vi, stmt.node.id());
106+
Self::search_initialization(cx, vi, stmt.id);
108107
}
109108
}
110109
}
@@ -287,7 +286,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> {
287286
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
288287
if self.initialization_found {
289288
match stmt.node {
290-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => {
289+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => {
291290
self.search_slow_extend_filling(expr);
292291
self.search_slow_resize_filling(expr);
293292
},

0 commit comments

Comments
 (0)