@@ -446,15 +446,15 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
446
446
struct ProhibitOpaqueVisitor < ' tcx > {
447
447
opaque_identity_ty : Ty < ' tcx > ,
448
448
generics : & ' tcx ty:: Generics ,
449
- ty : Option < Ty < ' tcx > > ,
450
449
} ;
451
450
452
451
impl < ' tcx > ty:: fold:: TypeVisitor < ' tcx > for ProhibitOpaqueVisitor < ' tcx > {
452
+ type BreakTy = Option < Ty < ' tcx > > ;
453
+
453
454
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> ControlFlow < Self :: BreakTy > {
454
455
debug ! ( "check_opaque_for_inheriting_lifetimes: (visit_ty) t={:?}" , t) ;
455
456
if t != self . opaque_identity_ty && t. super_visit_with ( self ) . is_break ( ) {
456
- self . ty = Some ( t) ;
457
- return ControlFlow :: BREAK ;
457
+ return ControlFlow :: Break ( Some ( t) ) ;
458
458
}
459
459
ControlFlow :: CONTINUE
460
460
}
@@ -463,7 +463,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
463
463
debug ! ( "check_opaque_for_inheriting_lifetimes: (visit_region) r={:?}" , r) ;
464
464
if let RegionKind :: ReEarlyBound ( ty:: EarlyBoundRegion { index, .. } ) = r {
465
465
if * index < self . generics . parent_count as u32 {
466
- return ControlFlow :: BREAK ;
466
+ return ControlFlow :: Break ( None ) ;
467
467
} else {
468
468
return ControlFlow :: CONTINUE ;
469
469
}
@@ -494,18 +494,17 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
494
494
InternalSubsts :: identity_for_item ( tcx, def_id. to_def_id ( ) ) ,
495
495
) ,
496
496
generics : tcx. generics_of ( def_id) ,
497
- ty : None ,
498
497
} ;
499
498
let prohibit_opaque = tcx
500
499
. explicit_item_bounds ( def_id)
501
500
. iter ( )
502
- . any ( |( predicate, _) | predicate. visit_with ( & mut visitor) . is_break ( ) ) ;
501
+ . try_for_each ( |( predicate, _) | predicate. visit_with ( & mut visitor) ) ;
503
502
debug ! (
504
503
"check_opaque_for_inheriting_lifetimes: prohibit_opaque={:?}, visitor={:?}" ,
505
504
prohibit_opaque, visitor
506
505
) ;
507
506
508
- if prohibit_opaque {
507
+ if let Some ( ty ) = prohibit_opaque. break_value ( ) {
509
508
let is_async = match item. kind {
510
509
ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) => match origin {
511
510
hir:: OpaqueTyOrigin :: AsyncFn => true ,
@@ -525,7 +524,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
525
524
526
525
if let Ok ( snippet) = tcx. sess . source_map ( ) . span_to_snippet ( span) {
527
526
if snippet == "Self" {
528
- if let Some ( ty) = visitor . ty {
527
+ if let Some ( ty) = ty {
529
528
err. span_suggestion (
530
529
span,
531
530
"consider spelling out the type instead" ,
0 commit comments