Skip to content

Commit

Permalink
Add regression test for issue 281
Browse files Browse the repository at this point in the history
Without #![feature(impl_trait_in_bindings)]:

    error[E0562]: `impl Trait` is not allowed in paths
        --> tests/test.rs:1680:42
         |
    1680 |         async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> {
         |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = note: `impl Trait` is only allowed in arguments and return types of functions and methods

    error[E0562]: `impl Trait` is not allowed in the type of variable bindings
        --> tests/test.rs:1680:42
         |
    1680 |         async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> {
         |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = note: `impl Trait` is only allowed in arguments and return types of functions and methods
         = note: see issue #63065 <rust-lang/rust#63065> for more information
         = help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
         = note: this compiler was built on 2025-01-02; consider upgrading it if it is out of date

With #![feature(impl_trait_in_bindings)]:

    error[E0562]: `impl Trait` is not allowed in paths
        --> tests/test.rs:1680:42
         |
    1680 |         async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> {
         |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |
         = note: `impl Trait` is only allowed in arguments and return types of functions and methods
  • Loading branch information
dtolnay committed Jan 3, 2025
1 parent 7d8519d commit aff365f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,24 @@ pub mod issue277 {

fn g(_: &mut &()) {}
}

// https://github.com/dtolnay/async-trait/issues/281
pub mod issue281 {
use async_trait::async_trait;

#[async_trait]
pub trait Trait {
type Error;
async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error>;
}

pub struct T;

#[async_trait]
impl Trait for T {
type Error = ();
async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> {
Ok("Hello World")
}
}
}

0 comments on commit aff365f

Please sign in to comment.