]> git.lizzy.rs Git - rust.git/commitdiff
resolve: support `GenericBound::LangItemTrait`
authorDavid Wood <david@davidtw.co>
Tue, 4 Aug 2020 13:19:28 +0000 (14:19 +0100)
committerDavid Wood <david@davidtw.co>
Sun, 16 Aug 2020 14:42:29 +0000 (15:42 +0100)
This commit modifies name resolution to ensure that new scopes are
introduced from lang-item generic bounds.

Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
Signed-off-by: David Wood <david@davidtw.co>
src/librustc_resolve/late/lifetimes.rs

index e2f0d388f7e5373eaa0e470017e0aa75e8c2c0d3..31360d474736a813ea0f448bdbe2b54378e55fe7 100644 (file)
@@ -941,6 +941,24 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
         }
     }
 
+    fn visit_param_bound(&mut self, bound: &'tcx hir::GenericBound<'tcx>) {
+        match bound {
+            hir::GenericBound::LangItemTrait { .. } if !self.trait_ref_hack => {
+                let scope = Scope::Binder {
+                    lifetimes: FxHashMap::default(),
+                    s: self.scope,
+                    next_early_index: self.next_early_index(),
+                    track_lifetime_uses: true,
+                    opaque_type_parent: false,
+                };
+                self.with(scope, |_, this| {
+                    intravisit::walk_param_bound(this, bound);
+                });
+            }
+            _ => intravisit::walk_param_bound(self, bound),
+        }
+    }
+
     fn visit_poly_trait_ref(
         &mut self,
         trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
@@ -2296,6 +2314,16 @@ fn visit_poly_trait_ref(
                 self.outer_index.shift_out(1);
             }
 
+            fn visit_param_bound(&mut self, bound: &hir::GenericBound<'_>) {
+                if let hir::GenericBound::LangItemTrait { .. } = bound {
+                    self.outer_index.shift_in(1);
+                    intravisit::walk_param_bound(self, bound);
+                    self.outer_index.shift_out(1);
+                } else {
+                    intravisit::walk_param_bound(self, bound);
+                }
+            }
+
             fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
                 if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) {
                     match lifetime {