Rollup merge of #86661 - sexxi-goose:edition_fix, r=nikomatsakis
Editon 2021 enables precise capture r? `@nikomatsakis`
This commit is contained in:
commit
22f2332b35
141 changed files with 463 additions and 1282 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue