Skip to content

forbid defining opaque types with regions in closures #134688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ pub(crate) fn compute_regions<'a, 'tcx>(
infcx.set_tainted_by_errors(guar);
}

let remapped_opaque_tys = regioncx.infer_opaque_types(infcx, opaque_type_values);
let remapped_opaque_tys = regioncx.infer_opaque_types(
infcx,
infcx.tcx.is_typeck_child(body.source.def_id()),
opaque_type_values,
);

NllOutput {
regioncx,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn infer_opaque_types(
&self,
infcx: &InferCtxt<'tcx>,
is_typeck_child: bool,
opaque_ty_decls: FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>>,
) -> FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> {
let mut result: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>> = FxIndexMap::default();
Expand All @@ -73,6 +74,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {

for (opaque_type_key, concrete_type) in opaque_ty_decls {
debug!(?opaque_type_key, ?concrete_type);
if is_typeck_child && opaque_type_key.args.iter().any(|arg| arg.as_region().is_some()) {
let guar = infcx.dcx().span_err(
concrete_type.span,
"defining of opaque type in closure involving regions",
);
result.insert(opaque_type_key.def_id, OpaqueHiddenType {
span: concrete_type.span,
ty: Ty::new_error(infcx.tcx, guar),
});
continue;
}

let mut arg_regions: Vec<(ty::RegionVid, ty::Region<'_>)> =
vec![(self.universal_regions().fr_static, infcx.tcx.lifetimes.re_static)];
Expand Down
Loading