Skip to content

Commit 4cf5fc9

Browse files
authored
Unrolled build for rust-lang#117824
Rollup merge of rust-lang#117824 - WaffleLapkin:ptr_from_ref_stab, r=dtolnay Stabilize `ptr::{from_ref, from_mut}` I propose to stabilize the following APIs: ```rust // mod core::ptr pub const fn from_ref<T: ?Sized>(r: &T) -> *const T; pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T; ``` Tracking issue: rust-lang#106116 --- ``@RalfJung`` what do you think we should do with `from_mut`? Stabilize it as const, given that you can't call it anyway (no way to get `&mut` in `const fn`)? Defer stabilizing it as const leaving the same issue/feature? Change issue/feature? Change issue/feature to the "`&mut` in const fn" one?
2 parents 3f39cae + b863e9b commit 4cf5fc9

File tree

7 files changed

+74
-77
lines changed

7 files changed

+74
-77
lines changed

library/core/src/ptr/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ where
720720
/// type or mutability, in particular if the code is refactored.
721721
#[inline(always)]
722722
#[must_use]
723-
#[unstable(feature = "ptr_from_ref", issue = "106116")]
723+
#[stable(feature = "ptr_from_ref", since = "CURRENT_RUSTC_VERSION")]
724+
#[rustc_const_stable(feature = "ptr_from_ref", since = "CURRENT_RUSTC_VERSION")]
724725
#[rustc_never_returns_null_ptr]
725726
#[rustc_diagnostic_item = "ptr_from_ref"]
726727
pub const fn from_ref<T: ?Sized>(r: &T) -> *const T {
@@ -733,7 +734,9 @@ pub const fn from_ref<T: ?Sized>(r: &T) -> *const T {
733734
/// type or mutability, in particular if the code is refactored.
734735
#[inline(always)]
735736
#[must_use]
736-
#[unstable(feature = "ptr_from_ref", issue = "106116")]
737+
#[stable(feature = "ptr_from_ref", since = "CURRENT_RUSTC_VERSION")]
738+
#[rustc_const_stable(feature = "ptr_from_ref", since = "CURRENT_RUSTC_VERSION")]
739+
#[rustc_allow_const_fn_unstable(const_mut_refs)]
737740
#[rustc_never_returns_null_ptr]
738741
pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T {
739742
r

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@
338338
#![feature(portable_simd)]
339339
#![feature(prelude_2024)]
340340
#![feature(ptr_as_uninit)]
341-
#![feature(ptr_from_ref)]
342341
#![feature(raw_os_nonzero)]
343342
#![feature(round_ties_even)]
344343
#![feature(slice_internals)]

tests/ui/lint/ptr_null_checks.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-pass
22

3-
#![feature(ptr_from_ref)]
4-
53
use std::ptr;
64

75
extern "C" fn c_fn() {}

tests/ui/lint/ptr_null_checks.stderr

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: function pointers are not nullable, so checking them for null will always return false
2-
--> $DIR/ptr_null_checks.rs:14:8
2+
--> $DIR/ptr_null_checks.rs:12:8
33
|
44
LL | if (fn_ptr as *mut ()).is_null() {}
55
| ^------^^^^^^^^^^^^^^^^^^^^^^
@@ -10,7 +10,7 @@ LL | if (fn_ptr as *mut ()).is_null() {}
1010
= note: `#[warn(useless_ptr_null_checks)]` on by default
1111

1212
warning: function pointers are not nullable, so checking them for null will always return false
13-
--> $DIR/ptr_null_checks.rs:16:8
13+
--> $DIR/ptr_null_checks.rs:14:8
1414
|
1515
LL | if (fn_ptr as *const u8).is_null() {}
1616
| ^------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -20,7 +20,7 @@ LL | if (fn_ptr as *const u8).is_null() {}
2020
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
2121

2222
warning: function pointers are not nullable, so checking them for null will always return false
23-
--> $DIR/ptr_null_checks.rs:18:8
23+
--> $DIR/ptr_null_checks.rs:16:8
2424
|
2525
LL | if (fn_ptr as *const ()) == std::ptr::null() {}
2626
| ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | if (fn_ptr as *const ()) == std::ptr::null() {}
3030
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
3131

3232
warning: function pointers are not nullable, so checking them for null will always return false
33-
--> $DIR/ptr_null_checks.rs:20:8
33+
--> $DIR/ptr_null_checks.rs:18:8
3434
|
3535
LL | if (fn_ptr as *mut ()) == std::ptr::null_mut() {}
3636
| ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | if (fn_ptr as *mut ()) == std::ptr::null_mut() {}
4040
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
4141

4242
warning: function pointers are not nullable, so checking them for null will always return false
43-
--> $DIR/ptr_null_checks.rs:22:8
43+
--> $DIR/ptr_null_checks.rs:20:8
4444
|
4545
LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
4646
| ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,7 +50,7 @@ LL | if (fn_ptr as *const ()) == (0 as *const ()) {}
5050
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
5151

5252
warning: function pointers are not nullable, so checking them for null will always return false
53-
--> $DIR/ptr_null_checks.rs:24:8
53+
--> $DIR/ptr_null_checks.rs:22:8
5454
|
5555
LL | if <*const _>::is_null(fn_ptr as *const ()) {}
5656
| ^^^^^^^^^^^^^^^^^^^^------^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL | if <*const _>::is_null(fn_ptr as *const ()) {}
6060
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
6161

6262
warning: function pointers are not nullable, so checking them for null will always return false
63-
--> $DIR/ptr_null_checks.rs:26:8
63+
--> $DIR/ptr_null_checks.rs:24:8
6464
|
6565
LL | if (fn_ptr as *mut fn() as *const fn() as *const ()).is_null() {}
6666
| ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -70,7 +70,7 @@ LL | if (fn_ptr as *mut fn() as *const fn() as *const ()).is_null() {}
7070
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
7171

7272
warning: function pointers are not nullable, so checking them for null will always return false
73-
--> $DIR/ptr_null_checks.rs:28:8
73+
--> $DIR/ptr_null_checks.rs:26:8
7474
|
7575
LL | if (fn_ptr as *mut fn() as *const fn()).cast_mut().is_null() {}
7676
| ^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -80,7 +80,7 @@ LL | if (fn_ptr as *mut fn() as *const fn()).cast_mut().is_null() {}
8080
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
8181

8282
warning: function pointers are not nullable, so checking them for null will always return false
83-
--> $DIR/ptr_null_checks.rs:30:8
83+
--> $DIR/ptr_null_checks.rs:28:8
8484
|
8585
LL | if ((fn_ptr as *mut fn()).cast() as *const fn()).cast_mut().is_null() {}
8686
| ^^------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -90,7 +90,7 @@ LL | if ((fn_ptr as *mut fn()).cast() as *const fn()).cast_mut().is_null() {
9090
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
9191

9292
warning: function pointers are not nullable, so checking them for null will always return false
93-
--> $DIR/ptr_null_checks.rs:32:8
93+
--> $DIR/ptr_null_checks.rs:30:8
9494
|
9595
LL | if (fn_ptr as fn() as *const ()).is_null() {}
9696
| ^--------------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -100,7 +100,7 @@ LL | if (fn_ptr as fn() as *const ()).is_null() {}
100100
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
101101

102102
warning: function pointers are not nullable, so checking them for null will always return false
103-
--> $DIR/ptr_null_checks.rs:34:8
103+
--> $DIR/ptr_null_checks.rs:32:8
104104
|
105105
LL | if (c_fn as *const fn()).is_null() {}
106106
| ^----^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -110,117 +110,117 @@ LL | if (c_fn as *const fn()).is_null() {}
110110
= help: wrap the function pointer inside an `Option` and use `Option::is_none` to check for null pointer value
111111

112112
warning: references are not nullable, so checking them for null will always return false
113-
--> $DIR/ptr_null_checks.rs:38:8
113+
--> $DIR/ptr_null_checks.rs:36:8
114114
|
115115
LL | if (&mut 8 as *mut i32).is_null() {}
116116
| ^------^^^^^^^^^^^^^^^^^^^^^^^
117117
| |
118118
| expression has type `&mut i32`
119119

120120
warning: returned pointer of `from_mut` call is never null, so checking it for null will always return false
121-
--> $DIR/ptr_null_checks.rs:40:8
121+
--> $DIR/ptr_null_checks.rs:38:8
122122
|
123123
LL | if ptr::from_mut(&mut 8).is_null() {}
124124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125125

126126
warning: references are not nullable, so checking them for null will always return false
127-
--> $DIR/ptr_null_checks.rs:42:8
127+
--> $DIR/ptr_null_checks.rs:40:8
128128
|
129129
LL | if (&8 as *const i32).is_null() {}
130130
| ^--^^^^^^^^^^^^^^^^^^^^^^^^^
131131
| |
132132
| expression has type `&i32`
133133

134134
warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
135-
--> $DIR/ptr_null_checks.rs:44:8
135+
--> $DIR/ptr_null_checks.rs:42:8
136136
|
137137
LL | if ptr::from_ref(&8).is_null() {}
138138
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
139139

140140
warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
141-
--> $DIR/ptr_null_checks.rs:46:8
141+
--> $DIR/ptr_null_checks.rs:44:8
142142
|
143143
LL | if ptr::from_ref(&8).cast_mut().is_null() {}
144144
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145145

146146
warning: returned pointer of `from_ref` call is never null, so checking it for null will always return false
147-
--> $DIR/ptr_null_checks.rs:48:8
147+
--> $DIR/ptr_null_checks.rs:46:8
148148
|
149149
LL | if (ptr::from_ref(&8).cast_mut() as *mut i32).is_null() {}
150150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151151

152152
warning: references are not nullable, so checking them for null will always return false
153-
--> $DIR/ptr_null_checks.rs:50:8
153+
--> $DIR/ptr_null_checks.rs:48:8
154154
|
155155
LL | if (&8 as *const i32) == std::ptr::null() {}
156156
| ^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157157
| |
158158
| expression has type `&i32`
159159

160160
warning: references are not nullable, so checking them for null will always return false
161-
--> $DIR/ptr_null_checks.rs:53:8
161+
--> $DIR/ptr_null_checks.rs:51:8
162162
|
163163
LL | if (ref_num as *const i32) == std::ptr::null() {}
164164
| ^-------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165165
| |
166166
| expression has type `&i32`
167167

168168
warning: references are not nullable, so checking them for null will always return false
169-
--> $DIR/ptr_null_checks.rs:55:8
169+
--> $DIR/ptr_null_checks.rs:53:8
170170
|
171171
LL | if (b"\0" as *const u8).is_null() {}
172172
| ^-----^^^^^^^^^^^^^^^^^^^^^^^^
173173
| |
174174
| expression has type `&[u8; 1]`
175175

176176
warning: references are not nullable, so checking them for null will always return false
177-
--> $DIR/ptr_null_checks.rs:57:8
177+
--> $DIR/ptr_null_checks.rs:55:8
178178
|
179179
LL | if ("aa" as *const str).is_null() {}
180180
| ^----^^^^^^^^^^^^^^^^^^^^^^^^^
181181
| |
182182
| expression has type `&str`
183183

184184
warning: references are not nullable, so checking them for null will always return false
185-
--> $DIR/ptr_null_checks.rs:59:8
185+
--> $DIR/ptr_null_checks.rs:57:8
186186
|
187187
LL | if (&[1, 2] as *const i32).is_null() {}
188188
| ^-------^^^^^^^^^^^^^^^^^^^^^^^^^
189189
| |
190190
| expression has type `&[i32; 2]`
191191

192192
warning: references are not nullable, so checking them for null will always return false
193-
--> $DIR/ptr_null_checks.rs:61:8
193+
--> $DIR/ptr_null_checks.rs:59:8
194194
|
195195
LL | if (&mut [1, 2] as *mut i32) == std::ptr::null_mut() {}
196196
| ^-----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197197
| |
198198
| expression has type `&mut [i32; 2]`
199199

200200
warning: references are not nullable, so checking them for null will always return false
201-
--> $DIR/ptr_null_checks.rs:63:8
201+
--> $DIR/ptr_null_checks.rs:61:8
202202
|
203203
LL | if (static_i32() as *const i32).is_null() {}
204204
| ^------------^^^^^^^^^^^^^^^^^^^^^^^^^
205205
| |
206206
| expression has type `&i32`
207207

208208
warning: references are not nullable, so checking them for null will always return false
209-
--> $DIR/ptr_null_checks.rs:65:8
209+
--> $DIR/ptr_null_checks.rs:63:8
210210
|
211211
LL | if (&*{ static_i32() } as *const i32).is_null() {}
212212
| ^------------------^^^^^^^^^^^^^^^^^^^^^^^^^
213213
| |
214214
| expression has type `&i32`
215215

216216
warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false
217-
--> $DIR/ptr_null_checks.rs:69:8
217+
--> $DIR/ptr_null_checks.rs:67:8
218218
|
219219
LL | if ptr::NonNull::new(&mut 8).unwrap().as_ptr().is_null() {}
220220
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221221

222222
warning: returned pointer of `as_ptr` call is never null, so checking it for null will always return false
223-
--> $DIR/ptr_null_checks.rs:71:8
223+
--> $DIR/ptr_null_checks.rs:69:8
224224
|
225225
LL | if ptr::NonNull::<u8>::dangling().as_ptr().is_null() {}
226226
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/lint/reference_casting.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// check-fail
22

3-
#![feature(ptr_from_ref)]
4-
53
extern "C" {
64
// N.B., mutability can be easily incorrect in FFI calls -- as
75
// in C, the default is mutable pointers.

0 commit comments

Comments
 (0)