Skip to content

Commit 0ac5851

Browse files
authored
Rollup merge of #113795 - compiler-errors:doc, r=spastorino
Properly document `lifetime_mapping` in `OpaqueTy` Also use an `Option` to signify that the value is actually present, instead of just no captured lifetimes.
2 parents 0084c2c + 603fd42 commit 0ac5851

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1619,13 +1619,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16191619
debug!(?hir_bounds);
16201620

16211621
let lifetime_mapping = if in_trait {
1622-
self.arena.alloc_from_iter(
1623-
collected_lifetime_mapping
1624-
.iter()
1625-
.map(|(lifetime, def_id)| (**lifetime, *def_id)),
1622+
Some(
1623+
&*self.arena.alloc_from_iter(
1624+
collected_lifetime_mapping
1625+
.iter()
1626+
.map(|(lifetime, def_id)| (**lifetime, *def_id)),
1627+
),
16261628
)
16271629
} else {
1628-
&mut []
1630+
None
16291631
};
16301632

16311633
let opaque_ty_item = hir::OpaqueTy {
@@ -2090,13 +2092,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20902092
debug!("lower_async_fn_ret_ty: generic_params={:#?}", generic_params);
20912093

20922094
let lifetime_mapping = if in_trait {
2093-
self.arena.alloc_from_iter(
2094-
collected_lifetime_mapping
2095-
.iter()
2096-
.map(|(lifetime, def_id)| (**lifetime, *def_id)),
2095+
Some(
2096+
&*self.arena.alloc_from_iter(
2097+
collected_lifetime_mapping
2098+
.iter()
2099+
.map(|(lifetime, def_id)| (**lifetime, *def_id)),
2100+
),
20972101
)
20982102
} else {
2099-
&mut []
2103+
None
21002104
};
21012105

21022106
let opaque_ty_item = hir::OpaqueTy {

compiler/rustc_hir/src/hir.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -2664,10 +2664,19 @@ pub struct OpaqueTy<'hir> {
26642664
pub generics: &'hir Generics<'hir>,
26652665
pub bounds: GenericBounds<'hir>,
26662666
pub origin: OpaqueTyOrigin,
2667-
// Opaques have duplicated lifetimes, this mapping connects the original lifetime with the copy
2668-
// so we can later generate bidirectional outlives predicates to enforce that these lifetimes
2669-
// stay in sync.
2670-
pub lifetime_mapping: &'hir [(Lifetime, LocalDefId)],
2667+
/// Return-position impl traits (and async futures) must "reify" any late-bound
2668+
/// lifetimes that are captured from the function signature they originate from.
2669+
///
2670+
/// This is done by generating a new early-bound lifetime parameter local to the
2671+
/// opaque which is substituted in the function signature with the late-bound
2672+
/// lifetime.
2673+
///
2674+
/// This mapping associated a captured lifetime (first parameter) with the new
2675+
/// early-bound lifetime that was generated for the opaque.
2676+
pub lifetime_mapping: Option<&'hir [(Lifetime, LocalDefId)]>,
2677+
/// Whether the opaque is a return-position impl trait (or async future)
2678+
/// originating from a trait method. This makes it so that the opaque is
2679+
/// lowered as an associated type.
26712680
pub in_trait: bool,
26722681
}
26732682

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
6666
let opaque_ty_id = tcx.hir().local_def_id_to_hir_id(opaque_def_id.expect_local());
6767
let opaque_ty_node = tcx.hir().get(opaque_ty_id);
6868
let Node::Item(&Item {
69-
kind: ItemKind::OpaqueTy(OpaqueTy { lifetime_mapping, .. }),
69+
kind: ItemKind::OpaqueTy(OpaqueTy { lifetime_mapping: Some(lifetime_mapping), .. }),
7070
..
7171
}) = opaque_ty_node
7272
else {

0 commit comments

Comments
 (0)