@@ -2,7 +2,7 @@ use clippy_config::Conf;
2
2
use clippy_utils:: diagnostics:: span_lint_and_sugg;
3
3
use clippy_utils:: is_from_proc_macro;
4
4
use clippy_utils:: msrvs:: { self , Msrv } ;
5
- use clippy_utils:: ty:: same_type_and_consts;
5
+ use clippy_utils:: ty:: { same_type_and_consts, ty_from_hir_ty } ;
6
6
use rustc_data_structures:: fx:: FxHashSet ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
@@ -12,7 +12,6 @@ use rustc_hir::{
12
12
self as hir, AmbigArg , Expr , ExprKind , FnRetTy , FnSig , GenericArgsParentheses , GenericParam , GenericParamKind ,
13
13
HirId , Impl , ImplItemKind , Item , ItemKind , Pat , PatKind , Path , QPath , Ty , TyKind ,
14
14
} ;
15
- use rustc_hir_analysis:: lower_ty;
16
15
use rustc_lint:: { LateContext , LateLintPass } ;
17
16
use rustc_middle:: ty:: Ty as MiddleTy ;
18
17
use rustc_session:: impl_lint_pass;
@@ -73,7 +72,6 @@ impl UseSelf {
73
72
enum StackItem {
74
73
Check {
75
74
impl_id : LocalDefId ,
76
- in_body : u32 ,
77
75
types_to_skip : FxHashSet < HirId > ,
78
76
} ,
79
77
NoCheck ,
@@ -117,7 +115,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
117
115
. collect ( ) ;
118
116
StackItem :: Check {
119
117
impl_id : item. owner_id . def_id ,
120
- in_body : 0 ,
121
118
types_to_skip,
122
119
}
123
120
} else {
@@ -186,27 +183,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
186
183
}
187
184
}
188
185
189
- fn check_body ( & mut self , _: & LateContext < ' _ > , _: & hir:: Body < ' _ > ) {
190
- // `lower_ty` cannot be called in `Body`s or it will panic (sometimes). But in bodies
191
- // we can use `cx.typeck_results.node_type(..)` to get the `ty::Ty` from a `hir::Ty`.
192
- // However the `node_type()` method can *only* be called in bodies.
193
- if let Some ( & mut StackItem :: Check { ref mut in_body, .. } ) = self . stack . last_mut ( ) {
194
- * in_body = in_body. saturating_add ( 1 ) ;
195
- }
196
- }
197
-
198
- fn check_body_post ( & mut self , _: & LateContext < ' _ > , _: & hir:: Body < ' _ > ) {
199
- if let Some ( & mut StackItem :: Check { ref mut in_body, .. } ) = self . stack . last_mut ( ) {
200
- * in_body = in_body. saturating_sub ( 1 ) ;
201
- }
202
- }
203
186
204
187
fn check_ty ( & mut self , cx : & LateContext < ' tcx > , hir_ty : & Ty < ' tcx , AmbigArg > ) {
205
188
if !hir_ty. span . from_expansion ( )
206
189
&& self . msrv . meets ( msrvs:: TYPE_ALIAS_ENUM_VARIANTS )
207
190
&& let Some ( & StackItem :: Check {
208
191
impl_id,
209
- in_body,
210
192
ref types_to_skip,
211
193
} ) = self . stack . last ( )
212
194
&& let TyKind :: Path ( QPath :: Resolved ( _, path) ) = hir_ty. kind
@@ -215,12 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
215
197
Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. } | Res :: Def ( DefKind :: TyParam , _)
216
198
)
217
199
&& !types_to_skip. contains ( & hir_ty. hir_id )
218
- && let ty = if in_body > 0 {
219
- cx. typeck_results ( ) . node_type ( hir_ty. hir_id )
220
- } else {
221
- // We don't care about ignoring infer vars here
222
- lower_ty ( cx. tcx , hir_ty. as_unambig_ty ( ) )
223
- }
200
+ && let ty = ty_from_hir_ty ( cx, hir_ty)
224
201
&& let impl_ty = cx. tcx . type_of ( impl_id) . instantiate_identity ( )
225
202
&& same_type_and_consts ( ty, impl_ty)
226
203
// Ensure the type we encounter and the one from the impl have the same lifetime parameters. It may be that
0 commit comments