-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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 :)
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.