Skip to content

Commit

Permalink
Adapt comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Oct 5, 2024
1 parent 12b94cd commit 7a0204e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ enum Scope<'a> {
s: ScopeRef<'a>,
},

/// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
/// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
/// Remap lifetimes that appear in opaque types to fresh lifetime parameters. Given:
/// `fn foo<'a>() -> impl MyTrait<'a> { ... }`
///
/// HIR tells us that `'a` refer to the lifetime bound on `foo`.
/// However, typeck and borrowck for opaques are work based on using a new generics type.
/// `type MyAnonTy<'b> = impl MyTrait<'b>;`
/// ^ ^ this gets resolved in the scope of
/// the opaque_ty generics
///
/// This scope collects the mapping `'a -> 'b`.
Opaque {
/// The opaque type we are traversing.
def_id: LocalDefId,
Expand Down Expand Up @@ -546,11 +549,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
}
}

/// Resolve the lifetimes that are applied to the opaque type.
/// These are resolved in the current scope.
/// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
/// `fn foo<'a>() -> MyAnonTy<'a> { ... }`
/// ^ ^this gets resolved in the current scope
/// Resolve the lifetimes inside the opaque type, and save them into
/// `opaque_captured_lifetimes`.
///
/// This method has special handling for opaques that capture all lifetimes,
/// like async desugaring.
#[instrument(level = "debug", skip(self))]
fn visit_opaque_ty(&mut self, opaque: &'tcx rustc_hir::OpaqueTy<'tcx>) {
let mut captures = FxIndexMap::default();
Expand Down Expand Up @@ -813,9 +816,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
};
self.with(scope, |this| this.visit_ty(mt.ty));
}
hir::TyKind::OpaqueDef(opaque_ty) => {
self.visit_opaque_ty(opaque_ty);
}
_ => intravisit::walk_ty(self, ty),
}
}
Expand Down

0 comments on commit 7a0204e

Please sign in to comment.