rust-lang / impl-trait-utils

Utilities for working with impl traits in Rust.
Apache License 2.0
89 stars 9 forks source link

make with generics #16

Closed demosdemon closed 1 month ago

demosdemon commented 8 months ago

Suppose you wanted to write a tower-esque trait using RPITIT:

pub trait LocalService<Request> {
    type Response;
    type Error;

    async fn execute(self, request: Request) -> Result<Self::Response, Self::Error>;
}

This now works, but if I want to use make to add a Send variant, the macro fails:

error: expected `:`
 --> src/example.rs:1:30
  |
1 | #[trait_variant::make(Service<Request>: Send)]
  |                              ^

Omitting the generic parameters yields a different error:

error[E0412]: cannot find type `Request` in this scope
 --> src/example.rs:6:37
  |
6 |     async fn execute(self, request: Request) -> Result<Self::Response, Self::Error>;
  |                                     ^^^^^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 + use core::error::Request;
  |
1 + use std::error::Request;
  |

error[E0107]: missing generics for trait `LocalService`
 --> src/example.rs:2:11
  |
2 | pub trait LocalService<Request> {
  |           ^^^^^^^^^^^^ expected 1 generic argument
  |
note: trait defined here, with 1 generic parameter: `Request`
 --> src/example.rs:2:11
  |
2 | pub trait LocalService<Request> {
  |           ^^^^^^^^^^^^ -------
help: add missing generic argument
  |
2 | pub trait LocalService<Request><Request> {
  |                       +++++++++

error[E0107]: missing generics for trait `Service`
 --> src/example.rs:1:23
  |
1 | #[trait_variant::make(Service: Send)]
  |                       ^^^^^^^ expected 1 generic argument
  |
note: trait defined here, with 1 generic parameter: `Request`
 --> src/example.rs:1:23
  |
1 | #[trait_variant::make(Service: Send)]
  |                       ^^^^^^^
2 | pub trait LocalService<Request> {
  |                        -------
help: add missing generic argument
  |
1 | #[trait_variant::make(Service<Request>: Send)]
  |                              +++++++++
mx00s commented 3 months ago

Should this be closed?