Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
resolve: support GenericBound::LangItemTrait
This commit modifies name resolution to ensure that new scopes are
introduced from lang-item generic bounds.

Co-authored-by: Matthew Jasper <[email protected]>
Signed-off-by: David Wood <[email protected]>
  • Loading branch information
davidtwco and matthewjasper committed Aug 16, 2020
commit 8367af469b9005c8f5c1777a48548a80e4658076
28 changes: 28 additions & 0 deletions src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,24 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, '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>,
Expand Down Expand Up @@ -2296,6 +2314,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
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 {
Expand Down