Skip to content

compiler diagnostic typo when implementing a non object trait to an object trait #98500

Closed

Description

Given the following code:

pub trait Elements
where
	Self: IntoWasmAbi,
{
	fn get_pos(&self) -> Vec2<f64>;
	fn get_pos_json(&self) -> String;
	fn get_collision_bodies(&self) -> &HashMap<String, CollisionBody>;
	fn add_collision_body(&mut self);
	fn remove_collision_body(&mut self);
	fn draw_collisions(&self, engine: &Engine);
}

#[wasm_bindgen]
pub struct Engine {
	window_dimensions: Vec2<u32>,
	speed: f64,
	acceleration: f64,
	elements: HashMap<String, Box<dyn Elements<Abi = String>>>,
	context: CanvasRenderingContext2d,
}

The current output is:

194 | pub trait Elements
    |           -------- this trait cannot be made into an object...
    = help: consider turning `describe` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects
help: consider turning `describe` into a method by giving it a `&self` argument
    |
56  |     fn describe&self();
    |                +++++
194 | pub trait Elements
    |           -------- this trait cannot be made into an object...
    = help: consider turning `describe` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects
help: consider turning `describe` into a method by giving it a `&self` argument
    |
56  |     fn describe(&self);
    |                 +++++

The IntoWasmAbi is a trait from another crate btw, I don't think this should be the right answer because you can't really modify the other crate. I mean, you can, but not inside the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions