-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust nightly removed the lifetime from Pattern #1219
Conversation
src/pattern.rs
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be?
fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right right. This all makes sense now. Got it. I was confused myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect 😄
I've added back that explicit lifetime
src/pattern.rs
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, can this be 't
instead of 'h
to be consistent? I don't think there is a shadowing concern here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks!
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
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