Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output better error messages when deriving ContentHash for an enum fails
Consider this code: ``` struct NoContentHash {} #[derive(ContentHash)] enum Hashable { NoCanHash(NoContentHash), Empty, } ``` Before this commit, it generates an error like this: ``` error[E0277]: the trait bound `NoContentHash: ContentHash` is not satisfied --> lib/src/content_hash.rs:150:10 | 150 | #[derive(ContentHash)] | ^^^^^^^^^^^ the trait `ContentHash` is not implemented for `NoContentHash` 151 | enum Hashable { 152 | NoCanHash(NoContentHash), | --------- required by a bound introduced by this call | = help: the following other types implement trait `ContentHash`: bool i32 i64 u8 u32 u64 std::collections::HashMap<K, V> BTreeMap<K, V> and 35 others For more information about this error, try `rustc --explain E0277`. ``` After this commit, it generates a better error message: ``` error[E0277]: the trait bound `NoContentHash: ContentHash` is not satisfied --> lib/src/content_hash.rs:152:15 | 152 | NoCanHash(NoContentHash), | ^^^^^^^^^^^^^ the trait `ContentHash` is not implemented for `NoContentHash` | = help: the following other types implement trait `ContentHash`: bool i32 i64 u8 u32 u64 std::collections::HashMap<K, V> BTreeMap<K, V> and 35 others For more information about this error, try `rustc --explain E0277`. error: could not compile `jj-lib` (lib) due to 1 previous error ``` It also works for enum variants with named fields: ``` error[E0277]: the trait bound `NoContentHash: ContentHash` is not satisfied --> lib/src/content_hash.rs:152:23 | 152 | NoCanHash { named: NoContentHash }, | ^^^^^^^^^^^^^ the trait `ContentHash` is not implemented for `NoContentHash` | = help: the following other types implement trait `ContentHash`: bool i32 i64 u8 u32 u64 std::collections::HashMap<K, V> BTreeMap<K, V> and 35 others For more information about this error, try `rustc --explain E0277`. ```
- Loading branch information