Rollup merge of #116326 - Colonial-Dev:issue-116165-fix, r=joshtriplett

Correct misleading std::fmt::Binary example (#116165)

Nothing too crazy...

- Add two to the width specifier (so all 32 bits are correctly displayed)
- Pad out the compared string so the assert passes
- Add `// Note` comment highlighting the need for the extra width when using the `#` flag.

The exact contents (and placement?) of the note are, of course, highly bikesheddable.
This commit is contained in:
Matthias Krüger 2023-10-02 16:23:53 +02:00 committed by GitHub
commit b3853ccc9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -791,8 +791,10 @@ pub trait Octal {
/// assert_eq!(format!("l as binary is: {l:b}"), "l as binary is: 1101011");
///
/// assert_eq!(
/// format!("l as binary is: {l:#032b}"),
/// "l as binary is: 0b000000000000000000000001101011"
/// // Note that the `0b` prefix added by `#` is included in the total width, so we
/// // need to add two to correctly display all 32 bits.
/// format!("l as binary is: {l:#034b}"),
/// "l as binary is: 0b00000000000000000000000001101011"
/// );
/// ```
#[stable(feature = "rust1", since = "1.0.0")]