Closed
Description
When trying to use associated functions and trait objects we get the following type of errors:
error[E0038]: the trait `content::database::utils::CodeNormalizer` cannot be made into an object
--> src/content/database/utils.rs:175:16
|
175 | const SYSTEMS: &[Box<&dyn CodeNormalizer>] = &[
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `content::database::utils::CodeNormalizer` cannot be made into an object
|
= note: method `normalize` has no receiver
= note: method `get_name` has no receiver
There are two possible cases for intent:
- we're trying to do something that Rust doesn't allow, which is having associated functions that don't take
self
in a trait object - we have zero-sized structs that implement a given trait to carry a bunch of functionality
In the former case, the explanation leaves a lot to be desired: what is a receiver
? Why are we calling it a method
when it's really a function
in this case? Maybe we forgot to have self
as the first argument? Should we be suggesting adding it? Why aren't we pointing at the trait fn definition nor the impl?
For the second case, I believe if we can detect it it'd be great, because we could customize the help text to suggest adding &self
in a confident manner, as we wouldn't have to care about lifetime issues.