Issue with hover tooltips and autocompletion in binary crates
When working on a binary crate, I encountered a weird issue:
For a module I would not get tooltips on certain methods and types if the module was not imported into main.rs.
For example, consider the following project:
. ├── Cargo.lock ├── Cargo.toml ├── src │ ├── main.rs │ ├── mod1.rs │ └── subfolder_mod │ └── mod.rs
For the function
mod1.rs
fn slice_to_string(slice: &[u32]) -> String {
slice
.iter()
.map(|number| number.to_string())
.collect::<Vec<String>>()
.join(" ")
}
I would not get any tooltips on hover, and also could not go to definition, for map, to_string, collect, join and the type of number UNLESS I brought the module into the scope of main.rs like so:
in main.rs
mod mod1;
fn main() {unimplemented!()}
After doing so the tooltips were as expected, altough autocomplete for iterator combinators still didn't work (it never has, for me).
It doesn't matter if slice_to_string is public or private, or is actually used in main or not, only that the module it's contained in is in the scope of main.rs.
Functions in subfolder_mod would show the exact same behavior.
Moving mod1.rs into it's own subfolder, i.e. changing the layout to:
├── Cargo.lock ├── Cargo.toml ├── src │ ├── main.rs │ ├── mod1 │ │ └── mod.rs │ └── some_mod │ └── mod.rs
Doesn't help.
For lib crates, this issue doesn't seem to exist, as far as I could tell.
Did I get something wrong?
Advice is greatly appreciated :slightly_smiling_face:
edit: On an unrelated note, clippy thaught me that I could've written .map(std::string::ToString::to_string)