about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs25
-rw-r--r--tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs10
-rw-r--r--tests/ui/async-await/async-closures/is-fn.rs24
-rw-r--r--tests/ui/async-await/async-closures/move-is-async-fn.rs10
-rw-r--r--tests/ui/async-await/async-closures/once.rs6
-rw-r--r--tests/ui/async-await/async-closures/refd.rs13
-rw-r--r--tests/ui/async-await/async-fn/higher-ranked-async-fn.rs31
-rw-r--r--tests/ui/async-await/async-fn/project.rs12
-rw-r--r--tests/ui/suggestions/silenced-binding-typo.stderr2
9 files changed, 121 insertions, 12 deletions
diff --git a/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs b/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs
index f15ca30b7e3..be4af9b7962 100644
--- a/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs
+++ b/tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs
@@ -18,6 +18,13 @@ extern {
 #[repr(transparent)]
 pub struct Type3(i32);
 
+#[cfi_encoding = "i"]
+pub struct Type4(i32);
+
+#[cfi_encoding = "j"]
+#[repr(transparent)]
+pub struct Type5(u32);
+
 pub fn foo0(_: Type1) { }
 // CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 pub fn foo1(_: Type1, _: Type1) { }
@@ -36,6 +43,18 @@ pub fn foo7(_: *mut Type3, _: *mut Type3) { }
 // CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 pub fn foo8(_: *mut Type3, _: *mut Type3, _: *mut Type3) { }
 // CHECK: define{{.*}}foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo9(_: Type4) { }
+// CHECK: define{{.*}}foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo10(_: Type4, _: Type4) { }
+// CHECK: define{{.*}}foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo11(_: Type4, _: Type4, _: Type4) { }
+// CHECK: define{{.*}}foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo12(_: Type5) { }
+// CHECK: define{{.*}}foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo13(_: Type5, _: Type5) { }
+// CHECK: define{{.*}}foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
+pub fn foo14(_: Type5, _: Type5, _: Type5) { }
+// CHECK: define{{.*}}foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
 
 // CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFv3FooE"}
 // CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFv3FooS_E"}
@@ -46,3 +65,9 @@ pub fn foo8(_: *mut Type3, _: *mut Type3, _: *mut Type3) { }
 // CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvP3BazE"}
 // CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvP3BazS0_E"}
 // CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvP3BazS0_S0_E"}
+// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFviE"}
+// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFviiE"}
+// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFviiiE"}
+// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvjE"}
+// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvjjE"}
+// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvjjjE"}
diff --git a/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs b/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs
index 9c3b458cd3a..be436465315 100644
--- a/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs
+++ b/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs
@@ -8,11 +8,15 @@ extern crate block_on;
 
 fn main() {
     block_on::block_on(async {
-        let x = async || {};
-
         async fn needs_async_fn_once(x: impl async FnOnce()) {
             x().await;
         }
-        needs_async_fn_once(x).await;
+
+        needs_async_fn_once(async || {}).await;
+
+        needs_async_fn_once(|| async {}).await;
+
+        async fn foo() {}
+        needs_async_fn_once(foo).await;
     });
 }
diff --git a/tests/ui/async-await/async-closures/is-fn.rs b/tests/ui/async-await/async-closures/is-fn.rs
new file mode 100644
index 00000000000..64cc28e425f
--- /dev/null
+++ b/tests/ui/async-await/async-closures/is-fn.rs
@@ -0,0 +1,24 @@
+//@ aux-build:block-on.rs
+//@ edition:2021
+//@ build-pass
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+
+#![feature(async_closure)]
+
+use std::future::Future;
+
+extern crate block_on;
+
+// Check that closures that don't capture any state may implement `Fn`.
+
+fn main() {
+    block_on::block_on(async {
+        async fn call_once<F: Future>(x: impl FnOnce(&'static str) -> F) -> F::Output {
+            x("hello, world").await
+        }
+        call_once(async |x: &'static str| {
+            println!("hello, {x}");
+        }).await
+    });
+}
diff --git a/tests/ui/async-await/async-closures/move-is-async-fn.rs b/tests/ui/async-await/async-closures/move-is-async-fn.rs
index 0ccd137266d..79e2298f609 100644
--- a/tests/ui/async-await/async-closures/move-is-async-fn.rs
+++ b/tests/ui/async-await/async-closures/move-is-async-fn.rs
@@ -2,7 +2,7 @@
 //@ edition:2021
 //@ build-pass
 
-#![feature(async_closure)]
+#![feature(async_closure, async_fn_traits)]
 
 extern crate block_on;
 
@@ -15,7 +15,11 @@ fn main() {
         c().await;
         c().await;
 
-        fn is_static<T: 'static>(_: T) {}
-        is_static(c);
+        fn is_static<T: 'static>(_: &T) {}
+        is_static(&c);
+
+        // Check that `<{async fn} as AsyncFnOnce>::CallOnceFuture` owns its captures.
+        fn call_once<F: async FnOnce()>(f: F) -> F::CallOnceFuture { f() }
+        is_static(&call_once(c));
     });
 }
diff --git a/tests/ui/async-await/async-closures/once.rs b/tests/ui/async-await/async-closures/once.rs
index 55e4cedb267..761df3de444 100644
--- a/tests/ui/async-await/async-closures/once.rs
+++ b/tests/ui/async-await/async-closures/once.rs
@@ -1,6 +1,8 @@
 //@ aux-build:block-on.rs
 //@ edition:2021
 //@ build-pass
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
 
 #![feature(async_closure)]
 
@@ -8,11 +10,11 @@ use std::future::Future;
 
 extern crate block_on;
 
-struct NoCopy;
+// Check that async closures always implement `FnOnce`
 
 fn main() {
     block_on::block_on(async {
-        async fn call_once<F: Future>(x: impl Fn(&'static str) -> F) -> F::Output {
+        async fn call_once<F: Future>(x: impl FnOnce(&'static str) -> F) -> F::Output {
             x("hello, world").await
         }
         call_once(async |x: &'static str| {
diff --git a/tests/ui/async-await/async-closures/refd.rs b/tests/ui/async-await/async-closures/refd.rs
index 1d9bc1a601b..0b8d3d7aff5 100644
--- a/tests/ui/async-await/async-closures/refd.rs
+++ b/tests/ui/async-await/async-closures/refd.rs
@@ -2,8 +2,6 @@
 //@ edition:2021
 //@ build-pass
 
-// check that `&{async-closure}` implements `AsyncFn`.
-
 #![feature(async_closure)]
 
 extern crate block_on;
@@ -13,6 +11,15 @@ struct NoCopy;
 fn main() {
     block_on::block_on(async {
         async fn call_once(x: impl async Fn()) { x().await }
-        call_once(&async || {}).await
+
+        // check that `&{async-closure}` implements `async Fn`.
+        call_once(&async || {}).await;
+
+        // check that `&{closure}` implements `async Fn`.
+        call_once(&|| async {}).await;
+
+        // check that `&fndef` implements `async Fn`.
+        async fn foo() {}
+        call_once(&foo).await;
     });
 }
diff --git a/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs b/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs
new file mode 100644
index 00000000000..5680c057737
--- /dev/null
+++ b/tests/ui/async-await/async-fn/higher-ranked-async-fn.rs
@@ -0,0 +1,31 @@
+//@ aux-build:block-on.rs
+//@ edition:2018
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+//@ build-pass (since it ICEs during mono)
+
+#![feature(async_closure)]
+
+extern crate block_on;
+
+use std::future::Future;
+
+async fn f(arg: &i32) {}
+
+async fn func<F>(f: F)
+where
+    F: async for<'a> Fn(&'a i32),
+{
+    let x: i32 = 0;
+    f(&x).await;
+}
+
+fn main() {
+    block_on::block_on(async {
+        // Function
+        func(f).await;
+
+        // Regular closure (doesn't capture)
+        func(|x: &i32| async {});
+    });
+}
diff --git a/tests/ui/async-await/async-fn/project.rs b/tests/ui/async-await/async-fn/project.rs
new file mode 100644
index 00000000000..302564bb951
--- /dev/null
+++ b/tests/ui/async-await/async-fn/project.rs
@@ -0,0 +1,12 @@
+//@ edition:2018
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+//@ check-pass
+
+#![feature(async_closure, unboxed_closures, async_fn_traits)]
+
+fn project<F: async Fn<()>>(_: F) -> Option<F::Output> { None }
+
+fn main() {
+    let x: Option<i32> = project(|| async { 1i32 });
+}
diff --git a/tests/ui/suggestions/silenced-binding-typo.stderr b/tests/ui/suggestions/silenced-binding-typo.stderr
index 8dbd94208d6..c362d00c713 100644
--- a/tests/ui/suggestions/silenced-binding-typo.stderr
+++ b/tests/ui/suggestions/silenced-binding-typo.stderr
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `x` in this scope
 LL |     let _y = x;
    |              ^
    |
-help: a local variable with a similar name exists, consider changing it
+help: a local variable with a similar name exists, consider renaming `_x` into `x`
    |
 LL |     let x = 42;
    |         ~