Skip to content

Commit 22f2332

Browse files
authoredJun 28, 2021
Rollup merge of #86661 - sexxi-goose:edition_fix, r=nikomatsakis
Editon 2021 enables precise capture r? `@nikomatsakis`
2 parents 5028581 + 10a37bf commit 22f2332

File tree

141 files changed

+463
-1282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+463
-1282
lines changed
 

‎compiler/rustc_mir_build/src/build/expr/as_place.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
217217
ty::ClosureKind::FnOnce => {}
218218
}
219219

220+
// We won't be building MIR if the closure wasn't local
221+
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
222+
let closure_span = tcx.hir().span(closure_hir_id);
223+
220224
let (capture_index, capture) = if let Some(capture_details) =
221225
find_capture_matching_projections(
222226
typeck_results,
@@ -226,7 +230,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
226230
) {
227231
capture_details
228232
} else {
229-
if !tcx.features().capture_disjoint_fields {
233+
if !enable_precise_capture(tcx, closure_span) {
230234
bug!(
231235
"No associated capture found for {:?}[{:#?}] even though \
232236
capture_disjoint_fields isn't enabled",
@@ -242,8 +246,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
242246
return Err(from_builder);
243247
};
244248

245-
let closure_ty = typeck_results
246-
.node_type(tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local()));
249+
let closure_ty = typeck_results.node_type(closure_hir_id);
247250

248251
let substs = match closure_ty.kind() {
249252
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
@@ -780,3 +783,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
780783
}
781784
}
782785
}
786+
787+
/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
788+
/// user is using Rust Edition 2021 or higher.
789+
fn enable_precise_capture(tcx: TyCtxt<'_>, closure_span: Span) -> bool {
790+
tcx.features().capture_disjoint_fields || closure_span.rust_2021()
791+
}

‎src/test/ui/closures/2229_closure_analysis/arrays-completely-captured.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![feature(capture_disjoint_fields)]
2-
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3-
//~| `#[warn(incomplete_features)]` on by default
4-
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
1+
// edition:2021
52
#![feature(rustc_attrs)]
63

74
// Ensure that capture analysis results in arrays being completely captured.

0 commit comments

Comments
 (0)
Please sign in to comment.