I see, thanks for the explanation.  Looks like a compiler bug, then.
I'll work around it with an unsafe transmute for now.

Thanks,
Christian.


On Mon, Dec 2, 2013 at 5:49 AM, Felix S. Klock II <[email protected]> wrote:
> rust-dev-
>
> In general, we need to ensure that for an expression `<source> as <target>`
> that any borrowed pointers in the type of <source> are not obscured [1] by
> the cast.
>
> A  collection of conditions sufficient to enforce this are listed in a
> comment in librustc/middle/kind.rs that I think is apropos here:
>
> https://github.com/mozilla/rust/blob/master/src/librustc/middle/kind.rs#L488
>
> However, there are probably other conditions that would also suffice that we
> might add to that set.
>
> In particular, I do not see anything immediately wrong with your example;
> the type-expression  `&'a V` should ensure that `V` does not contain any
> lifetimes that are shorter than 'a, and therefore it should be safe to cast
> `v: &'a V` to a `&'a T`.
>
> I have filed this as issue #10766 [2].
>
> Cheers,
> -Felix
>
> [1] https://github.com/mozilla/rust/issues/5723
>
> [2] https://github.com/mozilla/rust/issues/10766
>
>
> On 30/11/2013 23:22, Christian Ohler wrote:
>>
>> Hi all,
>>
>> I'm trying to learn rust and ran into an error message I don't
>> understand, and would appreciate some help.  This code:
>>
>> trait T {}
>>
>> fn f<'a, V: T>(v: &'a V) -> &'a T {
>>      v as &'a T
>> }
>>
>>
>> is rejected with this error message:
>>
>> trait-cast.rs:4:4: 4:5 error: value may contain borrowed pointers; add
>> `'static` bound
>> trait-cast.rs:4     v as &'a T
>>
>>
>> I'm trying to upcast from V to T so that I can put v in a container of
>> element type T (in code not shown here).  The suggestion to add a
>> 'static bound doesn't sound like what I'm looking for.
>>
>> What is the concern about borrowed pointers here?  What would an
>> implementation of T and a caller of f look like to lead to a safety
>> problem?
>>
>> I'm using a version of rust that is a few days old.
>>
>> Thanks,
>> Christian.
>> _______________________________________________
>> Rust-dev mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/rust-dev
>
>
>
> --
> irc: pnkfelix on irc.mozilla.org
> email: {fklock, pnkfelix}@mozilla.com
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to