I was trying to see how to use region pointers to return nested data in a
data structure containing unique pointers. This works:
struct T1 { value: int }
struct T2 { t1: ~T1 }
fn value(t2: &r/T2) -> &r/int {
&t2.t1.value
}
fn main() {
let t2 = ~T2{ t1: ~T1{ value: 5 } };
Can you post the code that doesn't work? I have an idea of what might
be going on, but it's easier for me to explain if I see the code
you're trying to compile :-)
Cheers,
Tim
--
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
"We know there'd hardly be no one in prison
Here's something I tried that seemed the closest to working, but I don't
know if I'm on the right track at all:
struct T1 { value: int }
struct T2 { t1: option::Option<~T1> }
fn value(t2: &r/T2, def: &r/int) -> &r/int {
match t2.t1 {
Some(ref t1) => &t1.value,
I suspect this is a borrowck bug (or at least shortcoming), but I
don't know the borrowck rules well enough to say for sure. I suggest
filing this code as an issue.
Cheers,
Tim
--
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
"We know there'd hardly be no one in pris
On 12/24/12 3:48 PM, Tim Chevalier wrote:
I suspect this is a borrowck bug (or at least shortcoming), but I
don't know the borrowck rules well enough to say for sure. I suggest
filing this code as an issue.
I vote bug as well.
Patrick
___
Rust-dev
On Monday, December 24, 2012, Patrick Walton wrote:
> On 12/24/12 3:48 PM, Tim Chevalier wrote:
>
>> I suspect this is a borrowck bug (or at least shortcoming), but I
>> don't know the borrowck rules well enough to say for sure. I suggest
>> filing this code as an issue.
>>
>
> I vote bug as well.
Turns out the issue was borrowing from a reborrowed value. i.e. this
doesn't work:
fn rereborrow(v: &r/int) -> &r/int {
&*&*v
}
I've filed an issue: https://github.com/mozilla/rust/issues/4285
Incidentally, I can make my original code work by eliminating the
intermediate borrow:
struct T1
This is actually bug 3148: https://github.com/mozilla/rust/issues/3148
You can use explicit type declarations as a workaround for the time
being. Your rewrite also works in the same manner: it overcomes a
shortcoming in the region inferencer. I hope we can fix this soon, it's
not terribly di