[rust-dev] Question about lifetime analysis (a 0.5 transition question)

Steve Jenson stevej at fruitless.org
Fri Dec 28 13:20:46 PST 2012

On Thu, Dec 27, 2012 at 3:16 PM, Niko Matsakis <niko at alum.mit.edu> wrote:

> I'm sorry for not replying more quickly, I was not checking e-mail over
> xmas break.  I do not know of any general problems with @ and borrowing.
> In any event, this is a misdiagnosis.

No problem with reply timing.

>  The problem is this: the declaration of iter looks like this:
>      impl<K: Copy Eq Ord, V: Copy> RBMap<K, V>: iter::BaseIter<(&K, &V)>
> In the context of a type declaration, an & means `&self`, where `self` is
> the lifetime parameter associated with the type/impl/whatever (just as the
> impl has two type parameters K and V, it also has an implicit lifetime
> parameter `self`).  So, this declaration written out more explicitly would
> be:
>     impl<K: Copy Eq Ord, V: Copy> RBMap<K, V>: iter::BaseIter<(&self/K,
> &self/V)>
> However, your method declaration is:
>     pure fn each(&self, f: fn(&(&K, &V)) -> bool) { ... }
> In the context of a function declaration, & means "a fresh lifetime".  So
> this winds up being short for a declaration life this:
>     pure fn each(&self, f: fn(&a/(&a/K, &a/V)) -> bool) { ... }
> However, the trait declares that `each` should have this type:
>     pure fn each(&self, f: fn(&a/(&self/K, &self/V)) -> bool) { ... }
> So I think that if you change your declaraiton of `each()` to:
>     pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) { ... }
> It will work just fine.  I apologize for the cryptic error message.
> Working on it.

Unfortunately not but a much more interesting set of error messages about
lifetimes is coming out now: http://pastebin.com/SYwCw1ac

And here is a link to the each method again (I pushed this broken version
to github so I can share the exact changes I made)


Thanks a bunch for all of your clarifying comments and blog posts.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20121228/1dbeaf83/attachment.html>

More information about the Rust-dev mailing list