Skip to content

Generalize core::str::pattern::Pattern to work with any haystacks - #161606

Open
pacak wants to merge 3 commits into
rust-lang:mainfrom
pacak:generalize-pattern
Open

pacak wants to merge 3 commits into
rust-lang:mainfrom
pacak:generalize-pattern

Conversation

@pacak

@pacak pacak commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

  1. Add a type parameter to Pattern so it can work with other haystack types (my goal is OsStr specifically)
  2. Move the whole thing from core::str::Pattern to core::pattern::Pattern to reflect that

Not very useful on its own, but required to extend pattern splitting API to OsStr.

Contains changes from #161604, I'll rebase one that test lands.

Part of the #160971 cinematic universe.

This PR is part of a stack containing 16 PRs:

  1. main
  2. "Generalize core::str::pattern::Pattern to work with any haystacks" (this PR)
  3. core: introduce internal core::pattern::{Split,SplitN} types #161754 (Compare)
  4. Revert "Add ByteNeedle search in StrSearcherImpl" #163557 (Compare)
  5. core: add core::pattern::EmptyNeedleSearcher internal type #161755 (Compare)
  6. core: add try_next_code_point{,_reverse} internal functions #161756 (Compare)
  7. core: add internal core::str_bytes module handling string-like slices #161757 (Compare)
  8. coretests: Add a few tests for backward multibyte predicate #161758 (Compare)
  9. core: add concept of Flavour to core::str_bytes #161759 (Compare)
  10. core: add memchr-based single-ascii byte search to str_bytes #161760 (Compare)
  11. core::str_bytes: use unsafe for indexing #161762 (Compare)
  12. core: skip emitting rejects if result doesn't cary it #161608 (Compare)
  13. std: add pattern matching to OsStr #161763 (Compare)
  14. core: add core::pattern::Predicate wrapper type #161764 (Compare)
  15. core, std: support various [char] matchers for Pattern<&OsStr> #161765 (Compare)
  16. std: add OsStr pattern benchmarks #161610 (Compare)
  17. core/std: inline small functions #161761 (Compare)

@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
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: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

@pacak

pacak commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

stdarch is developed in its own repository

I'm not sure what's the right approach here. Sync it after this lands? A separate pull request?

@folkertdev

Copy link
Copy Markdown
Contributor

This is fine, it's a tiny change, we'll handle the sync after it merges.

@pacak

pacak commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

r? @nia-e

@rustbot rustbot assigned nia-e and unassigned JohnTitor Aug 23, 2026
@pacak

pacak commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

#161608 (review) - I'm going to try this

@pacak
pacak force-pushed the generalize-pattern branch from 9471adf to 0a4f4c4 Compare August 24, 2026 09:41
@rustbot

This comment has been minimized.

@pacak
pacak marked this pull request as draft August 24, 2026 13:12
@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 Aug 24, 2026
@pacak
pacak force-pushed the generalize-pattern branch from 0a4f4c4 to ae668d2 Compare August 25, 2026 13:46
@pacak pacak changed the title Generalize std::str::Pattern to be generic over the haystack and rehome it generalize-pattern Aug 25, 2026
@rustbot

This comment has been minimized.

@pacak pacak changed the title generalize-pattern Generalize core::str::pattern::Pattern to work with any haystacks Nov 12, 2026
@pacak

pacak commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@nia-e thoughts? Should I ask rustbot for reroll?

@rust-log-analyzer

This comment has been minimized.

@pacak pacak changed the title Generalize core::str::pattern::Pattern to work with any haystacks generalize-pattern Nov 12, 2026
@pacak
pacak force-pushed the generalize-pattern branch from 81a936e to 2524e8f Compare November 12, 2026 22:34
@pacak pacak changed the title generalize-pattern Generalize core::str::pattern::Pattern to work with any haystacks Nov 12, 2026
@rust-bors

This comment has been minimized.

@pacak pacak changed the title Generalize core::str::pattern::Pattern to work with any haystacks generalize-pattern Nov 18, 2026
@pacak
pacak force-pushed the generalize-pattern branch from 2524e8f to 3a199dd Compare November 18, 2026 19:55
@rustbot

This comment has been minimized.

@pacak pacak changed the title generalize-pattern Generalize core::str::pattern::Pattern to work with any haystacks Nov 18, 2026
Add a Haystack trait describing something that can be searched in and
make core::str::Pattern (and related types) generic on that trait.
This will allow Pattern to be used for types other than str (most
notably OsStr).

This somewhat follows the Pattern API 2.0 design.  While that design is
apparently abandoned (?), it is somewhat helpful when going for patterns
on OsStr, so I’m going with it unless someone tells me otherwise. ;)

For now leave Pattern, Haystack et al in core::str::pattern.  Since
they are no longer str-specific, I’ll move them to core::pattern in
future commit.  This one leaves them in place to make the diff
smaller.

@pacak:

Original code had pattern parametrized by a reference (`Pattern<&str>`),
I changed it to be `Pattern<str>`.

Original code had indices in Haystack abstracted as an associated type
Cursor. Replaced with usize - Cursor adds noise with not much value.

Changed wording in 2-3 places - for example Searcher is generic over a
few types so it makes more sense to talk about split points in general
with utf8 split points as an example for `&str`.
Pattern is no longer str-specific, so move it from core::str::pattern
module to a new core::pattern module.  This introduces no changes in
behaviour or implementation.
@pacak pacak changed the title Generalize core::str::pattern::Pattern to work with any haystacks generalize-pattern Nov 19, 2026
@pacak
pacak force-pushed the generalize-pattern branch from 3a199dd to 816f4c7 Compare November 19, 2026 17:01
@rustbot

rustbot commented Nov 19, 2026

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.

@pacak pacak changed the title generalize-pattern Generalize core::str::pattern::Pattern to work with any haystacks Nov 19, 2026
@pacak

pacak commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned hanna-kruppe and unassigned nia-e Nov 19, 2026
@pacak

pacak commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@hanna-kruppe: this pull request is part of a stacked pull request (full list in the description), at some point I was asked to split it into smaller parts. The whole stack needs to be reviewed/merged eventually.

There is a zulip chat with some discussion already, but not much progress on the pull request itself.

https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Looking.20for.20reviewer.20for.20an.20OsStr.20.2B.20Pattern.20related.20change/with/639592987

I was pretty confident that the whole stack was ready back in August, but after a few rebases and refactors I had to do to accommodate whatever was merged - there might be something missing and I can't really see it, but I'll do whatever needs to be done.

There's two big parts to those pull requests, one group makes Pattern to take a parameter so it can work with other haystacks (PRs 2..12 + 17) and the rest uses this to make it work with OsString.. First half can be useful by itself - documentation for some slice methods mention some interest in parameterizing Pattern.

@hanna-kruppe

Copy link
Copy Markdown
Contributor

I'm sorry to disappoint when you've been already waiting for reviews for so long, but I can't review this:

  • Personally, I am neither very familiar with the pattern API + implementation, nor am I sufficiently motivated to take a lot of time to gain the necessary familiarity.
  • Even if I was invested and familar, I would be reluctant to review this PR without more team buy-in as it makes important API design decisions and it's not clear if those changes were ACP'd or otherwise discussed by the libs team.
  • The context of the huge PR stack also doesn't help. Maybe some parts are easier to review in isolation, but this one seems quite important and should likely not get a "one-off" reviewer. But I really don't want to sign up for reviewing more of this series.

I'm likely not alone with that, so I wouldn't expect re-rolling some more to find someone who's eager to review this. As much as I hate to send you back to square one, I suggest trying to go back to Zulip and talk to the libs team about finding someone who has the knowledge, interest, and time to shepherd this huge project in general (even if they may not review every single PR). I realize that you've tried that and it didn't work, but rolling random reviewers also doesn't work well for such huge projects.

@pacak

pacak commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Hmmm... Suggestion to reroll came from zulip :)

There's ACP rust-lang/libs-team#311 and "Going to count this as being tracked by #49802".

But I totally understand you. Will keep asking there I guess.

@hanna-kruppe

Copy link
Copy Markdown
Contributor

Oops, didn't realize you were told to re-roll by Trevor on Zulip. I don't want to stop you from re-rolling some more, but I'm pessimistic about the odds.

There's ACP rust-lang/libs-team#311 and "Going to count this as being tracked by #49802".

Thanks. At a glance the Haystack trait introduced here looks rather different than what the RFC sketched, and on the ACP the last word so far favored a separate OsStrPattern trait instead of generalizing Pattern. I don't have enough context to be sure about this, but it still seems like reviewing this requires much more judgement than "only" reviewing implementation.

@pacak

pacak commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

than what the RFC sketched, and on the ACP the rust-lang/libs-team#311 (comment) favored a separate OsStrPattern trait instead of generalizing Pattern

Implementation in this pull request predates that comment by a year... Also FnMut(char) -> bool is one of a few methods I actually want to use. Here it is solved by having user to use predicate function: foo.strip_prefix(predicate(|c| c != '/')).

Anyway, waiting for a reply on zulip I guess....

@clarfonthey clarfonthey self-assigned this Nov 20, 2026
@clarfonthey

clarfonthey commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

So, resharing what I mentioned on Zulip:

unfortunately I don't think we have the bandwidth as a team to review this right now, but once I'm done with #156496 I think I should be fine to take this on. I just don't want to promise anything since already taking on one big review has been a lot.

r? clarfonthey

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-str Area: `str` and `String` 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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants