Skip to content

Commit 73a3c7e

Browse files
committed
[REFACTOR] add fn finalize_opaque_types
1 parent 801821d commit 73a3c7e

File tree

1 file changed

+49
-39
lines changed
  • compiler/rustc_borrowck/src/type_check

1 file changed

+49
-39
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -200,46 +200,8 @@ pub(crate) fn type_check<'mir, 'tcx>(
200200
);
201201

202202
translate_outlives_facts(&mut cx);
203-
let opaque_type_values =
204-
infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
205-
206-
opaque_type_values
207-
.into_iter()
208-
.map(|(opaque_type_key, decl)| {
209-
cx.fully_perform_op(
210-
Locations::All(body.span),
211-
ConstraintCategory::OpaqueType,
212-
CustomTypeOp::new(
213-
|infcx| {
214-
infcx.register_member_constraints(
215-
param_env,
216-
opaque_type_key,
217-
decl.hidden_type.ty,
218-
decl.hidden_type.span,
219-
);
220-
Ok(InferOk { value: (), obligations: vec![] })
221-
},
222-
|| "opaque_type_map".to_string(),
223-
),
224-
)
225-
.unwrap();
226-
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
227-
trace!(
228-
"finalized opaque type {:?} to {:#?}",
229-
opaque_type_key,
230-
hidden_type.ty.kind()
231-
);
232-
if hidden_type.has_infer_types_or_consts() {
233-
infcx.tcx.sess.delay_span_bug(
234-
decl.hidden_type.span,
235-
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
236-
);
237-
hidden_type.ty = infcx.tcx.ty_error();
238-
}
239203

240-
(opaque_type_key, (hidden_type, decl.origin))
241-
})
242-
.collect()
204+
cx.finalize_opaque_types()
243205
},
244206
);
245207

@@ -2680,6 +2642,54 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26802642
self.check_iscleanup(&body, block_data);
26812643
}
26822644
}
2645+
2646+
/// Generates member constraints for the opaque types found so far.
2647+
/// Returns a map to their hidden types.
2648+
fn finalize_opaque_types(
2649+
&mut self,
2650+
) -> VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)> {
2651+
let opaque_type_values =
2652+
self.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
2653+
2654+
opaque_type_values
2655+
.into_iter()
2656+
.map(|(opaque_type_key, decl)| {
2657+
let param_env = self.param_env;
2658+
self.fully_perform_op(
2659+
Locations::All(self.body.span),
2660+
ConstraintCategory::OpaqueType,
2661+
CustomTypeOp::new(
2662+
|infcx| {
2663+
infcx.register_member_constraints(
2664+
param_env,
2665+
opaque_type_key,
2666+
decl.hidden_type.ty,
2667+
decl.hidden_type.span,
2668+
);
2669+
Ok(InferOk { value: (), obligations: vec![] })
2670+
},
2671+
|| "opaque_type_map".to_string(),
2672+
),
2673+
)
2674+
.unwrap();
2675+
let mut hidden_type = self.infcx.resolve_vars_if_possible(decl.hidden_type);
2676+
trace!(
2677+
"finalized opaque type {:?} to {:#?}",
2678+
opaque_type_key,
2679+
hidden_type.ty.kind()
2680+
);
2681+
if hidden_type.has_infer_types_or_consts() {
2682+
self.infcx.tcx.sess.delay_span_bug(
2683+
decl.hidden_type.span,
2684+
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
2685+
);
2686+
hidden_type.ty = self.infcx.tcx.ty_error();
2687+
}
2688+
2689+
(opaque_type_key, (hidden_type, decl.origin))
2690+
})
2691+
.collect()
2692+
}
26832693
}
26842694

26852695
trait NormalizeLocation: fmt::Debug + Copy {

0 commit comments

Comments
 (0)