diff --git a/src/test/ui/async-await/async-trait-fn-with-default-body.rs b/src/test/ui/async-await/async-trait-fn-with-default-body.rs new file mode 100644 index 0000000000000..6fbcce7ce2740 --- /dev/null +++ b/src/test/ui/async-await/async-trait-fn-with-default-body.rs @@ -0,0 +1,18 @@ +// edition:2018 + +// FIXME: enable the async_fn_in_trait feature in this test after 101665 is fixed and we can +// actually test these. + +trait T { + async fn foo() {} //~ ERROR functions in traits cannot be declared `async` + //~^ ERROR mismatched types + async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async` + //~^ ERROR mismatched types + async fn baz() { //~ ERROR functions in traits cannot be declared `async` + //~^ ERROR mismatched types + // Nested item must not ICE. + fn a() {} + } +} + +fn main() {} diff --git a/src/test/ui/async-await/async-trait-fn-with-default-body.stderr b/src/test/ui/async-await/async-trait-fn-with-default-body.stderr new file mode 100644 index 0000000000000..49d5258d12c27 --- /dev/null +++ b/src/test/ui/async-await/async-trait-fn-with-default-body.stderr @@ -0,0 +1,90 @@ +error[E0706]: functions in traits cannot be declared `async` + --> $DIR/async-trait-fn-with-default-body.rs:7:5 + | +LL | async fn foo() {} + | -----^^^^^^^^^ + | | + | `async` because of this + | + = note: `async` trait functions are not currently supported + = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: see issue #91611 for more information + = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable + +error[E0706]: functions in traits cannot be declared `async` + --> $DIR/async-trait-fn-with-default-body.rs:9:5 + | +LL | async fn bar(&self) {} + | -----^^^^^^^^^^^^^^ + | | + | `async` because of this + | + = note: `async` trait functions are not currently supported + = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: see issue #91611 for more information + = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable + +error[E0706]: functions in traits cannot be declared `async` + --> $DIR/async-trait-fn-with-default-body.rs:11:5 + | +LL | async fn baz() { + | -----^^^^^^^^^ + | | + | `async` because of this + | + = note: `async` trait functions are not currently supported + = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: see issue #91611 for more information + = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable + +error[E0308]: mismatched types + --> $DIR/async-trait-fn-with-default-body.rs:7:20 + | +LL | async fn foo() {} + | ^^ expected associated type, found opaque type + | + ::: $SRC_DIR/core/src/future/mod.rs:LL:COL + | +LL | pub const fn from_generator(gen: T) -> impl Future + | ------------------------------- the found opaque type + | + = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn-with-default-body.rs:7:20>) + found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) + +error[E0308]: mismatched types + --> $DIR/async-trait-fn-with-default-body.rs:9:25 + | +LL | async fn bar(&self) {} + | ^^ expected associated type, found opaque type + | + ::: $SRC_DIR/core/src/future/mod.rs:LL:COL + | +LL | pub const fn from_generator(gen: T) -> impl Future + | ------------------------------- the found opaque type + | + = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn-with-default-body.rs:9:25>) + found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) + +error[E0308]: mismatched types + --> $DIR/async-trait-fn-with-default-body.rs:11:20 + | +LL | async fn baz() { + | ____________________^ +LL | | +LL | | // Nested item must not ICE. +LL | | fn a() {} +LL | | } + | |_____^ expected associated type, found opaque type + | + ::: $SRC_DIR/core/src/future/mod.rs:LL:COL + | +LL | pub const fn from_generator(gen: T) -> impl Future + | ------------------------------- the found opaque type + | + = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn-with-default-body.rs:11:20>) + found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0308, E0706. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/async-await/async-trait-fn.rs b/src/test/ui/async-await/async-trait-fn.rs index 0ea685986db40..a883a8f87b7ad 100644 --- a/src/test/ui/async-await/async-trait-fn.rs +++ b/src/test/ui/async-await/async-trait-fn.rs @@ -1,14 +1,17 @@ // edition:2018 +// check-pass + +#![feature(async_fn_in_trait)] //~ WARN the feature `async_fn_in_trait` is incomplete + trait T { - async fn foo() {} //~ ERROR functions in traits cannot be declared `async` - //~^ ERROR mismatched types - async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async` - //~^ ERROR mismatched types - async fn baz() { //~ ERROR functions in traits cannot be declared `async` - //~^ ERROR mismatched types - // Nested item must not ICE. - fn a() {} - } + async fn foo(); + // async fn bar(&self); +} + +struct Impl; + +impl T for Impl { + async fn foo() {} } fn main() {} diff --git a/src/test/ui/async-await/async-trait-fn.stderr b/src/test/ui/async-await/async-trait-fn.stderr index 4fa54c6e36960..32b83740aaf1d 100644 --- a/src/test/ui/async-await/async-trait-fn.stderr +++ b/src/test/ui/async-await/async-trait-fn.stderr @@ -1,90 +1,11 @@ -error[E0706]: functions in traits cannot be declared `async` - --> $DIR/async-trait-fn.rs:3:5 +warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/async-trait-fn.rs:4:12 | -LL | async fn foo() {} - | -----^^^^^^^^^ - | | - | `async` because of this +LL | #![feature(async_fn_in_trait)] + | ^^^^^^^^^^^^^^^^^ | - = note: `async` trait functions are not currently supported - = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: `#[warn(incomplete_features)]` on by default = note: see issue #91611 for more information - = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable -error[E0706]: functions in traits cannot be declared `async` - --> $DIR/async-trait-fn.rs:5:5 - | -LL | async fn bar(&self) {} - | -----^^^^^^^^^^^^^^ - | | - | `async` because of this - | - = note: `async` trait functions are not currently supported - = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait - = note: see issue #91611 for more information - = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable - -error[E0706]: functions in traits cannot be declared `async` - --> $DIR/async-trait-fn.rs:7:5 - | -LL | async fn baz() { - | -----^^^^^^^^^ - | | - | `async` because of this - | - = note: `async` trait functions are not currently supported - = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait - = note: see issue #91611 for more information - = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable - -error[E0308]: mismatched types - --> $DIR/async-trait-fn.rs:3:20 - | -LL | async fn foo() {} - | ^^ expected associated type, found opaque type - | - ::: $SRC_DIR/core/src/future/mod.rs:LL:COL - | -LL | pub const fn from_generator(gen: T) -> impl Future - | ------------------------------- the found opaque type - | - = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn.rs:3:20>) - found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) - -error[E0308]: mismatched types - --> $DIR/async-trait-fn.rs:5:25 - | -LL | async fn bar(&self) {} - | ^^ expected associated type, found opaque type - | - ::: $SRC_DIR/core/src/future/mod.rs:LL:COL - | -LL | pub const fn from_generator(gen: T) -> impl Future - | ------------------------------- the found opaque type - | - = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn.rs:5:25>) - found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) - -error[E0308]: mismatched types - --> $DIR/async-trait-fn.rs:7:20 - | -LL | async fn baz() { - | ____________________^ -LL | | -LL | | // Nested item must not ICE. -LL | | fn a() {} -LL | | } - | |_____^ expected associated type, found opaque type - | - ::: $SRC_DIR/core/src/future/mod.rs:LL:COL - | -LL | pub const fn from_generator(gen: T) -> impl Future - | ------------------------------- the found opaque type - | - = note: expected associated type `impl Future` (trait associated opaque type at <$DIR/async-trait-fn.rs:7:20>) - found opaque type `impl Future` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>) - -error: aborting due to 6 previous errors +warning: 1 warning emitted -Some errors have detailed explanations: E0308, E0706. -For more information about an error, try `rustc --explain E0308`.