Skip to content

Commit

Permalink
Change to warn by default / fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Oct 26, 2020
1 parent 5643a06 commit 737bfef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/methods.rs
Expand Up @@ -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`"
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/ffi/c_str.rs
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/lint/lint-temporary-cstring-as-ptr.rs
@@ -1,4 +1,5 @@
// ignore-tidy-linelength
#![deny(temporary_cstring_as_ptr)]

use std::ffi::CString;

Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
@@ -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
Expand Down

0 comments on commit 737bfef

Please sign in to comment.