mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Change to warn by default / fix typo
This commit is contained in:
parent
5643a0662a
commit
737bfeffd2
@ -10,7 +10,7 @@ use rustc_span::{
|
||||
|
||||
declare_lint! {
|
||||
pub TEMPORARY_CSTRING_AS_PTR,
|
||||
Deny,
|
||||
Warn,
|
||||
"detects getting the inner pointer of a temporary `CString`"
|
||||
}
|
||||
|
||||
|
@ -1265,7 +1265,7 @@ impl CStr {
|
||||
/// behavior when `ptr` is used inside the `unsafe` block:
|
||||
///
|
||||
/// ```no_run
|
||||
/// # #![allow(unused_must_use)] #![allow(temporary_cstring_as_ptr)]
|
||||
/// # #![allow(unused_must_use, temporary_cstring_as_ptr)]
|
||||
/// use std::ffi::CString;
|
||||
///
|
||||
/// let ptr = CString::new("Hello").expect("CString::new failed").as_ptr();
|
||||
|
@ -1,4 +1,5 @@
|
||||
// ignore-tidy-linelength
|
||||
#![deny(temporary_cstring_as_ptr)]
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
error: getting the inner pointer of a temporary `CString`
|
||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:6:48
|
||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:48
|
||||
|
|
||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||
| ---------------------------------- ^^^^^^ this pointer will be invalid
|
||||
| |
|
||||
| this `CString` is deallocated at the end of the expression, bind it to a variable to extend its lifetime
|
||||
|
|
||||
= note: `#[deny(temporary_cstring_as_ptr)]` on by default
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
|
||||
|
|
||||
LL | #![deny(temporary_cstring_as_ptr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: pointers do not have a lifetime; when calling `as_ptr` the `CString` is deallocated because nothing is referencing it as far as the type system is concerned
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user