@@ -30,7 +30,6 @@ declare_clippy_lint! {
30
30
///
31
31
/// ### Known problems
32
32
/// - Unaddressed false negative in fn bodies of trait implementations
33
- /// - False positive with associated types in traits (#4140)
34
33
///
35
34
/// ### Example
36
35
/// ```rust
@@ -235,24 +234,13 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
235
234
then { } else { return ; }
236
235
}
237
236
match expr. kind {
238
- ExprKind :: Struct ( QPath :: Resolved ( _, path) , ..) => match path. res {
239
- Res :: SelfTyParam { .. } | Res :: SelfTyAlias { .. } => ( ) ,
240
- Res :: Def ( DefKind :: Variant , _) => lint_path_to_variant ( cx, path) ,
241
- _ => span_lint ( cx, path. span ) ,
242
- } ,
243
- // tuple struct instantiation (`Foo(arg)` or `Enum::Foo(arg)`)
237
+ ExprKind :: Struct ( QPath :: Resolved ( _, path) , ..) => check_path ( cx, path) ,
244
238
ExprKind :: Call ( fun, _) => {
245
239
if let ExprKind :: Path ( QPath :: Resolved ( _, path) ) = fun. kind {
246
- if let Res :: Def ( DefKind :: Ctor ( ctor_of, _) , ..) = path. res {
247
- match ctor_of {
248
- CtorOf :: Variant => lint_path_to_variant ( cx, path) ,
249
- CtorOf :: Struct => span_lint ( cx, path. span ) ,
250
- }
251
- }
240
+ check_path ( cx, path) ;
252
241
}
253
242
} ,
254
- // unit enum variants (`Enum::A`)
255
- ExprKind :: Path ( QPath :: Resolved ( _, path) ) => lint_path_to_variant ( cx, path) ,
243
+ ExprKind :: Path ( QPath :: Resolved ( _, path) ) => check_path ( cx, path) ,
256
244
_ => ( ) ,
257
245
}
258
246
}
@@ -268,15 +256,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
268
256
| PatKind :: Struct ( QPath :: Resolved ( _, path) , _, _) = pat. kind;
269
257
if cx. typeck_results( ) . pat_ty( pat) == cx. tcx. type_of( impl_id) ;
270
258
then {
271
- match path. res {
272
- Res :: Def ( DefKind :: Ctor ( ctor_of, _) , ..) => match ctor_of {
273
- CtorOf :: Variant => lint_path_to_variant( cx, path) ,
274
- CtorOf :: Struct => span_lint( cx, path. span) ,
275
- } ,
276
- Res :: Def ( DefKind :: Variant , ..) => lint_path_to_variant( cx, path) ,
277
- Res :: Def ( DefKind :: Struct , ..) => span_lint( cx, path. span) ,
278
- _ => ( )
279
- }
259
+ check_path( cx, path) ;
280
260
}
281
261
}
282
262
}
@@ -314,6 +294,16 @@ fn span_lint(cx: &LateContext<'_>, span: Span) {
314
294
) ;
315
295
}
316
296
297
+ fn check_path ( cx : & LateContext < ' _ > , path : & Path < ' _ > ) {
298
+ match path. res {
299
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , _) | DefKind :: Variant , ..) => {
300
+ lint_path_to_variant ( cx, path) ;
301
+ } ,
302
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , _) | DefKind :: Struct , ..) => span_lint ( cx, path. span ) ,
303
+ _ => ( ) ,
304
+ }
305
+ }
306
+
317
307
fn lint_path_to_variant ( cx : & LateContext < ' _ > , path : & Path < ' _ > ) {
318
308
if let [ .., self_seg, _variant] = path. segments {
319
309
let span = path
0 commit comments