rust-lang / rust-lang/rust-analyzer
"Implement missing members" uses inaccessible type aliases
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
0.3.1641-standalone (144526c90 2023-08-28)
rustc version: (eg. output of rustc -V)
rustc 1.68.2 (9eb3afe9e 2023-03-27)
relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)
VS Code settings:
{
"rust-analyzer.cargo.features": "all"
}
Description
When the Quick Fix "Implement missing members" is used for missing trait method implementations whose signature uses inaccessible type aliases, then rust-analyzer will nonetheless use those inaccessible type aliases in the generated code, leading to errors and possibly confusion for the user.
Other tools seem to handle that better, for example cargo doc will in the generated documentation not show the inaccessible type, but instead the public type it refers to.
Expected behavior
If the type alias is inaccessible, rust-analyzer should instead use the accessible referenced type.
(And ideally not crash if the referenced type is inaccessible as well.)
How to reproduce
- Use the following Rust code
ℹ️ Note: rust-analyzer shows an error that not allmod my_mod { type PrivateAlias = u32; pub trait MyTrait { fn do_something() -> PrivateAlias; } } struct MyStruct; impl my_mod::MyTrait for MyStruct { // ... select "Implement missing members" }MyTraitmethods are implemented forMyStruct - Select "Implement missing members"
❌ Bug: rust-analyzer creates the following code:
This does not compile becauseimpl my_mod::MyTrait for MyStruct { fn do_something() -> PrivateAlias { todo!() } }PrivateAliasis inaccessible
This is a bit contrived; for my actual use case I had type IoError = std::io::Error to avoid name conflicts or confusion in my private implementation because there are multiple types called Error, but I don't want to publicly expose that type alias.
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
Start with the Quick Fix entry point for "Implement missing members" and reproduce the issue with the Rust snippet in the report. Trace how the generated method signature resolves a private type alias, then add coverage for the inaccessible-alias case and verify that the generated implementation uses an accessible referenced type and does not crash when that type is also inaccessible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100