Skip to content

Rollup of 9 pull requests #142929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jun 24, 2025
Merged

Rollup of 9 pull requests #142929

merged 30 commits into from
Jun 24, 2025

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Jun 23, 2025

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

Ayush1325 and others added 30 commits June 6, 2025 10:14
Some UEFI systems based on American Megatrends Inc. v3.3 do not provide
RNG support [1]. So fallback to rdrand in such cases.

[1]: rust-lang#138252 (comment)

Signed-off-by: Ayush Singh <[email protected]>
…oes.

Add a doctest with a non-empty-by-default iterator.
We modify rustc_ast_lowering to prevent all unsupported ABIs
from leaking through the HIR without being checked for target support.
Previously ad-hoc checking on various HIR items required making sure
we check every HIR item which could contain an `extern "{abi}"` string.
This is a losing proposition compared to gating the lowering itself.

As a consequence, unsupported ABI strings will now hard-error instead of
triggering the FCW `unsupported_fn_ptr_calling_conventions`.
This FCW was upgraded to warn in dependencies in Rust 1.87 which was
released on 2025 May 17, and it is now 2025 June, so it has become
active within a stable Rust version.

As we already had errored on these ABIs in most other positions, and
have warned for fn ptrs, this breakage has had reasonable foreshadowing.

However, this does cause errors for usages of `extern "{abi}"` that were
theoretically writeable within source but could not actually be applied
in any useful way by Rust programmers without either warning or error.
For instance, trait declarations without impls were never checked.
These are the exact kinds of leakages that this new approach prevents.

A deprecation cycle is not useful for these marginal cases as upon impl,
even default impls within traits, different HIR objects would be used.
Details of our HIR analysis meant that those objects did get checked.

We choose to error twice if an ABI is also barred by a feature gate
on the presumption that usage of a target-incorrect ABI is intentional.

Co-authored-by: Ralf Jung <[email protected]>
We have fairly different error messages now and handle more cases,
so we augment the test in tests/ui/abi/unsupported.rs with more examples
to handle structs, traits, and impls on same when those feature
the unsupported ABIs of interest.
Signed-off-by: Jonathan Brouwer <[email protected]>
the minimum function alignment was skipped on functions without attributes. That is because in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes
Change `core::iter::Fuse`'s `Default` impl to do what its docs say it does

The [docs on `impl<I: Default> Default for core::iter::Fuse<I>`](https://doc.rust-lang.org/nightly/std/iter/struct.Fuse.html#impl-Default-for-Fuse%3CI%3E) say (as the `I: Default` bound implies) that `Fuse::<I>::default` "Creates a `Fuse` iterator from the default value of `I`". However, the implementation creates a `Fuse` with `Fuse { iter: Default::default() }`, and since the `iter` field is an `Option<I>`, this is actually `Fuse { iter: None }`, not `Fuse { iter: Some(I::default()) }`, so `Fuse::<I>::default()` always returns an empty iterator, even if `I::default()` would not be empty.

This PR changes `Fuse`'s `Default` implementation to match the documentation. This will be a behavior change for anyone currently using `Fuse::<I>::default()` where `I::default()` is not an empty iterator[^1], as `Fuse::<I>::default()` will now also not be an empty iterator.

(Alternately, the docs could be updated to reflect what the current implementation actually does, i.e. returns an always-exhausted iterator that never yields any items (even if `I::default()` would have yielded items). With this option, the `I: Default` bound could also be removed to reflect that no `I` is ever created.)

[Current behavior example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a1e0adc4badca3dc11bfb70a99213249) (maybe an example like this should be added to the docs either way?)

This PR changes publicly observable behavior, so I think requires at least a T-libs-api FCP?

r? libs-api

cc rust-lang#140961

`impl<I: Default> Default for Fuse<I>` was added in 1.70.0 (rust-lang#99929), and it's docs and behavior do not appear to have changed since (`Fuse`'s `iter` field has been an `Option` since before the impl was added).

[^1]: IIUC it is a "de facto" guideline for the stdlib that an iterator type's `default()` should be empty (and for iterators where that would not make sense, they should not implement `Default`): cc rust-lang/libs-team#77 (comment) , so for stdlib iterators, I don't think this would change anything. However, if a user has a custom `Iterator` type `I`, *and* they are using `Fuse<I>`, *and* they call `Fuse::<I>::default()`, this may change the behavior of their code.
…boet

std: sys: random: uefi: Provide rdrand based fallback

Some UEFI systems based on American Megatrends Inc. v3.3 do not provide RNG support [1]. So fallback to rdrand in such cases.

[1]: rust-lang#138252 (comment)

Fixes rust-lang#138252

cc `@seijikun`
…abi, r=jdonszelmann,RalfJung

Reject unsupported `extern "{abi}"`s consistently in all positions

Modify the handling of `extern "{abi}"` in the compiler so that it has consistent errors without regard to the position in the grammar.

## What

Implement the following breakages:
- Promote [`unsupported_fn_ptr_calling_conventions`] from a warning to a hard error
- Guarantee future edge-cases like trait declarations will not escape so that *ABIs that have already been unusable in most positions* will now be unusable in **all positions**. See "How" and "Why or Why Not" for more details.

In particular, these architecture-specific ABIs now only compile on their architectures[^4]:
  - amdgpu: "gpu-kernel"
  - arm: "aapcs", "C-cmse-nonsecure-entry", "C-cmse-nonsecure-call"
  - avr: "avr-interrupt", "avr-non-blocking-interrupt"
  - msp430: "msp430-interrupt"
  - nvptx64: "gpu-kernel", "ptx-kernel"
  - riscv32 and riscv64: "riscv-interrupt-m", "riscv-interrupt-s"
  - x86: "thiscall"
  - x86 and x86_64: "x86-interrupt"
  - x86_64: "sysv64", "win64"

ABIs that are logically x86-specific but actually permitted on all Windows targets remain permitted on Windows, as before. For non-Windows targets, they error if we had previously done so in other positions.

## How

We modify rustc_ast_lowering to prevent unsupported ABIs from leaking through the HIR without being checked for target support. They now emit hard errors for every case where we would return `Invalid` from `AbiMap::canonize_abi`. Previously ad-hoc checking on various HIR items required making sure we check every HIR item which could contain an `extern "{abi}"` string. This is a losing proposition compared to gating the lowering itself.

As a consequence, unsupported ABI strings error instead of triggering the warning `unsupported_fn_ptr_calling_conventions`. The code is also simpler compared to alternative implementations that might e.g. split on unstable vs. stable, only suffering some unavoidable complication to support the newly-revived `unsupported_calling_conventions` lint.[^5]

However, per rust-lang#86232 this does cause errors for rare usages of `extern "{abi}"` that were theoretically possible to write in Rust source, without previous warning or error. For instance, trait declarations without impls were never checked. These are the exact kinds of leakages that this new approach prevents.

This differs from the following PRs:
- rust-lang#141435 is orthogonal, as it adds a new lint for ABIs we have not warned on and are not touched by this PR
- rust-lang#141877 is subsumed by this, in that this simply cuts out bad functionality instead of adding epicycles for stable code

## Why or Why Not

We already made the decision to issue the `unsupported_fn_ptr_calling_conventions` future compatibility warning. It has warned in dependencies since rust-lang#135767, which reached stable with Rust 1.87. That was released on 2025 May 17, and it is now June. As we already had erred on these ABI strings in most other positions, and warn on stable for function pointer types, this breakage has had reasonable foreshadowing.

Upgrading the warning to an error addresses a real problem. In some cases the Rust compiler can attempt to actually compute the ABI for calling a function with an unsupported ABI. We could accept this case and compute unsupported ABIs according to some other ABI, silently[^6]. However, this obviously exposes Rust to errors in codegen. We cannot lower directly to the "obvious", target-incorrect ABI and then trust code generators like LLVM to reliably error on these cases, either.

Other considerations include:
- We could refactor the compiler to defer ABI computations, but that seems like it would suffer the "whack-a-mole" problem close to linking instead of after parsing and expansion.
- We could run a deprecation cycle for the edge cases, but we would be warning highly marginal cases, like this trait declaration without a definition that cannot be implemented without error[^9].
```rust
pub trait UsedToSneakBy {
    pub extern "gpu-kernel" fn sneaky();
}
```
- The [crater run] on this PR's draft form suggests the primary issue is with implementations on function pointers, which has already been warned on, so it does not seem like we would be benefiting any real code.
- Converting this to a hard error now, in the same cycle that we ship the reanimation of the `unsupported_calling_conventions` lint, means people who would otherwise have to deal with two lints only have to update their code in one batch. Of course, one of them is as breakage.

r? lang

Fixes rust-lang#86232
Fixes rust-lang#132430
Fixes rust-lang#138738
Fixes rust-lang#142107

[`unsupported_fn_ptr_calling_conventions`]: rust-lang#130260
[crater run]: rust-lang#142134 (comment)
[^9]: Upon any impl, even for provided fn within trait declarations, e.g. `pub extern "gpu-kernel" fn sneaky() {}`, different HIR types were used which would, in fact, get checked. Likewise for anything with function pointers. Thus we would be discussing deprecation cycles for code that is impotent or forewarned[^7].
[^4]: Some already will not compile, due to reaching ICEs or LLVM errors.
[^5]: That lint cannot be moved in a similar way yet because lints operate on HIR, so you cannot emit lints when the HIR has not been completely formed.
[^6]:  We already do this for all `AbiStr` we cannot parse, pretending they are `ExternAbi::Rust`, but we also emit an error to prevent reaching too far into codegen.
[^7]: It actually did appear in two cases in rustc's test suite because we are a collection of Rust edge-cases by the simple fact that we don't care if the code actually runs. These cases are being excised in 643a9d2
Add codegen timing section

And since we now start and end the sections also using separate functions, also add some light checking if we're generating the sections correctly.

I'm integrating `--timings` into Cargo, and I realized that the codegen timings would be quite useful for that. Frontend can be computed simply as `[start of compilation, start of codegen]` for now.

r? `@nnethercote`
…oval, r=Kobzol

Move error code explanation removal check into tidy

Follow-up of rust-lang#142677.

This PR replaces a shell script with rust code.

r? ghost
Don't suggest changing a  method inside a expansion

Fixes rust-lang#139830
r? compiler
Fix install-template.sh for Solaris tr

Allow to run install.sh also on Solaris where tr is not GNU tr.
…t, r=jdonszelmann

Fix comment on NoMangle

Fix comment on NoMangle.
This was discussed in comments of rust-lang#142823 (comment) and rust-lang#142921
…no-attributes, r=workingjubilee

fix `-Zmin-function-alignment` on functions without attributes

tracking issue: rust-lang#82232
related: rust-lang#142854

The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes.

r? `@workingjubilee`
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Jun 23, 2025
@workingjubilee
Copy link
Member Author

@bors rollup=never r+ p=5

@bors
Copy link
Collaborator

bors commented Jun 23, 2025

📌 Commit b7a9cd8 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 23, 2025
@bors
Copy link
Collaborator

bors commented Jun 24, 2025

⌛ Testing commit b7a9cd8 with merge 99b18d6...

@bors
Copy link
Collaborator

bors commented Jun 24, 2025

☀️ Test successful - checks-actions
Approved by: workingjubilee
Pushing 99b18d6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 24, 2025
@bors bors merged commit 99b18d6 into rust-lang:master Jun 24, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 24, 2025
@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#140985 Change core::iter::Fuse's Default impl to do what its d… a1f6564261683ea21b39b53e1b2f245f39188f17 (link)
#141324 std: sys: random: uefi: Provide rdrand based fallback 806f96117d2406ed1d94c5a10c82137784dd2d11 (link)
#142134 Reject unsupported extern "{abi}"s consistently in all po… b3eccef72ff3736322b4453785f4658afcdd7611 (link)
#142784 Add codegen timing section c33ae7a8819af26c8a8f22193ac0c895f4623d92 (link)
#142827 Move error code explanation removal check into tidy 46b2b45cc8b2dece0433488261775706043c60ec (link)
#142873 Don't suggest changing a method inside a expansion 02e2ed91f1ee40bcb2b8fce8360ea27f1cb54964 (link)
#142908 Fix install-template.sh for Solaris tr f9e7a0b418cc768a104cc0a744ac5cbd0416ea7c (link)
#142922 Fix comment on NoMangle 688c6ad7e9a4e396620c8ddfff36c36aeed02922 (link)
#142923 fix -Zmin-function-alignment on functions without attribu… a3a27b8105e5675e67f2afc2fd4532a7633c2621 (link)

previous master: 706f244db5

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 706f244 (parent) -> 99b18d6 (this PR)

Test differences

Show 287 test diffs

Stage 1

  • [crashes] tests/crashes/132430.rs: pass -> [missing] (J1)
  • [crashes] tests/crashes/138738.rs: pass -> [missing] (J1)
  • [ui] tests/ui/abi/unsupported-abi-transmute.rs: [missing] -> pass (J1)
  • [ui] tests/ui/abi/unsupported-varargs-fnptr.rs: [missing] -> pass (J1)
  • [ui] tests/ui/macros/missing-writer-issue-139830.rs: [missing] -> pass (J1)

Stage 2

  • [crashes] tests/crashes/132430.rs: pass -> [missing] (J0)
  • [crashes] tests/crashes/138738.rs: ignore (only executed when the architecture is x86_64) -> [missing] (J2)
  • [ui] tests/ui/abi/unsupported-varargs-fnptr.rs: [missing] -> pass (J3)
  • [crashes] tests/crashes/138738.rs: pass -> [missing] (J4)
  • [ui] tests/ui/abi/unsupported-varargs-fnptr.rs: [missing] -> ignore (only executed when the architecture is x86_64) (J5)
  • [ui] tests/ui/abi/unsupported-abi-transmute.rs: [missing] -> pass (J6)
  • [ui] tests/ui/macros/missing-writer-issue-139830.rs: [missing] -> pass (J6)

Additionally, 275 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 99b18d6c5062449db8e7ccded4cb69b555a239c3 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-x86_64-apple: 11631.9s -> 8093.5s (-30.4%)
  2. aarch64-apple: 3917.0s -> 4982.2s (27.2%)
  3. x86_64-gnu-miri: 4619.3s -> 5870.3s (27.1%)
  4. x86_64-apple-1: 6583.5s -> 7706.1s (17.1%)
  5. mingw-check-1: 1523.8s -> 1740.0s (14.2%)
  6. i686-gnu-1: 7213.0s -> 8029.4s (11.3%)
  7. x86_64-apple-2: 4938.9s -> 4402.0s (-10.9%)
  8. mingw-check-2: 1854.9s -> 2055.3s (10.8%)
  9. i686-gnu-2: 5511.3s -> 6019.1s (9.2%)
  10. x86_64-gnu-llvm-19-1: 3307.4s -> 3607.8s (9.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` A-testsuite Area: The testsuite used to check the correctness of rustc A-tidy Area: The tidy tool merged-by-bors This PR was explicitly merged by bors. rollup A PR which is a rollup S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.