Check needs_infer before needs_drop in HIR generator analysis
This commit is contained in:
parent
eecde5850c
commit
5b06898d21
@ -6,8 +6,11 @@
|
|||||||
use hir::{def_id::DefId, Body, HirId, HirIdMap};
|
use hir::{def_id::DefId, Body, HirId, HirIdMap};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::hir::place::{PlaceBase, Projection, ProjectionKind};
|
|
||||||
use rustc_middle::ty::{ParamEnv, TyCtxt};
|
use rustc_middle::ty::{ParamEnv, TyCtxt};
|
||||||
|
use rustc_middle::{
|
||||||
|
hir::place::{PlaceBase, Projection, ProjectionKind},
|
||||||
|
ty::TypeVisitable,
|
||||||
|
};
|
||||||
|
|
||||||
pub(super) fn find_consumed_and_borrowed<'a, 'tcx>(
|
pub(super) fn find_consumed_and_borrowed<'a, 'tcx>(
|
||||||
fcx: &'a FnCtxt<'a, 'tcx>,
|
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||||
@ -198,11 +201,13 @@ fn mutate(
|
|||||||
|
|
||||||
// If the type being assigned needs dropped, then the mutation counts as a borrow
|
// If the type being assigned needs dropped, then the mutation counts as a borrow
|
||||||
// since it is essentially doing `Drop::drop(&mut x); x = new_value;`.
|
// since it is essentially doing `Drop::drop(&mut x); x = new_value;`.
|
||||||
//
|
let ty = self.tcx.erase_regions(assignee_place.place.base_ty);
|
||||||
// FIXME(drop-tracking): We need to be more responsible about inference
|
if ty.needs_infer() {
|
||||||
// variables here, since `needs_drop` is a "raw" type query, i.e. it
|
self.tcx.sess.delay_span_bug(
|
||||||
// basically requires types to have been fully resolved.
|
self.tcx.hir().span(assignee_place.hir_id),
|
||||||
if assignee_place.place.base_ty.needs_drop(self.tcx, self.param_env) {
|
&format!("inference variables in {ty}"),
|
||||||
|
);
|
||||||
|
} else if ty.needs_drop(self.tcx, self.param_env) {
|
||||||
self.places
|
self.places
|
||||||
.borrowed
|
.borrowed
|
||||||
.insert(TrackedValue::from_place_with_projections_allowed(assignee_place));
|
.insert(TrackedValue::from_place_with_projections_allowed(assignee_place));
|
||||||
|
@ -382,6 +382,10 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
|||||||
let ty = self.fcx.resolve_vars_if_possible(ty);
|
let ty = self.fcx.resolve_vars_if_possible(ty);
|
||||||
let ty = self.fcx.tcx.erase_regions(ty);
|
let ty = self.fcx.tcx.erase_regions(ty);
|
||||||
if ty.needs_infer() {
|
if ty.needs_infer() {
|
||||||
|
self.fcx
|
||||||
|
.tcx
|
||||||
|
.sess
|
||||||
|
.delay_span_bug(expr.span, &format!("inference variables in {ty}"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)
|
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)
|
||||||
|
Loading…
Reference in New Issue
Block a user