forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 rust-lang#93176 (comment)
- Loading branch information
1 parent
6df63cc
commit c93968a
Showing
4 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/ui/feature-gates/feature-gate-unsafe_pin_internals.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// edition:2018 | ||
#![forbid(incomplete_features, unsafe_code)] | ||
#![feature(unsafe_pin_internals)] | ||
//~^ ERROR the feature `unsafe_pin_internals` is incomplete and may not be safe to use | ||
|
||
use core::{marker::PhantomPinned, pin::Pin}; | ||
|
||
/// The `unsafe_pin_internals` is indeed unsound. | ||
fn non_unsafe_pin_new_unchecked<T>(pointer: &mut T) -> Pin<&mut T> { | ||
Pin { pointer } | ||
} | ||
|
||
fn main() { | ||
let mut self_referential = PhantomPinned; | ||
let _: Pin<&mut PhantomPinned> = non_unsafe_pin_new_unchecked(&mut self_referential); | ||
core::mem::forget(self_referential); // move and disable drop glue! | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/feature-gates/feature-gate-unsafe_pin_internals.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: the feature `unsafe_pin_internals` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/feature-gate-unsafe_pin_internals.rs:3:12 | ||
| | ||
LL | #![feature(unsafe_pin_internals)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/feature-gate-unsafe_pin_internals.rs:2:11 | ||
| | ||
LL | #![forbid(incomplete_features, unsafe_code)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|