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

Reply via email to