Skip to content

Conversation

@GuillaumeGomez
Copy link
Member

Follow-up of #146992.

cc @yotamofek
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 Oct 27, 2025
@GuillaumeGomez
Copy link
Member Author

I don't think it'll impact performance but just in case:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 27, 2025
Simplify code to generate line numbers in highlight
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 27, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 27, 2025

☀️ Try build successful (CI)
Build commit: b384be5 (b384be56b050599ec6a78499b3413da442fb9150, parent: 34a8c7368c84fc699fc83a8851a02f93fd655931)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b384be5): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -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.4% [-0.5%, -0.2%] 7
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 4.1%)

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)
4.1% [3.3%, 4.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.665s -> 475.551s (0.40%)
Artifact size: 390.50 MiB -> 390.48 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 27, 2025
@GuillaumeGomez
Copy link
Member Author

It's actually faster. I'm surprised. Oh well, good surprises are welcome I guess. 😆

@lolbinarycat
Copy link
Contributor

I'm not surprised at all, it's removing an intermediate allocation, I would expect that to improve performance slightly.

Comment on lines 443 to 446
/// Used for non-scraped code examples, ie source code pages and code examples in documentation.
Normal(u32),
/// Code examples without line numbers.
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. as far as I can tell, code examples in documentation don't have line numbers (and if they did, we wouldn't want them to have line number anchors, otherwise multiple examples would end up with conflicting IDs)
  2. the dead_code seems unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I'm guessing it's because the data of the Empty variant (i.e. the u32) is never read?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

if let Some(backline) = token_handler.handle_backline() {
token_handler.push_token_without_backline_check(
None,
Cow::Owned(backline.to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that we're using Cow::Owned here didn't sit right to me, so I did some digging and found out push_token_without_backline_check has overly restrictive lifetimes. It should use text: Cow<'_, str>, not text: Cow<'a, str>.

Actually, I think it could even be just text: &str, since it doesn't look like the code ever takes advantage of the Owned case and instead just uses it as impl Display, but that would require more refactoring than just changing a lifetime

Copy link
Member Author

Choose a reason for hiding this comment

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

backline is a LineNumber, so we need to convert it to something compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, I think impl Display would also work? not sure the monomorphization would be worth it, could maybe experiment in a follow-up PR.

Regardless, the lifetime still is overly restrictive, and it's hard to see that as anything but a mistake.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum, might be worth trying in a follow-up.

/// used to generate links.
href_context: Option<HrefContext<'a, 'tcx>>,
write_line_number: fn(u32) -> String,
write_line_number: fn(u32) -> LineNumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

The enum is a nice touch, but maybe we can go one step further and make it into a data-less, C-like enum? So line_number: LineNumber or something, instead of holding an fn pointer.
Fn pointers probably aren't great for perf (I think they can't be inlined? unless the compiler/LLVM are smart enough to make it into a sort-of enum?)
And also, might make code slightly nicer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Gonna implement that.

Comment on lines 443 to 446
/// Used for non-scraped code examples, ie source code pages and code examples in documentation.
Normal(u32),
/// Code examples without line numbers.
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I'm guessing it's because the data of the Empty variant (i.e. the u32) is never read?

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

This PR was rebased onto a different master 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

Simplified it even further thanks to both your feedback! Let's check perf now. =D

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 31, 2025
Simplify code to generate line numbers in highlight
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 31, 2025
@lolbinarycat
Copy link
Contributor

In favor of merging this and refactoring push_token_without_backline_check in a followup PR if @yotamofek don't have any more concerns.

// https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr
// Do not show "1 2 3 4 5 ..." in web search results.
format!("<a href=#{line} id={line} data-nosnippet>{line}</a>")
/// Represents line numbers to be generated as HTML.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
/// Represents line numbers to be generated as HTML.
/// Represents the type of line number to be generated as HTML.

maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, adding it. :)

/// used to generate links.
href_context: Option<HrefContext<'a, 'tcx>>,
write_line_number: fn(u32) -> String,
write_line_number: LineNumberKind,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
write_line_number: LineNumberKind,
line_number_kind: LineNumberKind,

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea.

@yotamofek
Copy link
Contributor

In favor of merging this and refactoring push_token_without_backline_check in a followup PR if @yotamofek don't have any more concerns.

Apart from two super-small nits, I think this should be merged :)

@GuillaumeGomez
Copy link
Member Author

Let's wait for perf first then. :)

@rust-bors
Copy link

rust-bors bot commented Oct 31, 2025

☀️ Try build successful (CI)
Build commit: d3e852c (d3e852cfcc15185557dd95819dd6ced0d5d965de, parent: 51f5892019f8fb07864647d46c4eb577d3b0719f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d3e852c): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -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.3%, -0.1%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary -2.0%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 5.5%)

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)
5.5% [5.5%, 5.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

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)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 474.501s -> 475.417s (0.19%)
Artifact size: 390.85 MiB -> 390.89 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 31, 2025
@GuillaumeGomez
Copy link
Member Author

Nice! Thanks to both of you. :)

@bors r=yotamofek,lolbinarycat rollup

@bors
Copy link
Collaborator

bors commented Oct 31, 2025

📌 Commit 5fabd2d has been approved by yotamofek,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 Oct 31, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 1, 2025
…ht, r=yotamofek,lolbinarycat

Simplify code to generate line numbers in highlight

Follow-up of rust-lang#146992.

cc `@yotamofek`
r? `@lolbinarycat`
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 1, 2025
…ht, r=yotamofek,lolbinarycat

Simplify code to generate line numbers in highlight

Follow-up of rust-lang#146992.

cc ``@yotamofek``
r? ``@lolbinarycat``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 1, 2025
…ht, r=yotamofek,lolbinarycat

Simplify code to generate line numbers in highlight

Follow-up of rust-lang#146992.

cc ```@yotamofek```
r? ```@lolbinarycat```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 1, 2025
…ht, r=yotamofek,lolbinarycat

Simplify code to generate line numbers in highlight

Follow-up of rust-lang#146992.

cc ````@yotamofek````
r? ````@lolbinarycat````
bors added a commit that referenced this pull request Nov 1, 2025
Rollup of 10 pull requests

Successful merges:

 - #135602 (Tweak output of missing lifetime on associated type)
 - #139751 (Implement pin-project in pattern matching for `&pin mut|const T`)
 - #142682 (Update bundled musl to 1.2.5)
 - #148171 (Simplify code to generate line numbers in highlight)
 - #148263 (Unpin `libc` and `rustix` in `compiler` and `rustbook`)
 - #148301 ([rustdoc search] Include extern crates when filtering on `import`)
 - #148330 (Don't require dlltool with the dummy backend on MinGW)
 - #148338 (cleanup: upstream dropped amx-transpose functionality)
 - #148340 (Clippy subtree update)
 - #148343 (`nonpoison::Condvar` should take `MutexGuard` by reference)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Nov 1, 2025
Rollup of 10 pull requests

Successful merges:

 - #135602 (Tweak output of missing lifetime on associated type)
 - #139751 (Implement pin-project in pattern matching for `&pin mut|const T`)
 - #142682 (Update bundled musl to 1.2.5)
 - #148171 (Simplify code to generate line numbers in highlight)
 - #148263 (Unpin `libc` and `rustix` in `compiler` and `rustbook`)
 - #148301 ([rustdoc search] Include extern crates when filtering on `import`)
 - #148330 (Don't require dlltool with the dummy backend on MinGW)
 - #148338 (cleanup: upstream dropped amx-transpose functionality)
 - #148340 (Clippy subtree update)
 - #148343 (`nonpoison::Condvar` should take `MutexGuard` by reference)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit efcf705 into rust-lang:master Nov 1, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 1, 2025
rust-timer added a commit that referenced this pull request Nov 1, 2025
Rollup merge of #148171 - GuillaumeGomez:line-number-highlight, r=yotamofek,lolbinarycat

Simplify code to generate line numbers in highlight

Follow-up of #146992.

cc `````@yotamofek`````
r? `````@lolbinarycat`````
@GuillaumeGomez GuillaumeGomez deleted the line-number-highlight branch November 3, 2025 10:51
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants