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

Support trait objects for source in Error #252

Merged
merged 1 commit into from
Jul 1, 2023

Conversation

JelteF
Copy link
Owner

@JelteF JelteF commented Mar 23, 2023

If you used boxed dyn Error traits as a source a compile error would
occur:

 --> tests/error/derives_for_enums_with_source.rs:5:17
  |
5 | #[derive(Debug, Error)]
  |                 ^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `(dyn std::error::Error + Send + 'static)`
  = help: the trait `std::error::Error` is implemented for `Box<T>`
  = note: required for `Box<(dyn std::error::Error + Send + 'static)>` to implement `std::error::Error`
  = note: required for the cast from `Box<(dyn std::error::Error + Send + 'static)>` to the object type `dyn std::error::Error`
  = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)

This fixes that by shamelessly "borrowing" a fix from thiserror.

Resolves #122

Checklist

  • [ ] Documentation is updated (if required)
  • Tests are added/updated (if required)
  • CHANGELOG entry is added (if required)

@JelteF JelteF requested a review from tyranron April 3, 2023 18:27
@JelteF JelteF force-pushed the fix-error-source-trait-objects branch 2 times, most recently from 218b72f to 97f4075 Compare April 8, 2023 18:25
@JelteF JelteF added this to the 1.0.0 milestone May 8, 2023
@JelteF JelteF force-pushed the fix-error-source-trait-objects branch 2 times, most recently from 001242d to 3b2b660 Compare July 1, 2023 16:08
If you used boxed `dyn Error` traits as a source a compile error would
occur:
```
 --> tests/error/derives_for_enums_with_source.rs:5:17
  |
5 | #[derive(Debug, Error)]
  |                 ^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `(dyn std::error::Error + Send + 'static)`
  = help: the trait `std::error::Error` is implemented for `Box<T>`
  = note: required for `Box<(dyn std::error::Error + Send + 'static)>` to implement `std::error::Error`
  = note: required for the cast from `Box<(dyn std::error::Error + Send + 'static)>` to the object type `dyn std::error::Error`
  = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This fixes that by shamelessly "borrowing" a fix from [`thiserror`].

[`thiserror`]: https://github.com/dtolnay/thiserror

Fixes #122

Redid this commit, because I accidentally pushed to master without a PR.
@JelteF JelteF enabled auto-merge (squash) July 1, 2023 16:13
@JelteF JelteF disabled auto-merge July 1, 2023 16:13
@JelteF JelteF merged commit 37cae22 into master Jul 1, 2023
15 checks passed
@JelteF JelteF deleted the fix-error-source-trait-objects branch July 1, 2023 16:13
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

Successfully merging this pull request may close these issues.

Support trait objects for source in Error
1 participant