Skip to content

Commit dda5e32

Browse files
committed
review + add tests
1 parent a582e96 commit dda5e32

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-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, _) => {
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
// regression test for #116242.
5+
use std::future;
6+
7+
fn main() {
8+
let mut recv = future::ready(());
9+
let _combined_fut = async {
10+
let _ = || read(&mut recv);
11+
};
12+
13+
drop(recv);
14+
}
15+
16+
fn read<F: future::Future>(_: &mut F) -> F::Output {
17+
todo!()
18+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// edition: 2021
3+
4+
// regression test found while working on #117134.
5+
use std::future;
6+
7+
fn main() {
8+
let mut recv = future::ready(());
9+
let _combined_fut = async {
10+
let _ = || read(&mut recv);
11+
};
12+
13+
let _uwu = (String::new(), _combined_fut);
14+
// Dropping a coroutine as part of a more complex
15+
// types should not add unnecessary liveness
16+
// constraints.
17+
18+
drop(recv);
19+
}
20+
21+
fn read<F: future::Future>(_: &mut F) -> F::Output {
22+
todo!()
23+
}

0 commit comments

Comments
 (0)