diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-06-29 08:46:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-29 08:46:12 +0900 |
| commit | 22f2332b353c9522b31d004887dd6500aae55901 (patch) | |
| tree | 34ac1cf1b1808248a38f26ae17c40a073368e2f1 /compiler | |
| parent | 5028581a1f792837c8db299f823f628d92c304be (diff) | |
| parent | 10a37bf847c1f24bfc321cebc550d1811eea3a9b (diff) | |
| download | rust-22f2332b353c9522b31d004887dd6500aae55901.tar.gz rust-22f2332b353c9522b31d004887dd6500aae55901.zip | |
Rollup merge of #86661 - sexxi-goose:edition_fix, r=nikomatsakis
Editon 2021 enables precise capture r? `@nikomatsakis`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/as_place.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 5511cd4c73b..bedb8b1c58b 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -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() +} |
