Skip to content

Commit 6f69625

Browse files
authored
Rollup merge of rust-lang#127481 - a1phyr:pattern_gat, r=Amanieu
Remove generic lifetime parameter of trait `Pattern` Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway. cc rust-lang#27721
2 parents d6080a1 + 772315d commit 6f69625

15 files changed

+207
-198
lines changed

library/alloc/src/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl str {
269269
without modifying the original"]
270270
#[stable(feature = "rust1", since = "1.0.0")]
271271
#[inline]
272-
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
272+
pub fn replace<P: Pattern>(&self, from: P, to: &str) -> String {
273273
let mut result = String::new();
274274
let mut last_end = 0;
275275
for (start, part) in self.match_indices(from) {
@@ -309,7 +309,7 @@ impl str {
309309
#[must_use = "this returns the replaced string as a new allocation, \
310310
without modifying the original"]
311311
#[stable(feature = "str_replacen", since = "1.16.0")]
312-
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
312+
pub fn replacen<P: Pattern>(&self, pat: P, to: &str, count: usize) -> String {
313313
// Hope to reduce the times of re-allocation
314314
let mut result = String::with_capacity(32);
315315
let mut last_end = 0;

library/alloc/src/string.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1497,10 +1497,7 @@ impl String {
14971497
/// ```
14981498
#[cfg(not(no_global_oom_handling))]
14991499
#[unstable(feature = "string_remove_matches", reason = "new API", issue = "72826")]
1500-
pub fn remove_matches<'a, P>(&'a mut self, pat: P)
1501-
where
1502-
P: for<'x> Pattern<'x>,
1503-
{
1500+
pub fn remove_matches<P: Pattern>(&mut self, pat: P) {
15041501
use core::str::pattern::Searcher;
15051502

15061503
let rejections = {
@@ -2288,35 +2285,41 @@ impl<'a> Extend<Cow<'a, str>> for String {
22882285
reason = "API not fully fleshed out and ready to be stabilized",
22892286
issue = "27721"
22902287
)]
2291-
impl<'a, 'b> Pattern<'a> for &'b String {
2292-
type Searcher = <&'b str as Pattern<'a>>::Searcher;
2288+
impl<'b> Pattern for &'b String {
2289+
type Searcher<'a> = <&'b str as Pattern>::Searcher<'a>;
22932290

2294-
fn into_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher {
2291+
fn into_searcher(self, haystack: &str) -> <&'b str as Pattern>::Searcher<'_> {
22952292
self[..].into_searcher(haystack)
22962293
}
22972294

22982295
#[inline]
2299-
fn is_contained_in(self, haystack: &'a str) -> bool {
2296+
fn is_contained_in(self, haystack: &str) -> bool {
23002297
self[..].is_contained_in(haystack)
23012298
}
23022299

23032300
#[inline]
2304-
fn is_prefix_of(self, haystack: &'a str) -> bool {
2301+
fn is_prefix_of(self, haystack: &str) -> bool {
23052302
self[..].is_prefix_of(haystack)
23062303
}
23072304

23082305
#[inline]
2309-
fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
2306+
fn strip_prefix_of(self, haystack: &str) -> Option<&str> {
23102307
self[..].strip_prefix_of(haystack)
23112308
}
23122309

23132310
#[inline]
2314-
fn is_suffix_of(self, haystack: &'a str) -> bool {
2311+
fn is_suffix_of<'a>(self, haystack: &'a str) -> bool
2312+
where
2313+
Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>,
2314+
{
23152315
self[..].is_suffix_of(haystack)
23162316
}
23172317

23182318
#[inline]
2319-
fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> {
2319+
fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&str>
2320+
where
2321+
Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>,
2322+
{
23202323
self[..].strip_suffix_of(haystack)
23212324
}
23222325
}

library/alloc/tests/str.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1927,12 +1927,10 @@ mod pattern {
19271927
}
19281928
}
19291929

1930-
fn cmp_search_to_vec<'a>(
1931-
rev: bool,
1932-
pat: impl Pattern<'a, Searcher: ReverseSearcher<'a>>,
1933-
haystack: &'a str,
1934-
right: Vec<SearchStep>,
1935-
) {
1930+
fn cmp_search_to_vec<P>(rev: bool, pat: P, haystack: &str, right: Vec<SearchStep>)
1931+
where
1932+
P: for<'a> Pattern<Searcher<'a>: ReverseSearcher<'a>>,
1933+
{
19361934
let mut searcher = pat.into_searcher(haystack);
19371935
let mut v = vec![];
19381936
loop {
@@ -2191,9 +2189,9 @@ generate_iterator_test! {
21912189
fn different_str_pattern_forwarding_lifetimes() {
21922190
use std::str::pattern::Pattern;
21932191

2194-
fn foo<'a, P>(p: P)
2192+
fn foo<P>(p: P)
21952193
where
2196-
for<'b> &'b P: Pattern<'a>,
2194+
for<'b> &'b P: Pattern,
21972195
{
21982196
for _ in 0..3 {
21992197
"asdf".find(&p);

0 commit comments

Comments
 (0)