1
+ use std:: ops:: ControlFlow ;
2
+
1
3
use clippy_utils:: diagnostics:: span_lint_and_then;
2
4
use clippy_utils:: { fn_def_id, is_from_proc_macro, is_lint_allowed} ;
3
5
use hir:: intravisit:: { walk_expr, Visitor } ;
@@ -153,35 +155,39 @@ impl<'hir> RetTy<'hir> {
153
155
/// given `ty` is not an `OpaqueDef`.
154
156
fn inner_ < ' tcx > ( cx : & LateContext < ' tcx > , ty : & Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
155
157
/// Visitor to find the type binding.
156
- struct BindingVisitor < ' tcx > {
157
- res : Option < Ty < ' tcx > > ,
158
- }
159
- impl < ' tcx > Visitor < ' tcx > for BindingVisitor < ' tcx > {
160
- fn visit_assoc_type_binding ( & mut self , type_binding : & ' tcx hir:: TypeBinding < ' tcx > ) {
161
- if self . res . is_some ( ) {
162
- return ;
163
- }
164
- if let hir:: TypeBindingKind :: Equality {
158
+ struct BindingVisitor ;
159
+
160
+ impl < ' tcx > Visitor < ' tcx > for BindingVisitor {
161
+ type Result = ControlFlow < Ty < ' tcx > > ;
162
+
163
+ fn visit_assoc_item_constraint (
164
+ & mut self ,
165
+ constraint : & ' tcx hir:: AssocItemConstraint < ' tcx > ,
166
+ ) -> Self :: Result {
167
+ if let hir:: AssocItemConstraintKind :: Equality {
165
168
term : hir:: Term :: Ty ( ty) ,
166
- } = type_binding . kind
169
+ } = constraint . kind
167
170
{
168
- self . res = Some ( * ty) ;
171
+ ControlFlow :: Break ( * ty)
172
+ } else {
173
+ ControlFlow :: Continue ( ( ) )
169
174
}
170
175
}
171
176
}
172
177
173
- let TyKind :: OpaqueDef ( item_id, ..) = ty. kind else {
174
- return None ;
175
- } ;
176
- let opaque_ty_item = cx. tcx . hir ( ) . item ( item_id) ;
177
-
178
- // Sinces the `item_id` is from a `TyKind::OpaqueDef`,
179
- // therefore the `Item` related to it should always be `OpaqueTy`.
180
- assert ! ( matches!( opaque_ty_item. kind, ItemKind :: OpaqueTy ( _) ) ) ;
181
-
182
- let mut vis = BindingVisitor { res : None } ;
183
- vis. visit_item ( opaque_ty_item) ;
184
- vis. res
178
+ if let TyKind :: OpaqueDef ( item_id, ..) = ty. kind
179
+ && let opaque_ty_item = cx. tcx . hir ( ) . item ( item_id)
180
+ && let ItemKind :: OpaqueTy ( _) = opaque_ty_item. kind
181
+ {
182
+ let mut vis = BindingVisitor ;
183
+ // Use `vis.break_value()` once it's stablized.
184
+ match vis. visit_item ( opaque_ty_item) {
185
+ ControlFlow :: Break ( res) => Some ( res) ,
186
+ ControlFlow :: Continue ( ( ) ) => None ,
187
+ }
188
+ } else {
189
+ None
190
+ }
185
191
}
186
192
187
193
match fn_ret_ty {
@@ -198,7 +204,12 @@ impl<'hir> RetTy<'hir> {
198
204
}
199
205
}
200
206
fn is_never ( & self ) -> bool {
201
- let Self :: Return ( ty) = self else { return false } ;
202
- matches ! ( ty. kind, TyKind :: Never )
207
+ matches ! (
208
+ self ,
209
+ RetTy :: Return ( Ty {
210
+ kind: TyKind :: Never ,
211
+ ..
212
+ } )
213
+ )
203
214
}
204
215
}
0 commit comments