Skip to content

[rustdoc] Remove UrlFragment::render method to unify clean::types::links and anchor - #149028

Merged
bors merged 3 commits into
rust-lang:mainfrom
GuillaumeGomez:unify-anchor
Nov 21, 2025
Merged

[rustdoc] Remove UrlFragment::render method to unify clean::types::links and anchor#149028
bors merged 3 commits into
rust-lang:mainfrom
GuillaumeGomez:unify-anchor

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Member

Fixes#148648.
First part of #148547.

The last part will be about handle AssocItemLink differently (either remove it or change how we do it).

r? @lolbinarycat

@rustbotrustbot 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 Nov 17, 2025
@lolbinarycat

Copy link
Copy Markdown
Contributor

I think we should block this on #149026 just to be safe.

@lolbinarycatlolbinarycat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks pretty good, just a few nits.

I am somewhat tempted to say in the future we should also unify the impl block section naming into the same function so that this same logic can be used for sidebar generation, but I'm not sure if that would be better than the status quo or not.

View changes since this review

Comment threadsrc/librustdoc/formats/item_type.rs Outdated
Comment threadsrc/librustdoc/html/format.rs Outdated
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

I think we should block this on #149026 just to be safe.

I actually tested with this one but I don't mind waiting. 😉

@GuillaumeGomez
GuillaumeGomezforce-pushed the unify-anchor branch 2 times, most recently from 3ad2a47 to 772c662CompareNovember 17, 2025 21:18
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Applied suggestions.

@rustbot

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
MemberAuthor

Rebased on #149026.

Comment threadsrc/librustdoc/html/format.rs Outdated
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Replaced the returned value of fragment.

Comment threadsrc/librustdoc/html/format.rs Outdated
};
let s;
let kind = if tcx.def_kind(parent_def_id) == DefKind::Variant {
s = format!("variant.{}.field", tcx.item_name(parent_def_id).as_str());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now that we're using from_fn, we shouldn't need this intermediate allocation either, it should be possible to rewrite this branch just as a series of calls to write!.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Applied suggestion.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Added back the # I removed by mistake.

/// becoming a `TyMethod`).
pub(crate) fn from_def_kind(kind: DefKind, parent_kind: Option<DefKind>) -> Self {
match kind {
pub(crate) fn from_def_id(def_id: DefId, tcx: TyCtxt<'_>) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

now that i think about it, wouldn't of_def_id be a more descriptive name?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Not exactly seems it involves a type conversion, not a direct translation.

Comment threadsrc/librustdoc/html/format.rs Outdated
} else {
String::new()
};
f.write_char('#').unwrap();

@lolbinarycatlolbinarycatNov 21, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why are we using unwrap here instead of ?, the from_fn closure returns a Result containing fmt::Error.

in fact, the last write! of each branch does cascade it's error, so we should do the same with the others.

the unwrap in the other function is fine because there we have a concrete type of String.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Arf indeed. Got so used to the unwrap everywhere that I simply used it here without second thought. Gonna check on a separate PRs to do the same change in the other from_fn calls.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

Updated!

@lolbinarycat

Copy link
Copy Markdown
Contributor

just realized if you don't give a top-level comment along with your review, rustbot doesn't have anywhere to put the "view changes since this review" link.

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

You can click on the force-push link to see what happened. In this case I didn't rebase so it's a perfect use-case for it. :)

@lolbinarycat

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Nov 21, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 8f76773 has been approved by lolbinarycat

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2025
bors added a commit that referenced this pull request Nov 21, 2025
Rollup of 7 pull requests
Successful merges:
- #146978 (Emit error when using path-segment keyword as cfg pred)
- #148719 (Allow unnormalized types in drop elaboration)
- #148795 (add `rust.rustflags` and per target `rustflags` options to `bootstrap.toml`)
- #149028 ([rustdoc] Remove `UrlFragment::render` method to unify `clean::types::links` and `anchor`)
- #149043 ( rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution)
- #149098 (Fix error message for calling a non-tuple struct)
- #149151 (Add test for importing path-segment keyword)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 110471b into rust-lang:mainNov 21, 2025
11 checks passed
@rustbotrustbot added this to the 1.93.0 milestone Nov 21, 2025
rust-timer added a commit that referenced this pull request Nov 21, 2025
Rollup merge of #149028 - GuillaumeGomez:unify-anchor, r=lolbinarycat
[rustdoc] Remove `UrlFragment::render` method to unify `clean::types::links` and `anchor`
Fixes#148648.
First part of #148547.
The last part will be about handle `AssocItemLink` differently (either remove it or change how we do it).
r? `@lolbinarycat`
@GuillaumeGomez
GuillaumeGomez deleted the unify-anchor branch November 22, 2025 10:30
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 24, 2025
…amofek,lolbinarycat
[rustdoc] Make more functions return `fmt::Result` and reduce number of `.unwrap()` calls
Following our discussion in rust-lang#149028 (comment), this PR makes more function return `fmt::Result`, allowing to use `?` a lot more, and also reducing number of `.unwrap()` calls.
r? `@lolbinarycat`
rust-timer added a commit that referenced this pull request Nov 24, 2025
Rollup merge of #149208 - GuillaumeGomez:less-unwraps, r=yotamofek,lolbinarycat
[rustdoc] Make more functions return `fmt::Result` and reduce number of `.unwrap()` calls
Following our discussion in #149028 (comment), this PR makes more function return `fmt::Result`, allowing to use `?` a lot more, and also reducing number of `.unwrap()` calls.
r? `@lolbinarycat`
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Nov 25, 2025
…lbinarycat
[rustdoc] Make more functions return `fmt::Result` and reduce number of `.unwrap()` calls
Following our discussion in rust-lang/rust#149028 (comment), this PR makes more function return `fmt::Result`, allowing to use `?` a lot more, and also reducing number of `.unwrap()` calls.
r? `@lolbinarycat`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
Rollup of 7 pull requests
Successful merges:
- rust-lang/rust#146978 (Emit error when using path-segment keyword as cfg pred)
- rust-lang/rust#148719 (Allow unnormalized types in drop elaboration)
- rust-lang/rust#148795 (add `rust.rustflags` and per target `rustflags` options to `bootstrap.toml`)
- rust-lang/rust#149028 ([rustdoc] Remove `UrlFragment::render` method to unify `clean::types::links` and `anchor`)
- rust-lang/rust#149043 ( rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution)
- rust-lang/rust#149098 (Fix error message for calling a non-tuple struct)
- rust-lang/rust#149151 (Add test for importing path-segment keyword)
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant 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] html::format::print_anchor doesn't handle fields of fields correctly

5 participants

@GuillaumeGomez@lolbinarycat@rustbot@rust-log-analyzer@bors