Skip to content

Commit 5b06898

Browse files
Check needs_infer before needs_drop in HIR generator analysis
1 parent eecde58 commit 5b06898

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ use crate::{
66
use hir::{def_id::DefId, Body, HirId, HirIdMap};
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir as hir;
9-
use rustc_middle::hir::place::{PlaceBase, Projection, ProjectionKind};
109
use rustc_middle::ty::{ParamEnv, TyCtxt};
10+
use rustc_middle::{
11+
hir::place::{PlaceBase, Projection, ProjectionKind},
12+
ty::TypeVisitable,
13+
};
1114

1215
pub(super) fn find_consumed_and_borrowed<'a, 'tcx>(
1316
fcx: &'a FnCtxt<'a, 'tcx>,
@@ -198,11 +201,13 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
198201

199202
// If the type being assigned needs dropped, then the mutation counts as a borrow
200203
// since it is essentially doing `Drop::drop(&mut x); x = new_value;`.
201-
//
202-
// FIXME(drop-tracking): We need to be more responsible about inference
203-
// variables here, since `needs_drop` is a "raw" type query, i.e. it
204-
// basically requires types to have been fully resolved.
205-
if assignee_place.place.base_ty.needs_drop(self.tcx, self.param_env) {
204+
let ty = self.tcx.erase_regions(assignee_place.place.base_ty);
205+
if ty.needs_infer() {
206+
self.tcx.sess.delay_span_bug(
207+
self.tcx.hir().span(assignee_place.hir_id),
208+
&format!("inference variables in {ty}"),
209+
);
210+
} else if ty.needs_drop(self.tcx, self.param_env) {
206211
self.places
207212
.borrowed
208213
.insert(TrackedValue::from_place_with_projections_allowed(assignee_place));

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
382382
let ty = self.fcx.resolve_vars_if_possible(ty);
383383
let ty = self.fcx.tcx.erase_regions(ty);
384384
if ty.needs_infer() {
385+
self.fcx
386+
.tcx
387+
.sess
388+
.delay_span_bug(expr.span, &format!("inference variables in {ty}"));
385389
return true;
386390
}
387391
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)

0 commit comments

Comments
 (0)