-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Confusing error msg for lifetime mismatch (possibly a bug in lifetime inference as well) #32008
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
Comments
This is an error that appears when you call: |
Should the definition of |
That is a good fix to that particular library (already merged). This about Should the definition of Add not be more like this — |
We don't auto-reborrow when we don't have a known target type. Maybe we should use subtyping in overloaded operator matching? Lifetime errors sucking is a known issue. |
Actually, in this case the lifetime error wasn't totally stupid. The compiler thinks that the lifetimes of the references must be related (this is a bug that should be fixed), and it proposes that you force them to be equal (in fact, an Of course, with the problem being that the lifetimes are related, just satisfying that leads to another error down the line. Type errors tend to be like that. |
Ran into this (Playground) just now. It’s weird that use std::ops::Add;
struct Foo;
impl<'a> Add<&'a Foo> for &'a Foo {
type Output = Foo;
fn add(self, rhs: &'a Foo) -> Self::Output { Foo }
}
fn foo<'a, 'b>(x: &'a Foo, y: &'b Foo) -> Foo {
x + y
// ^^^^^ cannot infer an appropriate lifetime for lifetime parameter `'a`
// due to conflicting requirements
}
fn main() { } |
Rust 1.22 fixes the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixes the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008 and rust-lang/rust#45435 for the issue and fix in Rust.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008, rust-lang/rust#45425, and rust-lang/rust#45435 for the relevant Rust issues/PRs.)
Rust 1.23 fixed the original issue (rust-ndarray#103) that required `'b` to be added. (See rust-lang/rust#32008, rust-lang/rust#45425, and rust-lang/rust#45435 for the relevant Rust issues/PRs.)
Originally opened in wrong repository (rfcs) as [0].
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:
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.
Anyway, if any part of the documentation (error: no extended information for [E0495]) can enlighten me, pointers accepted gladly.
[0] rust-lang/rfcs#1523 (comment)
[1] daniel-vainsencher/online_weighted_stats@8f9cf03
[2] daniel-vainsencher/online_weighted_stats@0bfc04d
@bluss said: I think this is a representative minimization.
https://play.rust-lang.org/?gist=59e6b8c113e4e7eda1fe&version=stable
I get completely different error messages at that playground link, btw,
though still somewhat confusing: it is not clear why the block suffix does
not suffice, seems to cover the relevant part of the anonymous lifetime.
The text was updated successfully, but these errors were encountered: