Clarify that `LocalKey::try_with` may return `AccessError`
The docs for `LocalKey::try_with` state that the function *will* return an `AccessError` when the key has been destroyed. That's not actually guaranteed:
- `LocalKey::with` uses `try_with` internally and its docs explicitly acknowledge that it does not always panic when the destructor has run. If `try_with` really did detect every destroyed thread-local, `with` could always panic.
- The top-level `LocalKey` docs already note: "On all platforms it's possible for TLS to re-initialize other TLS slots during destruction."
Change *will* to *may* to accurately reflect the best-effort nature of the destroyed-key check.
Closesrust-lang/rust#157889
@rustbot label +A-docs
Fixes for QNX SDP 8
This PR contains libstd fixes so libstd can be build for QNX SDP 8.
It requires patches to libc-0.2 and cc-rs. The cc-rs patch [was merged]([rust-lang/cc-rs#1775](https://github.com/rust-lang/cc-rs/issues/1775)) already. I have a patch for libc-1.0 [here](https://github.com/rust-lang/libc/issues/5241) which will need backporting to libc-0.2 once merged.
With these in place, I was able to remotely `test tests/ui library/std library/alloc library/core` for `x86_64-pc-qnx` using a remote-test-server running on QNX SDP 8.0's QEMU BSP image. The only tests that failed were the two `tests/ui/codegen/huge-stacks.rs` tests, and I did not have enough RAM to run them.
Rename some `body_id` to `body_def_id`
Since body IDs and item IDs are distinct things, try to use names that do not conflate them. `body_def_id` is a little easier to read as "body-owning definition ID" whereas `body_id` is hard not to just read as "body ID".
Related: rust-lang/rust#158611 - I noticed this afterwards. I suspect that `FnCtxt` ought to keep `body_def_id` but maybe add `body_id: BodyId` in addition.
delegation: support mapping of all arguments with `Self` type
This PR supports applying target expression to arguments of `Self` type.
That the first part of this feature which touches AST -> HIR lowering only and allows lowering of delegation's block several times when there are no definitions inside.
The second part will adjust typeck so we can apply adjustments to all mapped arguments as to the first argument of delegation. This should also eventually weak the condition of argument mapping allowing `Box<Self>`, `Arc<Self>`, etc.
Part of rust-lang/rust#118212.
r? @petrochenkov
disallow `extern "custom"` on wasm and spirv targets
tracking issue: https://github.com/rust-lang/rust/issues/140829
I'm not sure if we should exclude any other architectures? The GPU ones are a bit suspect maybe?
std: unconditionally use `preadv`/`pwritev` on AArch64 macOS
The stars happened to line up perfectly: macOS 11.0 was the first version to support ARM, and also the first version with `preadv`/`pwritev`. Thus we don't need to use weak linkage if the target is `aarch64-apple-darwin`.
1) setsid/setpgrp: check child's group process ID
Linux [1], FreeBSD [2] and the Open Group [3] manuals for both setsid and
setpgrp state that the calling process will be assigned a process group ID that
matches its process ID so check that's the case in the test by calling
getpgid on the child process ID.
on QNX8 (as of GA8.0.2) libc::kill(pgid) appears unable to terminate the
child process so skip that check on that target as it's behavior that
libstd provides no API for
[1]: https://man7.org/linux/man-pages/man2/setsid.2.html
[2]: https://man.freebsd.org/cgi/man.cgi?query=setsid&sektion=2
[3]: https://pubs.opengroup.org/onlinepubs/000095399/functions/setsid.html
2) fix handling of sockaddr_un.len on QNX
also extend the existing tests to exercise the getsockname(2) and
getpeername(2) paths with both named and unnamed Unix sockets
3) Additional fixes library/std after earlier PR renamed some targets
4) Replace more instances of "QNX Neutrino / QNX OS" with "QNX SDP" and fix up some documentation URLs
5) Tests ignored on target_os = "nto" should also be ignored on target_os = "qnx".
6) Simplify nto-qnx.md documentation
cc-rs now knows about QNX so the environment isn't required
* Support mapping of all arguments with Self type
* Address some review comments
* Review: use #[cfg(debug_assertions)] on the whole module
* Review: emit error when trying to map non-receiver argument when block contains definitions
* Use `cfg_select`
* Fix tidy
* Unify mapping with `should_generate_block`
* Better naming and message for error
* loop -> `extend`
Rollup of 13 pull requests
Successful merges:
- rust-lang/rust#158478 (Use correct typing mode in mir building for the next solver)
- rust-lang/rust#158796 (Distinguish null reference production from null pointer dereference in UB checks)
- rust-lang/rust#158821 (add regression test for late-bound type method probe ICE)
- rust-lang/rust#158245 (Update the rustc_perf submodule)
- rust-lang/rust#158346 (Prevent rustdoc auto-trait ICEs with `-Znext-solver=globally`)
- rust-lang/rust#158536 (Instatiate binder instead of skipping when suggesting function arg error)
- rust-lang/rust#158553 (Avoid infinite recursion when trying to build valtrees for self-referential consts)
- rust-lang/rust#158679 (Document blocking guarantees for `std::sync`)
- rust-lang/rust#158826 (Reorganize `tests/ui/issues` [19/N])
- rust-lang/rust#158860 (Delete `impl_def_id` field from `ImplHeader`)
- rust-lang/rust#158867 (rewrite `Align::max_for_target` in a more obvious way)
- rust-lang/rust#158878 (borrowck: Inline `free_region_constraint_info()` to simplify the code)
- rust-lang/rust#158881 (Update mdbook to 0.5.4)
borrowck: Inline `free_region_constraint_info()` to simplify the code
For reference, the helper function was introduced in 2a3969a3f7. But, the code becomes simpler if we remove the helper function, so let's remove it.
This takes us one step closer (this is commit 3 of 4) towards the end result illustrated in https://github.com/rust-lang/rust/pull/158623.
Document blocking guarantees for `std::sync`
Per rust-lang/rust#157728, this PR documents how exactly functions/methods in `std::mpsc` (and `mpmc`) block.
Copied from the issue:
> For the wasm part of this specifically, yes, using a mutex anywhere is basically forbidden on the main thread in browsers. Personally I don't think it's reasonable to expect the standard library to use zero mutexes on wasm and make absolutely everything lock-free. This is a consequence of browsers and not something Rust can "just" fix. Basically I would not recommend changing the implementation and instead leaving it as-is. I'll note that there's a long and storied history of blocking-the-main-thread-with-wasm-threads in the browser, and I'm not putting in all the context here.
>
> \- alexcrichton
(P.S. documentation seems to be line wrapped but doesn't have a consistent wrapping width? I tried to match the surrounding style as best as I could; let me know if there's something better I should've done)
Fixesrust-lang/rust#157728
Avoid infinite recursion when trying to build valtrees for self-referential consts
This PR adds cycle detection to `const_to_valtree_inner` by using a tricolor DFS, so self-referential statics in pats don't cause valtree construction to recurse infinitely. Instead, we now return a new `ValTreeCreationError::CyclicConst`, similar to the current `InvalidConst` and `NodesOverflow` variants.
fixesrust-lang/rust#144719
Update the rustc_perf submodule
I hope this is a thing that's ok to do, I never update submodules but this one seems to be 8 months old and we got some new benchmarks in the meantime.
r? @Kobzol
Distinguish null reference production from null pointer dereference in UB checks
Closesrust-lang/rust#154044
This change distinguishes null reference production from actual null pointer dereferences in the UB checks.
Producing a reference from a null pointer (for example, `&*ptr`) is undefined behavior even if no memory is dereferenced. This change introduces a dedicated `AssertKind::NullReferenceConstructed` and runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences.
Summary
- Add `AssertKind::NullReferenceConstructed`.
- Emit it for null reference production in the MIR null check pass.
- Add `panic_null_reference_constructed` and its lang item.
- Keep `NullPointerDereference` for actual dereferences.
- Update the affected UI tests.
Use correct typing mode in mir building for the next solver
Previously, we used typing env `non_body_analysis` when building MIR body.
This is wrong because we're in a body and should reveal opaque types defined in this scope.
Fixesrust-lang/rust#158439Fixesrust-lang/rust#158429
r? lcnr or anyone familiar with typing modes.
Polish some macro parsing code
I'm working on some optimizations to `macro_parser.rs` and the surrounding code (specifically, changing the current BFS approach into a DFS), and these changes fell out during that effort. I think they make the code more accessible in addition to laying some foundations for my future work (in particular, the handling of ambiguities).
This is my first proper entrance into rustc code, please let me know if I'm holding something wrong :)
The commits are organized and individually reviewable.
r? @nnethercote
`body_id` is often used to mean "ID of a body-owning node", which is
confusing since the obvious reading of "body ID" is wrong.
`body_def_id` is easier to read as "body-owning definition ID".
Rollup of 12 pull requests
Successful merges:
- rust-lang/rust#156976 (enable eager `param_env` norm in new solver)
- rust-lang/rust#158537 (Add `std::io::cursor::WriteThroughCursor`)
- rust-lang/rust#158540 (Move `std::io::Seek` to `core::io`)
- rust-lang/rust#157820 (consider subtyping when checking if an infer var is sized)
- rust-lang/rust#158505 (Update POSIX edition links)
- rust-lang/rust#158853 (Fix typo for link on nto-qnx.md)
- rust-lang/rust#157466 (Better error message when bare type in impl parameter list)
- rust-lang/rust#157966 (Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an `impl Trait` bound)
- rust-lang/rust#158381 (Expose debug scope of statement and terminator in rustc_public)
- rust-lang/rust#158405 (rustc_target: Add ARMv8-M related target features)
- rust-lang/rust#158770 (Weaken guarantee for `From<legacy::RangeInclusive> for RangeInclusive`)
- rust-lang/rust#158820 (Fix rustdoc ICE on deprecated note in inlined re-export chain)
Weaken guarantee for `From<legacy::RangeInclusive> for RangeInclusive`
As per https://github.com/rust-lang/rust/pull/155114#issuecomment-4845403701, this `From` impl no longer guarantees panicking for exhausted iterators. Instead, it only guarantees that the conversion will either panic or produce an empty range.
This is done so that we can optimize the implementation of `legacy::RangeInclusive` in a way such that we cannot check if it has been exhausted in a generic context without a `Step` and/or `PartialOrd` bound.
If this PR and/or rust-lang/rust#155114 merges after the 1.98.0 beta branch promotion from the main branch, then this will need a beta backport, since this PR changes the stable guarantee previously made in rust-lang/rust#155421.
This PR conflicts with and/or blocks rust-lang/rust#155114.
rustc_target: Add ARMv8-M related target features
This adds the following unstable target features to `feature(arm_target_feature)` (tracking issue: https://github.com/rust-lang/rust/issues/150246):
- `acquire-release`: Armv8 atomic instructions
- `v6m`: Armv6-M instructions (implies `v6`)
- `v8m`: Armv8-M baseline instructions (implies `v6m`)
- `v8m.main`: Armv8-M mainline instructions (implies `v7`)
- `v8.1m.main`: Armv8.1-M mainline instructions (implies `v8m.main`)
- `mve`: M-Profile Vector Extension (Helium) for integer ops (implies `v8.1m.main`, `dsp`, and `fpregs`)
- `mve.fp`: MVE for integer & float ops (implies `mve`)
The target feature names match with [definitions in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-22.1.8/llvm/lib/Target/ARM/ARMFeatures.td#L597-L741). The dependencies should also match those in LLVM, unless there is no corresponding feature in Rust.
This also adds `mve` to vector ABI check and resolve this comment.
973ad0d0ab/compiler/rustc_target/src/target_features.rs (L1076-L1078)
One of the motivations for adding this: In LLVM, the `v8` target feature is not enabled for ARMv8-M targets, and `v8m`/`v8m.main` is enabled instead, so currently there is no way to detect ARMv8-M from target features.
```console
$ rustc +nightly --print cfg --target thumbv8m.main-none-eabihf | grep target_feature
target_feature="fpregs"
target_feature="mclass"
target_feature="thumb-mode"
target_feature="thumb2"
target_feature="v5te"
target_feature="v6"
target_feature="v6k"
target_feature="v6t2"
target_feature="v7"
```
r? @davidtwco
cc @jonathanpallant
@rustbot label +O-arm +A-target-feature
Expose debug scope of statement and terminator in rustc_public
Currently, `scope` is exposed for variables, but it is a meaningless number since the boundary of each scope is not available. This PR changes `span` fields of statement and terminator to `source_info` which includes scope as well.
Disclaimer: Written by LLM
Better error message when bare type in impl parameter list
Fixesrust-lang/rust#147889
Marking this PR ready for feedback on this problem.
The approach I'm trying is to create a snapshot parser and attempt to re-parse the input in another way. If it succeeds, we successfully predicted the user's intention and emit the related help message. If it fails, we cancel the errors produced during the attempt and report the original error.
The problem is that parse functions may internally recover from parse failures and emit errors directly, which means we can't cancel them later. I saw that we have a `recovery` field to control the recovery mechanism, but it seems there are (maybe) a lot of places in the parser that don't check the recovery field before doing their recovery logic.
Should we always use `look_ahead` instead of using a snapshot parser and calling another parse function?
Update POSIX edition links
Comments that reference https://pubs.opengroup.org point to issue 7 (the 2018 edition of IEEE Std 1003.1-2017), with one link still on the older issue 6. The latest issue is 8 (the 2024 edition, IEEE Std 1003.1-2024). From https://www.opengroup.org/austin/papers/posix_faq.html:
> Q3. What is the latest version of POSIX.1?
>
> The 1003.1-2024 standard was published in June 2024. The standard is
> formally known as: IEEE Std 1003.1-2024 The Open Group Technical
> Standard Base Specifications, Issue 8
Issue 8 lives at https://pubs.opengroup.org/onlinepubs/9799919799/.
This PR points all older-edition links to issue 8.
Most links are a straight edition bump, but links with a section anchor needed their anchor rechecked, because section numbering shifts between editions. Verified against the 2024 edition:
- Pathname Resolution moved from 4.13 (`tag_04_13`) to 4.16 (`tag_04_16`)
- Field Splitting moved from `tag_18_06_05` to `tag_19_06_05`
- LC_CTYPE (`tag_07_03_01`) was unchanged
The Miri changes (`src/tools/miri/`) are kept in a separate commit since that's a synced subtree. I'm happy to move them to a `rust-lang/miri` PR if preferred.
consider subtyping when checking if an infer var is sized
That is, when checking if an inference variable (say `?0`) is sized, with this PR, we now check for obligations like `?1: Sized`, where `?0` and `?1` are transitively related via subtyping (previously we were checking for `?0 = ?1`). This is sound because subtyping cannot change sized-ness.
This fixes the 4-th point/issue from https://github.com/rust-lang/rust/issues/155924. Specifically, it makes this code compile:
```rust
fn blah(e: !) {
let source = Box::new(e);
let _: Box<dyn Send> = source;
}
```
This also fixes `tests/ui/impl-trait/unsized_coercion.rs` on new solver, see https://github.com/rust-lang/rust/pull/157820#discussion_r3420501603.
r? types