Commit Graph

49486 Commits

Author SHA1 Message Date
Samuel Tardieu
202d1f5bf4 Rollup merge of #144675 - jieyouxu:compiletest-staging, r=Kobzol
Reject running `compiletest` self-tests against stage 0 rustc unless explicitly allowed

Currently, in `pr-check-1`, we run `python3 ../x.py test --stage 0 src/tools/compiletest`, which is `compiletest` self-tests against stage 0 rustc. This makes it very annoying for PRs wanting to change target spec JSON format, which `compiletest` depends on for target information, as otherwise `compiletest` would have to know how to handle 2 different target spec JSON formats and know when to pick which.

Instead of doing that, we change `compiletest` self-tests to reject running against stage 0 `rustc` *unless* explicitly allowed with `build.compiletest-allow-stage0=true`. `build.compiletest-allow-stage0` is a proper bootstrap config option in favor of the ad-hoc `COMPILETEST_FORCE_STAGE0` env var. This means that:

- `./x test src/tools/compiletest --stage=0` is not allowed, unless `build.compiletest-allow-stage0=true` is set. In this scenario, `compiletest` self-tests should be expected to fail unless the stage 0 `rustc` as provided is like codegen_cranelift where it's *actually* built from in-tree `rustc` sources.
- In CI, we change `./x test src/tools/compiletest --stage=0` to `./x test src/tools/compiletest --stage=1`, and move it to `pr-check-2`. Yes, this involves building the stage 1 compiler, but `pr-check-2` already has to build stage 1 compiler to test stage 1 library crates.
- Crucially, this means that **`compiletest` is only intended to support one target spec JSON format**, namely the one corresponding to the in-tree `rustc`.
- This should preserve the `compiletest-use-stage0-libtest` UX optimization where changing `compiler/` tree should still not require rebuilding `compiletest` as long as `build.compiletest-use-stage0-libtest=true`, as that should remain orthogonal. This is completely unlike my previous attempt at https://github.com/rust-lang/rust/pull/144563 that tries to do a way more invasive change which would cause the rebuild problem.

Best reviewed commit-by-commit.

---

r? `@Kobzol`
2025-07-30 19:49:03 +02:00
Samuel Tardieu
175121903a Rollup merge of #144655 - jdonszelmann:cleanup-codegen-fn-attrs, r=WaffleLapkin
clean up codegen fn attrs

This honestly had become a mess over time and needed some love. No behavior should've changed, and I effectively just moved code around. Though, I can't promise there weren't any bugs in the original code with how randomly it was organised.....

r? `@WaffleLapkin`
2025-07-30 19:49:02 +02:00
Samuel Tardieu
b38ece9021 Rollup merge of #143465 - kornelski:extern-name, r=petrochenkov
Support multiple crate versions in --extern-html-root-url

Rustdoc's `--extern-html-root-url` used to use `tcx.crate_name()` to identify crates, but that used crates' internal names from their metadata, instead of names given to them in `--extern`. That was confusing, because both `--extern…` arguments seem related and use similar syntax. Crucially, this didn't work correctly with Cargo's package aliases or multiple versions of crates.

`sess.opts.externs` lacks `CrateNum`, and `Resolver.extern_prelude` gets destroyed before `rustdoc` has a chance to see it, so I've had to save this mapping in `CStore`.

Just in case, I've kept the previous mapping by crate name as a fallback for crates that weren't matched by their extern name.

Fixes rust-lang/rust#76296
2025-07-30 19:49:01 +02:00
Michael Goulet
2ae048e1df Distinguish appending and replacing self ty in predicates 2025-07-30 17:48:27 +00:00
Jana Dönszelmann
3fe0e24356 only extract lang items once 2025-07-30 16:44:16 +02:00
Jana Dönszelmann
1d589c87be clean up codegen fn attrs 2025-07-30 16:39:16 +02:00
lcnr
2b065e7c0b extend comment 2025-07-30 14:30:57 +02:00
lcnr
df2e54376c add comment and opaque type fixme 2025-07-30 14:01:37 +02:00
lcnr
b6cbe33aeb handle region dependent goals due to infer vars 2025-07-30 14:01:37 +02:00
Jieyou Xu
a7fcc738c9 Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
Stuart Cook
08e26fc678 Rollup merge of #144666 - compiler-errors:correct-late, r=lqd
Make sure to account for the right item universal regions in borrowck

Fixes https://github.com/rust-lang/rust/issues/144608.

The ICE comes from a mismatch between the liberated late bound regions (i.e. "`ReLateParam`"s) that come from promoting closure outlives, and the regions we have in our region vid mapping from `UniversalRegions`.

When building `UniversalRegions`, we end up using the liberated regions from the binder of the closure's signature:

c8bb4e8a12/compiler/rustc_borrowck/src/universal_regions.rs (L521)

Notably, this signature may be anonymized if the closure signature being deduced comes from an external constraints:

c8bb4e8a12/compiler/rustc_hir_typeck/src/closure.rs (L759-L762)

This is true in the test file I committed, where the signature is influenced by the `impl FnMut(&mut ())` RPIT.

However, when promoting a type outlives constraint we end up creating a late bound lifetime mapping that disagrees with those liberated late bound regions we constructed in `UniversalRegions`:

c8bb4e8a12/compiler/rustc_borrowck/src/universal_regions.rs (L299)

Specifically, in `for_each_late_bound_region_in_item` (which is called by `for_each_late_bound_region_in_recursive_scope`), we were using `tcx.late_bound_vars` which uses the late bound regions *from the HIR*. This query both undercounts the late bound regions (e.g. those that end up being deduced from bounds), and also doesn't account for the fact that we anonymize them in the signature as mentioned above.

c8bb4e8a12/compiler/rustc_borrowck/src/universal_regions.rs (L977)

This PR fixes that function to use the *correct signature*, which properly considers the bound vars that come from deducing the signature of the closure, and which comes from the closure's args from the `type_of` query.
2025-07-30 17:59:40 +10:00
Stuart Cook
02a68e42fd Rollup merge of #144268 - xizheyin:find-oldest-ancestor, r=jieyouxu
Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`

As I was using it, I realized that the function is supposed to walk up to expand the chain? This seems to be the opposite of what I understood.

r? `@jieyouxu`
2025-07-30 17:59:38 +10:00
Ralf Jung
ba5b6b9ec4 const-eval: full support for pointer fragments 2025-07-30 08:13:58 +02:00
Michael Goulet
98d08ff014 Make sure to account for the right item universal regions in borrowck 2025-07-30 04:07:19 +00:00
Scott McMurray
fe08ba0bae Re-block SRoA on SIMD types
Fixes 144621
2025-07-29 20:41:34 -07:00
Zalathar
2e6f4a5922 coverage: Re-land "Enlarge empty spans during MIR instrumentation"
This allows us to assume that coverage spans will only be discarded during
codegen in very unusual situations.
2025-07-30 13:17:05 +10:00
bors
919c409243 Auto merge of #144577 - oli-obk:wrapping-niche, r=scottmcm
Pick the largest niche even if the largest niche is wrapped around

fixes rust-lang/rust#144388

r? `@scottmcm`
2025-07-30 02:57:04 +00:00
Jacob Pratt
72f4ff2c45 Rollup merge of #144640 - FractalFir:m68k_arch, r=Urgau
Add support for the m68k architecture in 'object_architecture'

This is a tiny PR that adds the m68k architecture to `object_architecture`. This allows us to build rmeta files for that ISA(we use the object crate to pack metadata into object files).
2025-07-29 18:55:22 -04:00
Jacob Pratt
0912d66c7f Rollup merge of #144605 - LorrensP-2158466:cache-extern-prelude, r=petrochenkov
Resolve: cachify `ExternPreludeEntry.binding` through a `Cell`

Provides interior mutability to the `binding` field of `ExternPreludeEntry` as this field behaves like a cache. Per [zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/531390914).

A little preparatory work for batched import resolution, which is part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion).

r? `@petrochenkov`
2025-07-29 18:55:20 -04:00
bors
686bc1c5f9 Auto merge of #144557 - cjgillot:lower-more-span, r=compiler-errors
Complete span AST lowering.

r? `@ghost`
2025-07-29 17:39:48 +00:00
Oli Scherer
219bad4946 Reuse sign_extend helper 2025-07-29 14:17:48 +00:00
Oli Scherer
75bdbf25e3 Pick the largest niche even if the largest niche is wrapped around 2025-07-29 14:08:15 +00:00
Stuart Cook
9bb4087320 Rollup merge of #144615 - cjgillot:fn-sig-rib, r=petrochenkov
Make resolve_fn_signature responsible for its own rib.

Small simplification in late resolver rib bookkeeping.

r? `@petrochenkov`
2025-07-29 23:50:37 +10:00
Stuart Cook
b76cb79e79 Rollup merge of #144589 - compiler-errors:postfix-yield-after-cast, r=petrochenkov
Account for `.yield` in illegal postfix operator message

Fixes rust-lang/rust#144527
2025-07-29 23:50:37 +10:00
Stuart Cook
3d5e2fad1c Rollup merge of #144587 - petrochenkov:optstdprel, r=nnethercote
expand: Micro-optimize prelude injection

Use `splice` to avoid shifting the other items twice.
Put `extern crate std;` first so it's already resolved when we resolve `::std::prelude::rust_20XX`.
2025-07-29 23:50:36 +10:00
Stuart Cook
826c462c32 Rollup merge of #144566 - scottmcm:align-of-slice, r=oli-obk
Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`

I spotted this while working on the inliner (rust-lang/rust#144561).  In particular, if [`Layout::for_value`](https://doc.rust-lang.org/std/alloc/struct.Layout.html#method.for_value) inlines, then it can be pretty easy to end up with an `align_of_val::<[T]>` today (demo: <https://rust.godbolt.org/z/Tesnscj4a>) where we can save at least a block, if not more, by using the version that's an rvalue and not a call.
2025-07-29 23:50:35 +10:00
Stuart Cook
f8370285cf Rollup merge of #144560 - Zalathar:auto-derived, r=compiler-errors
coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`

One of the contributing factors behind https://github.com/rust-lang/rust/issues/141577#issuecomment-3120667286 was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with `#[automatically_derived]` (rust-lang/rust#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for `#[coverage(..)]` attributes to also treat `#[automatically_derived]` as an implied `#[coverage(off)]` for the purposes of coverage instrumentation.

---

This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.
2025-07-29 23:50:35 +10:00
LorrensP-2158466
c39b4479ce "Cachify" ExternPreludeEntry.binding through a Cell. 2025-07-29 15:47:32 +02:00
FractalFir
652b9eb98b Add support for the m68k architecture in 'object_architecture' 2025-07-29 12:42:48 +02:00
Stuart Cook
f5c573662e Rollup merge of #144626 - RalfJung:cc-pin-comment, r=lqd
cc dependencies: clarify comment

This caused confusion in https://github.com/rust-lang/rust/pull/144570

r? ``@jieyouxu``
2025-07-29 20:19:54 +10:00
Stuart Cook
15ddf9c7b3 Rollup merge of #144609 - Muscraft:right-align, r=compiler-errors
feat: Right align line numbers

As part of my work on getting `annotate-snipptes` to be used as `rustc`'s renderer, I realized that `rustc` left-aligned line numbers, while `annotate-snippets` right-aligned them. This PR switches `rustc` to right-align the line numbers, matching `annotate-snippets`. In practice, this change isn't very noticeable in day-to-day output, as it only shows up when a diagnostic span contains line numbers with different lengths (9->10, 99->100, 999->1000, etc.).

`rustc`
```
error[E0412]: cannot find type `F` in this scope
  --> $DIR/ui-testing-optout.rs:92:10
   |
4  | type A = B;
   | ----------- similarly named type alias `A` defined here
...
92 | type E = F;
   |          ^ help: a type alias with a similar name exists: `A`
```
`annotate-snippets`
```
error[E0412]: cannot find type `F` in this scope
  --> $DIR/ui-testing-optout.rs:92:10
   |
 4 | type A = B;
   | ----------- similarly named type alias `A` defined here
...
92 | type E = F;
   |          ^ help: a type alias with a similar name exists: `A`
```

r? ``@compiler-errors``
2025-07-29 20:19:53 +10:00
Stuart Cook
dbcf168568 Rollup merge of #144451 - ShoyuVanilla:loop-match-upvar, r=oli-obk
fix: Reject upvar scrutinees for `loop_match`

Fixes https://github.com/rust-lang/rust/issues/144051

I think we should reject upvars as they are not locals but somewhat like field access
2025-07-29 20:19:49 +10:00
Stuart Cook
b3962e8811 Rollup merge of #144407 - godzie44:godzie44/fix_dwarf_inconsistency, r=wesleywiser
fix(debuginfo): disable overflow check for recursive non-enum types

Commit b10edb4 introduce an overflow check when generating debuginfo for expanding recursive types. While this check works correctly for enums, it can incorrectly prune valid debug information for structures.

For example see rust-lang/rust#143241 (https://github.com/rust-lang/rust/issues/143241#issuecomment-3073721477). Furthermore, for structures such check does not make sense, since structures with recursively expanding types simply will not compile (there is a `hir_analysis_recursive_generic_parameter` for that).

closes rust-lang/rust#143241
2025-07-29 20:19:49 +10:00
Zalathar
682f744f89 coverage: Treat #[automatically_derived] as #[coverage(off)] 2025-07-29 19:56:31 +10:00
Zalathar
b4d0c91635 coverage: Rename CoverageStatus to CoverageAttrKind
This patch also prepares the affected code in `coverage_attr_on` for some
subsequent changes.
2025-07-29 19:55:54 +10:00
lcnr
64a27c2e37 resuse eagerly resolved goal from previous iteration 2025-07-29 09:47:10 +00:00
Ralf Jung
e532080507 cc dependencies: clarify comment 2025-07-29 09:22:24 +02:00
xizheyin
81176b1a6c Create two methods to fix find_oldest_ancestor_in_same_ctxt
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-29 14:54:47 +08:00
Scott McMurray
8ef9233339 Simplify align_of_val::<[T]>(…)align_of::<T>() 2025-07-28 23:19:06 -07:00
Stuart Cook
e08a308561 Rollup merge of #144578 - FractalFir:m68k_fix, r=compiler-errors
Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.

The compiler relies on `hir::Lifetime` being aligned to at least 4 bytes(for the purposes of pointer tagging).

However, on some systems(like m68k) with lower alignment requirements(eg. usize / u32 aligned to 2 bytes),`hir::Lifetime` will be aligned to only 2 bytes.

This causes the compilation to fail on those systems - a const assert in the compiler fails.

This PR makes the aligement requriement of hir::Lifetime explict. This has no effect on platforms where that already is the case(repr align can only raise alignment), but ensures the alignment will stay correct no matter what.
2025-07-29 16:16:45 +10:00
Stuart Cook
fce74bacf3 Rollup merge of #144573 - BoxyUwU:patkind_constant_ptr_docs, r=lcnr
Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
2025-07-29 16:16:44 +10:00
bors
cb6785f73d Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Remove `[T]::array_chunks(_mut)`

Since libs-api is proposing as much in https://github.com/rust-lang/rust/issues/74985#issuecomment-3024465102

Closes rust-lang/rust#74985
Closes rust-lang/rust#76354

try-job: dist-various-1
try-job: dist-various-2
2025-07-29 02:27:52 +00:00
Camille GILLOT
be9d3bcfed Make resolve_fn_signature responsible for its own rib. 2025-07-29 00:33:21 +00:00
Scott Schafer
aa9767290e feat: Right align line numbers 2025-07-28 16:32:11 -06:00
Kornel
081b565478 Allow cargo fix to partially apply mismatched_lifetime_syntaxes 2025-07-28 20:03:05 +01:00
bors
e3514bde96 Auto merge of #144377 - camsteffen:simplify-impl-of-method, r=fee1-dead
Rename impl_of_method and trait_of_item

This PR used to tweak the implementation of impl_of_method, but that introduced a perf regression.

Rename impl_of_method and trait_of_item to impl_of_assoc and trait_of_assoc respectively. This reflects how the two functions are closely related. And it reflects the behavior more accurately as the functions check whether the input is an associated item.
2025-07-28 16:38:15 +00:00
Michael Goulet
2db97b2f7d Account for .yield in illegal postfix operator message 2025-07-28 16:09:59 +00:00
Cameron Steffen
cdcfdd1a1b Tweak docs 2025-07-28 09:54:55 -05:00
Cameron Steffen
b43164cef6 Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
Cameron Steffen
172af038a7 Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00