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      rustc test.rs


On Feb 2, 2013, at 12:47 PM, Niko Matsakis<n...@alum.mit.edu>  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
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to