diff options
| author | Nathan Whitaker <nathan.whitaker01@gmail.com> | 2020-08-23 14:21:58 -0400 |
|---|---|---|
| committer | Nathan Whitaker <nathan.whitaker01@gmail.com> | 2020-10-26 18:19:48 -0400 |
| commit | 737bfeffd2805f2372c934999afd8ea87921d835 (patch) | |
| tree | f5e75fcead421ff7d64ee575424263685623aadf | |
| parent | 5643a0662af337c1096975400040c4442da439ca (diff) | |
| download | rust-737bfeffd2805f2372c934999afd8ea87921d835.tar.gz rust-737bfeffd2805f2372c934999afd8ea87921d835.zip | |
Change to warn by default / fix typo
| -rw-r--r-- | compiler/rustc_lint/src/methods.rs | 2 | ||||
| -rw-r--r-- | library/std/src/ffi/c_str.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/lint-temporary-cstring-as-ptr.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr | 8 |
4 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/methods.rs b/compiler/rustc_lint/src/methods.rs index 1e67e9dd7de..f1e44fbe2a2 100644 --- a/compiler/rustc_lint/src/methods.rs +++ b/compiler/rustc_lint/src/methods.rs @@ -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`" } diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index 53966396e11..a9ab0d1d83b 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -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(); diff --git a/src/test/ui/lint/lint-temporary-cstring-as-ptr.rs b/src/test/ui/lint/lint-temporary-cstring-as-ptr.rs index 54f57e1dd77..73a9d6677c7 100644 --- a/src/test/ui/lint/lint-temporary-cstring-as-ptr.rs +++ b/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; diff --git a/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr b/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr index 9ceb71ba8d9..ee06bfc2fad 100644 --- a/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr +++ b/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 |
