Yup, that was pretty much it. (I suspected something like that might be
happening.) Thanks!
To future generations of confused souls: when the impl is parameterized, the
function probably doesn't need to be.
On Wed, 22 Jan 2014, Huon Wilson wrote:
On 22/01/14 12:41, Scott Lawrence wrote:
This code compiles successfully: http://ix.io/a34 . I believe this behavior
is correct. Just so it's clear what this code does: f() takes a `&mut int`
and adds it to an array - the idea is that all of the `&mut int` can be
changed at some later time. Naturally, there's some fancy lifetime juggling
involved in this (which I may have gotten wrong).
Uncommenting the commented parts (the method f() in the impl A, in
particular) yields the error message shown at the bottom, which appears to
say that the lifetime created in the second parameter of f() does not
necessarily outlive itself.
Is there some especially complicated aspect of lifetimes as they interact
with &self, or is this indeed a bug?
I think it's the compiler tricking you: the 'a in `fn f<'a>(&mut self, ...)`
is shadowing the `impl<'a> A<'a>` i.e. they are different lifetimes that
happen to have the same identifier. Changing it to `fn f(&mut self, &'a mut
int)` should work.
There's a bug open about warning on shadowed generics, because, as this
demonstrates, you end up with hard-to-diagnose error messages:
https://github.com/mozilla/rust/issues/11658
Huon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
--
Scott Lawrence
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev