diff --git a/compiler/rustc_hir_analysis/src/check/generator_interior.rs b/compiler/rustc_hir_analysis/src/check/generator_interior.rs index 898419b5b2374..42fcdad23961f 100644 --- a/compiler/rustc_hir_analysis/src/check/generator_interior.rs +++ b/compiler/rustc_hir_analysis/src/check/generator_interior.rs @@ -378,9 +378,11 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { 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); + // Regions are not needed to prove if something needs drop let ty = self.fcx.tcx.erase_regions(ty); + // All int/float types are trivially drop, so those infer variables can be erased + let ty = self.fcx.resolve_numeric_literals_with_default(ty); if ty.needs_infer() { return true; } diff --git a/compiler/rustc_hir_analysis/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs b/compiler/rustc_hir_analysis/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs index e22675e9d5f4e..c5ff6c99dc8fd 100644 --- a/compiler/rustc_hir_analysis/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs +++ b/compiler/rustc_hir_analysis/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs @@ -6,8 +6,12 @@ use crate::{ use hir::{def_id::DefId, Body, HirId, HirIdMap}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; -use rustc_middle::hir::place::{PlaceBase, Projection, ProjectionKind}; +use rustc_infer::infer::InferenceLiteralEraser; use rustc_middle::ty::{ParamEnv, TyCtxt}; +use rustc_middle::{ + hir::place::{PlaceBase, Projection, ProjectionKind}, + ty::{TypeFoldable, TypeVisitable}, +}; pub(super) fn find_consumed_and_borrowed<'a, 'tcx>( fcx: &'a FnCtxt<'a, 'tcx>, @@ -196,9 +200,13 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> { return; } + // Regions are not needed to prove if something needs drop + let ty = self.tcx.erase_regions(assignee_place.place.base_ty); + // All int/float types are trivially drop, so those infer variables can be erased + let ty = ty.fold_with(&mut InferenceLiteralEraser { tcx: self.tcx }); // 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;`. - if assignee_place.place.base_ty.needs_drop(self.tcx, self.param_env) { + if ty.needs_infer() || ty.needs_drop(self.tcx, self.param_env) { self.places .borrowed .insert(TrackedValue::from_place_with_projections_allowed(assignee_place)); diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 5a5e9db81a243..0c349ee02474c 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1840,9 +1840,8 @@ impl<'tcx> TyOrConstInferVar<'tcx> { } /// Replace `{integer}` with `i32` and `{float}` with `f64`. -/// Used only for diagnostics. -struct InferenceLiteralEraser<'tcx> { - tcx: TyCtxt<'tcx>, +pub struct InferenceLiteralEraser<'tcx> { + pub tcx: TyCtxt<'tcx>, } impl<'tcx> TypeFolder<'tcx> for InferenceLiteralEraser<'tcx> { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 646369633133c..cf420bafeb12f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2205,7 +2205,10 @@ impl<'tcx> Ty<'tcx> { // These aren't even `Clone` ty::Str | ty::Slice(..) | ty::Foreign(..) | ty::Dynamic(..) => false, - ty::Int(..) | ty::Uint(..) | ty::Float(..) => true, + ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_)) + | ty::Int(..) + | ty::Uint(..) + | ty::Float(..) => true, // The voldemort ZSTs are fine. ty::FnDef(..) => true, diff --git a/src/test/ui/generator/issue-102645.rs b/src/test/ui/generator/issue-102645.rs new file mode 100644 index 0000000000000..0589c5a009a1b --- /dev/null +++ b/src/test/ui/generator/issue-102645.rs @@ -0,0 +1,23 @@ +// compile-flags: -Zdrop-tracking + +#![feature(generators, generator_trait)] + +use std::ops::Generator; +use std::pin::Pin; + +fn main() { + let mut a = 5; + let mut b = || { + let d = 6; + yield; + _zzz(); // #break + a = d; + }; + Pin::new(&mut b).resume(); + //~^ ERROR this function takes 1 argument but 0 arguments were supplied + // This type error is required to reproduce the ICE... +} + +fn _zzz() { + () +} diff --git a/src/test/ui/generator/issue-102645.stderr b/src/test/ui/generator/issue-102645.stderr new file mode 100644 index 0000000000000..7b4d502132517 --- /dev/null +++ b/src/test/ui/generator/issue-102645.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/issue-102645.rs:16:22 + | +LL | Pin::new(&mut b).resume(); + | ^^^^^^-- an argument of type `()` is missing + | +note: associated function defined here + --> $SRC_DIR/core/src/ops/generator.rs:LL:COL + | +LL | fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState; + | ^^^^^^ +help: provide the argument + | +LL | Pin::new(&mut b).resume(()); + | ~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`.