Skip to content

Fix jump to def link generation on primitive type associated methods#156736

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
GuillaumeGomez:primitive-assoc-methods
May 24, 2026
Merged

Fix jump to def link generation on primitive type associated methods#156736
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
GuillaumeGomez:primitive-assoc-methods

Conversation

@GuillaumeGomez
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez commented May 19, 2026

Fixes #156707.

Interestingly enough, the inference fails on primitive type, so instead I go around a bit by generating a PrimitiveType and then tweak a bit the href generation.

r? @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels May 19, 2026
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from c139ad7 to af73ce7 Compare May 19, 2026 17:08
@rust-bors

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from af73ce7 to 260409a Compare May 19, 2026 21:21
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 19, 2026

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.

@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from 260409a to d1bcc86 Compare May 22, 2026 10:29
Copy link
Copy Markdown
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review

View changes since this review

Comment thread src/librustdoc/html/format.rs Outdated
Comment thread src/librustdoc/clean/types.rs Outdated
@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from d1bcc86 to a1dba63 Compare May 22, 2026 12:42
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 22, 2026

The GCC codegen subtree was changed

cc @antoyo

@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from a1dba63 to 300dc46 Compare May 22, 2026 12:43
@rust-log-analyzer

This comment has been minimized.

Comment thread src/librustdoc/html/span_map.rs Outdated
@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from 300dc46 to 8951062 Compare May 22, 2026 12:52
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);
Copy link
Copy Markdown
Member

@fmease fmease May 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Comment thread src/librustdoc/html/format.rs Outdated
Comment on lines +454 to +455
// 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.
Copy link
Copy Markdown
Member

@fmease fmease May 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

View changes since the review

Comment thread src/librustdoc/html/format.rs Outdated
Comment on lines +460 to +466
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))
}
};
Copy link
Copy Markdown
Member

@fmease fmease May 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
};

View changes since the review

@fmease
Copy link
Copy Markdown
Member

fmease commented May 23, 2026

Then r=me, thanks!

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 23, 2026
@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from 8951062 to abf1c7c Compare May 23, 2026 15:21
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the primitive-assoc-methods branch from abf1c7c to 0c7388c Compare May 23, 2026 17:07
@GuillaumeGomez
Copy link
Copy Markdown
Member Author

@bors r=fmease rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 23, 2026

📌 Commit 0c7388c has been approved by fmease

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 23, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request May 23, 2026
…hods, r=fmease

Fix jump to def link generation on primitive type associated methods

Fixes rust-lang#156707.

Interestingly enough, the inference fails on primitive type, so instead I go around a bit by generating a `PrimitiveType` and then tweak a bit the `href` generation.

r? @fmease
rust-bors Bot pushed a commit that referenced this pull request May 23, 2026
Rollup of 4 pull requests

Successful merges:

 - #156736 (Fix jump to def link generation on primitive type associated methods)
 - #156828 (Add unstable Share trait)
 - #156830 (Add `#[doc(alias = "phi")]` for float `GOLDEN_RATIO` constants)
 - #156860 (Fix Pieter-Louis Schoeman mailmap entry)
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 24, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 24, 2026

☀️ Test successful - CI
Approved by: fmease
Duration: 3h 9m 46s
Pushing e1ff77d to main...

@rust-bors rust-bors Bot merged commit e1ff77d into rust-lang:main May 24, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone May 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing dd8b2d6 (parent) -> e1ff77d (this PR)

Test differences

Show 6 test diffs

Stage 1

  • [rustdoc-html] tests/rustdoc-html/jump-to-def/prim-method.rs: [missing] -> pass (J1)

Stage 2

  • [rustdoc-html] tests/rustdoc-html/jump-to-def/prim-method.rs: [missing] -> pass (J0)

Additionally, 4 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard e1ff77d89857bfbf7ce8eefe09b450a7ed5c67ca --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-ohos-armv7: 48m 20s -> 1h 13m (+51.3%)
  2. x86_64-gnu-llvm-21-2: 1h 2m -> 1h 32m (+46.4%)
  3. dist-apple-various: 1h 23m -> 1h 48m (+30.5%)
  4. i686-gnu-2: 1h 41m -> 1h 10m (-29.8%)
  5. x86_64-gnu-aux: 2h 12m -> 1h 41m (-23.7%)
  6. dist-i686-mingw: 2h 7m -> 1h 37m (-23.4%)
  7. armhf-gnu: 1h 37m -> 1h 17m (-20.6%)
  8. dist-various-2: 42m 4s -> 50m 41s (+20.5%)
  9. dist-sparcv9-solaris: 1h 33m -> 1h 14m (-20.4%)
  10. dist-i686-linux: 1h 47m -> 1h 27m (-18.8%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e1ff77d): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -4.6%, secondary 0.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.7% [6.7%, 6.7%] 1
Improvements ✅
(primary)
-4.6% [-6.0%, -3.9%] 3
Improvements ✅
(secondary)
-5.4% [-5.4%, -5.4%] 1
All ❌✅ (primary) -4.6% [-6.0%, -3.9%] 3

Cycles

Results (secondary 9.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
9.4% [8.0%, 12.2%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 511.311s -> 511.791s (0.09%)
Artifact size: 400.72 MiB -> 400.68 MiB (-0.01%)

@GuillaumeGomez GuillaumeGomez deleted the primitive-assoc-methods branch May 25, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc generates broken link for inherent methods on primitive types on source code pages under --generate-link-to-definition

5 participants