review + add tests
This commit is contained in:
parent
a582e9638b
commit
dda5e32ab0
@ -67,7 +67,7 @@ struct NeedsDropTypes<'tcx, F> {
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
// Whether to reveal coroutine witnesses, this is set
|
// Whether to reveal coroutine witnesses, this is set
|
||||||
// to `false` unless we compute `needs_drop` for a generator witness.
|
// to `false` unless we compute `needs_drop` for a coroutine witness.
|
||||||
reveal_coroutine_witnesses: bool,
|
reveal_coroutine_witnesses: bool,
|
||||||
query_ty: Ty<'tcx>,
|
query_ty: Ty<'tcx>,
|
||||||
seen_tys: FxHashSet<Ty<'tcx>>,
|
seen_tys: FxHashSet<Ty<'tcx>>,
|
||||||
@ -138,11 +138,11 @@ fn next(&mut self) -> Option<NeedsDropResult<Ty<'tcx>>> {
|
|||||||
// computed on MIR, while this very method is used to build MIR.
|
// computed on MIR, while this very method is used to build MIR.
|
||||||
// To avoid cycles, we consider that coroutines always require drop.
|
// To avoid cycles, we consider that coroutines always require drop.
|
||||||
//
|
//
|
||||||
// HACK: Because we erase regions contained in the generator witness, we
|
// HACK: Because we erase regions contained in the coroutine witness, we
|
||||||
// have to conservatively assume that every region captured by the
|
// have to conservatively assume that every region captured by the
|
||||||
// generator has to be live when dropped. This results in a lot of
|
// coroutine has to be live when dropped. This results in a lot of
|
||||||
// undesirable borrowck errors. During borrowck, we call `needs_drop`
|
// undesirable borrowck errors. During borrowck, we call `needs_drop`
|
||||||
// for the generator witness and check whether any of the contained types
|
// for the coroutine witness and check whether any of the contained types
|
||||||
// need to be dropped, and only require the captured types to be live
|
// need to be dropped, and only require the captured types to be live
|
||||||
// if they do.
|
// if they do.
|
||||||
ty::Coroutine(_, args, _) => {
|
ty::Coroutine(_, args, _) => {
|
||||||
|
18
tests/ui/dropck/coroutine-liveness-1.rs
Normal file
18
tests/ui/dropck/coroutine-liveness-1.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// check-pass
|
||||||
|
// edition: 2021
|
||||||
|
|
||||||
|
// regression test for #116242.
|
||||||
|
use std::future;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut recv = future::ready(());
|
||||||
|
let _combined_fut = async {
|
||||||
|
let _ = || read(&mut recv);
|
||||||
|
};
|
||||||
|
|
||||||
|
drop(recv);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read<F: future::Future>(_: &mut F) -> F::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
23
tests/ui/dropck/coroutine-liveness-2.rs
Normal file
23
tests/ui/dropck/coroutine-liveness-2.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// check-pass
|
||||||
|
// edition: 2021
|
||||||
|
|
||||||
|
// regression test found while working on #117134.
|
||||||
|
use std::future;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut recv = future::ready(());
|
||||||
|
let _combined_fut = async {
|
||||||
|
let _ = || read(&mut recv);
|
||||||
|
};
|
||||||
|
|
||||||
|
let _uwu = (String::new(), _combined_fut);
|
||||||
|
// Dropping a coroutine as part of a more complex
|
||||||
|
// types should not add unnecessary liveness
|
||||||
|
// constraints.
|
||||||
|
|
||||||
|
drop(recv);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read<F: future::Future>(_: &mut F) -> F::Output {
|
||||||
|
todo!()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user