Skip to content

Commit 44ced4f

Browse files
committed
Adapt comments.
1 parent 51aed84 commit 44ced4f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,14 @@ enum Scope<'a> {
158158
s: ScopeRef<'a>,
159159
},
160160

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

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

0 commit comments

Comments
 (0)