File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
compiler/rustc_typeck/src/check
src/test/ui/lint/must_not_suspend Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff 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
465468pub fn check_must_not_suspend_ty < ' tcx > (
466469 fcx : & FnCtxt < ' _ , ' tcx > ,
467470 ty : Ty < ' tcx > ,
Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments