Skip to content

Commit c93968a

Browse files
Mark unsafe_pin_internals as incomplete.
This thus still makes it technically possible to enable the feature, and thus to trigger UB without `unsafe`, but this is fine since incomplete features are known to be potentially unsound (labelled "may not be safe"). This follows from the discussion at #93176 (comment)
1 parent 6df63cc commit c93968a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ declare_features! (
161161
(active, staged_api, "1.0.0", None, None),
162162
/// Added for testing E0705; perma-unstable.
163163
(active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
164+
/// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
165+
/// Marked `incomplete` since perma-unstable and unsound.
166+
(incomplete, unsafe_pin_internals, "1.61.0", None, None),
164167
/// Use for stable + negative coherence and strict coherence depending on trait's
165168
/// rustc_strict_coherence value.
166169
(active, with_negative_coherence, "1.60.0", None, None),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ symbols! {
14551455
unsafe_block_in_unsafe_fn,
14561456
unsafe_cell,
14571457
unsafe_no_drop_flag,
1458+
unsafe_pin_internals,
14581459
unsize,
14591460
unsized_fn_params,
14601461
unsized_locals,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition:2018
2+
#![forbid(incomplete_features, unsafe_code)]
3+
#![feature(unsafe_pin_internals)]
4+
//~^ ERROR the feature `unsafe_pin_internals` is incomplete and may not be safe to use
5+
6+
use core::{marker::PhantomPinned, pin::Pin};
7+
8+
/// The `unsafe_pin_internals` is indeed unsound.
9+
fn non_unsafe_pin_new_unchecked<T>(pointer: &mut T) -> Pin<&mut T> {
10+
Pin { pointer }
11+
}
12+
13+
fn main() {
14+
let mut self_referential = PhantomPinned;
15+
let _: Pin<&mut PhantomPinned> = non_unsafe_pin_new_unchecked(&mut self_referential);
16+
core::mem::forget(self_referential); // move and disable drop glue!
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: the feature `unsafe_pin_internals` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/feature-gate-unsafe_pin_internals.rs:3:12
3+
|
4+
LL | #![feature(unsafe_pin_internals)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/feature-gate-unsafe_pin_internals.rs:2:11
9+
|
10+
LL | #![forbid(incomplete_features, unsafe_code)]
11+
| ^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)