Skip to content

default impl for methods with impl trait arguments? #126

@wfraser

Description

@wfraser

Given the code:

use async_trait::async_trait; // 0.1.36
use tokio; // 0.2.21

#[async_trait]
trait MyTrait {
    async fn blah(&self, values: impl Iterator<Item = i32> + Send + 'async_trait) {
        println!("this is the default");
    }
}

struct S;

#[async_trait]
impl MyTrait for S {
    async fn blah(&self, values: impl Iterator<Item = i32> + Send + 'async_trait) {
        for value in values {
            println!("{}", value);
        }
    }
}

#[tokio::main]
async fn main() {
    let s = S;
    s.blah([1, 2, 3].iter().cloned()).await;
}

this fails to compile with the error:

error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
 --> src/main.rs:4:1
  |
4 | #[async_trait]
  | ^^^^^^^^^^^^^^ explicit generic argument not allowed
  |
  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

If I remove the default body, it works.

Is this intended to be supported? I can work around it by boxing and using dyn, i.e. values: Box<dyn Iterator<Item=i32> + Send + 'async_trait> but that's not ideal.

Thanks for this crate!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions