Skip to content

Commit 41a674e

Browse files
committed
review + add tests
1 parent a582e96 commit 41a674e

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

compiler/rustc_ty_utils/src/needs_drop.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct NeedsDropTypes<'tcx, F> {
6767
tcx: TyCtxt<'tcx>,
6868
param_env: ty::ParamEnv<'tcx>,
6969
// Whether to reveal coroutine witnesses, this is set
70-
// to `false` unless we compute `needs_drop` for a generator witness.
70+
// to `false` unless we compute `needs_drop` for a coroutine witness.
7171
reveal_coroutine_witnesses: bool,
7272
query_ty: Ty<'tcx>,
7373
seen_tys: FxHashSet<Ty<'tcx>>,
@@ -138,11 +138,11 @@ where
138138
// computed on MIR, while this very method is used to build MIR.
139139
// To avoid cycles, we consider that coroutines always require drop.
140140
//
141-
// HACK: Because we erase regions contained in the generator witness, we
141+
// HACK: Because we erase regions contained in the coroutine witness, we
142142
// have to conservatively assume that every region captured by the
143-
// generator has to be live when dropped. This results in a lot of
143+
// coroutine has to be live when dropped. This results in a lot of
144144
// undesirable borrowck errors. During borrowck, we call `needs_drop`
145-
// for the generator witness and check whether any of the contained types
145+
// for the coroutine witness and check whether any of the contained types
146146
// need to be dropped, and only require the captured types to be live
147147
// if they do.
148148
ty::Coroutine(_, args, _) => {
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
// regression test for #116242.
4+
use std::future;
5+
6+
fn main() {
7+
let mut recv = future::ready(());
8+
let _combined_fut = async {
9+
let _ = || read(&mut recv);
10+
};
11+
12+
drop(recv);
13+
}
14+
15+
fn read<F: future::Future>(_: &mut F) -> F::Output {
16+
todo!()
17+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
3+
// regression test found while working on #117134.
4+
use std::future;
5+
6+
fn main() {
7+
let mut recv = future::ready(());
8+
let _combined_fut = async {
9+
let _ = || read(&mut recv);
10+
};
11+
12+
let _uwu = (String::new(), _combined_fut);
13+
// Dropping a coroutine as part of a more complex
14+
// types should not add unnecessary liveness
15+
// constraints.
16+
17+
drop(recv);
18+
}
19+
20+
fn read<F: future::Future>(_: &mut F) -> F::Output {
21+
todo!()
22+
}

0 commit comments

Comments
 (0)