Fix jump to def link generation on primitive type associated methods#156736
Fix jump to def link generation on primitive type associated methods#156736GuillaumeGomez wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
c139ad7 to
af73ce7
Compare
This comment has been minimized.
This comment has been minimized.
af73ce7 to
260409a
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. |
260409a to
d1bcc86
Compare
d1bcc86 to
a1dba63
Compare
|
The GCC codegen subtree was changed cc @antoyo |
a1dba63 to
300dc46
Compare
This comment has been minimized.
This comment has been minimized.
300dc46 to
8951062
Compare
| if def_id != original_def_id && matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) { | ||
| let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); | ||
| def_id = infcx | ||
| let ty = tcx.type_of(def_id); |
There was a problem hiding this comment.
Could you use the normalized type for both the ADT check and the primitive one? So set ty to the normalized type? Something like the following (pseudo code):
let ty = tcx.type_of(def_id);
let ty =
...query_normalize(...ty...)
.map(...resolve_vars_if_possible...)
.unwrap_or(ty);That's because I'm relatively sure we're currently failing at finding the definition if the impl contains free alias types (unlikely scenario but normalizing is simply the correct thing to do).
Consider:
rustc a.rs --crate-type=lib:#![feature(lazy_type_alias, rustc_attrs)] #![rustc_coherence_is_core] type Identity<T> = T; impl Identity<u8> { pub fn inherent(self) {} }
rustdoc b.rs -L. --generate-link-to-definition -Zunstable-options:fn scope() { extern crate a; 0u8.inherent(); }
So under your PR I presume inherent still 404s but please double-check that locally.
| // If the parent is an impl of a primitive type, it'll fail because primitives aren't | ||
| // ADT, so instead we use `type_of` to get the actual primitive type. |
There was a problem hiding this comment.
| // If the parent is an impl of a primitive type, it'll fail because primitives aren't | |
| // ADT, so instead we use `type_of` to get the actual primitive type. |
I mean we're also using type_of in the ADT case. It's just that we first check if it's an ADT then if it's a primitive if it's not the former.
| let (fqp, shortty): (Vec<Symbol>, ItemType) = match prim { | ||
| Some(prim) => (vec![crate_name, prim.as_sym()], ItemType::Primitive), | ||
| None => { | ||
| let relative = clean::inline::item_relative_path(tcx, def_id); | ||
| (once(crate_name).chain(relative).collect(), ItemType::from_def_id(def_id, tcx)) | ||
| } | ||
| }; |
There was a problem hiding this comment.
| let (fqp, shortty): (Vec<Symbol>, ItemType) = match prim { | |
| Some(prim) => (vec![crate_name, prim.as_sym()], ItemType::Primitive), | |
| None => { | |
| let relative = clean::inline::item_relative_path(tcx, def_id); | |
| (once(crate_name).chain(relative).collect(), ItemType::from_def_id(def_id, tcx)) | |
| } | |
| }; | |
| let mut fqp = vec![crate_name]; | |
| let shortty = if let Some(prim) = prim { | |
| fqp.push(prim.as_sym()); | |
| ItemType::Primitive | |
| } else { | |
| fqp.append(&mut clean::inline::item_relative_path(tcx, def_id)); | |
| ItemType::from_def_id(def_id, tcx) | |
| }; |
|
Then r=me, thanks! |
Fixes #156707.
Interestingly enough, the inference fails on primitive type, so instead I go around a bit by generating a
PrimitiveTypeand then tweak a bit thehrefgeneration.r? @fmease