Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/core/src/panic/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::ptr::NonNull;
pub struct Location<'a> {
// A raw pointer is used rather than a reference because the pointer is valid for one more byte
// than the length stored in this pointer; the additional byte is the NUL-terminator used by
// `Location::file_with_nul`.
// `Location::file_as_c_str`.
filename: NonNull<str>,
line: u32,
col: u32,
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a> Location<'a> {
#[must_use]
#[unstable(feature = "file_with_nul", issue = "141727")]
#[inline]
pub const fn file_with_nul(&self) -> &'a CStr {
pub const fn file_as_c_str(&self) -> &'a CStr {
let filename = self.filename.as_ptr();

// SAFETY: The filename is valid for `filename_len+1` bytes, so this addition can't
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
const fn assert_file_has_trailing_zero() {
let caller = core::panic::Location::caller();
let file_str = caller.file();
let file_with_nul = caller.file_with_nul();
if file_str.len() != file_with_nul.count_bytes() {
let file_cstr = caller.file_as_c_str();
if file_str.len() != file_cstr.count_bytes() {
panic!("mismatched lengths");
}
let trailing_byte: core::ffi::c_char = unsafe {
*file_with_nul.as_ptr().offset(file_with_nul.count_bytes() as _)
*file_cstr.as_ptr().offset(file_cstr.count_bytes() as _)
};
if trailing_byte != 0 {
panic!("trailing byte was nonzero")
Expand Down
Loading