@@ -172,7 +172,6 @@ enum Scope<'a> {
172172 /// it should be shifted by the number of `Binder`s in between the
173173 /// declaration `Binder` and the location it's referenced from.
174174 Binder {
175- scope_type : BinderScopeType ,
176175 s : ScopeRef < ' a > ,
177176 } ,
178177
@@ -199,35 +198,19 @@ enum Scope<'a> {
199198 Root ,
200199}
201200
202- #[ derive( Copy , Clone , Debug ) ]
203- enum BinderScopeType {
204- /// Any non-concatenating binder scopes.
205- Normal ,
206- /// Within a syntactic trait ref, there may be multiple poly trait refs that
207- /// are nested (under the `associated_type_bounds` feature). The binders of
208- /// the inner poly trait refs are extended from the outer poly trait refs
209- /// and don't increase the late bound depth. If you had
210- /// `T: for<'a> Foo<Bar: for<'b> Baz<'a, 'b>>`, then the `for<'b>` scope
211- /// would be `Concatenating`. This also used in trait refs in where clauses
212- /// where we have two binders `for<> T: for<> Foo` (I've intentionally left
213- /// out any lifetimes because they aren't needed to show the two scopes).
214- /// The inner `for<>` has a scope of `Concatenating`.
215- Concatenating ,
216- }
217-
218201type ScopeRef < ' a > = & ' a Scope < ' a > ;
219202
220203const ROOT_SCOPE : ScopeRef < ' static > = & Scope :: Root ;
221204
222205impl < ' a , ' tcx > LifetimeContext < ' a , ' tcx > {
223206 /// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
224- fn poly_trait_ref_binder_info ( & mut self ) -> BinderScopeType {
207+ fn poly_trait_ref_needs_binder ( & mut self ) -> bool {
225208 let mut scope = self . scope ;
226209 loop {
227210 match scope {
228211 // Nested poly trait refs have the binders concatenated
229- Scope :: Binder { .. } => break BinderScopeType :: Concatenating ,
230- Scope :: Body | Scope :: Root => break BinderScopeType :: Normal ,
212+ Scope :: Binder { .. } => break false ,
213+ Scope :: Body | Scope :: Root => break true ,
231214 Scope :: Static { s, .. } | Scope :: ObjectLifetimeDefault { s, .. } => scope = s,
232215 }
233216 }
@@ -249,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
249232
250233 fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
251234 if let hir:: ExprKind :: Closure ( ..) = e. kind {
252- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
235+ let scope = Scope :: Binder { s : self . scope } ;
253236 self . with ( scope, |this| {
254237 // a closure has no bounds, so everything
255238 // contained within is scoped within its binder.
@@ -287,7 +270,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
287270 | hir:: ItemKind :: Fn ( ..)
288271 | hir:: ItemKind :: Impl ( ..) => {
289272 // These kinds of items have only early-bound lifetime parameters.
290- let scope = Scope :: Binder { scope_type : BinderScopeType :: Normal , s : ROOT_SCOPE } ;
273+ let scope = Scope :: Binder { s : ROOT_SCOPE } ;
291274 self . with ( scope, |this| intravisit:: walk_item ( this, item) ) ;
292275 }
293276 }
@@ -296,7 +279,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
296279 fn visit_foreign_item ( & mut self , item : & ' tcx hir:: ForeignItem < ' tcx > ) {
297280 match item. kind {
298281 hir:: ForeignItemKind :: Fn ( ..) => {
299- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
282+ let scope = Scope :: Binder { s : self . scope } ;
300283 self . with ( scope, |this| intravisit:: walk_foreign_item ( this, item) )
301284 }
302285 hir:: ForeignItemKind :: Static ( ..) | hir:: ForeignItemKind :: Type => {
@@ -309,7 +292,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
309292 fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty < ' tcx > ) {
310293 match ty. kind {
311294 hir:: TyKind :: BareFn ( ..) => {
312- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
295+ let scope = Scope :: Binder { s : self . scope } ;
313296 self . with ( scope, |this| {
314297 // a bare fn has no bounds, so everything
315298 // contained within is scoped within its binder.
@@ -342,7 +325,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
342325 use self :: hir:: TraitItemKind :: * ;
343326 match trait_item. kind {
344327 Fn ( ..) | Type ( ..) => {
345- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
328+ let scope = Scope :: Binder { s : self . scope } ;
346329 self . with ( scope, |this| intravisit:: walk_trait_item ( this, trait_item) ) ;
347330 }
348331 // Only methods and types support generics.
@@ -354,7 +337,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
354337 use self :: hir:: ImplItemKind :: * ;
355338 match impl_item. kind {
356339 Fn ( ..) | TyAlias ( ..) => {
357- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
340+ let scope = Scope :: Binder { s : self . scope } ;
358341 self . with ( scope, |this| intravisit:: walk_impl_item ( this, impl_item) ) ;
359342 }
360343 // Only methods and types support generics.
@@ -378,7 +361,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
378361 // scope. If there happens to be a nested poly trait ref (an error), that
379362 // will be `Concatenating` anyways, so we don't have to worry about the depth
380363 // being wrong.
381- let scope = Scope :: Binder { s : self . scope , scope_type : BinderScopeType :: Normal } ;
364+ let scope = Scope :: Binder { s : self . scope } ;
382365 self . with ( scope, |this| intravisit:: walk_where_predicate ( this, predicate) )
383366 }
384367 & hir:: WherePredicate :: RegionPredicate ( ..) | & hir:: WherePredicate :: EqPredicate ( ..) => {
@@ -389,15 +372,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
389372
390373 fn visit_param_bound ( & mut self , bound : & ' tcx hir:: GenericBound < ' tcx > ) {
391374 match bound {
392- hir:: GenericBound :: LangItemTrait ( ..) => {
393- // FIXME(jackh726): This is pretty weird. `LangItemTrait` doesn't go
394- // through the regular poly trait ref code, so we don't get another
395- // chance to introduce a binder. For now, I'm keeping the existing logic
396- // of "if there isn't a Binder scope above us, add one", but I
397- // imagine there's a better way to go about this.
398- let scope_type = self . poly_trait_ref_binder_info ( ) ;
399-
400- let scope = Scope :: Binder { s : self . scope , scope_type } ;
375+ // FIXME(jackh726): This is pretty weird. `LangItemTrait` doesn't go
376+ // through the regular poly trait ref code, so we don't get another
377+ // chance to introduce a binder. For now, I'm keeping the existing logic
378+ // of "if there isn't a Binder scope above us, add one", but I
379+ // imagine there's a better way to go about this.
380+ hir:: GenericBound :: LangItemTrait ( ..) if self . poly_trait_ref_needs_binder ( ) => {
381+ let scope = Scope :: Binder { s : self . scope } ;
401382 self . with ( scope, |this| intravisit:: walk_param_bound ( this, bound) ) ;
402383 }
403384 _ => intravisit:: walk_param_bound ( self , bound) ,
@@ -411,14 +392,16 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
411392 ) {
412393 debug ! ( "visit_poly_trait_ref(trait_ref={:?})" , trait_ref) ;
413394
414- let scope_type = self . poly_trait_ref_binder_info ( ) ;
415-
416- // Always introduce a scope here, even if this is in a where clause and
417- // we introduced the binders around the bounded Ty. In that case, we
418- // just reuse the concatenation functionality also present in nested trait
419- // refs.
420- let scope = Scope :: Binder { s : self . scope , scope_type } ;
421- self . with ( scope, |this| intravisit:: walk_poly_trait_ref ( this, trait_ref, modifier) ) ;
395+ if self . poly_trait_ref_needs_binder ( ) {
396+ // Always introduce a scope here, even if this is in a where clause and
397+ // we introduced the binders around the bounded Ty. In that case, we
398+ // just reuse the concatenation functionality also present in nested trait
399+ // refs.
400+ let scope = Scope :: Binder { s : self . scope } ;
401+ self . with ( scope, |this| intravisit:: walk_poly_trait_ref ( this, trait_ref, modifier) ) ;
402+ } else {
403+ intravisit:: walk_poly_trait_ref ( self , trait_ref, modifier) ;
404+ }
422405 }
423406}
424407
@@ -601,11 +584,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
601584 let mut scope = self . scope ;
602585 let lifetime = loop {
603586 match * scope {
604- Scope :: Binder { s, scope_type, .. } => {
605- match scope_type {
606- BinderScopeType :: Normal => late_depth += 1 ,
607- BinderScopeType :: Concatenating => { }
608- }
587+ Scope :: Binder { s, .. } => {
588+ late_depth += 1 ;
609589 scope = s;
610590 }
611591
0 commit comments