@@ -908,7 +908,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
908
908
} )
909
909
. collect ( ) ;
910
910
if !lifetimes. is_empty ( ) {
911
- self . trait_ref_hack = true ;
912
911
let next_early_index = self . next_early_index ( ) ;
913
912
let scope = Scope :: Binder {
914
913
lifetimes,
@@ -920,9 +919,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
920
919
let result = self . with ( scope, |old_scope, this| {
921
920
this. check_lifetime_params ( old_scope, & bound_generic_params) ;
922
921
this. visit_ty ( & bounded_ty) ;
922
+ this. trait_ref_hack = true ;
923
923
walk_list ! ( this, visit_param_bound, bounds) ;
924
+ this. trait_ref_hack = false ;
924
925
} ) ;
925
- self . trait_ref_hack = false ;
926
926
result
927
927
} else {
928
928
self . visit_ty ( & bounded_ty) ;
@@ -957,13 +957,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
957
957
debug ! ( "visit_poly_trait_ref(trait_ref={:?})" , trait_ref) ;
958
958
959
959
let should_pop_missing_lt = self . is_trait_ref_fn_scope ( trait_ref) ;
960
- if !self . trait_ref_hack
960
+
961
+ let trait_ref_hack = take ( & mut self . trait_ref_hack ) ;
962
+ if !trait_ref_hack
961
963
|| trait_ref. bound_generic_params . iter ( ) . any ( |param| match param. kind {
962
964
GenericParamKind :: Lifetime { .. } => true ,
963
965
_ => false ,
964
966
} )
965
967
{
966
- if self . trait_ref_hack {
968
+ if trait_ref_hack {
967
969
struct_span_err ! (
968
970
self . tcx. sess,
969
971
trait_ref. span,
@@ -993,10 +995,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
993
995
this. check_lifetime_params ( old_scope, & trait_ref. bound_generic_params ) ;
994
996
walk_list ! ( this, visit_generic_param, trait_ref. bound_generic_params) ;
995
997
this. visit_trait_ref ( & trait_ref. trait_ref ) ;
996
- } )
998
+ } ) ;
997
999
} else {
998
1000
self . visit_trait_ref ( & trait_ref. trait_ref ) ;
999
1001
}
1002
+ self . trait_ref_hack = trait_ref_hack;
1000
1003
if should_pop_missing_lt {
1001
1004
self . missing_named_lifetime_spots . pop ( ) ;
1002
1005
}
0 commit comments