Why is `let ref a: Trait = Struct` forbidden?

Viewed 310

We have a noncopyable type and a trait:

struct Struct;
trait Trait {}
impl Trait for Struct {}

If we create a &Struct and dereference it, we get an rvalue reference that we can use to initialize a by-ref binding:

let a: &Struct = &Struct;
let ref a: Struct = *a;

We can also directly initialize that by ref binding:

let ref a: Struct = Struct;

But if we declare our variable binding to require a reference, only the first code snippet works

let a: &Trait = &Struct;
let ref a: Trait = *a;

Attempting to do this directly

let ref a: Trait = Struct;

Or by going through loops

let a: &Struct = &Struct;
let ref a: Trait = *a;

Or

let ref a: Trait = *&Struct;

Will give us a mismatched types error. Obviously they aren't the same type, but inference works for references.

Is this simply not implemented (yet?) or is there a deeper reason it's disallowed?

1 Answers
Related