77// option. This file may not be copied, modified, or distributed
88// except according to those terms.
99
10+ use crate :: rustc:: hir:: def:: { CtorKind , Def } ;
1011use crate :: rustc:: hir:: intravisit:: { walk_path, walk_ty, NestedVisitorMap , Visitor } ;
1112use crate :: rustc:: hir:: * ;
1213use crate :: rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
@@ -30,8 +31,7 @@ use if_chain::if_chain;
3031/// - False positive when using associated types (#2843)
3132/// - False positives in some situations when using generics (#3410)
3233/// - False positive when type from outer function can't be used (#3463)
33- /// - Does not diagnose tuple structs (#3498)
34- /// - Does not trigger in lifetimed struct
34+ /// - Does not trigger in lifetimed structs
3535///
3636/// **Example:**
3737/// ```rust
@@ -232,10 +232,15 @@ struct UseSelfVisitor<'a, 'tcx: 'a> {
232232
233233impl < ' a , ' tcx > Visitor < ' tcx > for UseSelfVisitor < ' a , ' tcx > {
234234 fn visit_path ( & mut self , path : & ' tcx Path , _id : HirId ) {
235- if self . item_path . def == path. def && path. segments . last ( ) . expect ( SEGMENTS_MSG ) . ident . name != SelfUpper . name ( ) {
236- span_use_self_lint ( self . cx , path) ;
235+ if path. segments . last ( ) . expect ( SEGMENTS_MSG ) . ident . name != SelfUpper . name ( ) {
236+ if self . item_path . def == path. def {
237+ span_use_self_lint ( self . cx , path) ;
238+ } else if let Def :: StructCtor ( ctor_did, CtorKind :: Fn ) = path. def {
239+ if self . item_path . def . opt_def_id ( ) == self . cx . tcx . parent_def_id ( ctor_did) {
240+ span_use_self_lint ( self . cx , path) ;
241+ }
242+ }
237243 }
238-
239244 walk_path ( self , path) ;
240245 }
241246
0 commit comments