diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-15 18:13:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-15 18:13:28 -0400 |
| commit | d077146a15fd1f31c30fbb37cec70e2325a05adf (patch) | |
| tree | 64f65581bf25d23ce45e1f3fa535f68d998ee97c /tests | |
| parent | 7a05f26a3b03b9387e2fe9c9fcbe012dc5423b29 (diff) | |
| parent | 2218ff1940bc8baafcc1acf2c861d48499e20d06 (diff) | |
| download | rust-d077146a15fd1f31c30fbb37cec70e2325a05adf.tar.gz rust-d077146a15fd1f31c30fbb37cec70e2325a05adf.zip | |
Rollup merge of #144907 - ShoyuVanilla:no-const-async, r=fmease
fix: Reject async assoc fns of const traits/impls in ast_passes Fixes rust-lang/rust#117629
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/crashes/117629.rs | 10 | ||||
| -rw-r--r-- | tests/ui/traits/const-traits/const-trait-async-assoc-fn.rs | 18 | ||||
| -rw-r--r-- | tests/ui/traits/const-traits/const-trait-async-assoc-fn.stderr | 18 |
3 files changed, 36 insertions, 10 deletions
diff --git a/tests/crashes/117629.rs b/tests/crashes/117629.rs deleted file mode 100644 index f63365395c6..00000000000 --- a/tests/crashes/117629.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ known-bug: #117629 -//@ edition:2021 - -#![feature(const_trait_impl)] - -const trait Tr { - async fn ft1() {} -} - -fn main() {} diff --git a/tests/ui/traits/const-traits/const-trait-async-assoc-fn.rs b/tests/ui/traits/const-traits/const-trait-async-assoc-fn.rs new file mode 100644 index 00000000000..00fdccc2ac8 --- /dev/null +++ b/tests/ui/traits/const-traits/const-trait-async-assoc-fn.rs @@ -0,0 +1,18 @@ +//@ edition: 2021 +#![feature(const_trait_impl)] + +const trait Tr { + async fn ft1() {} +//~^ ERROR async functions are not allowed in `const` traits +} + +const trait Tr2 { + fn f() -> impl std::future::Future<Output = ()>; +} + +impl const Tr2 for () { + async fn f() {} +//~^ ERROR async functions are not allowed in `const` trait impls +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/const-trait-async-assoc-fn.stderr b/tests/ui/traits/const-traits/const-trait-async-assoc-fn.stderr new file mode 100644 index 00000000000..09ba0969dc9 --- /dev/null +++ b/tests/ui/traits/const-traits/const-trait-async-assoc-fn.stderr @@ -0,0 +1,18 @@ +error: async functions are not allowed in `const` traits + --> $DIR/const-trait-async-assoc-fn.rs:5:5 + | +LL | const trait Tr { + | ----- associated functions of `const` cannot be declared `async` +LL | async fn ft1() {} + | ^^^^^ + +error: async functions are not allowed in `const` trait impls + --> $DIR/const-trait-async-assoc-fn.rs:14:5 + | +LL | impl const Tr2 for () { + | ----- associated functions of `const` cannot be declared `async` +LL | async fn f() {} + | ^^^^^ + +error: aborting due to 2 previous errors + |
