about summary refs log tree commit diff
path: root/tests/ui/unsafe-fields
diff options
context:
space:
mode:
authorJack Wrenn <jack@wrenn.fyi>2025-02-28 16:32:06 +0000
committerJack Wrenn <jack@wrenn.fyi>2025-02-28 16:32:06 +0000
commit91034adf30b3055e489d59f4483ed5def9cc9f19 (patch)
treedc5295049ed689972d27ab0ad7e8461b84556aa9 /tests/ui/unsafe-fields
parent2f581937e1c06adb4607df1b571c0bef6d98e6ec (diff)
downloadrust-91034adf30b3055e489d59f4483ed5def9cc9f19.tar.gz
rust-91034adf30b3055e489d59f4483ed5def9cc9f19.zip
Do not require that unsafe fields lack drop glue
Instead, we adopt the position that introducing an `unsafe` field
itself carries a safety invariant: that if you assign an invariant
to that field weaker than what the field's destructor requires,
you must ensure that field is in a droppable state in your
destructor.

See:
- https://github.com/rust-lang/rfcs/pull/3458#discussion_r1971676100
- https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/unsafe.20fields.20RFC/near/502113897
Diffstat (limited to 'tests/ui/unsafe-fields')
-rw-r--r--tests/ui/unsafe-fields/unsafe-fields.rs2
-rw-r--r--tests/ui/unsafe-fields/unsafe-fields.stderr17
2 files changed, 3 insertions, 16 deletions
diff --git a/tests/ui/unsafe-fields/unsafe-fields.rs b/tests/ui/unsafe-fields/unsafe-fields.rs
index 637471582d7..cb86479bb20 100644
--- a/tests/ui/unsafe-fields/unsafe-fields.rs
+++ b/tests/ui/unsafe-fields/unsafe-fields.rs
@@ -17,7 +17,7 @@ fn f(a: A) {
 }
 
 struct WithInvalidUnsafeField {
-    unsafe unsafe_noncopy_field: Vec<u32>, //~ ERROR
+    unsafe unsafe_noncopy_field: Vec<u32>,
 }
 
 struct WithManuallyDropUnsafeField {
diff --git a/tests/ui/unsafe-fields/unsafe-fields.stderr b/tests/ui/unsafe-fields/unsafe-fields.stderr
index a1c5d2b44cd..d0e2dc16a13 100644
--- a/tests/ui/unsafe-fields/unsafe-fields.stderr
+++ b/tests/ui/unsafe-fields/unsafe-fields.stderr
@@ -1,15 +1,3 @@
-error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be unsafe
-  --> $DIR/unsafe-fields.rs:20:5
-   |
-LL |     unsafe unsafe_noncopy_field: Vec<u32>,
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: unsafe fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
-help: wrap the field type in `ManuallyDrop<...>`
-   |
-LL |     unsafe unsafe_noncopy_field: std::mem::ManuallyDrop<Vec<u32>>,
-   |                                  +++++++++++++++++++++++        +
-
 error[E0133]: use of unsafe field is unsafe and requires unsafe block
   --> $DIR/unsafe-fields.rs:15:30
    |
@@ -69,7 +57,6 @@ LL |         &raw const self.unsafe_field
    |
    = note: unsafe fields may carry library invariants
 
-error: aborting due to 8 previous errors
+error: aborting due to 7 previous errors
 
-Some errors have detailed explanations: E0133, E0740.
-For more information about an error, try `rustc --explain E0133`.
+For more information about this error, try `rustc --explain E0133`.