rust-lang / rust-analyzer

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

Invalid completion for function parameters of cfg'd functions #17708

Open RossSmyth opened 2 months ago

RossSmyth commented 2 months ago

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer 1.80.0 (05147895 2024-07-21)

rustc version: (eg. output of rustc -V)

rustc 1.80.0 (051478957 2024-07-21)

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)

Helix 24.7 (dbaa6366)

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

None I believe

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

N/A

code snippet to reproduce: Insert the following code into a module that does not have Path currently imported in the namespace. The return parameter can be any type that has a type parameter.

#[cfg(windows)]
pub fn test_case() -> Option<Path> {

}

While typing the Path parameter, select the completion for inserting a use statement image

The result:

This one showed up for the first time while creating this issue. I tried recreating it a few times and was unsuccessful. image

This is what usually happens image

Both are invalid, the use statement is not visible for the return parameter of the cfg'd out function.

RossSmyth commented 2 months ago

When I write code like this I always use fully-qualified paths in the function parameters if the cfg'd out code uses types not used elsewhere in the module. But I'm not sure if that's the desired action