rust-lang / rust-analyzer

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

`add_explicit_type` code action not available for `#[doc(hidden)]` types #17934

Open adaszko opened 3 weeks ago

adaszko commented 3 weeks ago

rust-analyzer version: rust-analyzer version: 0.3.2078-standalone (fa0032624 2024-08-17)

rustc version: rustc 1.80.0 (051478957 2024-07-21)

editor or extension: Both Neovim and VSCode

code snippet to reproduce:

main.rs:

use ustr::UstrSet;

pub fn bar() -> UstrSet {
    todo!();
}

fn main() {
    let _i = 123;
    let foo = bar();
}

Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
ustr = "1.0.0"

When I try to perform the add_explicit_type code action on the variable i of a simple type the code action shows up just fine:

image

Whereas when I try to do the same thing on the variable foo that uses a type from an external crate (ustr in this case):

image

There's no code action available for inserting the type of foo.

Same behavior under VSCode.

adaszko commented 3 weeks ago

VSCode:

image image
ChayimFriedman2 commented 2 weeks ago

The problem is that UstrSet contains a #[doc(hidden)] type (IdentityHasher).

Fixing this will be hard. We probably don't want to insert #[doc(hidden)] types, the assist is correct in this regard. Ideally we will insert the type alias UstrSet, but this is hard to do with the current infrastructure.

adaszko commented 2 weeks ago

The problem is that UstrSet contains a #[doc(hidden)] type (IdentityHasher).

Fixing this will be hard. We probably don't want to insert #[doc(hidden)] types, the assist is correct in this regard. Ideally we will insert the type alias UstrSet, but this is hard to do with the current infrastructure.

Thanks for looking into it. I'm assuming rust-analyzer leverages the rustdoc infrastructure to collect exported crate members and that's the reason it won't work.

Are there any plans for an alternative way of collecting exported members?

ChayimFriedman2 commented 2 weeks ago

I'm assuming rust-analyzer leverages the rustdoc infrastructure to collect exported crate members and that's the reason it won't work.

No, it uses its own infrastructure.

Expanding to the type alias won't work because we always evaluate type aliases (rustc does the same).