@@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177
177
178
178
// We now fake capture information for all variables that are mentioned within the closure
179
179
// 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 ) {
181
181
let mut capture_information: InferredCaptureInformation < ' tcx > = Default :: default ( ) ;
182
182
183
183
if let Some ( upvars) = self . tcx . upvars_mentioned ( closure_def_id) {
@@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
212
212
213
213
// If we have an origin, store it.
214
214
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 ) {
216
216
( origin. 0 , restrict_capture_precision ( origin. 1 ) )
217
217
} else {
218
218
( origin. 0 , Place { projections : vec ! [ ] , ..origin. 1 } )
@@ -1924,3 +1924,13 @@ fn determine_place_ancestry_relation(
1924
1924
PlaceAncestryRelation :: Divergent
1925
1925
}
1926
1926
}
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