diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-28 23:10:35 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-28 23:10:35 +1000 |
| commit | c83811762091e45a4cccff2f4546eac88928201b (patch) | |
| tree | 15a51f7a4efac493a98890d3caeb68889bf596a0 | |
| parent | d2ce84e30663628350be144b66fddb86526c3758 (diff) | |
| parent | dacae07b6d8c42f5eca57de9c18e17349994d654 (diff) | |
| download | rust-c83811762091e45a4cccff2f4546eac88928201b.tar.gz rust-c83811762091e45a4cccff2f4546eac88928201b.zip | |
Rollup merge of #145928 - Darksonn:file_as_c_str, r=joshtriplett
Rename `Location::file_with_nul` to `file_as_c_str` This renames the method to be consistent with the ongoing T-libs-api FCP found at https://github.com/rust-lang/rust/issues/141727#issuecomment-3228016708. I did not rename the unstable feature as we are going to be stabilizing it soon anyway. This will probably break RfL, so it will require an updated commit hash for the Linux Kernel that I will add here soon. r? `@Amanieu`
| -rw-r--r-- | library/core/src/panic/location.rs | 4 | ||||
| -rw-r--r-- | tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/library/core/src/panic/location.rs b/library/core/src/panic/location.rs index cafdcfa2c2e..7a68d393906 100644 --- a/library/core/src/panic/location.rs +++ b/library/core/src/panic/location.rs @@ -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, @@ -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 diff --git a/tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs b/tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs index 65e61a21f1a..7902f40b09b 100644 --- a/tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs +++ b/tests/ui/rfcs/rfc-2091-track-caller/file-is-nul-terminated.rs @@ -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") |
