rust/compiler
Guillaume Gomez 015e9371e0
Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau
debug-fmt-detail option

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:

1. A more thorough stripping of debug symbols. Binaries stripped of debug symbols still retain some of them through `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.
   * In my testing it gives about 2% binary size reduction on top of all other binary-minimizing best practices (including `panic_immediate_abort`). There are targets like Web WASM or embedded where users pay attention to binary sizes.
   * Users distributing closed-source binaries may not want to "leak" any symbol names as a matter of principle.
2. Adds ability to test whether code depends on specifics of the `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](https://www.hyrumslaw.com/). An option that "breaks" it can act as a [grease](https://www.rfc-editor.org/rfc/rfc8701.html).

This implementation is a `-Z fmt-debug=opt` flag that takes:

* `full` — the default, current state.
* `none` — makes derived `Debug` and `{:?}` no-ops. Explicit `impl 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 derived `Debug` 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 the `Debug` code, and compatibility. There are popular proc-macro crates that use `Debug::fmt` as a way to convert enum values into their Rust source code.

There's a corresponding `cfg` flag: `#[cfg(fmt_debug = "none")]` that can be used in user code to react to this setting to minimize custom `Debug` implementations or remove unnecessary formatting helper functions.
2024-08-29 16:21:46 +02:00
..
rustc Link std statically in rustc_driver 2024-08-11 04:16:53 +02:00
rustc_abi ABI compat check: detect unadjusted ABI mismatches 2024-08-27 09:04:59 +02:00
rustc_arena compiler: Remove feature(new_uninit) 2024-08-27 10:17:05 -07:00
rustc_ast Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau 2024-08-27 00:41:57 +02:00
rustc_ast_ir Add warn(unreachable_pub) to several crates. 2024-08-16 08:46:13 +10:00
rustc_ast_lowering fmt-debug option 2024-08-28 23:32:40 +01:00
rustc_ast_passes Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau 2024-08-27 00:41:57 +02:00
rustc_ast_pretty Add warn(unreachable_pub) to rustc_ast_pretty. 2024-08-16 08:46:46 +10:00
rustc_attr Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau 2024-08-27 00:41:57 +02:00
rustc_baked_icu_data Don't add warn(unreachable_pub) to rustc_baked_icu. 2024-08-16 08:46:52 +10:00
rustc_borrowck Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, r=compiler-errors 2024-08-27 00:42:00 +02:00
rustc_builtin_macros Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau 2024-08-29 16:21:46 +02:00
rustc_codegen_cranelift Rollup merge of #128731 - RalfJung:simd-shuffle-vector, r=workingjubilee 2024-08-27 01:46:50 -05:00
rustc_codegen_gcc Rollup merge of #128731 - RalfJung:simd-shuffle-vector, r=workingjubilee 2024-08-27 01:46:50 -05:00
rustc_codegen_llvm Rollup merge of #128192 - mrkajetanp:feature-detect, r=Amanieu 2024-08-28 19:12:49 -07:00
rustc_codegen_ssa Implement RFC 3525. 2024-08-28 09:54:23 +02:00
rustc_const_eval Rollup merge of #129666 - RalfJung:raw-eq-align, r=compiler-errors 2024-08-28 17:12:19 +02:00
rustc_data_structures Update indexmap and use IndexMap::append 2024-08-13 16:16:57 -07:00
rustc_driver Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_driver_impl Rollup merge of #129667 - dev-ardi:rustc_driver-cleanup, r=michaelwoerister 2024-08-28 17:12:19 +02:00
rustc_error_codes Add warn(unreachable_pub) to rustc_error_codes. 2024-08-27 11:49:59 +10:00
rustc_error_messages Add warn(unreachable_pub) to rustc_error_messages. 2024-08-27 11:52:08 +10:00
rustc_errors Add warn(unreachable_pub) to rustc_errors. 2024-08-27 12:03:37 +10:00
rustc_expand Add warn(unreachable_pub) to rustc_expand. 2024-08-27 12:40:38 +10:00
rustc_feature Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau 2024-08-29 16:21:46 +02:00
rustc_fluent_macro Add warn(unreachable_pub) to rustc_fluent_macro. 2024-08-27 12:56:54 +10:00
rustc_fs_util Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_graphviz Add warn(unreachable_pub) to rustc_graphviz. 2024-08-27 12:58:29 +10:00
rustc_hir Implement RFC 3525. 2024-08-28 09:54:23 +02:00
rustc_hir_analysis Auto merge of #129546 - compiler-errors:no-pred-on, r=fee1-dead 2024-08-28 04:41:43 +00:00
rustc_hir_pretty Add warn(unreachable_pub) to rustc_hir_pretty. 2024-08-27 13:25:40 +10:00
rustc_hir_typeck Implement RFC 3525. 2024-08-28 09:54:23 +02:00
rustc_incremental Add warn(unreachable_pub) to rustc_incremental. 2024-08-27 14:30:20 +10:00
rustc_index Rollup merge of #129401 - workingjubilee:partial-initialization-of-stabilization, r=dtolnay,joboet 2024-08-28 19:12:52 -07:00
rustc_index_macros Remove usage of specialization from newtype_index! 2024-06-30 16:42:53 +00:00
rustc_infer Add warn(unreachable_pub) to rustc_infer. 2024-08-27 14:47:56 +10:00
rustc_interface fmt-debug option 2024-08-28 23:32:40 +01:00
rustc_lexer Add warn(unreachable_pub) to rustc_lexer. 2024-08-27 15:12:46 +10:00
rustc_lint Add warn(unreachable_pub) to rustc_lint. 2024-08-27 15:24:11 +10:00
rustc_lint_defs Add warn(unreachable_pub) to rustc_lint_defs. 2024-08-27 15:25:49 +10:00
rustc_llvm Rollup merge of #129648 - nnethercote:unreachable_pub-2, r=Urgau 2024-08-27 18:59:29 +02:00
rustc_log Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_macros Remove a couple of unused feature enables 2024-08-26 19:52:14 +00:00
rustc_metadata Rollup merge of #129689 - compiler-errors:impl-lifetime, r=michaelwoerister 2024-08-28 19:12:54 -07:00
rustc_middle Rollup merge of #129401 - workingjubilee:partial-initialization-of-stabilization, r=dtolnay,joboet 2024-08-28 19:12:52 -07:00
rustc_mir_build Implement RFC 3525. 2024-08-28 09:54:23 +02:00
rustc_mir_dataflow rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_mir_transform coverage: Rename CodeRegion to SourceRegion 2024-08-28 22:17:42 +10:00
rustc_monomorphize Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
rustc_next_trait_solver safe transmute: Rename BikeshedIntrinsicFrom to TransmuteFrom 2024-08-27 14:05:54 +00:00
rustc_parse Rollup merge of #129667 - dev-ardi:rustc_driver-cleanup, r=michaelwoerister 2024-08-28 17:12:19 +02:00
rustc_parse_format Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_passes Auto merge of #127537 - veluca93:struct_tf, r=BoxyUwU 2024-08-28 22:54:55 +00:00
rustc_pattern_analysis Rollup merge of #128965 - Zalathar:no-pat, r=Nadrieril 2024-08-15 18:44:16 -07:00
rustc_privacy Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
rustc_query_impl Simplify some redundant field names 2024-08-21 01:31:42 -04:00
rustc_query_system fix: simple typo in compiler directory 2024-08-20 20:50:32 +08:00
rustc_resolve Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
rustc_sanitizers Rollup merge of #129345 - compiler-errors:scratch4, r=jieyouxu 2024-08-21 18:15:06 +02:00
rustc_serialize Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_session fmt-debug option 2024-08-28 23:32:40 +01:00
rustc_smir Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
rustc_span Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau 2024-08-29 16:21:46 +02:00
rustc_symbol_mangling Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
rustc_target Rollup merge of #129712 - randomPoison:trusty-tier-3-fix, r=saethlin 2024-08-28 19:12:55 -07:00
rustc_trait_selection Rollup merge of #129343 - estebank:time-version, r=jieyouxu 2024-08-28 19:12:50 -07:00
rustc_traits Remove redundant type ops 2024-08-14 14:18:17 -04:00
rustc_transmute Removes dead code from the compiler 2024-08-25 13:41:39 +08:00
rustc_ty_utils Auto merge of #128506 - compiler-errors:by-move-body, r=cjgillot 2024-08-27 23:30:24 +00:00
rustc_type_ir Rollup merge of #129526 - compiler-errors:fx, r=lqd 2024-08-26 01:49:02 +02:00
rustc_type_ir_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
stable_mir Introduce methods for obtaining Location for statements and terminators 2024-08-23 12:45:38 -04:00