Closed
Description
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:
- The basic error message is not very clear:
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. - The compiler suggests something that doesn't work. I don't expect suggestions to always work, but maybe its worth pointing this case out so that the suggestion can be improved or made conditional.
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) { - @bluss suggested that rustc should be able to infer for the self and data borrows the intersection of their lifetimes, hence this should not be happening at all. I have no idea.
- The work around in [2] suggested by @bluss leaves me even more confused. I can change the lifetime of data by ... (what is that, actually, reborrowing it?), and then the borrow of self is ok? But if that's a good way to go about things, maybe the compiler should suggest this method sometimes.
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
Metadata
Metadata
Assignees
Labels
No labels