From 1d0b6c122ba6c79e3a11d9f80f9d79125a260bb4 Mon Sep 17 00:00:00 2001 From: alimf17 Date: Fri, 2 Aug 2024 13:55:45 -0400 Subject: [PATCH 1/3] Update what-unsafe-does.md --- src/what-unsafe-does.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/what-unsafe-does.md b/src/what-unsafe-does.md index 372538e..3fb0721 100644 --- a/src/what-unsafe-does.md +++ b/src/what-unsafe-does.md @@ -5,7 +5,7 @@ The only things that are different in Unsafe Rust are that you can: * Dereference raw pointers * Call `unsafe` functions (including C functions, compiler intrinsics, and the raw allocator) * Implement `unsafe` traits -* Mutate statics +* Access or modify mutable statics * Access fields of `union`s That's it. The reason these operations are relegated to Unsafe is that misusing From 16d2f21daea641f4da7c5821446d7816af4d9c81 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 3 Aug 2024 13:10:52 +0200 Subject: [PATCH 2/3] repr(int) enums: both size and sign matter --- src/other-reprs.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/other-reprs.md b/src/other-reprs.md index 228b22b..289da57 100644 --- a/src/other-reprs.md +++ b/src/other-reprs.md @@ -42,7 +42,7 @@ says they should still consume a byte of space. difference from a struct is that the fields aren’t named. * `repr(C)` is equivalent to one of `repr(u*)` (see the next section) for -fieldless enums. The chosen size is the default enum size for the target platform's C +fieldless enums. The chosen size and sign is the default enum size and sign for the target platform's C application binary interface (ABI). Note that enum representation in C is implementation defined, so this is really a "best guess". In particular, this may be incorrect when the C code of interest is compiled with certain flags. @@ -79,7 +79,7 @@ More details are in the [RFC 1758][rfc-transparent] and the [RFC 2645][rfc-trans ## repr(u*), repr(i*) -These specify the size to make a fieldless enum. If the discriminant overflows +These specify the size and sign to make a fieldless enum. If the discriminant overflows the integer it has to fit in, it will produce a compile-time error. You can manually ask Rust to allow this by setting the overflowing element to explicitly be 0. However Rust will not allow you to create an enum where two variants have @@ -89,7 +89,7 @@ The term "fieldless enum" only means that the enum doesn't have data in any of its variants. A fieldless enum without a `repr(u*)` or `repr(C)` is still a Rust native type, and does not have a stable ABI representation. Adding a `repr` causes it to be treated exactly like the specified -integer size for ABI purposes. +integer type for ABI purposes. If the enum has fields, the effect is similar to the effect of `repr(C)` in that there is a defined layout of the type. This makes it possible to From d5ba0cb399ea8c3a1a5eced724dad8c648dc8bb4 Mon Sep 17 00:00:00 2001 From: Guillaume Boisseau Date: Thu, 21 Mar 2024 02:01:08 +0100 Subject: [PATCH 3/3] Stabilize `min_exhaustive_patterns` --- src/exotic-sizes.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/exotic-sizes.md b/src/exotic-sizes.md index c4a6d24..5e6a395 100644 --- a/src/exotic-sizes.md +++ b/src/exotic-sizes.md @@ -137,9 +137,9 @@ because the `Err` case doesn't actually exist (strictly speaking, this is only an optimization that is not guaranteed, so for example transmuting one into the other is still Undefined Behavior). -The following *could* also compile: +The following also compiles: -```rust,compile_fail +```rust enum Void {} let res: Result = Ok(0); @@ -148,8 +148,6 @@ let res: Result = Ok(0); let Ok(num) = res; ``` -But this trick doesn't work yet. - One final subtle detail about empty types is that raw pointers to them are actually valid to construct, but dereferencing them is Undefined Behavior because that wouldn't make sense.