nit: Inline may_need_drop
This commit is contained in:
parent
5b06898d21
commit
134de38e4d
@ -377,19 +377,6 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
||||
debug!("is_borrowed_temporary: {:?}", self.drop_ranges.is_borrowed_temporary(expr));
|
||||
|
||||
let ty = self.fcx.typeck_results.borrow().expr_ty_adjusted_opt(expr);
|
||||
let may_need_drop = |ty: Ty<'tcx>| {
|
||||
// Avoid ICEs in needs_drop.
|
||||
let ty = self.fcx.resolve_vars_if_possible(ty);
|
||||
let ty = self.fcx.tcx.erase_regions(ty);
|
||||
if ty.needs_infer() {
|
||||
self.fcx
|
||||
.tcx
|
||||
.sess
|
||||
.delay_span_bug(expr.span, &format!("inference variables in {ty}"));
|
||||
return true;
|
||||
}
|
||||
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)
|
||||
};
|
||||
|
||||
// Typically, the value produced by an expression is consumed by its parent in some way,
|
||||
// so we only have to check if the parent contains a yield (note that the parent may, for
|
||||
@ -407,9 +394,18 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
||||
// src/test/ui/generator/drop-tracking-parent-expression.rs.
|
||||
let scope = if self.drop_ranges.is_borrowed_temporary(expr)
|
||||
|| ty.map_or(true, |ty| {
|
||||
let needs_drop = may_need_drop(ty);
|
||||
debug!(?needs_drop, ?ty);
|
||||
needs_drop
|
||||
// Avoid ICEs in needs_drop.
|
||||
let ty = self.fcx.resolve_vars_if_possible(ty);
|
||||
let ty = self.fcx.tcx.erase_regions(ty);
|
||||
if ty.needs_infer() {
|
||||
self.fcx
|
||||
.tcx
|
||||
.sess
|
||||
.delay_span_bug(expr.span, &format!("inference variables in {ty}"));
|
||||
true
|
||||
} else {
|
||||
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)
|
||||
}
|
||||
}) {
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user