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

feat!(render): render_report can accept more types #371

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheLostLambda
Copy link
Contributor

This PR builds on PR #367! Merging this should be equivalent to merging both!

You can now pass a &dyn Diagnostic (as before), or a Report (or &Report, &mut Report, or Box<Report>), or anything else that implements Diagnostic to render_report.

More generally, users can use the AsDiagnostic trait wherever they want to write functions that accept either a Report or Diagnostic — this improves ergonomics in a world where impl Diagnostic for Report is impossible.

BREAKING CHANGE: Because more types can now be passed to render_report, Report::as_ref() can get confused about types, and inference fails. The solution is removing the .as_ref() altogether since Report is now a directly accepted type.

This would also effectively close #366 (for my purposes, at least), since anything accepting AsDiagnostic will work for Report and anything that implements Diagnostic!

BEFORE MERGING: After getting the green light from you, but before merging this, I'll have to properly fill in the documentation for AsDiagnostic! I don't think WOOF and BARK is particularly helpful, but I didn't want to write docs before knowing if you'd be interested in accepting this PR!

Brings things in line with best practices as described in "Rust for
Rustaceans" when it comes to "Ergonomic Trait Implementations" in Chapter
3. Practically means that people can pass more types to any functions
taking either `dyn Diagnostic` or `impl Diagnostic`.

BREAKING CHANGE: Added blanket impls may overlap with manual user impls.
If these impls are just hacks to achieve the same as the blanket ones do,
then they can simply be removed. If the impls for `T` and `&T` differ
semantically, then the user would need to employ the newtype pattern to
avoid overlap.
You can now pass a `&dyn Diagnostic` (as before), or a `Report` (or
`&Report`, `&mut Report`, or `Box<Report>`), or anything else that
implements `Diagnostic` to `render_report`.

More generally, users can use the `AsDiagnostic` trait wherever they want
to write functions that accept either a `Report` or `Diagnostic` — this
improves ergonomics in a world where `impl Diagnostic for Report` is
impossible.

BREAKING CHANGE: Because more types can now be passed to `render_report`,
`Report::as_ref()` can get confused about types and inference fails. The
solution is removing the `.as_ref()` altogether since `Report` is now a
directly accepted type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A semver-major breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a reason that Report doesn't implement Error and Diagnostic?
2 participants