When writing Tower services for my app (possibly when chaining multiple of them) I get a return type mismatch error from rust-analyzer but no issues from rustc.
Since rustc compiles my code perfectly fine, I assume this is a limitation in how rust-analyzer resolves deeply nested Tower traits (not dealing correctly with complex trait bounds), rather than an issue with my code.
Is this a known limitation of rust-analyzer or a big oversight from my part?
How could the trait be rewritten to avoid rust-analyzer complaints?
RA uses the next-gen trait solver already, so this could be related. If you get the same error on nightly with -Z next-solver=globally and think it's a bug, you could file a bug report (or look for an existing one that seems the same).
This could be a next-solver issue like @quinedot has said. It could also be a recursion limit issue; rust-analyzer hardcodes the recursion limit to 50, which is lower than rustc's default 128 and cannot be customized.
This is the exact RA error: expected Pin<Box<dyn Future<Output = Result<ExecuteResponse, Error>> + Send + 'static, Global>>, found Pin<Box<impl Future<Output = Result<ExecuteResponse, RequestError>>, Global>> where type Error = InnerService::Error; (which is RequestError).
I don't know whether this issue is related Conversion of generated future fails, although it should succeed · Issue #92929 · rust-lang/rust · GitHub
Thanks everyone for all your help! At the moment I think I will stick with the stable rustc and RA while the nightly build fixes the trait issue, it unfortunately causes RA to panic on some proc_macros. I'm looking forward to the stabilization of 1.99!
That is incorrect. rustc gets diagnostic from cargo check (if you have check on save enabled), which can cause errors even if it is clean on the terminal due to different flags, but most of the time not, and r-a own analysis, which is totally independent of Cargo and rustc.
r-a does depend on Cargo for few things. For example, discovering workspaces, running check on save, or running tests when requested by the user. None of them can emit a trait error except check on save, and as I said it is likely not involved here.