Merge branch 'master' into handle-drop-zst

pull/425/head
pwbh 2 weeks ago committed by GitHub
commit 510aeeb1a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,12 +1,17 @@
name: CI name: CI
on: [push, pull_request] on:
pull_request:
merge_group:
env:
MDBOOK_VERSION: 0.4.40
jobs: jobs:
test: test:
name: Test name: Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Update rustup - name: Update rustup
run: rustup self update run: rustup self update
- name: Install Rust - name: Install Rust
@ -15,11 +20,9 @@ jobs:
rustup toolchain install nightly -c rust-docs rustup toolchain install nightly -c rust-docs
rustup default nightly rustup default nightly
- name: Install mdbook - name: Install mdbook
env:
MDBOOK_VER: v0.4.3
run: | run: |
mkdir bin mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/${{ env.MDBOOK_VER }}/mdbook-${{ env.MDBOOK_VER }}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
echo "$(pwd)/bin" >> $GITHUB_PATH echo "$(pwd)/bin" >> $GITHUB_PATH
- name: Report versions - name: Report versions
run: | run: |
@ -33,3 +36,19 @@ jobs:
curl -sSLo linkcheck.sh \ curl -sSLo linkcheck.sh \
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
sh linkcheck.sh --all nomicon sh linkcheck.sh --all nomicon
# The success job is here to consolidate the total success/failure state of
# all other jobs. This job is then included in the GitHub branch protection
# rule which prevents merges unless all other jobs are passing. This makes
# it easier to manage the list of jobs via this yml file and to prevent
# accidentally adding new jobs without also updating the branch protections.
success:
name: Success gate
if: always()
needs:
- test
runs-on: ubuntu-latest
steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
- name: Done
run: exit 0

@ -19,7 +19,10 @@ Note that the default features have been disabled. This is a critical step -
disabled.** disabled.**
Alternatively, we can use the unstable `rustc_private` private feature together Alternatively, we can use the unstable `rustc_private` private feature together
with an `extern crate libc;` declaration as shown in the examples below. with an `extern crate libc;` declaration as shown in the examples below. Note that
windows-msvc targets do not require a libc, and correspondingly there is no `libc`
crate in their sysroot. We do not need the `extern crate libc;` below, and having it
on a windows-msvc target would be a compile error.
## Writing an executable without `std` ## Writing an executable without `std`
@ -39,11 +42,12 @@ in the same format as C (aside from the exact integer types being used):
#![allow(internal_features)] #![allow(internal_features)]
#![no_std] #![no_std]
// Necessary for `panic = "unwind"` builds on some platforms. // Necessary for `panic = "unwind"` builds on cfg(unix) platforms.
#![feature(panic_unwind)] #![feature(panic_unwind)]
extern crate unwind; extern crate unwind;
// Pull in the system libc library for what crt0.o likely requires. // Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc; extern crate libc;
use core::panic::PanicInfo; use core::panic::PanicInfo;
@ -73,11 +77,12 @@ compiler's name mangling too:
#![no_std] #![no_std]
#![no_main] #![no_main]
// Necessary for `panic = "unwind"` builds on some platforms. // Necessary for `panic = "unwind"` builds on cfg(unix) platforms.
#![feature(panic_unwind)] #![feature(panic_unwind)]
extern crate unwind; extern crate unwind;
// Pull in the system libc library for what crt0.o likely requires. // Pull in the system libc library for what crt0.o likely requires.
#[cfg(not(windows))]
extern crate libc; extern crate libc;
use core::ffi::{c_char, c_int}; use core::ffi::{c_char, c_int};

@ -102,7 +102,7 @@ struct Boxy<T> {
} }
``` ```
will have its data1 and data2's fields destructors whenever it "would" be will have the destructors of its `data1` and `data2` fields called whenever it "would" be
dropped, even though it itself doesn't implement Drop. We say that such a type dropped, even though it itself doesn't implement Drop. We say that such a type
*needs Drop*, even though it is not itself Drop. *needs Drop*, even though it is not itself Drop.
@ -163,8 +163,8 @@ impl<T> Drop for SuperBox<T> {
# fn main() {} # fn main() {}
``` ```
However this has fairly odd semantics: you're saying that a field that *should* However this has fairly odd semantics: you are saying that a field that *should*
always be Some *may* be None, just because that happens in the destructor. Of always be Some *may* be None, just because of what happens in the destructor. Of
course this conversely makes a lot of sense: you can call arbitrary methods on course this conversely makes a lot of sense: you can call arbitrary methods on
self during the destructor, and this should prevent you from ever doing so after self during the destructor, and this should prevent you from ever doing so after
deinitializing the field. Not that it will prevent you from producing any other deinitializing the field. Not that it will prevent you from producing any other

@ -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 an optimization that is not guaranteed, so for example transmuting one into the
other is still Undefined Behavior). other is still Undefined Behavior).
The following *could* also compile: The following also compiles:
```rust,compile_fail ```rust
enum Void {} enum Void {}
let res: Result<u32, Void> = Ok(0); let res: Result<u32, Void> = Ok(0);
@ -148,8 +148,6 @@ let res: Result<u32, Void> = Ok(0);
let Ok(num) = res; 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 One final subtle detail about empty types is that raw pointers to them are
actually valid to construct, but dereferencing them is Undefined Behavior actually valid to construct, but dereferencing them is Undefined Behavior
because that wouldn't make sense. because that wouldn't make sense.

@ -42,7 +42,7 @@ says they should still consume a byte of space.
difference from a struct is that the fields arent named. difference from a struct is that the fields arent named.
* `repr(C)` is equivalent to one of `repr(u*)` (see the next section) for * `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 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 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. 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*) ## 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 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 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 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 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. 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 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)` 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 in that there is a defined layout of the type. This makes it possible to

@ -268,7 +268,7 @@ To see why `fn(T) -> U` should be covariant over `U`, consider the following sig
fn get_str() -> &'a str; fn get_str() -> &'a str;
``` ```
This function claims to produce a `str` bound by some liftime `'a`. As such, it is perfectly valid to This function claims to produce a `str` bound by some lifetime `'a`. As such, it is perfectly valid to
provide a function with the following signature instead: provide a function with the following signature instead:
<!-- ignore: simplified code --> <!-- ignore: simplified code -->

@ -5,7 +5,7 @@ The only things that are different in Unsafe Rust are that you can:
* Dereference raw pointers * Dereference raw pointers
* Call `unsafe` functions (including C functions, compiler intrinsics, and the raw allocator) * Call `unsafe` functions (including C functions, compiler intrinsics, and the raw allocator)
* Implement `unsafe` traits * Implement `unsafe` traits
* Mutate statics * Access or modify mutable statics
* Access fields of `union`s * Access fields of `union`s
That's it. The reason these operations are relegated to Unsafe is that misusing That's it. The reason these operations are relegated to Unsafe is that misusing
@ -41,6 +41,9 @@ language cares about is preventing the following things:
[`NonNull`] that is null. (Requesting custom invalid values is an unstable [`NonNull`] that is null. (Requesting custom invalid values is an unstable
feature, but some stable libstd types, like `NonNull`, make use of it.) feature, but some stable libstd types, like `NonNull`, make use of it.)
For a more detailed explanation about "Undefined Bahavior", you may refer to
[the reference][behavior-considered-undefined].
"Producing" a value happens any time a value is assigned, passed to a "Producing" a value happens any time a value is assigned, passed to a
function/primitive operation or returned from a function/primitive operation. function/primitive operation or returned from a function/primitive operation.
@ -75,6 +78,8 @@ Rust considers it "safe" to:
* Abort the program * Abort the program
* Delete the production database * Delete the production database
For more detailed information, you may refer to [the reference][behavior-not-considered-unsafe].
However any program that actually manages to do such a thing is *probably* However any program that actually manages to do such a thing is *probably*
incorrect. Rust provides lots of tools to make these things rare, but incorrect. Rust provides lots of tools to make these things rare, but
these problems are considered impractical to categorically prevent. these problems are considered impractical to categorically prevent.
@ -84,3 +89,5 @@ these problems are considered impractical to categorically prevent.
[race]: races.html [race]: races.html
[target features]: ../reference/attributes/codegen.html#the-target_feature-attribute [target features]: ../reference/attributes/codegen.html#the-target_feature-attribute
[`NonNull`]: ../std/ptr/struct.NonNull.html [`NonNull`]: ../std/ptr/struct.NonNull.html
[behavior-considered-undefined]: ../reference/behavior-considered-undefined.html
[behavior-not-considered-unsafe]: ../reference/behavior-not-considered-unsafe.html

Loading…
Cancel
Save