Skip to content

Commit 6fe56c3

Browse files
committed
mieeeep
1 parent fdcf5a9 commit 6fe56c3

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
4646
let tcx = infcx.tcx;
4747
// We need to eagerly map all regions to NLL vars here, as we need to make sure we've
4848
// introduced nll vars for all used placeholders.
49-
let opaque_types = opaque_types
49+
let mut opaque_types = opaque_types
5050
.into_iter()
5151
.map(|entry| {
5252
fold_regions(tcx, infcx.resolve_vars_if_possible(entry), |r, _| {
@@ -84,6 +84,14 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
8484
let mut scc_values =
8585
RegionValues::new(location_map, universal_regions.len(), placeholder_indices);
8686
scc_values.propagate_constraints(&constraint_sccs);
87+
for entry in &mut opaque_types {
88+
// Map all opaque types to their SCC representatives.
89+
*entry = fold_regions(tcx, *entry, |r, _| {
90+
let scc = constraint_sccs.scc(r.as_var());
91+
let vid = constraint_sccs.annotation(scc).representative;
92+
Region::new_var(tcx, vid)
93+
})
94+
}
8795

8896
let mut unexpected_hidden_regions = Vec::new();
8997

@@ -99,8 +107,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
99107
let mut arg_regions = vec![(universal_regions.fr_static, tcx.lifetimes.re_static)];
100108
for (_idx, captured_arg) in opaque_type_key.iter_captured_args(tcx) {
101109
if let Some(region) = captured_arg.as_region() {
102-
let scc = constraint_sccs.scc(region.as_var());
103-
let vid = constraint_sccs.annotation(scc).representative;
110+
let vid = region.as_var();
104111
if matches!(definitions[vid].origin, NllRegionVariableOrigin::FreeRegion)
105112
&& !matches!(
106113
universal_regions.region_classification(vid),
@@ -117,8 +124,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
117124
debug!(?opaque_type_key, ?hidden_type, "check defining use");
118125

119126
let opaque_type_key = opaque_type_key.fold_captured_lifetime_args(tcx, |region| {
120-
let scc = constraint_sccs.scc(region.as_var());
121-
let vid = constraint_sccs.annotation(scc).representative;
127+
let vid = region.as_var();
122128
if matches!(definitions[vid].origin, NllRegionVariableOrigin::FreeRegion) {
123129
definitions[vid].external_name.unwrap()
124130
} else {
@@ -174,6 +180,15 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
174180
}
175181

176182
for &(key, hidden_type) in &opaque_types {
183+
if !tcx.use_typing_mode_borrowck() {
184+
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
185+
&& alias_ty.def_id == key.def_id.to_def_id()
186+
&& alias_ty.args == key.args
187+
{
188+
continue;
189+
}
190+
}
191+
177192
let Some(expected) = root_cx.get_concrete_opaque_type(key.def_id) else {
178193
let guar =
179194
tcx.dcx().span_err(hidden_type.span, "non-defining use in the defining scope");
@@ -257,10 +272,9 @@ struct OpaqueHiddenTypeFolder<'a, 'tcx> {
257272

258273
impl<'tcx> OpaqueHiddenTypeFolder<'_, 'tcx> {
259274
#[instrument(level = "debug", skip(self))]
260-
fn apply_member_constraint(&mut self, r: RegionVid) -> Option<Region<'tcx>> {
261-
let member = self.constraint_sccs.scc(r);
262-
let r = self.constraint_sccs.annotation(member).representative;
263-
if let Some((_, reg)) = self.arg_regions.iter().copied().find(|&(vid, _)| vid == r) {
275+
fn apply_member_constraint(&mut self, member_vid: RegionVid) -> Option<Region<'tcx>> {
276+
let member = self.constraint_sccs.scc(member_vid);
277+
if let Some((_, reg)) = self.arg_regions.iter().copied().find(|&(vid, _)| vid == member_vid) {
264278
debug!("member equal to arg");
265279
return Some(reg);
266280
}

0 commit comments

Comments
 (0)