rust/tests/ui/check-cfg
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
..
allow-at-crate-level.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
allow-macro-cfg.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
allow-same-level.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
allow-same-level.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
allow-top-level.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
allow-upper-level.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
cargo-build-script.rs Don't suggest adding the unexpected cfgs the build-script it-self 2024-05-22 20:58:57 +02:00
cargo-build-script.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
cargo-feature.none.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
cargo-feature.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
cargo-feature.some.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
cfg-value-for-cfg-name-duplicate.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
cfg-value-for-cfg-name-duplicate.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
cfg-value-for-cfg-name-multiple.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
cfg-value-for-cfg-name-multiple.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
cfg-value-for-cfg-name.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
cfg-value-for-cfg-name.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
compact-names.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
compact-names.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
compact-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
compact-values.stderr Convert unexpected_cfg_{name,value} to struct diagnostics 2024-05-21 20:16:39 +00:00
concat-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
concat-values.stderr Convert unexpected_cfg_{name,value} to struct diagnostics 2024-05-21 20:16:39 +00:00
diagnotics.cargo.stderr Fix quote escaping inside check-cfg value 2024-05-20 11:44:09 +02:00
diagnotics.rs Fix quote escaping inside check-cfg value 2024-05-20 11:44:09 +02:00
diagnotics.rustc.stderr Fix quote escaping inside check-cfg value 2024-05-20 11:44:09 +02:00
empty-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
empty-values.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
exhaustive-names-values.empty_cfg.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
exhaustive-names-values.feature.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
exhaustive-names-values.full.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
exhaustive-names-values.rs Fix test problems discovered by the revision check 2024-05-09 14:47:09 +10:00
exhaustive-names.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
exhaustive-names.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
exhaustive-values.empty_cfg.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
exhaustive-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
exhaustive-values.without_names.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
invalid-arguments.any_values.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.anything_else.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.boolean.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.cfg_none.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.giberich.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.ident_in_values_1.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.ident_in_values_2.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.mixed_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.mixed_values_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.multiple_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.multiple_values_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.multiple_values.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.none_not_empty.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.not_empty_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.not_empty_values_any.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.rs Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.string_for_name_1.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.string_for_name_2.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.unknown_meta_item_1.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.unknown_meta_item_2.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.unknown_meta_item_3.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.unterminated.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.values_any_before_ident.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
invalid-arguments.values_any_missing_values.stderr Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
mix.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
mix.stderr Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau 2024-08-29 16:21:46 +02:00
my-awesome-platform.json Honor current target when checking conditional compilation values 2023-03-09 21:55:00 +01:00
no-expected-values.empty.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
no-expected-values.mixed.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
no-expected-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
no-expected-values.simple.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
order-independant.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
order-independant.values_after.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
order-independant.values_before.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
stmt-no-ice.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
stmt-no-ice.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
unexpected-cfg-name.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
unexpected-cfg-name.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
unexpected-cfg-value.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
unexpected-cfg-value.stderr Convert unexpected_cfg_{name,value} to struct diagnostics 2024-05-21 20:16:39 +00:00
unknown-values.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
values-none.concat_1.stderr Fix test problems discovered by the revision check 2024-05-09 14:47:09 +10:00
values-none.concat_2.stderr Fix test problems discovered by the revision check 2024-05-09 14:47:09 +10:00
values-none.explicit.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
values-none.implicit.stderr compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
values-none.rs Fix test problems discovered by the revision check 2024-05-09 14:47:09 +10:00
values-none.simple.stderr Fix test problems discovered by the revision check 2024-05-09 14:47:09 +10:00
values-target-json.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
well-known-names.rs compiletest: add no-auto-check-cfg directive 2024-05-04 11:30:38 +02:00
well-known-names.stderr fmt-debug option 2024-08-28 23:32:40 +01:00
well-known-values.rs fmt-debug option 2024-08-28 23:32:40 +01:00
well-known-values.stderr Rollup merge of #123940 - kornelski:remove-derived-debug, r=Urgau 2024-08-29 16:21:46 +02:00