about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-24 13:47:36 +0900
committerGitHub <noreply@github.com>2021-06-24 13:47:36 +0900
commit3998c03a652e4573f91ffa76a564f70955752b27 (patch)
tree80b7a5822ec75464855d9c21e31bea0c2731275d /compiler
parent6b618c82ba6e124dbc84419e43670f702735b076 (diff)
parentf265997b823f2b49f316f1a01f594c9c845c27a4 (diff)
downloadrust-3998c03a652e4573f91ffa76a564f70955752b27.tar.gz
rust-3998c03a652e4573f91ffa76a564f70955752b27.zip
Rollup merge of #86536 - sexxi-goose:edition, r=nikomatsakis
Edition 2021 enables disjoint capture

First part for https://github.com/rust-lang/project-rfc-2229/issues/43
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_typeck/src/check/upvar.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs
index 6baa185406e..4c9c3954624 100644
--- a/compiler/rustc_typeck/src/check/upvar.rs
+++ b/compiler/rustc_typeck/src/check/upvar.rs
@@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
         // We now fake capture information for all variables that are mentioned within the closure
         // We do this after handling migrations so that min_captures computes before
-        if !self.tcx.features().capture_disjoint_fields {
+        if !enable_precise_capture(self.tcx, span) {
             let mut capture_information: InferredCaptureInformation<'tcx> = Default::default();
 
             if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
@@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
             // If we have an origin, store it.
             if let Some(origin) = delegate.current_origin.clone() {
-                let origin = if self.tcx.features().capture_disjoint_fields {
+                let origin = if enable_precise_capture(self.tcx, span) {
                     (origin.0, restrict_capture_precision(origin.1))
                 } else {
                     (origin.0, Place { projections: vec![], ..origin.1 })
@@ -1924,3 +1924,13 @@ fn determine_place_ancestry_relation(
         PlaceAncestryRelation::Divergent
     }
 }
+
+/// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
+/// user is using Rust Edition 2021 or higher.
+///
+/// `span` is the span of the closure.
+fn enable_precise_capture(tcx: TyCtxt<'_>, span: Span) -> bool {
+    // We use span here to ensure that if the closure was generated by a macro with a different
+    // edition.
+    tcx.features().capture_disjoint_fields || span.rust_2021()
+}