Skip to content

Commit 17ba0ff

Browse files
committed
Auto merge of rust-lang#75671 - nathanwhit:cstring-temp-lint, r=oli-obk
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc. The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that. (cc rust-lang#53224). r? `@oli-obk`
2 parents 85189df + 2188283 commit 17ba0ff

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

std/src/ffi/c_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use crate::sys;
110110
/// of `CString` instances can lead to invalid memory accesses, memory leaks,
111111
/// and other memory errors.
112112
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
113+
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
113114
#[stable(feature = "rust1", since = "1.0.0")]
114115
pub struct CString {
115116
// Invariant 1: the slice ends with a zero byte and has a length of at least one.
@@ -1265,7 +1266,7 @@ impl CStr {
12651266
/// behavior when `ptr` is used inside the `unsafe` block:
12661267
///
12671268
/// ```no_run
1268-
/// # #![allow(unused_must_use)]
1269+
/// # #![allow(unused_must_use)] #![cfg_attr(not(bootstrap), allow(temporary_cstring_as_ptr))]
12691270
/// use std::ffi::CString;
12701271
///
12711272
/// let ptr = CString::new("Hello").expect("CString::new failed").as_ptr();

0 commit comments

Comments
 (0)