rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.34k stars 12.72k forks source link

`Send` bound of trait object make unexpected async block is not general enough error #130596

Open ethe opened 1 month ago

ethe commented 1 month ago

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4f2133cbf38d27366a8edd106b5485e5

I expected to see this happen: Same as below, compile pass: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=69e324c356bd126e575a971a7cbbf2fa

Instead, this happened:

error: implementation of `From` is not general enough
  --> src/lib.rs:44:9
   |
44 | /         Box::pin(async move {
45 | |             let response = self.send_request(request).await;
46 | |             match response {
47 | |                 Ok(response) => todo!(),
...  |
51 | |             }
52 | |         })
   | |__________^ implementation of `From` is not general enough
   |
   = note: `Box<(dyn std::error::Error + Send + Sync + 'static)>` must implement `From<Box<(dyn std::error::Error + Send + Sync + '0)>>`, for any lifetime `'0`...
   = note: ...but it actually implements `From<Box<(dyn std::error::Error + Send + Sync + 'static)>>`

error: could not compile `playground` (lib) due to 1 previous error; 1 warning emitted
csmoe commented 1 month ago

Duplicate of https://github.com/rust-lang/rust/issues/64552

Convert the type alias to a struct can workaround this https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b310f0b751f46eac66956c4eb1f85e7f