Skip to content

Change in behavior of debug format of strings containing \0 #95732

Closed
@carols10cents

Description

@carols10cents

I understand debug formatting is generally unstable, but wanted to raise this to make sure the change was intentional.

Code

I tried this test:

#[test]
fn quote_not_printable() {
    assert_eq!(format!("{:?}", "foo\0bar"), r#""foo\u{0}bar""#);
}

This test passes with stable Rust 1.60.0 (7737e0b 2022-04-04) (the release candidate that's going to be released tomorrow)

I expected this test to continue passing with 1.61.0-beta.1

Instead, I get this failure:


---- quote_not_printable stdout ----
thread 'quote_not_printable' panicked at 'assertion failed: `(left == right)`
  left: `"\"foo\\0bar\""`,
 right: `"\"foo\\u{0}bar\""`', src/lib.rs:3:5

Version it worked on

It most recently worked on: stable release candidate 1.60.0 (7737e0b 2022-04-04)

Version with regression

rustc --version --verbose:

rustc 1.61.0-beta.1 (0f231250b 2022-04-05)
binary: rustc
commit-hash: 0f231250ba7fe3a3f98a18aee9abfd65b104fb92
commit-date: 2022-04-05
host: aarch64-apple-darwin
release: 1.61.0-beta.1
LLVM version: 14.0.0

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions