dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

async_trait uses the raw `Box` identifier rather than a fully qualified path #214

Closed Stonks3141 closed 1 year ago

Stonks3141 commented 2 years ago

This prevents you from writing an async trait called Box or using async_trait when something else called Box is in scope.

Example (playground):

#[async_trait]
trait Box {
    async fn foo();
}

This expands to

trait Box {
    #[must_use]
    #[allow(clippy :: type_complexity, clippy :: type_repetition_in_bounds)]
    fn foo<'async_trait>()
    ->
        ::core::pin::Pin<Box<dyn ::core::future::Future<Output = ()> +
        ::core::marker::Send + 'async_trait>>;
}

Since the attribute macro uses the Box name as-is from the prelude instead of std::boxed::Box or alloc::boxed::Box, the compiler doesn't know you don't mean the Box trait.

I would think this could be fixed by replacing Box with alloc::boxed::Box in the macro output. This would mean that extern crate alloc would have to be added to the macro output somehow.

dtolnay commented 1 year ago

Duplicate of #163.