Avoid recording unnameable extern crate aliases in diagnostic metadata - #158997
Avoid recording unnameable extern crate aliases in diagnostic metadata#158997raushan728 wants to merge 2 commits into
extern crate aliases in diagnostic metadata#158997Conversation
|
r? @TaKO8Ki rustbot has assigned @TaKO8Ki. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| self.print_crate_name(cnum)?; | ||
| return Ok(true); | ||
| } | ||
|
|
There was a problem hiding this comment.
This is the wrong place to add this code.
What is the entry in visible_parent_map for MyTrait? Why isn't this entry printed directly? Why is the path using _ preferred?
There was a problem hiding this comment.
What is the entry in
visible_parent_mapforMyTrait?
form what i traced visible_parent_map already looks correct. For MyTrait it points back to the crate root, so i dont think the incorrect suggestion originates there.
Why isn't this entry printed directly?
while following the path logic , i found that after reaching the crate root try_print_visible_def_path_recur calls tcx.extern_crate(cnum) to decide how to refer to that crate in diagnostic. It doesn't stop at the visible_parent_map entry.
Why is the path using
_preferred?
that seems to come from the metadata recorded in process_extern_crate. for an extern crate inside a block, we currently still record it as ExternCrateSource::Extern(def_id), so tcx.extern_crate(cnum) later returns that block scoped alias. pretty.rs is then just printing the DefId it was given, which is why the suggestion ends up as crate::_::_my_crate.
based on that i moved the fix to process_extern_crate instead of pretty.rs so we avoid recording an unnameable extern crate as the diagnostic representation in the first place.
264014a to
6940778
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6940778 to
b236ee3
Compare
b236ee3 to
5d31258
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
…Source::Path` Use the `DefPath` to determine whether an `extern crate` item is globally nameable. `extern crate` items nested inside value namespaces cannot be referred to by a stable path outside their enclosing scope. Record them as `ExternCrateSource::Path` instead of `ExternCrateSource::Extern` so later path resolution does not reconstruct unnameable paths.
5d31258 to
f9f0a04
Compare
crate::_::_... paths for trait importsextern crate aliases in diagnostic metadata
the root cause was that block scoped
extern cratealiases were still being recorded asExternCrateSource::Extern(def_id). later, diagnostics reused that metadata and attempted to print paths through those aliases, producing unnameable paths such ascrate::_::_my_crate.this change detects
extern crateitems whoseDefPathpasses through a value namespace (for example inside functions orconstblocks) and records them asExternCrateSource::Pathinstead. diagnostics then fall back to the crate name rather than an unnameable alias.Closes #153459