Definition location suggestion for central libraries shows unhelpful system path
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
(First noticed in #159490)
When the compiler is showing the declaration of a wrongly used item as a suggestion, it gives out the full system path for the source file :
fn main() {
let mut x = 0;
errored(&x);
}
fn errored(wrong: &mut u32) {}
note: function defined here
--> src\main.rs:6:4
|
6 | fn errored(wrong: &mut u32) {}
| ^^^^^^^ ---------------
This works out fine for local projects , as this diagnostic seems to give out the relative path in which cargo is invoked which invokes rustc. The issue arises when the wrongly invoked item is in something where you shouldn't change, namely the standard library source code in your system, for example the read_line function:
fn main() {
let input = String::new();
std::io::stdin().read_line(&input).unwrap();
}
note: method defined here
--> /rustc/1159e78c4747b02ef996e55082b704c09b970588\library\std\src\io\stdio.rs:411:12
It is probably not a good idea for the end user to go to this exact path if they ever feel the need to patch something, so in my opinion it doesn't make sense that we currently show where it is.
Of course this can make sense for anyone debugging and playing around with the compiler in any shape or form, but for the end user I think this issue is worth considering, perhaps it could be something more like:
note: method defined here
--> std\src\io\stdio.rs:411:12
This works out for basicest of compiler debugging, and doesn't confuse the end user on something that they shouldn't change, but it may also lead to them searching std as a literal path as well, in which case extra warnings (a note like "(not a literal path)" maybe?) work fine.
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 diagnostic with the read_line example and compare it with the local errored example. Trace the compiler diagnostic path that formats the definition location, then determine how central-library paths should be displayed and add coverage for the resulting wording. Done means standard-library suggestions no longer expose an unhelpful absolute system path while local paths remain useful.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100