Skip to content

Replace custom trim_ascii_start with the standard library method#155134

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
thebabalola:fix/replace-trim-ascii-start-with-stdlib
Apr 14, 2026
Merged

Replace custom trim_ascii_start with the standard library method#155134
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
thebabalola:fix/replace-trim-ascii-start-with-stdlib

Conversation

@thebabalola
Copy link
Copy Markdown
Contributor

@thebabalola thebabalola commented Apr 10, 2026

The markdown parser in rustc_errors has a local trim_ascii_start function that strips leading ASCII whitespace from a byte slice. The standard library has had <[u8]>::trim_ascii_start() since Rust 1.80, which does the same thing.

This PR removes the custom function and calls the stdlib method directly in parse_unordered_li and parse_ordered_li. No behaviour change.

I also added a test covering the list item leading-whitespace trimming behaviour, including a tab case.

Fixes rustfoundation/interop-initiative#53

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 10, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 10, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 11 candidates

assert_eq!(t, MdTree::UnorderedListItem(vec![MdTree::PlainText("hello")].into()));
assert_eq!(r, b"");

// tab after the marker space — needs #[rustfmt::skip] or rustfmt removes it
Copy link
Copy Markdown
Member

@mati865 mati865 Apr 12, 2026

Choose a reason for hiding this comment

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

View changes since the review

I doubt rustfmt would rewrite string like that and I cannot reproduce the problem, how did you run into that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, I actually added the #[rustfmt::skip] out of caution after seeing a note in the tracking issue about rustfmt removing unusual whitespace. But since the tab is written as \t in the string literal (not a literal tab character), rustfmt won't touch it. I'll just remove the attribute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please squash the commit and update the description.

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.

Please squash the commit and update the description.

@thebabalola do you need help with squashing commits?

@rustbot author

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@teor2345 ... Already done, squashed to 2 commits and force pushed earlier. Thanks for checking..

@mati865
Copy link
Copy Markdown
Member

mati865 commented Apr 12, 2026

@rustbot author

@rustbot rustbot 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 Apr 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@thebabalola
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 13, 2026
The local trim_ascii_start function in the markdown parser duplicates
<[u8]>::trim_ascii_start() from the standard library (stable since 1.80).
Remove the custom function and call the stdlib method directly.

No behaviour change.

Fixes rustfoundation/interop-initiative#53
@thebabalola thebabalola force-pushed the fix/replace-trim-ascii-start-with-stdlib branch from 1fa81a8 to fdfdb08 Compare April 13, 2026 22:07
@thebabalola
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot 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 Apr 13, 2026
@mati865
Copy link
Copy Markdown
Member

mati865 commented Apr 14, 2026

Great, thanks!

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 14, 2026

📌 Commit fdfdb08 has been approved by mati865

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 14, 2026
…-start-with-stdlib, r=mati865

Replace custom trim_ascii_start with the standard library method

The markdown parser in `rustc_errors` has a local `trim_ascii_start` function that strips leading ASCII whitespace from a byte slice. The standard library has had `<[u8]>::trim_ascii_start()` since Rust 1.80, which does the same thing.

This PR removes the custom function and calls the stdlib method directly in `parse_unordered_li` and `parse_ordered_li`. No behaviour change.

I also added a test covering the list item leading-whitespace trimming behaviour, including a tab case.

Fixes rustfoundation/interop-initiative#53
rust-bors Bot pushed a commit that referenced this pull request Apr 14, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #154049 (delegation: Track more precise spans for glob delegations)
 - #155134 (Replace custom trim_ascii_start with the standard library method)
 - #155235 (add the `fma4` x86 target feature)
 - #155218 (coroutines: Skip the closure signature annotation check for tainted bodies)
 - #155274 (limit duplicate-profiler-builtins test to targets that can do dynamic linking)
 - #155276 (`#[rustc_must_match_exhaustively]` detect let else)
 - #155281 (Revert "allow `windows-gnu` targets to embed gdb visualizer scripts")
@rust-bors rust-bors Bot merged commit 5da0b6c into rust-lang:main Apr 14, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 14, 2026
rust-timer added a commit that referenced this pull request Apr 14, 2026
Rollup merge of #155134 - thebabalola:fix/replace-trim-ascii-start-with-stdlib, r=mati865

Replace custom trim_ascii_start with the standard library method

The markdown parser in `rustc_errors` has a local `trim_ascii_start` function that strips leading ASCII whitespace from a byte slice. The standard library has had `<[u8]>::trim_ascii_start()` since Rust 1.80, which does the same thing.

This PR removes the custom function and calls the stdlib method directly in `parse_unordered_li` and `parse_ordered_li`. No behaviour change.

I also added a test covering the list item leading-whitespace trimming behaviour, including a tab case.

Fixes rustfoundation/interop-initiative#53
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outreachy tracking issue for Rust whitespace check bugs

4 participants