@@ -101,33 +101,31 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
101
101
102
102
fn check_ty ( & mut self , cx : & LateContext < ' _ > , ty : & ' tcx Ty < ' tcx > ) {
103
103
match & ty. kind {
104
- TyKind :: Path ( qpath) => {
105
- if let QPath :: Resolved ( _, path) = qpath {
106
- if let Some ( last) = path. segments . iter ( ) . last ( ) {
107
- if lint_ty_kind_usage ( cx, last) {
108
- cx. struct_span_lint ( USAGE_OF_TY_TYKIND , path. span , |lint| {
109
- lint. build ( "usage of `ty::TyKind`" )
110
- . help ( "try using `Ty` instead" )
111
- . emit ( ) ;
112
- } )
113
- } else {
114
- if ty. span . from_expansion ( ) {
115
- return ;
116
- }
117
- if let Some ( t) = is_ty_or_ty_ctxt ( cx, ty) {
118
- if path. segments . len ( ) > 1 {
119
- cx. struct_span_lint ( USAGE_OF_QUALIFIED_TY , path. span , |lint| {
120
- lint. build ( & format ! ( "usage of qualified `ty::{}`" , t) )
121
- . span_suggestion (
122
- path. span ,
123
- "try using it unqualified" ,
124
- t,
125
- // The import probably needs to be changed
126
- Applicability :: MaybeIncorrect ,
127
- )
128
- . emit ( ) ;
129
- } )
130
- }
104
+ TyKind :: Path ( QPath :: Resolved ( _, path) ) => {
105
+ if let Some ( last) = path. segments . iter ( ) . last ( ) {
106
+ if lint_ty_kind_usage ( cx, last) {
107
+ cx. struct_span_lint ( USAGE_OF_TY_TYKIND , path. span , |lint| {
108
+ lint. build ( "usage of `ty::TyKind`" )
109
+ . help ( "try using `Ty` instead" )
110
+ . emit ( ) ;
111
+ } )
112
+ } else {
113
+ if ty. span . from_expansion ( ) {
114
+ return ;
115
+ }
116
+ if let Some ( t) = is_ty_or_ty_ctxt ( cx, ty) {
117
+ if path. segments . len ( ) > 1 {
118
+ cx. struct_span_lint ( USAGE_OF_QUALIFIED_TY , path. span , |lint| {
119
+ lint. build ( & format ! ( "usage of qualified `ty::{}`" , t) )
120
+ . span_suggestion (
121
+ path. span ,
122
+ "try using it unqualified" ,
123
+ t,
124
+ // The import probably needs to be changed
125
+ Applicability :: MaybeIncorrect ,
126
+ )
127
+ . emit ( ) ;
128
+ } )
131
129
}
132
130
}
133
131
}
@@ -169,37 +167,30 @@ fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
169
167
}
170
168
171
169
fn is_ty_or_ty_ctxt ( cx : & LateContext < ' _ > , ty : & Ty < ' _ > ) -> Option < String > {
172
- if let TyKind :: Path ( qpath) = & ty. kind {
173
- if let QPath :: Resolved ( _, path) = qpath {
174
- match path. res {
175
- Res :: Def ( _, def_id) => {
176
- if let Some ( name @ ( sym:: Ty | sym:: TyCtxt ) ) = cx. tcx . get_diagnostic_name ( def_id)
177
- {
178
- return Some ( format ! (
179
- "{}{}" ,
180
- name,
181
- gen_args( path. segments. last( ) . unwrap( ) )
182
- ) ) ;
183
- }
170
+ if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = & ty. kind {
171
+ match path. res {
172
+ Res :: Def ( _, def_id) => {
173
+ if let Some ( name @ ( sym:: Ty | sym:: TyCtxt ) ) = cx. tcx . get_diagnostic_name ( def_id) {
174
+ return Some ( format ! ( "{}{}" , name, gen_args( path. segments. last( ) . unwrap( ) ) ) ) ;
184
175
}
185
- // Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
186
- Res :: SelfTy ( None , Some ( ( did , _ ) ) ) => {
187
- if let ty :: Adt ( adt , substs ) = cx . tcx . type_of ( did) . kind ( ) {
188
- if let Some ( name @ ( sym :: Ty | sym :: TyCtxt ) ) =
189
- cx . tcx . get_diagnostic_name ( adt . did )
190
- {
191
- // NOTE: This path is currently unreachable as `Ty<'tcx>` is
192
- // defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
193
- // is not actually allowed.
194
- //
195
- // I(@lcnr) still kept this branch in so we don't miss this
196
- // if we ever change it in the future.
197
- return Some ( format ! ( "{}<{}>" , name , substs [ 0 ] ) ) ;
198
- }
176
+ }
177
+ // Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
178
+ Res :: SelfTy ( None , Some ( ( did, _ ) ) ) => {
179
+ if let ty :: Adt ( adt , substs ) = cx . tcx . type_of ( did ) . kind ( ) {
180
+ if let Some ( name @ ( sym :: Ty | sym :: TyCtxt ) ) =
181
+ cx . tcx . get_diagnostic_name ( adt . did )
182
+ {
183
+ // NOTE: This path is currently unreachable as ` Ty<'tcx>` is
184
+ // defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
185
+ // is not actually allowed.
186
+ //
187
+ // I(@lcnr) still kept this branch in so we don't miss this
188
+ // if we ever change it in the future.
189
+ return Some ( format ! ( "{}<{}>" , name , substs [ 0 ] ) ) ;
199
190
}
200
191
}
201
- _ => ( ) ,
202
192
}
193
+ _ => ( ) ,
203
194
}
204
195
}
205
196
0 commit comments