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

diagnostic::on_unimplemented for fundamental traits, providing better compile-time errors #3549

Open
chrisp60 opened this issue Feb 6, 2025 · 1 comment

Comments

@chrisp60
Copy link
Contributor

chrisp60 commented Feb 6, 2025

@gbj recently made a request in discord for some help in making use of the diagnostic::on_unimplemented attribute

I do not have a ton of time to work on this, but I at least wanted to make an issue that can be referenced and used to store locations where this may help. Discord isn't great for aggregating lists of things over long periods of time.

I encourage others to reference / comment / discuss places where we currently have confusing, or convoluted errors regarding trait implementations. This is likely not something that can reasonably be "finished" in a single PR.

I am just putting down some initial thoughts in case I can work on this at all, or first time contributors are looking for a place to start.

diagnostic::on_unimplemented

In short, this attribute is able to declare how a compile-time error is displayed when the user has an X that requires an implementation on Y, but Y is not implemented for X.

Traits that may benefit

  • the traits in reactive_graph (signal related things) would definitely be low hanging fruit.

In the wild

  • axum::Handler: suggesting to use #[axum::debug_handler]
  • std::Sync: shows an almost insane level of detail that is enabled through proper use of the attribute. Allowing someone to specify messages when the implementation is missing on a concrete type. This use does not seem to be in the reference, so maybe they are doing some compiler-blessed tech there?
    • Thinking about closures capturing too much and thus not reaching the blanket impl for IntoView?

diagnostic::do_not_recommend

Could be useful for some lower level blanket implementations that exist for rendering? Likely a lower priority to using the above attribute.

Limitations

This attribute is only available since 1.78, leptos currently has an msrv of 1.76. Any uses may need to gate the attribute if we wish to keep that. Raising msrv is definitely semver breaking (I think)? axum uses rustversion crate to easily achieve this attribute configuration.

@benwis
Copy link
Contributor

benwis commented Feb 6, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants