Skip to content

panic::Location Debug implementation now prints a byte array #142279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tgross35 opened this issue Jun 10, 2025 · 5 comments · Fixed by #142373
Closed

panic::Location Debug implementation now prints a byte array #142279

tgross35 opened this issue Jun 10, 2025 · 5 comments · Fixed by #142373
Assignees
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@tgross35
Copy link
Contributor

tgross35 commented Jun 10, 2025

Since #135054, the Debug implementation for std::panic::Location just prints the byte bag:

fn main() {
    dbg!(std::panic::Location::caller());
}

Stable:

[src/main.rs:2:5] std::panic::Location::caller() = Location {
    file: "src/main.rs",
    line: 2,
    col: 10,
}

Nightly:

[src/main.rs:2:5] std::panic::Location::caller() = Location {
    file_bytes_with_nul: [
        115,
        114,
        99,
        47,
        109,
        97,
        105,
        110,
        46,
        114,
        115,
        0,
    ],
    line: 2,
    col: 10,
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=698066c5427dd43cb12df0d2fb5b9300

Originally noticed at #142216.

@tgross35 tgross35 added the C-bug Category: This is a bug. label Jun 10, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 10, 2025
@tgross35 tgross35 added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 10, 2025
@tgross35
Copy link
Contributor Author

@cramertj is there a reason file_bytes_with_nul wasn't made a CStr in #135054? Other than .file() becoming O(n) once it becomes a thin pointer.

Might just need a handwritten debug implementation otherwise.

@tgross35
Copy link
Contributor Author

Cc @m-ou-se from the review ^

@Noratrieb Noratrieb added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jun 11, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 11, 2025
@m-ou-se m-ou-se added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 11, 2025
@Amanieu Amanieu added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. labels Jun 11, 2025
@m-ou-se m-ou-se self-assigned this Jun 11, 2025
@nealsid
Copy link

nealsid commented Jun 12, 2025

FYI, I was continuing to work on #142216 and wanted to make proposals based on after this change, so I merged it in, and, this might be a small issue but I noticed that backslashes in the path are printed twice on Windows (this has debug_refcell enabled in library/core):

PS C:\Users\neals\refcell-test> cargo +stage1 clean ; cargo +stage1 run
     Removed 28 files, 4.4MiB total
   Compiling refcell-test v0.1.0 (C:\Users\neals\refcell-test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.39s
     Running `target\debug\refcell-test.exe`
Hello, world! RefCell { value: 5 }

thread 'main' panicked at src\main.rs:10:15:
already borrowed: BorrowMutError { location: Location { file: "src\\main.rs", line: 7, column: 15 } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\refcell-test.exe` (exit code: 101)
PS C:\Users\neals\refcell-test> cargo +stage1 clean ; cargo +stage1 run

Without this change at HEAD, if you look at the bytes printed there is one backslash (92) in the byte array:

PS C:\Users\neals\refcell-test> cargo +stage1 clean ; cargo +stage1 run
     Removed 28 files, 4.4MiB total
   Compiling refcell-test v0.1.0 (C:\Users\neals\refcell-test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s
     Running `target\debug\refcell-test.exe`
Hello, world! RefCell { value: 5 }

thread 'main' panicked at src\main.rs:10:15:
already borrowed: BorrowMutError { location: Location { file_bytes_with_nul: [115, 114, 99, 92, 109, 97, 105, 110, 46, 114, 115, 0], line: 7, col: 15 } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\refcell-test.exe` (exit code: 101)

@tgross35
Copy link
Contributor Author

@nealsid isn't that the same way it printed before the regression to printing bytes?

Usually the Debug implementations are intended so you could copy+paste them to source, which means strings are escaped. The Display implementation shouldn't have this.

@nealsid
Copy link

nealsid commented Jun 13, 2025

@tgross35 you're right, building at 61413ae (the parent of the commit that caused the regression) shows that it was escaped previously as well. Thanks.

tgross35 added a commit to tgross35/rust that referenced this issue Jun 16, 2025
@bors bors closed this as completed in d9c83bb Jun 16, 2025
rust-timer added a commit that referenced this issue Jun 16, 2025
Rollup merge of #142373 - m-ou-se:debug-for-location, r=tgross35

Fix Debug for Location

Fixes #142279
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants