rust-lang / rust-lang/rust-analyzer
Anything related to the sys create isn't working
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Concrete example:
use std::alloc::{System, Layout};
use std::alloc::GlobalAlloc;
fn foo(layout: Layout) {
unsafe {
System.alloc(layout);
}
}
rust-analyzer doesn't show alloc in the auto-completions of System, even when the relevant trait (GlobalAlloc) is already imported.
Go to Definition on alloc also does not work, while on System it does.
The implementation of alloc (impl GlobalAlloc for System) exists inside the built-in sys crate, which has a different implementation for each environment (e.g. Linux, Windows).
The code defining the trait GlobalAlloc which declares fn alloc is not in sys but Go to Definition doesn't get me there, probably because without parsing sys it doesn't know that System implements this trait at all.
I was expecting for it to either go to the trait, or to the specific implementation in sys which matches my configuration, or to show all different implementations for me to choose.
In general, when browsing the sys built-in crate (after I reach it from a series of Go to Definitions from my code through the standard library), rust-analyzer does not work at all.
I realize std::sys is not defined as a public crate so it is mostly reachable from std code rather than user code, but this is a pretty big chunk of the standard library and not having rust-analyzer active when browsing code there is difficult.
If the problem is the cfg attributes because they cannot be resolved inside the analyzer, then maybe analyzing all of the possible implementations is possible.
Thanks!
rust-analyzer version: 7e95c14ea 2022-05-17 stable
rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18
relevant settings: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the missing completion and Go to Definition behavior with the provided System, Layout, and GlobalAlloc example. Start by tracing the built-in sys crate reached from std, including its platform-specific alloc implementations and cfg attributes, then compare that with the GlobalAlloc trait in core. Done means rust-analyzer provides useful navigation or completion for this implementation while browsing the relevant sys code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100