Skip to content

Commit 7821554

Browse files
committed
instantly_dangling_pointer: remove tracing & bless tests
1 parent 1647af0 commit 7821554

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

compiler/rustc_lint/src/dangling.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,19 @@ impl<'tcx> LateLintPass<'tcx> for InstantlyDanglingPtr {
4949
return;
5050
};
5151
let Ident { name: method_name, span: method_span } = method.ident;
52-
tracing::debug!(?method);
5352

5453
// The method is `.as_ptr()` or `.as_mut_ptr`.
5554
if method_name != sym::as_ptr && method_name != sym::as_mut_ptr {
5655
return;
5756
}
5857

5958
// It is called on a temporary rvalue.
60-
let is_temp = is_temporary_rvalue(receiver);
61-
tracing::debug!(receiver = ?receiver.kind, ?is_temp);
62-
if !is_temp {
59+
if !is_temporary_rvalue(receiver) {
6360
return;
6461
}
6562

6663
// The temporary value's type is array, box, Vec, String, or CString
6764
let ty = cx.typeck_results().expr_ty(receiver);
68-
tracing::debug!(?ty);
6965
let Some(is_cstring) = as_container(cx, ty) else {
7066
return;
7167
};

tests/ui/consts/zst_no_llvm_alloc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ 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-
assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
21-
assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
20+
#[expect(instantly_dangling_pointer)]
21+
{
22+
assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
23+
assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
24+
};
2225

2326
// statics must have a unique address (see https://github.com/rust-lang/rust/issues/18297, not
2427
// clear whether this is a stable guarantee)

tests/ui/lint/lint-temporary-cstring-as-param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ fn some_function(data: *const c_char) {}
77

88
fn main() {
99
some_function(CString::new("").unwrap().as_ptr());
10-
//~^ ERROR getting the inner pointer of a temporary `CString`
10+
//~^ ERROR this pointer will immediately dangle
1111
}

tests/ui/lint/lint-temporary-cstring-as-param.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: getting the inner pointer of a temporary `CString`
1+
error: this pointer will immediately dangle
22
--> $DIR/lint-temporary-cstring-as-param.rs:9:45
33
|
44
LL | some_function(CString::new("").unwrap().as_ptr());

tests/ui/lint/lint-temporary-cstring-as-ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::ffi::CString;
66
macro_rules! mymacro {
77
() => {
88
let s = CString::new("some text").unwrap().as_ptr();
9-
//~^ ERROR getting the inner pointer of a temporary `CString`
9+
//~^ ERROR this pointer will immediately dangle
1010
}
1111
}
1212

1313
fn main() {
1414
let s = CString::new("some text").unwrap().as_ptr();
15-
//~^ ERROR getting the inner pointer of a temporary `CString`
15+
//~^ ERROR this pointer will immediately dangle
1616
mymacro!();
1717
}

tests/ui/lint/lint-temporary-cstring-as-ptr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: getting the inner pointer of a temporary `CString`
1+
error: this pointer will immediately dangle
22
--> $DIR/lint-temporary-cstring-as-ptr.rs:14:48
33
|
44
LL | let s = CString::new("some text").unwrap().as_ptr();
@@ -14,7 +14,7 @@ note: the lint level is defined here
1414
LL | #![deny(temporary_cstring_as_ptr)]
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^
1616

17-
error: getting the inner pointer of a temporary `CString`
17+
error: this pointer will immediately dangle
1818
--> $DIR/lint-temporary-cstring-as-ptr.rs:8:52
1919
|
2020
LL | let s = CString::new("some text").unwrap().as_ptr();

0 commit comments

Comments
 (0)