about summary refs log tree commit diff
path: root/tests/ui/wf
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-04-15 20:13:31 -0400
committerMichael Goulet <michael@errs.io>2024-04-25 10:51:54 -0400
commit870ed4bfa2be044bafba589b9d53def3f0a8b005 (patch)
tree3e29f2605e688793f71ecfc7a65676029b79a0a5 /tests/ui/wf
parentb2fea557f3ca616ec1b1e119132d3f4205ed2bc2 (diff)
downloadrust-870ed4bfa2be044bafba589b9d53def3f0a8b005.tar.gz
rust-870ed4bfa2be044bafba589b9d53def3f0a8b005.zip
Add test
Diffstat (limited to 'tests/ui/wf')
-rw-r--r--tests/ui/wf/closure-wf.rs11
-rw-r--r--tests/ui/wf/closure-wf.stderr20
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/wf/closure-wf.rs b/tests/ui/wf/closure-wf.rs
new file mode 100644
index 00000000000..48baeb30ce5
--- /dev/null
+++ b/tests/ui/wf/closure-wf.rs
@@ -0,0 +1,11 @@
+trait Bound {}
+struct NeedsBound<T: Bound>(T);
+
+// Checks that we enforce that closure args are WF.
+
+fn constrain_inner<T, F: for<'a> FnOnce(&'a (), NeedsBound<T>)>(_: T, _: F) {}
+
+fn main() {
+    constrain_inner(1u32, |&(), _| ());
+    //~^ ERROR the trait bound `u32: Bound` is not satisfied
+}
diff --git a/tests/ui/wf/closure-wf.stderr b/tests/ui/wf/closure-wf.stderr
new file mode 100644
index 00000000000..4beef3bb7c5
--- /dev/null
+++ b/tests/ui/wf/closure-wf.stderr
@@ -0,0 +1,20 @@
+error[E0277]: the trait bound `u32: Bound` is not satisfied
+  --> $DIR/closure-wf.rs:9:33
+   |
+LL |     constrain_inner(1u32, |&(), _| ());
+   |                                 ^ the trait `Bound` is not implemented for `u32`
+   |
+help: this trait has no implementations, consider adding one
+  --> $DIR/closure-wf.rs:1:1
+   |
+LL | trait Bound {}
+   | ^^^^^^^^^^^
+note: required by a bound in `NeedsBound`
+  --> $DIR/closure-wf.rs:2:22
+   |
+LL | struct NeedsBound<T: Bound>(T);
+   |                      ^^^^^ required by this bound in `NeedsBound`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.