-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Replace all fmt.pad
with debug_struct
#84013
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
i guess this is fine since use std::fmt;
struct A;
struct B;
impl fmt::Debug for A {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("X").finish()
}
}
impl fmt::Debug for B {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("X")
}
}
fn main() {
assert_eq!(format!("<{:3?}>", A), "<X>");
assert_eq!(format!("<{:3?}>", B), "<X >");
} (sending this to a real T-libs member) r? @m-ou-se |
Some of these should probably use (I replaced a bunch of those recently in #83558, but I missed these since they used |
We somewhat regularly change or improve #[derive(Debug)]
struct A {
x: i32,
y: i32,
}
fn main() {
println!("{:#010?}", A { x: 1, y: 2 });
}
The only downside of the change in this PR is that in 'pretty' mode (
taking up a lot more space than |
I agree with the use of I also found two more cases ( |
Thanks! @bors r+ |
📌 Commit fdae757 has been approved by |
This comment has been minimized.
This comment has been minimized.
@bors r- |
I fixed |
@bors r+ |
📌 Commit fccc75c has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened. |
Replace all `fmt.pad` with `debug_struct` This replaces any occurrence of: - `f.pad("X")` with `f.debug_struct("X").finish()` - `f.pad("X { .. }")` with `f.debug_struct("X").finish_non_exhaustive()` This is in line with existing formatting code such as https://github.com/rust-lang/rust/blob/125505306744a0a5bb01d62337260a95d9ff8d57/library/std/src/sync/mpsc/mod.rs#L1470-L1475
Rollup of 12 pull requests Successful merges: - rust-lang#84013 (Replace all `fmt.pad` with `debug_struct`) - rust-lang#84119 (Move `sys::vxworks` code to `sys::unix`) - rust-lang#84212 (Replace `Void` in `sys` with never type) - rust-lang#84251 (fix 'const-stable since' for NonZeroU*::new_unchecked) - rust-lang#84301 (Document that `index` and `index_mut` can panic) - rust-lang#84365 (Improve the docstrings of the `Lto` struct.) - rust-lang#84378 (Fix broken doc link) - rust-lang#84379 (Add GAT related tests) - rust-lang#84380 (Write Rustdoc titles like "x in crate::mod - Rust") - rust-lang#84390 (Format `Struct { .. }` on one line even with `{:#?}`.) - rust-lang#84393 (Support `x.py doc std --open`) - rust-lang#84406 (Remove `delete` alias from `mem::drop`.) Failed merges: - rust-lang#84387 (Move `sys_common::poison` to `sync::poison`) r? `@ghost` `@rustbot` modify labels: rollup
This replaces any occurrence of:
f.pad("X")
withf.debug_struct("X").finish()
f.pad("X { .. }")
withf.debug_struct("X").finish_non_exhaustive()
This is in line with existing formatting code such as
rust/library/std/src/sync/mpsc/mod.rs
Lines 1470 to 1475 in 1255053