-
Notifications
You must be signed in to change notification settings - Fork 847
Make Level and LevelFilter Copy
#992
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
Conversation
This makes both structs easier to use because you no longer have to worry about borrow errors while working with them. There's no downside to making them `Copy` since both are wrappers around a `usize`. Ideally, this would make `Metadata::Level` return `Level` instead of `&Level`. However that's a breaking change, so I didn't make it here.
|
This is split out from #990 (see #990 (comment)). |
|
I don't know how to fix this error :( |
|
I tried this but it didn't work: diff --git a/tracing-core/src/metadata.rs b/tracing-core/src/metadata.rs
index 8dd216f..d9ea459 100644
--- a/tracing-core/src/metadata.rs
+++ b/tracing-core/src/metadata.rs
@@ -432,7 +432,7 @@ impl LevelFilter {
// `LevelFilter`. If this is the case, converting a `usize` value into a
// `LevelFilter` (in `LevelFilter::current`) will be an identity conversion,
// rather than generating a lookup table.
- const OFF_USIZE: usize = LevelInner::Error as usize + 1;
+ const OFF_USIZE: usize = unsafe { core::mem::transmute(LevelFilter(None)) };
/// Returns a `LevelFilter` that matches the most verbose [`Level`] that any
/// currently active [`Subscriber`] will enable.
@@ -851,7 +851,7 @@ mod tests {
#[test]
fn level_filter_reprs() {
let mapping = [
- (LevelFilter::OFF, LevelInner::Error as usize + 1),
+ (LevelFilter::OFF, LevelFilter::OFF_USIZE),
(LevelFilter::ERROR, LevelInner::Error as usize),
(LevelFilter::WARN, LevelInner::Warn as usize),
(LevelFilter::INFO, LevelInner::Info as usize), |
It was comparing the pointers, not the levels themselves. This also changes transmute to explicitly specify both types to make this easier to debug in the future.
1950b1c to
a4ceb23
Compare
|
Historically, we've avoided adding |
|
Given that there's an explicit test for transmuting between |
|
That's fair, in this particular case it's probably justified! :) |
hawkw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR changes crates that depend on tracing-core to remove clone calls and rely on Level and LevelFilter being Copy, those crates will no longer compile with older versions of tracing-core. Can we bump the tracing-core version and update tracing, tracing-log, and tracing-subscriber to depend on the new tracing-core version as part of this PR? Thanks!
Since this changes crates that depend on tracing-core to remove clone calls and rely on Level and LevelFilter being Copy, those crates will no longer compile with older versions of tracing-core. This bumps the version number for `tracing-core` and sets the minimum version to the new version for all affected crates. This avoids compile errors with a cached `Cargo.lock`.
|
Good idea, done! |
hawkw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this looks good to me.
in re:
Ideally, this would make
Metadata::LevelreturnLevelinstead of
&Level. However that's a breaking change, so I didn't make it here.
We can make this change in tracing-core 0.2 --- we'll add it to the list of planned breaking changes in #922
Fixed - Incorrect inlining of `Event::dispatch` and `Event::child_of`, which could result in `dispatcher::get_default` being inlined at the callsite (#994) Added - `Copy` implementations for `Level` and `LevelFilter` (#992) Thanks to new contributors @jyn514 and @TaKO8Ki for contributing to this release! Signed-off-by: Eliza Weisman <eliza@buoyant.io>
### Fixed - Incorrect inlining of `Event::dispatch` and `Event::child_of`, which could result in `dispatcher::get_default` being inlined at the callsite (#994) ### Added - `Copy` implementations for `Level` and `LevelFilter` (#992) Thanks to new contributors @jyn514 and @TaKO8Ki for contributing to this release! Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Fixed - Incorrect inlining of `Span::new`, `Span::new_root`, and `Span::new_child_of`, which could result in `dispatcher::get_default` being inlined at the callsite ([#994]) - Regression where using a struct field as a span or event field when other fields on that struct are borrowed mutably would fail to compile ([#987]) Changed - Updated `tracing-core` to 0.1.17 ([#992]) Added - `Instrument` trait and `Instrumented` type for attaching a `Span` to a `Future` ([#808]) - `Copy` implementations for `Level` and `LevelFilter` ([#992]) - Multiple documentation fixes and improvements ([#964], [#980], [#981]) Thanks to @nagisa, and new contributors @securityinsanity, @froydnj, @jyn514 and @TaKO8Ki for contributing to this release! [#994]: #994 [#992]: #992 [#987]: #987 [#980]: #980 [#981]: #981 [#964]: #964 [#808]: #808 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
### Fixed - Incorrect inlining of `Span::new`, `Span::new_root`, and `Span::new_child_of`, which could result in `dispatcher::get_default` being inlined at the callsite ([#994]) - Regression where using a struct field as a span or event field when other fields on that struct are borrowed mutably would fail to compile ([#987]) ### Changed - Updated `tracing-core` to 0.1.17 ([#992]) ### Added - `Instrument` trait and `Instrumented` type for attaching a `Span` to a `Future` ([#808]) - `Copy` implementations for `Level` and `LevelFilter` ([#992]) - Multiple documentation fixes and improvements ([#964], [#980], [#981]) Thanks to @nagisa, and new contributors @securityinsanity, @froydnj, @jyn514 and @TaKO8Ki for contributing to this release! [#994]: #994 [#992]: #992 [#987]: #987 [#980]: #980 [#981]: #981 [#964]: #964 [#808]: #808 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
* upstream/master: subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) docs: switch to intra-doc links in tracing-core (tokio-rs#1010) tracing-opentelemetry: implement additional record types (bool, i64, u64) (tokio-rs#1007) core: add intrusive linked list for callsite registry (tokio-rs#988) serde: allow tracing-serde to work on no_std. (tokio-rs#960) tracing: remove `Into<Option<Id>>` impl for `Span` (tokio-rs#1003) tracing: make `Entered` `!Send` (tokio-rs#1001) chore: fix nightly clippy warnings (tokio-rs#991) chore: bump all crate versions (tokio-rs#998) macros: fix the `tracing-macros` crate not compiling (tokio-rs#1000) tracing: prepare to release 0.1.21 (tokio-rs#997) core: prepare to release 0.1.17 (tokio-rs#996) subscriber: make `PartialOrd` & `Ord` impls more correct (tokio-rs#995) core, tracing: don't inline dispatcher::get_default (tokio-rs#994) core: make `Level` and `LevelFilter` `Copy` (tokio-rs#992)
Changed - Updated `tracing-core` to 0.1.17 ([#992]) Added - **env-filter**: Added support for filtering on targets which contain dashes ([#1014]) - **env-filter**: Added a warning when creating an `EnvFilter` that contains directives that would enable a level disabled by the `tracing` crate's `static_max_level` features ([#1021]) Thanks to @jyn514 and @bkchr for contributing to this release! [#992]: #992 [#1014]: #1014 [#1021]: #1021
Changed - Updated `tracing-core` to 0.1.17 ([#992]) Added - **env-filter**: Added support for filtering on targets which contain dashes ([#1014]) - **env-filter**: Added a warning when creating an `EnvFilter` that contains directives that would enable a level disabled by the `tracing` crate's `static_max_level` features ([#1021]) Thanks to @jyn514 and @bkchr for contributing to this release! [#992]: #992 [#1014]: #1014 [#1021]: #1021
### Changed - Updated `tracing-core` to 0.1.17 ([#992]) ### Added - **env-filter**: Added support for filtering on targets which contain dashes ([#1014]) - **env-filter**: Added a warning when creating an `EnvFilter` that contains directives that would enable a level disabled by the `tracing` crate's `static_max_level` features ([#1021]) Thanks to @jyn514 and @bkchr for contributing to this release! [#992]: #992 [#1014]: #1014 [#1021]: #1021
### Changed - Updated `tracing-core` to 0.1.17 ([tokio-rs#992]) ### Added - **env-filter**: Added support for filtering on targets which contain dashes ([tokio-rs#1014]) - **env-filter**: Added a warning when creating an `EnvFilter` that contains directives that would enable a level disabled by the `tracing` crate's `static_max_level` features ([tokio-rs#1021]) Thanks to @jyn514 and @bkchr for contributing to this release! [tokio-rs#992]: tokio-rs#992 [tokio-rs#1014]: tokio-rs#1014 [tokio-rs#1021]: tokio-rs#1021
Motivation
This makes both structs easier to use because you no longer have to
worry about borrow errors while working with them. There's no downside
to making them
Copysince both are wrappers around ausize.Ideally, this would make
Metadata::LevelreturnLevelinstead of&Level. However that's a breaking change, so I didn't make it here.Solution
Derive
Copyfor both structs and fix various warnings that popped up as a result.