Skip to content

Conversation

@GuillaumeGomez
Copy link
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

@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 Nov 17, 2025
@lolbinarycat
Copy link
Contributor

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

Copy link
Contributor

@lolbinarycat lolbinarycat left a comment

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

@GuillaumeGomez
Copy link
Member Author

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 GuillaumeGomez force-pushed the unify-anchor branch 2 times, most recently from 3ad2a47 to 772c662 Compare November 17, 2025 21:18
@GuillaumeGomez
Copy link
Member Author

Applied suggestions.

@rustbot
Copy link
Collaborator

rustbot commented Nov 18, 2025

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
Member Author

Rebased on #149026.

@GuillaumeGomez
Copy link
Member Author

Replaced the returned value of fragment.

};
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
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
Member Author

Applied suggestion.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

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
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
Member Author

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.

} else {
String::new()
};
f.write_char('#').unwrap();
Copy link
Contributor

@lolbinarycat lolbinarycat Nov 21, 2025

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
Member Author

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
Member Author

Updated!

@lolbinarycat
Copy link
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
Member Author

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
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 21, 2025

📌 Commit 8f76773 has been approved by lolbinarycat

It is now in the queue for this repository.

@bors bors 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:main Nov 21, 2025
11 checks passed
@rustbot rustbot 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-actions bot 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants