Replace links to `github.com/rust-lang/rfcs` with links to the Rust RFC Book
I noticed many error codes link to Rust RFCs via the [source GitHub `.md` files](https://github.com/rust-lang/rfcs/tree/master/text) instead of linking to the [RFC Book](https://rust-lang.github.io/rfcs/). This PR updates those links to point to the RFC book - I also updated any other links to RFCs in the repo (not including subtrees) while I was at it.
Reflection refactor ptrs
Tracking issue rust-lang/rust#146922
Part of the [Refactoring to many methods](https://rust-lang.zulipchat.com/#narrow/channel/572285-goals.2Freflection/topic/Refactoring.20to.20many.20methods/with/592226560) reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum `TypeKind` where the variants hold the types information to one that just tells you the type kind. Separate methods on `TypeId` provide a way to get to the data that used to be in the variant.
Since function pointers have a lot of fields it felt better to keep the `FnPtr` struct we have now then add an intrinsic for each field.
r? @oli-obk
docs(core): correct ARMv8-M Baseline atomic CAS support
ARMv8-M Baseline targets support CAS operations, but the atomic module docs incorrectly list them as load and store-only.
The incorrect ARMv8-M Baseline comment was introduced in rust-lang/rust#149241 while updating the atomic portability notes for ARMv4T/ARMv5TE.
Limit that restriction to ARMv6-M and include `thumbv8m.base-*` among the targets with full CAS support.
@rustbot label +A-docs +A-atomic +O-Arm +T-libs
Revise documentation of `NumBuffer` and `format_into()`.
The previous documentation was, in my opinion, overly focused on the implementation of these items, rather than how and when to use them. In particular, this new documentation:
* Begins the `format_into()` documentation with what it does when called.
* Specifies that `format_into()` is a specialized alternative to the more commonly used `Display`.
* Specifies that `NumBuffer` cannot be read or otherwise used by itself.
@rustbot label +A-docs
Add #[track_caller] to signed integer div/rem methods
Fixesrust-lang/rust#139672
The unsigned div/rem methods got #[track_caller] in 724fe8fcfb but
the signed side was missed. This adds it to the 8 signed methods
listed in the issue, including overflowing_div_euclid which the
issue missed but wrapping_div_euclid delegates to.
No test added, matching the unsigned side. cg_gcc doesn't
propagate track_caller through inlined div/rem yet so a runtime
check would fail on the gcc-core-tests CI job.
Report precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval
The precondition check was gated on `check_language_ub`, which is disabled in const-eval and Miri, on the grounds that the `assume` below it is language UB that the interpreter will catch anyway. It does catch it, but only as "`assume` called with `false`", which says nothing about what the caller did wrong.
This PR instead gates the check on `check_library_ub`, matching `get_unchecked_mut`, so that the interpreter reports the violated precondition.
Fixesrust-lang/rust#161611
* Add a test for the diagnostics on `<usize as SliceIndex>::get_unchecked` in const-eval
* Report a precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval
The precondition check was gated on `check_language_ub`, which is disabled in const-eval and Miri, on the grounds that the `assume` below it is language UB that the interpreter will catch anyway. It does catch it, but only as "`assume` called with `false`", which says nothing about what the caller did wrong.
This commit instead gates the check on `check_library_ub`, matching `get_unchecked_mut`, so that the interpreter reports the violated precondition.
* fixup! Report a precondition violation for `<usize as SliceIndex>::get_unchecked` in const-eval
* tweak comment
Co-authored-by: Ralf Jung <post@ralfj.de>
ARMv8-M Baseline targets support CAS operations, but the atomic module docs incorrectly list them as load and store-only.
Limit that restriction to ARMv6-M and include thumbv8m.base-* among the targets with full CAS support.
The previous documentation was, in my opinion, overly focused on the
implementation of these items, rather than how and when to use them.
This new documentation:
* Begins the `format_into()` documentation with what it does when called.
* Specifies that `format_into()` is a specialized alternative to the more
commonly used `Display`.
* Specifies that `NumBuffer` cannot be read or otherwise used by itself.
docs(time): clarify exact seconds for hour and minute
Documented that `Duration::from_hours` defines one hour as 3,600 seconds (60 minutes), and `Duration::from_mins` defines one minute as 60 seconds.
Doctests for these methods also appear to be based on these definitions.
The purpose of this is to clarify that `Duration` is a fixed length value that ignores factors such as a leap second.
This is inspired by <https://github.com/rust-lang/libs-team/issues/869#issuecomment-5500049965>.
It seems that no library in Rust handle leap seconds, so there isn't much point in documenting this. However, I don't think it would hurt to include it for the sake of consistency with rust-lang/rust#162195.
See also rust-lang/rust#120301
@rustbot label +A-docs
docs(time): clarify exact seconds for week and day
Documented that `Duration::from_weeks` defines one week as 604,800 seconds (7 days), and `Duration::from_days` defines one day as 86,400 seconds (24 hours).
Doctests for these methods also appear to be based on these definitions.
The purpose of this is to clarify that `Duration` is a fixed length value that ignores factors such as DST or a leap second.
This is inspired by <https://github.com/rust-lang/libs-team/issues/869#issuecomment-5500049965>.
See also rust-lang/rust#120301
@rustbot label +A-docs
core: mark float `ClampBounds` methods as `#[inline]`
Commit bd174e1b20 ("Implement clamp_to") added a few float methods that are not marked `#[inline]`. This causes `core` to require new symbols in soft-float builds, even if the methods are unused, e.g. from the Linux kernel:
ld.lld: error: undefined symbol: fmaximum_numf
>>> referenced by core.1f440ee8661e09f9-cgu.0
>>> rust/core.o:(<core::ops::range::RangeFrom<f32> as core::cmp:🗜️:ClampBounds<f32>>::clamp) in archive vmlinux.a
(and similar for `f{min,max}imum_num{f,}` and `__gt{s,d}f2`).
It is possible to work around this in the Linux side, but these methods should probably be `#[inline]` to begin with, like many other similar methods are.
Thus mark them as inline.
implement `Add` and `Sub` for `Complex`
tracking issue: https://github.com/rust-lang/rust/issues/154023
Adds the `Add` and `Sub` implementations described in the tracking issue. Some notes
- I also added a derive for `Eq`, which is useful for `Complex<{integer}>`
- The versions that add/sub by a scalar need a `Copy` bound. That seems fine for most actual use cases.
Apparently `num_complex` will `Clone` in these operations https://docs.rs/num-complex/latest/num_complex/struct.Complex.html#impl-Add%3CT%3E-for-%26Complex%3CT%3E, but that seems unlike `core` to me. Anyhow, libs can re-litigate that later.
docs(num): clarify conditions under which error occurs in `impl TryFrom<int> for int`
`impl_try_from_unbounded` always returns `Ok(T)`, but the documentation is written as if it may return an error, so I fixed this.
I also clarified that `impl_try_from_lower_bounded` returns an error only when the source value is less than `T::MIN`, and `impl_try_from_upper_bounded` returns an error only when the source value is greater than `T::MAX`.
While the original text
> This returns an error if the source value is outside of the range of the target type.
is fine for both cases, but I think the revised text makes it clearer that the error occurs at either the lower bound or the upper bound.
As for `impl_try_from_both_bounded`, I think the current text is fine, so I have not made any changes to it.
volatile: allow accesses to non-AM memory to trap
Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/610 by saying that yes, volatile accesses may trap. This also fixes what I believe to be the last case of "time-traveling UB" we have in Rust: with this change, UB always fully sequenced wrt observable events (I/O and volatile accesses). UB can still travel around unobservable events such as non-volatile memory accesses.
For writes, LLVM has already implemented the new semantics for a long time. For reads, LLVM only recently implemented the "may trap" semantics with LLVM 23. We still allow compiling rustc with older versions of LLVM. To (hopefully) prevent old LLVM from screwing this up with optimizations, this PR makes the backend emit an inline asm block *without* `willreturn`, which should prevent optimizations that break programs where a volatile load traps.
Cc @rust-lang/opsem @rust-lang/wg-llvm
Commit bd174e1b20 ("Implement clamp_to") added a few float methods that
are not marked `#[inline]`. This causes `core` to require new symbols
in soft-float builds, even if the methods are unused, e.g. from the
Linux kernel:
ld.lld: error: undefined symbol: fmaximum_numf
>>> referenced by core.1f440ee8661e09f9-cgu.0
>>> rust/core.o:(<core::ops::range::RangeFrom<f32> as core::cmp:🗜️:ClampBounds<f32>>::clamp) in archive vmlinux.a
(and similar for `f{min,max}imum_num{f,}` and `__gt{s,d}f2`).
It is possible to work around this in the Linux side, but these methods
should probably be `#[inline]` to begin with, like many other similar
methods are.
Thus mark them as inline.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
make it clear that Range cannot represent arbitrary ranges
This seems like a useful clarification, though it is already heavily implied by the first sentence in the docs.
What is less clear to me is what type one *should* use to represent arbitrary ranges. Should we recommend `(Bound<T>, Bound<T>)` for that purpose? It seems best-stuied, and is already used for that purpose by the btree collections and in https://github.com/rust-lang/rust/issues/136903. However, I suspect it is also common that one wants to represent an arbitrary range that's bounded on both sides. `RangeInclusive` can represent all those (though representing the empty range is a bit awkward), `Range` cannot.
Nominating for t-libs to get their general vibe on what we want to recommend here, if anything.
Change some `Infallible` to `!` in std
I believe this desirable since we recommend `!` over `Infallible`, so std follows its own advice. Most changes are to unstable features, but not all. Similar changes in compiler have to wait for a bootstrap update.
Rework `next_power_of_two` to always be `1 << …`
r? @clarfonthey
Who accidentally nerd-sniped me by mentioning rust-lang/rust#161069
This obviates that PR by reworking the `(checked_)next_power_of_two` logic to calculate the necessary exponent e, then return 2ᵉ, so it's structurally obvious from the IR -- the `shl nuw 1, …` instruction -- that it's always a power of two.
As always, the reason this is tricky is because shifts don't work for `<< Self::BITS`. The previous code handled that by checking `self <= 1` first, and thus doing a `-1 >> n` where `n < BITS`. This code instead flips the check: it looks up-front for a value that will wrap (an input above `1 << (BITS - 1)`) and thus by excluding those cases the calculated `1 << n` always has `n < BITS`. And the codegen tests show that, without needing any `llvm.assume`s, LLVM can take advantage of it to do things like rewriting `%` to masking. Plus the overflow check optimizes out for constrained inputs like slice lengths.