1
Fork 0

Editon 2021 enables precise capture

This commit is contained in:
Aman Arora 2021-06-27 02:22:46 -04:00
parent 3e9d7ecf78
commit b89ea96660
141 changed files with 462 additions and 1280 deletions

View file

@ -217,6 +217,10 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
ty::ClosureKind::FnOnce => {}
}
// We won't be building MIR if the closure wasn't local
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
let closure_span = tcx.hir().span(closure_hir_id);
let (capture_index, capture) = if let Some(capture_details) =
find_capture_matching_projections(
typeck_results,
@ -226,7 +230,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
) {
capture_details
} else {
if !tcx.features().capture_disjoint_fields {
if !enable_precise_capture(tcx, closure_span) {
bug!(
"No associated capture found for {:?}[{:#?}] even though \
capture_disjoint_fields isn't enabled",
@ -780,3 +784,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
}
/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
/// user is using Rust Edition 2021 or higher.
fn enable_precise_capture(tcx: TyCtxt<'_>, closure_span: Span) -> bool {
tcx.features().capture_disjoint_fields || closure_span.rust_2021()
}