@@ -883,7 +883,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
883
883
} )
884
884
. collect ( ) ;
885
885
if !lifetimes. is_empty ( ) {
886
- self . trait_ref_hack = true ;
887
886
let next_early_index = self . next_early_index ( ) ;
888
887
let scope = Scope :: Binder {
889
888
lifetimes,
@@ -895,9 +894,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
895
894
let result = self . with ( scope, |old_scope, this| {
896
895
this. check_lifetime_params ( old_scope, & bound_generic_params) ;
897
896
this. visit_ty ( & bounded_ty) ;
897
+ this. trait_ref_hack = true ;
898
898
walk_list ! ( this, visit_param_bound, bounds) ;
899
+ this. trait_ref_hack = false ;
899
900
} ) ;
900
- self . trait_ref_hack = false ;
901
901
result
902
902
} else {
903
903
self . visit_ty ( & bounded_ty) ;
@@ -932,13 +932,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
932
932
debug ! ( "visit_poly_trait_ref(trait_ref={:?})" , trait_ref) ;
933
933
934
934
let should_pop_missing_lt = self . is_trait_ref_fn_scope ( trait_ref) ;
935
- if !self . trait_ref_hack
935
+
936
+ let trait_ref_hack = take ( & mut self . trait_ref_hack ) ;
937
+ if !trait_ref_hack
936
938
|| trait_ref. bound_generic_params . iter ( ) . any ( |param| match param. kind {
937
939
GenericParamKind :: Lifetime { .. } => true ,
938
940
_ => false ,
939
941
} )
940
942
{
941
- if self . trait_ref_hack {
943
+ if trait_ref_hack {
942
944
struct_span_err ! (
943
945
self . tcx. sess,
944
946
trait_ref. span,
@@ -968,10 +970,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
968
970
this. check_lifetime_params ( old_scope, & trait_ref. bound_generic_params ) ;
969
971
walk_list ! ( this, visit_generic_param, trait_ref. bound_generic_params) ;
970
972
this. visit_trait_ref ( & trait_ref. trait_ref ) ;
971
- } )
973
+ } ) ;
972
974
} else {
973
975
self . visit_trait_ref ( & trait_ref. trait_ref ) ;
974
976
}
977
+ self . trait_ref_hack = trait_ref_hack;
975
978
if should_pop_missing_lt {
976
979
self . missing_named_lifetime_spots . pop ( ) ;
977
980
}
0 commit comments