rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.17k stars 1.58k forks source link

RA can't provide completions for a trait that has a subtrait with a trait bound on one of its associated types #18277

Open kanpov opened 2 days ago

kanpov commented 2 days ago

SUMMARY OF THE ISSUE: This is an example from my code, this trait definition will provide code completions via RA just fine:

pub trait FsOperation<R: Send + 'static>:
    IntoFuture<
    Output = Result<R, std::io::Error>,
    IntoFuture = Pin<Box<dyn Future<Output = Result<R, std::io::Error>> + Send + 'static>>,
> {
  // ... methods that should get completions
}

As you can see, it has a concrete requirement on the IntoFuture associated type of IntoFuture.

However, if, instead of making the associated type requirement a concrete type, I simply set a : Send bound (or any other trait bound) on it like so, everything still compiles through cargo and rustc, yet RA is unable to show the same completions even after saving and cargo check-ing:

pub trait FsOperation<R: Send + 'static>: IntoFuture<Output = Result<R, std::io::Error>, IntoFuture: Send> {
  // ... methods that should get completions but don't
}

Granted, this can be considered type system torture, but the language supports it just fine, so RA should as well.

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P) rust-analyzer version: 0.3.2137-standalone [/home/kanpov/.vscode/extensions/rust-lang.rust-analyzer-0.3.2137-linux-x64/server/rust-analyzer]

rustc version: (eg. output of rustc -V) rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable) VSCode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce: Snippets were provided above

davidbarsky commented 2 days ago

This probably depends on using the new trait solver in rust-analyzer. We're working on it, but it'll take some time.

kanpov commented 2 days ago

This probably depends on using the new trait solver in rust-analyzer. We're working on it, but it'll take some time.

Probably, since this is a decisively complicated type system case, but the interesting part is that RA doesn't error out or crash with its beloved textDocument/completion failed (which I still consistently get at least once a week), just refuses to do completions.

davidbarsky commented 2 days ago

but the interesting part is that RA doesn't error out or crash with its beloved textDocument/completion failed.

The two are unrelated: if you see a visible panic, that's a bug in rust-analyzer. If you get a reproduction/backtrace and report it, we'd appreciate tremendously. What you're seeing in this issue is rust-analyzer correctly timing out and giving up on solving this trait bound.