Skip to content
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

Merged
merged 3 commits into from
Aug 2, 2024

Conversation

mischnic
Copy link
Contributor

@mischnic mischnic commented Aug 2, 2024

Closes #1216

src/pattern.rs Outdated

fn into_searcher(self, haystack: &'t str) -> RegexSearcher<'r, 't> {
fn into_searcher(self, haystack: &str) -> RegexSearcher<'r, '_> {
Copy link
Member

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> {

Copy link
Contributor Author

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 {
   |      +++

Copy link
Member

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.

Copy link
Contributor Author

@mischnic mischnic Aug 2, 2024

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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> {
Copy link
Member

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.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

@BurntSushi BurntSushi merged commit 2970d29 into rust-lang:master Aug 2, 2024
16 checks passed
@BurntSushi
Copy link
Member

This fix is on crates.io in regex 1.10.6.

@mischnic mischnic deleted the nightly-pattern-change branch August 2, 2024 15:11
@mischnic
Copy link
Contributor Author

mischnic commented Aug 2, 2024

Great, thank you for the fast release!

mischnic added a commit to vercel/next.js that referenced this pull request Aug 5, 2024
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
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 14, 2024
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
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 15, 2024
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
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 16, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compilation error when compiling with nightly with unstable feature enabled
2 participants