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

Lifetime issue with Replacer #242

Closed
ArtemGr opened this issue May 27, 2016 · 2 comments
Closed

Lifetime issue with Replacer #242

ArtemGr opened this issue May 27, 2016 · 2 comments

Comments

@ArtemGr
Copy link

ArtemGr commented May 27, 2016

Trying to compile the following code

  struct TrReplace;
  impl Replacer for TrReplace {
    fn reg_replace<'a> (&'a mut self, caps: &Captures) -> Cow<'a, str> {
      let text = caps.at (0) .expect ("!caps 0");
      Cow::Borrowed (text)
    }
  }

with regex 0.1.58 and rustc 1.9.0-nightly (6e0f2f2f0 2016-03-16) I get the following error:

by_user.rs:1328:27: 1328:29 error: cannot infer an appropriate lifetime for lifetime parameter `'t` due to conflicting requirements [E0495]
by_user.rs:1328           let text = caps.at (0) .expect ("!caps 0");
                                                                   ^~
by_user.rs:1327:9: 1330:10 help: consider using an explicit lifetime parameter as shown: fn reg_replace<'a>(&'a mut self, caps: &Captures<'a>) -> Cow<'a, str>
by_user.rs:1327         fn reg_replace<'a> (&'a mut self, caps: &Captures) -> Cow<'a, str> {
by_user.rs:1328           let text = caps.at (0) .expect ("!caps 0");
by_user.rs:1329           Cow::Borrowed (text)
by_user.rs:1330         }
error: aborting due to previous error

I think returning an unmodified string from reg_replace is supposed to work, isn't it?

@BurntSushi
Copy link
Member

I think this is a dupe of #151. See my comment here: #151 (comment) --- Note that this is fixed for the bytes::Regex API and will also be fixed when 1.0 is out.

If you're stuck, then I think the best work-around is to probably copy the Replacer trait and the replace methods that use it from the 1.0 branch:

@ArtemGr
Copy link
Author

ArtemGr commented May 27, 2016

Indeed, somehow I missed the #151, thanks.

@ArtemGr ArtemGr closed this as completed May 27, 2016
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

No branches or pull requests

2 participants