]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir_typeck/src/generator_interior/mod.rs
Rollup merge of #107151 - tmiasko:dominators-no-inline, r=compiler-errors
[rust.git] / compiler / rustc_hir_typeck / src / generator_interior / mod.rs
index e4ac91befac610e8f71729bf7be89dacf1ababff..7af5260538568c0d873ad2767cdbb903e5a6517e 100644 (file)
@@ -71,10 +71,8 @@ fn record(
                                 yield_data.expr_and_pat_count, self.expr_count, source_span
                             );
 
-                            if self.fcx.sess().opts.unstable_opts.drop_tracking
-                                && self
-                                    .drop_ranges
-                                    .is_dropped_at(hir_id, yield_data.expr_and_pat_count)
+                            if self
+                                .is_dropped_at_yield_location(hir_id, yield_data.expr_and_pat_count)
                             {
                                 debug!("value is dropped at yield point; not recording");
                                 return false;
@@ -173,6 +171,18 @@ fn record(
             }
         }
     }
+
+    /// If drop tracking is enabled, consult drop_ranges to see if a value is
+    /// known to be dropped at a yield point and therefore can be omitted from
+    /// the generator witness.
+    fn is_dropped_at_yield_location(&self, value_hir_id: HirId, yield_location: usize) -> bool {
+        // short-circuit if drop tracking is not enabled.
+        if !self.fcx.sess().opts.unstable_opts.drop_tracking {
+            return false;
+        }
+
+        self.drop_ranges.is_dropped_at(value_hir_id, yield_location)
+    }
 }
 
 pub fn resolve_interior<'a, 'tcx>(
@@ -448,7 +458,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
         // the yield, even if it's not borrowed or referenced after the yield. Ideally this would
         // *only* happen for types with observable drop, not all types which wrap them, but that
         // doesn't match the behavior of MIR borrowck and causes ICEs. See the FIXME comment in
-        // src/test/ui/generator/drop-tracking-parent-expression.rs.
+        // tests/ui/generator/drop-tracking-parent-expression.rs.
         let scope = if self.drop_ranges.is_borrowed_temporary(expr)
             || ty.map_or(true, |ty| {
                 // Avoid ICEs in needs_drop.