Skip to content

Commit f1021bf

Browse files
committed
generic test
1 parent 110aecd commit f1021bf

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

+3
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ pub struct SuspendCheckData<'a, 'tcx> {
462462
// Returns whether it emitted a diagnostic or not
463463
// Note that this fn and the proceding one are based on the code
464464
// for creating must_use diagnostics
465+
//
466+
// Note that this technique was chosen over things like a `Suspend` marker trait
467+
// as it is simpler and has precendent in the compiler
465468
pub fn check_must_not_suspend_ty<'tcx>(
466469
fcx: &FnCtxt<'_, 'tcx>,
467470
ty: Ty<'tcx>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition:2018
2+
#![feature(must_not_suspend)]
3+
#![deny(must_not_suspend)]
4+
5+
#[must_not_suspend]
6+
struct No {}
7+
8+
async fn shushspend() {}
9+
10+
async fn wheeee<T>(t: T) {
11+
shushspend().await;
12+
drop(t);
13+
}
14+
15+
async fn yes() {
16+
wheeee(No {}).await; //~ ERROR `No` held across
17+
//~^ ERROR `No` held across
18+
}
19+
20+
fn main() {
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: `No` held across a suspend point, but should not be
2+
--> $DIR/generic.rs:16:12
3+
|
4+
LL | wheeee(No {}).await;
5+
| -------^^^^^------- the value is held across this suspend point
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/generic.rs:3:9
9+
|
10+
LL | #![deny(must_not_suspend)]
11+
| ^^^^^^^^^^^^^^^^
12+
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
13+
--> $DIR/generic.rs:16:12
14+
|
15+
LL | wheeee(No {}).await;
16+
| ^^^^^
17+
18+
error: `No` held across a suspend point, but should not be
19+
--> $DIR/generic.rs:16:12
20+
|
21+
LL | wheeee(No {}).await;
22+
| -------^^^^^------- the value is held across this suspend point
23+
|
24+
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
25+
--> $DIR/generic.rs:16:12
26+
|
27+
LL | wheeee(No {}).await;
28+
| ^^^^^
29+
30+
error: aborting due to 2 previous errors
31+

0 commit comments

Comments
 (0)