-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
debug-fmt-detail option #123940
base: master
Are you sure you want to change the base?
debug-fmt-detail option #123940
Conversation
Some changes occurred in cfg and check-cfg configuration cc @Urgau |
This comment has been minimized.
This comment has been minimized.
I'd love to see this happen. I have a suggestion for a refinement: In the This constant string should be |
7437d70
to
aabf2f6
Compare
This comment has been minimized.
This comment has been minimized.
aabf2f6
to
1721c63
Compare
Some changes occurred in tests/ui/check-cfg cc @Urgau |
This comment has been minimized.
This comment has been minimized.
@kpreid But There is |
1721c63
to
bceb534
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bf36e51
to
3905795
Compare
Some changes occurred in src/doc/rustc/src/check-cfg.md cc @Urgau |
This comment has been minimized.
This comment has been minimized.
3905795
to
92cac91
Compare
This comment has been minimized.
This comment has been minimized.
92cac91
to
8b214c8
Compare
This comment was marked as resolved.
This comment was marked as resolved.
8b214c8
to
320621e
Compare
This comment has been minimized.
This comment has been minimized.
320621e
to
9798774
Compare
This comment was marked as resolved.
This comment was marked as resolved.
9798774
to
f110a37
Compare
This comment was marked as resolved.
This comment was marked as resolved.
f110a37
to
f822fd1
Compare
This comment was marked as resolved.
This comment was marked as resolved.
f822fd1
to
ad584cd
Compare
@rfcbot fcp merge |
Team member @estebank has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment was marked as resolved.
This comment was marked as resolved.
Allows disabling `fmt::Debug` derive and debug formatting.
ad584cd
to
5dfa4ce
Compare
@@ -117,6 +117,10 @@ impl<'a> Argument<'a> { | |||
Self::new(x, Debug::fmt) | |||
} | |||
#[inline(always)] | |||
pub fn new_debug_noop<'b, T: Debug>(x: &'b T) -> Argument<'_> { | |||
Self::new(x, |_, _| Ok(())) | |||
} |
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.
Why are shallow
and none
implemented differently?
One have a separate function in the library, and another does not and is processed in rustc_builtin_macros
.
I suggest dropping the "detail" from the name. (Also maybe |
I'd like to propose a new option that makes
#[derive(Debug)]
generate no-op implementations that don't print anything, and makes{:?}
in format strings a no-op.There are a couple of motivations for this:
Debug
implementations. It's hard to avoid that without compiler's help, because debug formatting can be used in many places, including dependencies, and their loggers, asserts, panics, etc.panic_immediate_abort
). There are targets like Web WASM or embedded where users pay attention to binary sizes.Debug
format implementation in unwise ways (e.g. trying to get data unavailable via public interface, or using it as a serialization format). Because current Rust's debug implementation doesn't change, there's a risk of it becoming a fragile de-facto API that won't be possible to change in the future. An option that "breaks" it can act as a grease.This implementation is a
-Z debug-fmt-detail=opt
flag that takes:full
— the default, current state.none
— makes derivedDebug
and{:?}
no-ops. Explicitimpl Debug for T
implementations are left unharmed, but{:?}
format won't use them, so they may get dead-code eliminated if they aren't invoked directly.shallow
— makes derivedDebug
print only the type's name, without recursing into fields. Fieldless enums print their variant names.{:?}
works.The
shallow
option is a compromise between minimizing theDebug
code, and compatibility. There are popular proc-macro crates that useDebug::fmt
as a way to convert enum values into their Rust source code.There's a corresponding
cfg
flag:#[cfg(debug_fmt_detail = "none")]
that can be used in user code to react to this setting to minimize customDebug
implementations or remove unnecessary formatting helper functions.