rust/library/core/tests
bors f06f9bbd3a Auto merge of #88999 - Migi:master, r=oli-obk
Make `Duration` respect `width` when formatting using `Debug`

When printing or writing a `std::time::Duration` using `Debug` formatting, it previously completely ignored any specified `width`. This is unlike types like integers and floats, which do pad to `width`, for both `Display` and `Debug`, though not all types consider `width` in their `Debug` output (see e.g. #30164). Curiously, `Duration`'s `Debug` formatting *did* consider `precision`.

This PR makes `Duration` pad to `width` just like integers and floats, so that
```rust
format!("|{:8?}|", Duration::from_millis(1234))
```
returns
```
|1.234s  |
```

Before you ask "who formats `Debug` output?", note that `Duration` doesn't actually implement `Display`, so `Debug` is currently the only way to format `Duration`s. I think that's wrong, and `Duration` should get a `Display` implementation, but in the meantime there's no harm in making the `Debug` formatting respect `width` rather than ignore it.

I chose the default alignment to be left-aligned. The general rule Rust uses is: numeric types are right-aligned by default, non-numeric types left-aligned. It wasn't clear to me whether `Duration` is a numeric type or not. The fact that a formatted `Duration` can end with suffixes of variable length (`"s"`, `"ms"`, `"µs"`, etc.) made me lean towards left-alignment, but it would be trivial to change it.

Fixes issue #88059.
2021-09-24 15:22:26 +00:00
..
fmt Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
hash move object safety test to library/core 2021-08-15 13:00:25 -04:00
iter Consistent spelling of "adapter" in the standard library 2021-07-30 17:23:07 +02:00
num Temporarily rename int_roundings functions to avoid conflicts 2021-09-22 13:56:01 -07:00
ops
alloc.rs
any.rs
array.rs
ascii.rs
atomic.rs
bool.rs
cell.rs Add a few tests for UnsafeCell 2021-08-31 16:32:01 -07:00
char.rs
clone.rs
cmp.rs
const_ptr.rs
intrinsics.rs
lazy.rs
lib.rs Stabilize Iterator::map_while 2021-09-17 19:42:46 +03:00
macros.rs Allow leading pipe in matches!() patterns. 2021-07-15 22:05:45 +03:00
manually_drop.rs Test ManuallyDrop::clone_from. 2021-07-05 11:55:45 +00:00
mem.rs
nonzero.rs
ops.rs
option.rs Added some basic tests for Option::unzip() and Option::zip() (I noticed that zip had no tests) 2021-08-09 10:24:00 -05:00
pattern.rs
pin.rs
ptr.rs
result.rs
slice.rs Move to the top of file 2021-08-31 08:28:51 -07:00
str_lossy.rs
str.rs
task.rs
time.rs Make Duration's Debug format pad to width 2021-09-16 03:09:31 +02:00
tuple.rs
unicode.rs