-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Confusing error msg for lifetime mismatch (possibly a bug in lifetime inference as well) #1523
Comments
I think this is a representative minimization. Playground link. use std::ops::Add;
struct Foo;
impl<'a> Add<&'a Foo> for &'a Foo {
type Output = ();
fn add(self, rhs: &'a Foo) {}
}
fn try_to_add(input: &Foo) {
let local = Foo;
&*input + &local; // ok
input + &local; // error: `local` does not live long enough
}
fn main() {
} |
I get completely different error messages at your playground link, btw, On Tue, Mar 1, 2016 at 11:34 PM, bluss [email protected] wrote:
Daniel Vainsencher |
Wrong repository?
|
Oops, this should be in rust-lang/rust ! I didn't notice the difference. Thanks nagisa. |
@daniel-vainsencher, could you open a issue in rust-lang/rust? |
Opened in the right repo, copied over relevant information. |
The problem is demonstrated by compiling [1]. I can work around the problem by using [2](first half of the diff is relevant to this problem, second part not so much), or by patching ndarrays to give parameters of binary operators distinct lifetime parameters.
A few problems here:
src/lib.rs:30:28: 30:38 error: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements [E0495]
src/lib.rs:30 let delta = data - &self.mean;
<arrow pointing at &self.mean>
Lifetime of what expression cannot be inferred? What are the conflicting requirements? as someone with an only approximate mental model of lifetimes (i.e., a typical rust user) this is not helping me a lot to solve the problem nor to learn about lifetimes.
src/lib.rs:27:5: 38:6 help: consider using an explicit lifetime parameter as shown: fn next_value<'a>(&'a mut self, data: &'a V, weight: f64)
src/lib.rs:27 pub fn next_value(&mut self, data : &V, weight : f64) {
Anyway, if any part of the documentation (error: no extended information for [E0495]) can enlighten me, pointers accepted gladly.
[1] daniel-vainsencher/online_weighted_stats@8f9cf03
[2] daniel-vainsencher/online_weighted_stats@0bfc04d
The text was updated successfully, but these errors were encountered: