Skip to content

Commit 0c7e26b

Browse files
committed
instantly_dangling_pointer: rename to dangling_pointers_from_temporaries
1 parent 25ee70b commit 0c7e26b

File tree

14 files changed

+106
-111
lines changed

14 files changed

+106
-111
lines changed

compiler/rustc_lint/src/dangling.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare_lint! {
3535
// FIXME: does not catch UnsafeCell::get
3636
// FIXME: does not catch getting a ref to a temporary and then converting it to a ptr
3737
declare_lint! {
38-
/// The `instantly_dangling_pointer` lint detects getting a pointer to data
38+
/// The `dangling_pointers_from_temporaries` lint detects getting a pointer to data
3939
/// of a temporary that will immediately get dropped.
4040
///
4141
/// ### Example
@@ -63,20 +63,12 @@ declare_lint! {
6363
///
6464
/// If you need stronger guarantees, consider using references instead,
6565
/// as they are statically verified by the borrow-checker to never dangle.
66-
///
67-
/// Note: This lint does **not** get triggered by methods & functions
68-
/// that intentionally produce dangling pointers, such as:
69-
///
70-
/// - `core::ptr::dangling` & `core::ptr::dangling_mut`
71-
/// - `core::ptr::NonNull::dangling`
72-
/// - `std::alloc::Layout::dangling`
73-
///
74-
pub INSTANTLY_DANGLING_POINTER,
66+
pub DANGLING_POINTERS_FROM_TEMPORARIES,
7567
Warn,
76-
"detects getting a pointer that will immediately dangle"
68+
"detects getting a pointer from a temporary"
7769
}
7870

79-
declare_lint_pass!(DanglingPointers => [TEMPORARY_CSTRING_AS_PTR, INSTANTLY_DANGLING_POINTER]);
71+
declare_lint_pass!(DanglingPointers => [TEMPORARY_CSTRING_AS_PTR, DANGLING_POINTERS_FROM_TEMPORARIES]);
8072

8173
impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
8274
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
@@ -111,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
111103
&& is_interesting(cx, ty)
112104
{
113105
cx.emit_span_lint(
114-
INSTANTLY_DANGLING_POINTER,
106+
DANGLING_POINTERS_FROM_TEMPORARIES,
115107
method.ident.span,
116108
InstantlyDangling {
117109
callee: method.ident.name,

library/alloc/tests/boxed.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use core::ptr::NonNull;
55

66
#[test]
77
// FIXME(GrigorenkoPV)
8-
#[allow(unknown_lints, reason = "`instantly_dangling_pointer` does not exist at stage 0 yet")]
9-
#[allow(instantly_dangling_pointer)]
8+
#[allow(
9+
unknown_lints,
10+
reason = "`dangling_pointers_from_temporaries` does not exist at stage 0 yet"
11+
)]
12+
#[allow(dangling_pointers_from_temporaries)]
1013
fn uninitialized_zero_size_box() {
1114
assert_eq!(
1215
&*Box::<()>::new_uninit() as *const _,

tests/ui/consts/zst_no_llvm_alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717

1818
// The exact addresses returned by these library functions are not necessarily stable guarantees
1919
// but for now we assert that we're still matching.
20-
#[expect(instantly_dangling_pointer)]
20+
#[expect(dangling_pointers_from_temporaries)]
2121
{
2222
assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
2323
assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-allow.rs renamed to tests/ui/lint/dangling-ptr/allow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// This should not ICE.
44

5-
#![allow(instantly_dangling_pointer)]
5+
#![allow(dangling_pointers_from_temporaries)]
66

77
fn main() {
88
dbg!(String::new().as_ptr());

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-methods.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-types.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-issue123613.rs renamed to tests/ui/lint/dangling-ptr/issue123613.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![deny(instantly_dangling_pointer)]
1+
#![deny(dangling_pointers_from_temporaries)]
22

33
const MAX_PATH: usize = 260;
44
fn main() {
55
let str1 = String::with_capacity(MAX_PATH).as_mut_ptr();
6-
//~^ ERROR [instantly_dangling_pointer]
6+
//~^ ERROR [dangling_pointers_from_temporaries]
77
let str2 = String::from("TotototototototototototototototototoT").as_ptr();
8-
//~^ ERROR [instantly_dangling_pointer]
8+
//~^ ERROR [dangling_pointers_from_temporaries]
99
unsafe {
1010
std::ptr::copy_nonoverlapping(str2, str1, 30);
1111
println!("{:?}", String::from_raw_parts(str1, 30, 30));

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-issue123613.stderr renamed to tests/ui/lint/dangling-ptr/issue123613.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: getting a pointer from a temporary `String` will result in a dangling pointer
2-
--> $DIR/instantly-dangling-pointer-issue123613.rs:5:48
2+
--> $DIR/issue123613.rs:5:48
33
|
44
LL | let str1 = String::with_capacity(MAX_PATH).as_mut_ptr();
55
| ------------------------------- ^^^^^^^^^^ this pointer will immediately be invalid
@@ -9,13 +9,13 @@ LL | let str1 = String::with_capacity(MAX_PATH).as_mut_ptr();
99
= note: pointers do not have a lifetime; when calling `as_mut_ptr` the `String` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
1010
= help: for more information, see https://doc.rust-lang.org/reference/destructors.html
1111
note: the lint level is defined here
12-
--> $DIR/instantly-dangling-pointer-issue123613.rs:1:9
12+
--> $DIR/issue123613.rs:1:9
1313
|
14-
LL | #![deny(instantly_dangling_pointer)]
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | #![deny(dangling_pointers_from_temporaries)]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
error: getting a pointer from a temporary `String` will result in a dangling pointer
18-
--> $DIR/instantly-dangling-pointer-issue123613.rs:7:70
18+
--> $DIR/issue123613.rs:7:70
1919
|
2020
LL | let str2 = String::from("TotototototototototototototototototoT").as_ptr();
2121
| ----------------------------------------------------- ^^^^^^ this pointer will immediately be invalid

tests/ui/lint/dangling-ptr/methods.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![deny(dangling_pointers_from_temporaries)]
2+
3+
fn main() {
4+
vec![0u8].as_ptr(); //~ ERROR [dangling_pointers_from_temporaries]
5+
vec![0u8].as_mut_ptr(); //~ ERROR [dangling_pointers_from_temporaries]
6+
}

tests/ui/lint/dangling-ptr/instantly-dangling-pointer-methods.stderr renamed to tests/ui/lint/dangling-ptr/methods.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: getting a pointer from a temporary `Vec<u8>` will result in a dangling pointer
2-
--> $DIR/instantly-dangling-pointer-methods.rs:4:15
2+
--> $DIR/methods.rs:4:15
33
|
44
LL | vec![0u8].as_ptr();
55
| --------- ^^^^^^ this pointer will immediately be invalid
@@ -9,13 +9,13 @@ LL | vec![0u8].as_ptr();
99
= note: pointers do not have a lifetime; when calling `as_ptr` the `Vec<u8>` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
1010
= help: for more information, see https://doc.rust-lang.org/reference/destructors.html
1111
note: the lint level is defined here
12-
--> $DIR/instantly-dangling-pointer-methods.rs:1:9
12+
--> $DIR/methods.rs:1:9
1313
|
14-
LL | #![deny(instantly_dangling_pointer)]
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
LL | #![deny(dangling_pointers_from_temporaries)]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
error: getting a pointer from a temporary `Vec<u8>` will result in a dangling pointer
18-
--> $DIR/instantly-dangling-pointer-methods.rs:5:15
18+
--> $DIR/methods.rs:5:15
1919
|
2020
LL | vec![0u8].as_mut_ptr();
2121
| --------- ^^^^^^^^^^ this pointer will immediately be invalid

0 commit comments

Comments
 (0)