]> git.lizzy.rs Git - rust.git/commitdiff
generic test
authorGus Wynn <guswynn@gmail.com>
Sat, 18 Sep 2021 19:23:16 +0000 (12:23 -0700)
committerGus Wynn <guswynn@gmail.com>
Sat, 18 Sep 2021 19:23:16 +0000 (12:23 -0700)
compiler/rustc_typeck/src/check/generator_interior.rs
src/test/ui/lint/must_not_suspend/generic.rs [new file with mode: 0644]
src/test/ui/lint/must_not_suspend/generic.stderr [new file with mode: 0644]

index e8a24f01b7563ce528067250c0bc12a05d66d746..ac67d2b93c57bc36a41a1cfd223ef51cf91f5a45 100644 (file)
@@ -462,6 +462,9 @@ pub struct SuspendCheckData<'a, 'tcx> {
 // Returns whether it emitted a diagnostic or not
 // Note that this fn and the proceding one are based on the code
 // for creating must_use diagnostics
+//
+// Note that this technique was chosen over things like a `Suspend` marker trait
+// as it is simpler and has precendent in the compiler
 pub fn check_must_not_suspend_ty<'tcx>(
     fcx: &FnCtxt<'_, 'tcx>,
     ty: Ty<'tcx>,
diff --git a/src/test/ui/lint/must_not_suspend/generic.rs b/src/test/ui/lint/must_not_suspend/generic.rs
new file mode 100644 (file)
index 0000000..94457e3
--- /dev/null
@@ -0,0 +1,21 @@
+// edition:2018
+#![feature(must_not_suspend)]
+#![deny(must_not_suspend)]
+
+#[must_not_suspend]
+struct No {}
+
+async fn shushspend() {}
+
+async fn wheeee<T>(t: T) {
+    shushspend().await;
+    drop(t);
+}
+
+async fn yes() {
+    wheeee(No {}).await; //~ ERROR `No` held across
+    //~^ ERROR `No` held across
+}
+
+fn main() {
+}
diff --git a/src/test/ui/lint/must_not_suspend/generic.stderr b/src/test/ui/lint/must_not_suspend/generic.stderr
new file mode 100644 (file)
index 0000000..d853ba7
--- /dev/null
@@ -0,0 +1,31 @@
+error: `No` held across a suspend point, but should not be
+  --> $DIR/generic.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |     -------^^^^^------- the value is held across this suspend point
+   |
+note: the lint level is defined here
+  --> $DIR/generic.rs:3:9
+   |
+LL | #![deny(must_not_suspend)]
+   |         ^^^^^^^^^^^^^^^^
+help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
+  --> $DIR/generic.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |            ^^^^^
+
+error: `No` held across a suspend point, but should not be
+  --> $DIR/generic.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |     -------^^^^^------- the value is held across this suspend point
+   |
+help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
+  --> $DIR/generic.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |            ^^^^^
+
+error: aborting due to 2 previous errors
+