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

core: impl Value for dyn Error + Send/Sync #2066

Merged
merged 1 commit into from
Apr 11, 2022

Conversation

lilyball
Copy link
Contributor

Motivation

Value was already implemented for dyn Error + 'static, but rust doesn't silently coerce trait objects. This means that passing an error of type dyn Error + Send + Sync + 'static would not work. This is related to #1308.

Solution

Add impls for dyn Error + … variants for Send, Sync, and Send + Sync. These extra impls just delegate to the existing dyn Error + 'static impl.

Also update one of the examples to use dyn Error + Send + Sync to demonstrate that this works.

@lilyball lilyball requested review from hawkw and a team as code owners April 11, 2022 22:26
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me.

In general, it's a lot easier if we make changes that apply to both the master and v0.1.x branches on the master branch, and then backport them to v0.1.x when the change applies to both v0.1.x and v0.2. It's a bit more work to have to backport and forward-port changes. Would you mind changing this PR to be based on master, and I'll handle backporting it after it merges?

@lilyball
Copy link
Contributor Author

Ok. I wasn't sure how best to handle that. I'll rebase it onto master and move the base branch.

@lilyball lilyball changed the base branch from v0.1.x to master April 11, 2022 22:30
@lilyball
Copy link
Contributor Author

Oh good, GitHub appears to be rather confused by me force-pushing and then changing the base >_< I'll try again.

`Value` was already implemented for `dyn Error + 'static`, but rust
doesn't silently coerce trait objects. This means that passing an error
of type `dyn Error + Send + Sync + 'static` would not work. These extra
impls just delegate to the existing `dyn Error + 'static` impl.

Also update one of the examples to use `dyn Error + Send + Sync` to
demonstrate that this works.

Refs: tokio-rs#1308
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, looks great to me now! Thanks again!

@hawkw hawkw enabled auto-merge (squash) April 11, 2022 22:37
@hawkw hawkw merged commit c4bcf5c into tokio-rs:master Apr 11, 2022
hawkw pushed a commit that referenced this pull request Apr 12, 2022
## Motivation

`Value` was already implemented for `dyn Error + 'static`, but rust
doesn't silently coerce trait objects. This means that passing an error
of type `dyn Error + Send + Sync + 'static` would not work. This is
related to #1308.

## Solution

Add impls for `dyn Error + …` variants for `Send`, `Sync`, and `Send +
Sync`. These extra impls just delegate to the existing `dyn Error +
'static` impl.

Also update one of the examples to use `dyn Error + Send + Sync` to
demonstrate that this works.

Refs: #1308
hawkw added a commit that referenced this pull request Apr 12, 2022
# 0.1.25 (April 12, 2022)

This release adds additional `Value` implementations for
`std::error::Error` trait objects with auto trait bounds (`Send` and
`Sync`), as Rust will not auto-coerce trait objects. Additionally, it
fixes a bug when setting scoped dispatchers that was introduced in the
previous release ([v0.1.24]).

### Added

- `Value` implementations for `dyn Error + Send + 'static`, `dyn Error +
  Send + Sync + 'static`, `dyn Error + Sync + 'static` ([#2066])

### Fixed

- Failure to use the global default dispatcher if a thread has set a
  scoped default prior to setting the global default, and unset the
  scoped default after setting the global default ([#2065])

Thanks to @lilyball for contributing to this release!

[v0.1.24]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.24
[#2066]: #2066
[#2065]: #2065
hawkw added a commit that referenced this pull request Apr 12, 2022
# 0.1.25 (April 12, 2022)

This release adds additional `Value` implementations for
`std::error::Error` trait objects with auto trait bounds (`Send` and
`Sync`), as Rust will not auto-coerce trait objects. Additionally, it
fixes a bug when setting scoped dispatchers that was introduced in the
previous release ([v0.1.24]).

### Added

- `Value` implementations for `dyn Error + Send + 'static`, `dyn Error +
  Send + Sync + 'static`, `dyn Error + Sync + 'static` ([#2066])

### Fixed

- Failure to use the global default dispatcher if a thread has set a
  scoped default prior to setting the global default, and unset the
  scoped default after setting the global default ([#2065])

Thanks to @lilyball for contributing to this release!

[v0.1.24]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.24
[#2066]: #2066
[#2065]: #2065
hawkw added a commit that referenced this pull request Apr 12, 2022
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
#2066, but it may be useful for other boxed values as well.

Refs: #1308
hawkw added a commit that referenced this pull request Apr 14, 2022
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
#2066, but it may be useful for other boxed values as well.

Refs: #1308
hawkw added a commit that referenced this pull request Apr 14, 2022
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
#2066, but it may be useful for other boxed values as well.

Refs: #1308
hawkw added a commit that referenced this pull request Apr 14, 2022
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
#2066, but it may be useful for other boxed values as well.

Refs: #1308
hawkw added a commit that referenced this pull request Apr 14, 2022
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
#2066, but it may be useful for other boxed values as well.

Refs: #1308
@lilyball lilyball deleted the error-send-sync-value branch April 15, 2022 23:01
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.1.25 (April 12, 2022)

This release adds additional `Value` implementations for
`std::error::Error` trait objects with auto trait bounds (`Send` and
`Sync`), as Rust will not auto-coerce trait objects. Additionally, it
fixes a bug when setting scoped dispatchers that was introduced in the
previous release ([v0.1.24]).

### Added

- `Value` implementations for `dyn Error + Send + 'static`, `dyn Error +
  Send + Sync + 'static`, `dyn Error + Sync + 'static` ([tokio-rs#2066])

### Fixed

- Failure to use the global default dispatcher if a thread has set a
  scoped default prior to setting the global default, and unset the
  scoped default after setting the global default ([tokio-rs#2065])

Thanks to @lilyball for contributing to this release!

[v0.1.24]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.24
[tokio-rs#2066]: tokio-rs#2066
[tokio-rs#2065]: tokio-rs#2065
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
This commit adds a `Value` implementation for `Box<T> where T: Value`.
This is *primarily* intended to make `Box<dyn Error + ...>` implement
`Value`, building on the `Value` impls for `dyn Error + ...` added in
tokio-rs#2066, but it may be useful for other boxed values as well.

Refs: tokio-rs#1308
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.

2 participants