1
1
use rustc:: lint:: * ;
2
2
use rustc:: hir;
3
3
use rustc:: hir:: BindingAnnotation ;
4
+ use rustc:: hir:: def:: Def ;
5
+ use syntax:: ast;
4
6
use utils:: { snippet, span_lint_and_then} ;
5
7
6
8
/// **What it does:** Checks for variable declarations immediately followed by a
@@ -65,19 +67,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
65
67
let Some ( expr) = it. peek( ) ,
66
68
let hir:: StmtDecl ( ref decl, _) = stmt. node,
67
69
let hir:: DeclLocal ( ref decl) = decl. node,
68
- let hir:: PatKind :: Binding ( mode, def_id , ref name, None ) = decl. pat. node,
70
+ let hir:: PatKind :: Binding ( mode, canonical_id , ref name, None ) = decl. pat. node,
69
71
let hir:: StmtExpr ( ref if_, _) = expr. node,
70
72
let hir:: ExprIf ( ref cond, ref then, ref else_) = if_. node,
71
- !used_in_expr( cx, def_id , cond) ,
73
+ !used_in_expr( cx, canonical_id , cond) ,
72
74
let hir:: ExprBlock ( ref then) = then. node,
73
- let Some ( value) = check_assign( cx, def_id , & * then) ,
74
- !used_in_expr( cx, def_id , value) ,
75
+ let Some ( value) = check_assign( cx, canonical_id , & * then) ,
76
+ !used_in_expr( cx, canonical_id , value) ,
75
77
] , {
76
78
let span = stmt. span. to( if_. span) ;
77
79
78
80
let ( default_multi_stmts, default ) = if let Some ( ref else_) = * else_ {
79
81
if let hir:: ExprBlock ( ref else_) = else_. node {
80
- if let Some ( default ) = check_assign( cx, def_id , else_) {
82
+ if let Some ( default ) = check_assign( cx, canonical_id , else_) {
81
83
( else_. stmts. len( ) > 1 , default )
82
84
} else if let Some ( ref default ) = decl. init {
83
85
( true , & * * default )
@@ -130,15 +132,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
130
132
131
133
struct UsedVisitor < ' a , ' tcx : ' a > {
132
134
cx : & ' a LateContext < ' a , ' tcx > ,
133
- id : hir :: def_id :: DefId ,
135
+ id : ast :: NodeId ,
134
136
used : bool ,
135
137
}
136
138
137
139
impl < ' a , ' tcx > hir:: intravisit:: Visitor < ' tcx > for UsedVisitor < ' a , ' tcx > {
138
140
fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr ) {
139
141
if_let_chain ! { [
140
142
let hir:: ExprPath ( ref qpath) = expr. node,
141
- self . id == self . cx. tables. qpath_def( qpath, expr. hir_id) . def_id( ) ,
143
+ let Def :: Local ( local_id) = self . cx. tables. qpath_def( qpath, expr. hir_id) ,
144
+ self . id == local_id,
142
145
] , {
143
146
self . used = true ;
144
147
return ;
@@ -152,7 +155,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
152
155
153
156
fn check_assign < ' a , ' tcx > (
154
157
cx : & LateContext < ' a , ' tcx > ,
155
- decl : hir :: def_id :: DefId ,
158
+ decl : ast :: NodeId ,
156
159
block : & ' tcx hir:: Block ,
157
160
) -> Option < & ' tcx hir:: Expr > {
158
161
if_let_chain ! { [
@@ -161,7 +164,8 @@ fn check_assign<'a, 'tcx>(
161
164
let hir:: StmtSemi ( ref expr, _) = expr. node,
162
165
let hir:: ExprAssign ( ref var, ref value) = expr. node,
163
166
let hir:: ExprPath ( ref qpath) = var. node,
164
- decl == cx. tables. qpath_def( qpath, var. hir_id) . def_id( ) ,
167
+ let Def :: Local ( local_id) = cx. tables. qpath_def( qpath, var. hir_id) ,
168
+ decl == local_id,
165
169
] , {
166
170
let mut v = UsedVisitor {
167
171
cx: cx,
@@ -183,7 +187,7 @@ fn check_assign<'a, 'tcx>(
183
187
None
184
188
}
185
189
186
- fn used_in_expr < ' a , ' tcx : ' a > ( cx : & LateContext < ' a , ' tcx > , id : hir :: def_id :: DefId , expr : & ' tcx hir:: Expr ) -> bool {
190
+ fn used_in_expr < ' a , ' tcx : ' a > ( cx : & LateContext < ' a , ' tcx > , id : ast :: NodeId , expr : & ' tcx hir:: Expr ) -> bool {
187
191
let mut v = UsedVisitor {
188
192
cx : cx,
189
193
id : id,
0 commit comments