Change to warn by default / fix typo

This commit is contained in:
Nathan Whitaker 2020-08-23 14:21:58 -04:00
parent 5643a0662a
commit 737bfeffd2
4 changed files with 9 additions and 4 deletions

View File

@ -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`"
}

View File

@ -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();

View File

@ -1,4 +1,5 @@
// ignore-tidy-linelength
#![deny(temporary_cstring_as_ptr)]
use std::ffi::CString;

View File

@ -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