Skip to content

generalize-pattern - #161606

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

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

Conversation

@pacak

@pacak pacak commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

@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 rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 25, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Aug 25, 2026
@pacak
pacak marked this pull request as draft August 26, 2026 07:29
@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 26, 2026
@pacak
pacak force-pushed the generalize-pattern branch from ae668d2 to ebc1513 Compare August 26, 2026 07:35
@rust-bors

This comment has been minimized.

@pacak
pacak force-pushed the generalize-pattern branch from ebc1513 to 7f1c215 Compare August 26, 2026 19:56
@pacak
pacak force-pushed the generalize-pattern branch from 7f1c215 to ef9cc1d Compare September 16, 2026 16:39
@pacak
pacak marked this pull request as ready for review September 16, 2026 18:16
@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. has-merge-commits PR has merge commits, merge with caution. labels Sep 16, 2026

@teor2345 teor2345 left a comment

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.

This looks mostly OK, I just want to check some safety comments and stability risks with experienced reviewers.

View changes since this review

Comment thread library/alloc/src/string.rs Outdated
Comment thread library/core/src/str/pattern.rs Outdated
}
#[inline(always)]
unsafe fn get_unchecked(&self, range: Range<usize>) -> &Self {
// SAFETY: Caller promises position is a character boundary.

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.

There are two positions here, start and end, and the str method has extra requirements:
https://doc.rust-lang.org/std/primitive.str.html#method.get_unchecked

Suggested change
// SAFETY: Caller promises position is a character boundary.
// SAFETY: Caller promises start and end positions are both on character boundaries,
// start is not after end, and both are within the slice.

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.

done

Comment thread library/core/src/str/pattern.rs Outdated
}

unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
unsafe impl<'a> Searcher<'a, str> for CharSearcher<'a> {

@teor2345 teor2345 Sep 16, 2026

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.

This is a pre-existing issue: there is no safety comment here. It would be easier to review any changes to the impl if the safety guarantees were documented explicitly. Maybe the safety comment should go on all the next*() methods, because that seems to be what the trait is concerned about?

Here there's no change except the type parameter (and anything that changed on the trait), so this seems more like a nitpick.

There are 14 of these in this file, so this might be best left to another PR. Let's check with an experienced libs reviewer?

//!
//! For more details, see the traits [`Pattern`], [`Haystack`], [`Searcher`],
//! [`ReverseSearcher`] and [`DoubleEndedSearcher`]. Although this API is
//! unstable, it is exposed via stable methods on corresponding haystack types.

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.

Note this exposure in stable APIs, which implies some kind of stability guarantee…

/// assert_eq!("abcdef_z".find(|ch| ch > 'd' && ch < 'y'), Some(4));
/// assert_eq!("abcddd_z".find(|ch| ch > 'd' && ch < 'y'), None);
/// ```
pub trait Pattern<H: Haystack + ?Sized>: Sized {

@teor2345 teor2345 Sep 16, 2026

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.

So adding this generic could impact stable type inference, even though Pattern itself is unstable.

Do we need a crater run here? Or do we want to rely on the beta crater run later?
(This is a question for an experienced libs reviewer.)

Comment thread library/core/src/pattern.rs Outdated
/// [`cursor_at_front()`][Self::cursor_at_front]),
/// - the back of the haystack (as returned by
/// [`cursor_at_back()`][Self::cursor_at_back]), or
/// - any cursor returned by a [`Searcher`] or [`ReverseSearcher`].

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.

This might help explain why those positions are always safe.

Suggested change
/// - any cursor returned by a [`Searcher`] or [`ReverseSearcher`].
/// - any cursor returned by the [`Searcher`] or [`ReverseSearcher`] unsafe traits,
/// which are guaranteed to return valid split positions from their `next()` methods.

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.

done

Comment thread library/core/src/pattern.rs Outdated
///
/// # Safety
///
/// The range's start and end must be valid haystack split positions,

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.

See the second safety requirement of https://doc.rust-lang.org/std/primitive.str.html#method.get_unchecked

This was implied, but it's better to make safety comments explicit.

Suggested change
/// The range's start and end must be valid haystack split positions,
/// The range's start and end must be valid split positions inside the haystack,

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.

done

Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 17, 2026
coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from rust-lang#160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. rust-lang#161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. rust-lang#161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. rust-lang#161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. rust-lang#161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. rust-lang#161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. rust-lang#161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. rust-lang#161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. rust-lang#161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. rust-lang#161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. rust-lang#161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. rust-lang#161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. rust-lang#161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. rust-lang#161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. rust-lang#161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. rust-lang#161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 17, 2026
coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from rust-lang#160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. rust-lang#161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. rust-lang#161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. rust-lang#161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. rust-lang#161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. rust-lang#161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. rust-lang#161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. rust-lang#161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. rust-lang#161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. rust-lang#161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. rust-lang#161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. rust-lang#161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. rust-lang#161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. rust-lang#161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. rust-lang#161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. rust-lang#161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 17, 2026
coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from rust-lang#160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. rust-lang#161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. rust-lang#161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. rust-lang#161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. rust-lang#161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. rust-lang#161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. rust-lang#161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. rust-lang#161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. rust-lang#161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. rust-lang#161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. rust-lang#161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. rust-lang#161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. rust-lang#161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. rust-lang#161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. rust-lang#161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. rust-lang#161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
@pacak
pacak force-pushed the generalize-pattern branch 2 times, most recently from 60b9872 to e2acde3 Compare September 17, 2026 11:14
@pacak

pacak commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

I guess I'll rebase one more time once tests are merged.

Not sure what to do with stability guarantees.

I can look into describing safety requirements for searchers, probably a separate commit/PR.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 17, 2026
coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from rust-lang#160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. rust-lang#161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. rust-lang#161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. rust-lang#161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. rust-lang#161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. rust-lang#161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. rust-lang#161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. rust-lang#161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. rust-lang#161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. rust-lang#161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. rust-lang#161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. rust-lang#161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. rust-lang#161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. rust-lang#161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. rust-lang#161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. rust-lang#161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
@teor2345

Copy link
Copy Markdown
Member

Not sure what to do with stability guarantees.

Rust has a tool called "crater" to check ecosystem impact, I'm waiting on an experienced libs/types reviewer (which I am not) to see if it's worth doing for this PR specifically.

I can look into describing safety requirements for searchers, probably a separate commit/PR.

Let's also wait for a more experienced reviewer for this decision.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 17, 2026
coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from rust-lang#160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. rust-lang#161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. rust-lang#161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. rust-lang#161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. rust-lang#161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. rust-lang#161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. rust-lang#161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. rust-lang#161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. rust-lang#161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. rust-lang#161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. rust-lang#161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. rust-lang#161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. rust-lang#161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. rust-lang#161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. rust-lang#161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. rust-lang#161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
rust-bors Bot pushed a commit that referenced this pull request Sep 17, 2026
Rollup merge of #161596 - pacak:more-pat-tests, r=nia-e

coretests: Add more pattern tests.

Right now things are undertested and underspecified.

Some of the library code would get in a loop if searcher starts returning empty rejects.

And there's no tests for backwards multi byte char matchers. Pull request I'm reviving had a problem implementing that, so making sure it's tested before the actual code lands.

Right now it is possible to break both tests (and user code) without breaking anything else in the test suite I think.

This commit is extracted from #160971 with slight modifications.

<!-- start jj-vine stack -->
This PR is part of a stack containing 16 PRs:

1. `main`
2. **"coretests: Add more pattern tests." (this PR)**
3. #161606 ([Compare](https://github.com/pacak/rust/compare/more-pat-tests..generalize-pattern))
4. #161754 ([Compare](https://github.com/pacak/rust/compare/generalize-pattern..push-qvvokrsvvqww))
5. #161755 ([Compare](https://github.com/pacak/rust/compare/push-qvvokrsvvqww..push-wlxvvvxzrsly))
6. #161756 ([Compare](https://github.com/pacak/rust/compare/push-wlxvvvxzrsly..push-lkvnuzsvuqzt))
7. #161757 ([Compare](https://github.com/pacak/rust/compare/push-lkvnuzsvuqzt..push-wuxtmysppkst))
8. #161758 ([Compare](https://github.com/pacak/rust/compare/push-wuxtmysppkst..push-tnkxmkmykopl))
9. #161759 ([Compare](https://github.com/pacak/rust/compare/push-tnkxmkmykopl..push-umzmopsxmwry))
10. #161760 ([Compare](https://github.com/pacak/rust/compare/push-umzmopsxmwry..push-ptqpwloxpyru))
11. #161761 ([Compare](https://github.com/pacak/rust/compare/push-ptqpwloxpyru..push-rksmzopsvzlk))
12. #161762 ([Compare](https://github.com/pacak/rust/compare/push-rksmzopsvzlk..push-mkxpywoqusmn))
13. #161608 ([Compare](https://github.com/pacak/rust/compare/push-mkxpywoqusmn..flavor-pattern))
14. #161763 ([Compare](https://github.com/pacak/rust/compare/flavor-pattern..push-xoslomrztmly))
15. #161764 ([Compare](https://github.com/pacak/rust/compare/push-xoslomrztmly..push-pqpumynltyml))
16. #161765 ([Compare](https://github.com/pacak/rust/compare/push-pqpumynltyml..push-svrvnxkpuqul))
17. #161610 ([Compare](https://github.com/pacak/rust/compare/push-svrvnxkpuqul..osstr-pattern-tip))
<!-- end jj-vine stack -->
@rust-bors

This comment has been minimized.

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.  Just moves stuff around and adjusts
documentation.
@pacak
pacak force-pushed the generalize-pattern branch from e2acde3 to 5ad3f42 Compare September 17, 2026 18:55
@rustbot

rustbot commented Sep 17, 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.

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

Labels

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.

6 participants