@@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177177
178178 // We now fake capture information for all variables that are mentioned within the closure
179179 // We do this after handling migrations so that min_captures computes before
180- if !self . tcx . features ( ) . capture_disjoint_fields {
180+ if !enable_precise_capture ( self . tcx , span ) {
181181 let mut capture_information: InferredCaptureInformation < ' tcx > = Default :: default ( ) ;
182182
183183 if let Some ( upvars) = self . tcx . upvars_mentioned ( closure_def_id) {
@@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
212212
213213 // If we have an origin, store it.
214214 if let Some ( origin) = delegate. current_origin . clone ( ) {
215- let origin = if self . tcx . features ( ) . capture_disjoint_fields {
215+ let origin = if enable_precise_capture ( self . tcx , span ) {
216216 ( origin. 0 , restrict_capture_precision ( origin. 1 ) )
217217 } else {
218218 ( origin. 0 , Place { projections : vec ! [ ] , ..origin. 1 } )
@@ -1924,3 +1924,13 @@ fn determine_place_ancestry_relation(
19241924 PlaceAncestryRelation :: Divergent
19251925 }
19261926}
1927+
1928+ /// Precise capture is enabled if the feature gate `capture_disjoint_fields` is enabled or if
1929+ /// user is using Rust Edition 2021 or higher.
1930+ ///
1931+ /// `span` is the span of the closure.
1932+ fn enable_precise_capture ( tcx : TyCtxt < ' _ > , span : Span ) -> bool {
1933+ // We use span here to ensure that if the closure was generated by a macro with a different
1934+ // edition.
1935+ tcx. features ( ) . capture_disjoint_fields || span. rust_2021 ( )
1936+ }
0 commit comments