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 {
(ref a, _) => a
}
Niko
Erick Tryzelaar wrote:
That doesn't work. It triggers this error:
test2.rs:8:25: 8:30 error: moving out of dereference of immutable &
pointer
test2.rs:8 <http://test2.rs:8> let (ref a, _) = *self;
^~~~~
On Sat, Feb 2, 2013 at 6:21 AM, Niko Matsakis <[email protected]
<mailto:[email protected]>> wrote:
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 impl<T>(T, T): TupleVal<T> {
8 fn _1(&self) -> &self/T {
9 let&(ref a, _) = self;
10 a
11 }
Assertion failed: (getOperand(0)->getType() ==
cast<PointerType>(getOperand(1)->getType())->getElementType()&& "Ptr must be a pointer
to Val type!"), function AssertOK, file
/Volumes/Home/astavonin/Projects/rust/src/llvm/lib/VMCore/Instructions.cpp, line 1062.
zsh: abort rustctest.rs <http://test.rs>
On Feb 2, 2013, at 12:47 PM, Niko Matsakis<[email protected]>
<mailto:[email protected]> wrote:
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 this:
let&(ref a, _) = self;
a
The `ref` keyword indicates that the `a` variable should be a pointer into
the value being matched (here, `self`) and not copied out.
Niko
_______________________________________________
Rust-dev mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev