Skip to content

When using associated_type_defaults: Why do I need to reimplement method with default impl when overriding assoc type default? #53907

Closed
@Boscop

Description

@Boscop

rustc 1.30.0-nightly (02cb8f2 2018-08-29)

I'm using #![feature(associated_type_defaults)] and getting this error with the code below:

error[E0399]: the following trait items need to be reimplemented as `Msg` was overridden: `process`
   --> src\devices\bcr\mod.rs:110:2
    |
110 |     type Msg = ();
    |     ^^^^^^^^^^^^^^
pub trait DeviceSpecific {
	type Dev: Device;
}
pub trait DeviceApp<'a>: DeviceSpecific + Persistable {
	type Event: 'static;
	type BorrowedState;
	fn init_children_sync_viewers(&mut self, v: &Self::BorrowedState);
	fn handle_input(&mut self, e: <Self::Dev as Device>::InputEv, v: &mut Self::BorrowedState, now: u64) -> Option<Self::Event>;
	fn render(&self, device: &mut Self::Dev, v: &Self::BorrowedState);
	fn process<'b>(&'b mut self, device: &mut Self::Dev, events: Vec<<Self::Dev as Device>::InputEv>, v: &'b mut Self::BorrowedState, now: u64) -> Vec<Self::Event> where 'a: 'b {
		let r = events.into_iter().filter_map(|e| self.handle_input(e, v, now)).collect();
		self.render(device, v);
		r
	}
	type Msg: 'static = ();
	fn handle_msg(&mut self, e: Self::Msg);
}

/////

impl<'a> DeviceApp<'a> for BcrAppState {
	type Event = ();
	type BorrowedState = MyBorrowedState<'a>;
	fn init_children_sync_viewers(&mut self, v: &Self::BorrowedState) {
		// ...
	}
	fn handle_input(&mut self, e: <Self::Dev as Device>::InputEv, v: &mut Self::BorrowedState, now: u64) -> Option<Self::Event> {
		// ...
	}
	fn render(&self, device: &mut Self::Dev, v: &Self::BorrowedState) {
		// ...
	}
	type Msg = ();
	fn handle_msg(&mut self, _e: Self::Msg) {}
}

Why do I need to reimplement the process() method (which has a default impl) when overriding the Msg assoc type's default?
Why can't I keep using the default impl?
The process() method isn't even using the Msg assoc type.

Metadata

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-specializationArea: Trait impl specializationF-associated_type_defaults`#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions