Rust nightly removed the lifetime from Pattern#1219
Rust nightly removed the lifetime from Pattern#1219BurntSushi merged 3 commits intorust-lang:masterfrom mischnic:nightly-pattern-change
Conversation
| type Searcher<'t> = RegexSearcher<'r, 't>; | ||
|
|
||
| fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> { | ||
| fn into_searcher(self, haystack: &str) -> RegexSearcher<'r, '_> { |
There was a problem hiding this comment.
Should this be?
fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> {
There was a problem hiding this comment.
This lifetime setup is also used by the various Pattern impls in the standard library:
rust-lang/rust@772315d
Your version doesn't compile directly, the first suggestion below is exactly what I have implemented now (but with 't being elided) and the second suggestion is what was used before my PR and now fails to compile.
error[E0261]: use of undeclared lifetime name `'t`
--> src/pattern.rs:16:68
|
16 | fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> {
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'t` here
|
16 | fn into_searcher<'t>(self, haystack: &'t str) -> RegexSearcher<'r, 't> {
| ++++
help: consider introducing lifetime `'t` here
|
13 | impl<'t, 'r> Pattern for &'r Regex {
| +++
There was a problem hiding this comment.
I guess the problem I have here is how does the RegexSearcher connect its lifetime to the haystack? I must be missing something.
There was a problem hiding this comment.
What I wrote here is equivalent to this, which is how the &str lifetime flows into the RegexSearcher lifetime (I can commit that instead if you want)
fn into_searcher<'h>(self, haystack: &'h str) -> RegexSearcher<'r, 'h>Is that what you meant?
There was a problem hiding this comment.
Ooooo, yes, I get it now. Yes, please do write that. I'm usually fine with lifetime elision, but I think it actually helps a lot here.
There was a problem hiding this comment.
Right right. This all makes sense now. Got it. I was confused myself.
There was a problem hiding this comment.
Perfect 😄
I've added back that explicit lifetime
| type Searcher<'t> = RegexSearcher<'r, 't>; | ||
|
|
||
| fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> { | ||
| fn into_searcher<'h>(self, haystack: &'h str) -> RegexSearcher<'r, 'h> { |
There was a problem hiding this comment.
Sorry, can this be 't instead of 'h to be consistent? I don't think there is a shadowing concern here.
|
This fix is on crates.io in |
|
Great, thank you for the fast release! |
1. Upgrade to `nightly-2024-08-01` 2. Fix lints 3. Remove some unused structs 4. Bump `regex` because of rust-lang/regex#1219 Closes PACK-3178
1. Upgrade to `nightly-2024-08-01` 2. Fix lints 3. Remove some unused structs 4. Bump `regex` because of rust-lang/regex#1219 Closes PACK-3178
1. Upgrade to `nightly-2024-08-01` 2. Fix lints 3. Remove some unused structs 4. Bump `regex` because of rust-lang/regex#1219 Closes PACK-3178
Closes #1216