Interesting! I'm surprised to see that... anyway, try this:
```
let (ref a, _) = *self;
a
```
That's how we normally write it. It might workaround the bug (if not,
I'd like to know!)
Niko
Alexander Stavonin wrote:
Looks like I'd like to do something extremely difficult %)
7 implT(T,
Wow, interesting. Another bug! Actually, I just remembered that `ref`
bindings in `let` are still broken...I have a pending patch to fix that,
maybe I should go dust if off and see if I can finish it up. The way we
would *really* write this today is as follows:
match *self {
What you want is something like this (and corresponding changes to the
impl):
pub trait TupleValT {
pub pure fn _1(self) - self/T;
pub pure fn _2(self) - self/T;
}
The `self` declaration is called an explicit self declaration. What
you have currently written is called implicit self
Thank you! But I still can not compile it:
1 pub trait TupleValT {
2 pub pure fn _1(self) - self/T;
3 pub pure fn _2(self) - self/T;
4 }
5
6 impl T(T, T): TupleValT {
7 pure fn _1(self) - self/T {
8 let (a, _) = self;
You need let (a, _) = *self or let (a, _) = self. self is a
pointer to a tuple, not a tuple.
Niko
Alexander Stavonin wrote:
Thank you! But I still can not compile it:
1 pub trait TupleValT {
2 pub pure fn _1(self) - self/T;
3 pub pure fn _2(self) - self/T;
4 }
5
Thank you very much! I guess had better extend your Borrowed pointers
tutorial with information about traits. At least for me it's unclear from the
tutorial.
On Feb 2, 2013, at 9:08 AM, Niko Matsakis n...@alum.mit.edu wrote:
You need let (a, _) = *self or let (a, _) = self. self is a pointer
I made changes as you told me:
1 pub trait TupleValT {
2 pub pure fn _1(self) - self/T;
3 /*pub pure fn _2(self) - self/T;*/
4 }
5
6 impl
Sorry, I told you wrong. When you write:
let (a, _) = self;
a
You are actually copying the value out of `self` and into the stack
variable `a`. The error message is telling you that you are returning a
pointer into your stack frame, which is of course unsafe.
What you actually want is
I want to add function like _1(), _2(), etc for Rust tuple. Unfortunately I
do not understand how to tell compiler lifetime of returning result in case
of `trait`
pub trait TupleValT {
pub pure fn _1() - T;
pub pure fn _2() - T;
}
impl T(T, T): TupleValT {
pure fn _1() - T {