Closed
Description
The following used to work in nightly
, but doesn't anymore (I'm not sure when it changed):
#![feature(associated_type_defaults)]
pub trait Emitter<'a> {
type Ctxt: 'a;
type CtxtBrw: 'a = &'a Self::Ctxt;
fn get_cx(&'a self) -> Self::CtxtBrw;
}
struct MyCtxt;
struct MyEmitter {
ctxt: MyCtxt
}
impl <'a> Emitter<'a> for MyEmitter {
type Ctxt = MyCtxt;
fn get_cx(&'a self) -> &'a MyCtxt {
&self.ctxt
}
}
fn main() {
}
The above returns the following error:
<anon>:19:5: 21:6 error: method `get_cx` has an incompatible type for trait:
expected associated type,
found &-ptr [E0053]
<anon>:19 fn get_cx(&'a self) -> &'a MyCtxt {
<anon>:20 &self.ctxt
<anon>:21 }
<anon>:19:5: 21:6 help: see the detailed explanation for E0053
error: aborting due to previous error
playpen: application terminated with error code 101
If I manually implement CtxtBrw
then it does compile:
impl <'a> Emitter<'a> for MyEmitter {
type Ctxt = MyCtxt;
type CtxtBrw = &'a Self::Ctxt;
fn get_cx(&'a self) -> &'a MyCtxt {
&self.ctxt
}
}
Is this expected behaviour? And if so, what's the rationale so I know if I'm trying to do something I shouldn't :)