zkat / miette

Fancy extension for std::error::Error with pretty, detailed diagnostic printing.
https://docs.rs/miette
Apache License 2.0
1.85k stars 106 forks source link

feat(source): derive common traits for NamedSource, SourceSpan, and SourceOffset #340

Closed TheLostLambda closed 4 months ago

TheLostLambda commented 4 months ago

One-liner sanding off a small rough edge I came across: using NamedSource<String> (instead of simply String) severely limits which traits can be derived for the wrapping diagnostic. In my case, I lost the ability to clone my error!

image

I've brought things in line with https://rust-lang.github.io/api-guidelines/interoperability.html#types-eagerly-implement-common-traits-c-common-traits, leaving out Copy, Display, and Default, since those derives are either not possible or don't feel useful. The ones I've added here make sure people can .clone() errors, compare them, sort them, and use them in HashSets / HashMaps.

I also added Ord derives to the SourceSpan and SourceOffset types for the same reason!