Rollup of 8 pull requests
Successful merges:
- rust-lang/rust#140153 (Implement `Debug` for `EncodeWide`)
- rust-lang/rust#145724 (the `#[track_caller]` shim should not inherit `#[no_mangle]`)
- rust-lang/rust#147258 (iter repeat: panic on last)
- rust-lang/rust#147454 (Fix backtraces with `-C panic=abort` on qnx; emit unwind tables by default)
- rust-lang/rust#147468 (Implement fs api set_times and set_times_nofollow)
- rust-lang/rust#147764 (Undo CopyForDeref assertion in const qualif)
- rust-lang/rust#147805 (use module_child index as disambiguator for external items)
- rust-lang/rust#147824 (docs: update Motor OS target docs)
r? `@ghost`
`@rustbot` modify labels: rollup
use module_child index as disambiguator for external items
When defining the items of an external module, if that item is an underscore we use it's index as the disambiguator. This is needed for parallel import resolution, which is being worked on in rust-lang/rust#145108.
r? `@petrochenkov`
Fix backtraces with `-C panic=abort` on qnx; emit unwind tables by default
While syncing https://github.com/rust-lang/rust/pull/143613 into Ferrocene as part of https://github.com/ferrocene/ferrocene/pull/1803, we noted a failure on our QNX targets:
```
---- [ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs stdout ----
error: test did not exit with success! code=Some(134) so test would pass with `run-crash`
status: exit status: 134
command: RUSTC="/home/ci/project/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUST_TEST_THREADS="1" "/home/ci/project/build/x86_64-unknown-linux-gnu/stage1-tools-bin/remote-test-client" "run" "0" "/home/ci/project/build/x86_64-unknown-linux-gnu/test/ui/panics/panic-abort-backtrace-without-debuginfo/a"
--- stdout -------------------------------
uploaded "/home/ci/project/build/x86_64-unknown-linux-gnu/test/ui/panics/panic-abort-backtrace-without-debuginfo/a", waiting for result
died due to signal 6
------------------------------------------
--- stderr -------------------------------
thread 'main' (1) panicked at /home/ci/project/tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs:39:9:
ERROR: no `this_function_must_be_in_the_backtrace` in stderr! actual stderr:
thread 'main' (1) panicked at /home/ci/project/tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs:27:5:
generate panic backtrace
stack backtrace:
0: 0x4e66a53643 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h55e010263b1e3169
1: 0x4e66a68cd2 - core::fmt::write::h0d6e2e8752abc333
2: 0x4e66a16919 - std::io::Write::write_fmt::h71c4c024d832b384
3: 0x4e66a1f8e2 - std::sys::backtrace::BacktraceLock::print::hdd80dfdf90bb7100
4: 0x4e66a221e0 - std::panicking::default_hook::{{closure}}::h77758f25a686500f
5: 0x4e66a21f69 - std::panicking::default_hook::ha63f7d476af6c267
6: 0x4e66a22999 - std::panicking::panic_with_hook::h3a36a8a0f0dd8ccd
7: 0x4e66a21cac - std::panicking::begin_panic::{{closure}}::h570dedb92e232392
8: 0x4e66a1fa69 - std::sys::backtrace::__rust_end_short_backtrace::h5366eec354f92733
9: 0x4e669f9589 - std::panicking::begin_panic::h04a4bd4c33dd4056
10: 0x4e66a00aca - panic_abort_backtrace_without_debuginfo::and_this_function_too::h5b034b94cbe9c3d3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------------------------------------------
---- [ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs stdout end ----
failures:
[ui] tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs
test result: FAILED. 19958 passed; 1 failed; 328 ignored; 0 measured; 0 filtered out; finished in 1827.71s
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-pc-nto-qnx710
Build completed unsuccessfully in 0:43:28
Exited with code exit status 1
```
This patch applies the same fix as the one found in https://github.com/rust-lang/rust/pull/143613 of adding the `default_uwtable: true` to the target.
I've run it locally, when https://github.com/ferrocene/ferrocene/pull/1803 merges we'll know it has passed within our CI, which is about a close an analog as I can offer to Rust.
the `#[track_caller]` shim should not inherit `#[no_mangle]`
fixes https://github.com/rust-lang/rust/issues/143162
builds on https://github.com/rust-lang/rust/pull/143293 which introduced a mechanism to strip attributes from shims.
cc `@Jules-Bertholet` `@workingjubilee` `@bjorn3`
---
Summary:
This PR fixes an interaction between `#[track_caller]`, `#[no_mangle]`, and casting to a function pointer.
A function annotated with `#[track_caller]` internally has a hidden extra argument for the panic location. The `#[track_caller]` attribute is only allowed on `extern "Rust"` functions. When a function is annotated with both `#[no_mangle]` and `#[track_caller]`, the exported symbol has the signature that includes the extra panic location argument. This works on stable rust today:
```rust
extern "Rust" {
#[track_caller]
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static>;
}
mod provides {
use std::panic::Location;
#[track_caller] // UB if we did not have this!
#[no_mangle]
fn rust_track_caller_ffi_test_tracked() -> &'static Location<'static> {
Location::caller()
}
}
```
When a `#[track_caller]` function is converted to a function pointer, a shim is added to drop the additional argument. So this is a valid program:
```rust
#[track_caller]
fn foo() {}
fn main() {
let f = foo as fn();
f();
}
```
The issue arises when `foo` is additionally annotated with `#[no_mangle]`, the generated shim currently inherits this attribute, also exporting a symbol named `foo`, but one without the hidden panic location argument. The linker rightfully complains about a duplicate symbol.
The solution of this PR is to have the generated shim drop the `#[no_mangle]` attribute.
Implement `Debug` for `EncodeWide`
Since `std::os::windows::ffi::EncodeWide` was reexported from `std::sys_common::wtf8::EncodeWide`, which has `#![allow(missing_debug_implementations)]` in the parent module, it did not implement `Debug`. When it was moved to `core`, a placeholder impl was added; fill it in.
This becomes insta-stable.
r? libs-api
mismatched_lifetime_syntax lint refactors and optimizations
I found several opportunities to return early so I'm hoping those will have a perf improvement. Otherwise, it's various refactors for simplicity.
Limit impl_trait_header query to only trait impls
Changes `impl_trait_header` to panic on inherent impls intstead of returning None. A few downstream functions are split into option and non-option returning functions. This gets rid of a lot of unwraps where we know we have a trait impl, while there are still some cases where the Option is helpful.
Summary of changes to tcx methods:
* `impl_is_of_trait` (new)
* `impl_trait_header` -> `impl_trait_header`/`impl_opt_trait_header`
* `impl_trait_ref` -> `impl_trait_ref`/`impl_opt_trait_ref`
* `trait_id_of_impl` -> `impl_trait_id`/`impl_opt_trait_id`
Pre-compute MIR CFG caches for borrowck and other analyses
I was puzzled that https://github.com/rust-lang/rust/pull/142390 introduces additional computations of CFG traversals: borrowck computes them, right?
It turns out that borrowck clones the MIR body, so doesn't share its cache with other analyses.
This PR:
- forces the computation of all caches in `mir_promoted` query;
- modifies region renumbering to avoid dropping that cache.
`is_ascii` on an empty string or slice returns true
Update the description of the [`is_ascii`](https://doc.rust-lang.org/std/primitive.str.html#method.is_ascii) functions - an empty string or slice also returns `true`.
This follows the pattern of [`all()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.all). Clippy currently suggests to change `string.chars().all(|c| c.is_ascii())` into `string.is_ascii()`. This suggestion therefore seems fitting.
I've already questioned the behavior for this multiple times. I've always had to check the internals to conclude how it works. That's why I'm opening this PR to add it directly in the documentation.
style-guide: fix typo for empty struct advice
the advice appears to apply to empty structs with braces (parens/blocks), and a unit struct in the comment does not make sense. Fix the typo.
Use `bit_set::Word` in a couple more places.
It's a synonym for `u64` and there are a couple of places where we use `u64` where we should use `Word`, which this commit fixes.
I found this when I tried changing `Word` to `u128` (which made performance worse).
r? `````@Zalathar`````
Fix ICE on offsetted ZST pointer
I'm not sure this is the *right* fix, but it's simple enough and does roughly what I'd expect. Like with the previous optimization to codegen usize rather than a zero-sized static, there's no guarantee that we continue returning a particular value from the offsetting.
A grep for `const_usize.*align` found the same code copied to rustc_codegen_gcc and cranelift but a quick skim didn't find other cases of similar 'optimization'. That said, I'm not convinced I caught everything, it's not trivial to search for this.
Closesrust-lang/rust#147516
std: Add Motor OS std library port
Motor OS was added as a no-std Tier-3 target in
[PR 146848](https://github.com/rust-lang/rust/pull/146848) as x86_64-unknown-motor.
This PR adds the std library for Motor OS.
While the PR may seem large, all it does is proxy
std pal calls to [moto-rt](https://crates.io/crates/moto-rt). Where there is some non-trivial
code (e.g. thread::spawn), it is quite similar, often
identical, to what other platforms do.
Guard HIR lowered contracts with `contract_checks`
Refactor contract HIR lowering to ensure no contract code is executed when contract-checks are disabled.
The call to `contract_checks` is moved to inside the lowered fn body, and contract closures are built conditionally, ensuring no side-effects present in contracts occur when those are disabled. This partially addresses rust-lang/rust#139548, i.e. the bad behavior no longer happens with contract checks disabled (`-Zcontract-checks=no`).
The change is made in preparation for adding contract variable declarations - variables declared before the `requires` assertion, and accessible from both `requires` and `ensures`, but not in the function body (PR rust-lang/rust#144444). As those declarations may also have side-effects, it's good to guard them with `contract_checks` - the new lowering approach allows for this to be done easily.
Contracts tracking issue: rust-lang/rust#128044
**Known limiatations**:
- It is still possible to early return from the *function* from within a contract, e.g.
```rust
#[ensures({if x > 0 { return 0 }; |_| true})]
fn foo(x: u32) -> i32 {
42
}
```
When `foo` is called with an argument greater than 0, instead of `42`, `0` will be returned.
As this is not a regression, it is not addressed in this PR. However, it may be worth revisiting later down the line, as users may expect a form of early return from *contract specifications*, and so returning from the entire *function* could cause confusion.
- ~Contracts are still not optimised out when disabled. Currently, even when contracts are disabled, the code generated causes existing optimisations to fail, meaning even disabled contracts could impact runtime performance. This issue is blocking rust-lang/rust#136578, and has not been addressed in this PR, i.e. the `mir-opt` and `codegen` tests that fail in rust-lang/rust#136578 still fail with these new HIR lowering changes.~ Contracts should now be optimised out when disabled, however some regressions tests still need to be added to be sure that is indeed the case.
It's a synonym for `u64` and there are a couple of places where we use
`u64` where we should use `Word`, which this commit fixes.
I found this when I tried changing `Word` to `u128` (which made
performance worse).
Rollup of 11 pull requests
Successful merges:
- rust-lang/rust#143191 (Stabilize `rwlock_downgrade` library feature)
- rust-lang/rust#147444 (Allow printing a fully-qualified path in `def_path_str`)
- rust-lang/rust#147527 (Update t-compiler beta nomination Zulip msg)
- rust-lang/rust#147670 (some `ErrorGuaranteed` cleanups)
- rust-lang/rust#147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes)
- rust-lang/rust#147708 (const `mem::drop`)
- rust-lang/rust#147710 (Fix ICE when using contracts on async functions)
- rust-lang/rust#147716 (Fix some comments)
- rust-lang/rust#147718 (miri: use allocator_shim_contents codegen helper)
- rust-lang/rust#147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius)
- rust-lang/rust#147742 (Revert unintentional whitespace changes to rustfmt-excluded file)
r? `@ghost`
`@rustbot` modify labels: rollup