Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kkuriboh opened this issue Jun 25, 2022 · 0 comments · Fixed by #98506
Closed

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

kkuriboh opened this issue Jun 25, 2022 · 0 comments · Fixed by #98506
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kkuriboh
Copy link

kkuriboh commented Jun 25, 2022

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.

@kkuriboh kkuriboh added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 25, 2022
@compiler-errors compiler-errors self-assigned this Jun 25, 2022
@bors bors closed this as completed in 6391f23 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants