1
Fork 0

Rollup merge of #86661 - sexxi-goose:edition_fix, r=nikomatsakis

Editon 2021 enables precise capture

r? `@nikomatsakis`
This commit is contained in:
Yuki Okushi 2021-06-29 08:46:12 +09:00 committed by GitHub
commit 22f2332b35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
141 changed files with 463 additions and 1282 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",
@ -242,8 +246,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
return Err(from_builder);
};
let closure_ty = typeck_results
.node_type(tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()));
let closure_ty = typeck_results.node_type(closure_hir_id);
let substs = match closure_ty.kind() {
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
@ -780,3 +783,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()
}