Commit graph

43601 commits

Author SHA1 Message Date
Matthias Krüger
93b194516a
Rollup merge of #136640 - Zalathar:debuginfo-align-bits, r=compiler-errors
Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit

In #116096, function ZSTs were made to have debuginfo that gives them an alignment of “1”. But because alignment in LLVM debuginfo is denoted in *bits*, not bytes, this resulted in an alignment specification of 1 bit instead of 1 byte.

I don't know whether this has any practical consequences, but I noticed that a test started failing when I accidentally fixed the mistake while working on #136632, so I extracted the fix (and the test adjustment) to this PR.
2025-02-08 03:58:45 +01:00
Matthias Krüger
b4c4913abb
Rollup merge of #136664 - WaffleLapkin:un-map_or-true, r=compiler-errors
replace one `.map_or(true, ...)` with `.is_none_or(...)`

Randomly found while going through some of my old branches.
2025-02-07 18:26:29 +01:00
Matthias Krüger
7c0dff877f
Rollup merge of #136653 - dpaoliello:cleanllvm1, r=Zalathar
Remove dead code from rustc_codegen_llvm and the LLVM wrapper

First step to clean up the LLVM wrapper: remove existing dead code.

Split out of #135502

r? ``@Zalathar``
2025-02-07 18:26:28 +01:00
Matthias Krüger
7489e56e29
Rollup merge of #136598 - compiler-errors:unit-fallback, r=WaffleLapkin
Fix suggestion for `dependency_on_unit_never_type_fallback` involving closures + format args expansions

fixes #136562

r? wafflelapkin or reassign
2025-02-07 18:26:28 +01:00
Matthias Krüger
20f9e973d9
Rollup merge of #136577 - dianne:simple-pat-migration-simplification, r=Nadrieril
Pattern Migration 2024: try to suggest eliding redundant binding modifiers

This is based on #136475. Only the last commit is new.

This is a simpler, more restrictive alternative to #136496, meant to partially address #136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit.

Relevant tracking issue: #131414

``@rustbot`` label A-diagnostics A-patterns A-edition-2024

r? ``@Nadrieril``
2025-02-07 18:26:27 +01:00
Matthias Krüger
cbd44d7998
Rollup merge of #134367 - WaffleLapkin:trait_upcasting_as_a_treat, r=compiler-errors
Stabilize `feature(trait_upcasting)`

This feature was "done" for a while now, I think it's finally time to stabilize it! Stabilization report: https://github.com/rust-lang/rust/pull/134367#issuecomment-2545839841.
cc reference PR: https://github.com/rust-lang/reference/pull/1622.

Closes #65991 (tracking issue), closes #89460 (the lint is no longer future incompat).

r? compiler-errors
2025-02-07 18:26:25 +01:00
Matthias Krüger
0047263387
Rollup merge of #136644 - GuillaumeGomez:item-to-string, r=Urgau
Add `rustc_hir_pretty::item_to_string` function

Another one needed for rustdoc. :)

r? `@Urgau`
2025-02-07 12:02:02 +01:00
Matthias Krüger
5df99b0bd2
Rollup merge of #136627 - RalfJung:mir-validation-cfg-checker, r=compiler-errors
MIR validation: add comment explaining the limitations of CfgChecker

I hope this right but I am not sure.^^
Cc `@compiler-errors` `@lcnr` `@cjgillot` `@oli-obk`
2025-02-07 12:01:59 +01:00
Matthias Krüger
d84b499919
Rollup merge of #136565 - workingjubilee:fixup-abi-in-target, r=compiler-errors
compiler: Clean up weird `rustc_abi` reexports

Just general cleanup in `rustc_target` and `rustc_abi`. I was originally going to make a PR with a larger change that also fixed the last few crates and in doing so removed some clutter from `rustc_abi`, but wound up slightly stuck on it, then figured out how to fix it, and then got distracted by other things... so now I'm trying to figure out what I had figured out earlier.
2025-02-07 12:01:58 +01:00
Matthias Krüger
3ce7d9c638
Rollup merge of #136191 - klensy:const_a, r=compiler-errors
compiler: replace few consts arrays with statics to remove const dupes

Locally on `x86_64-pc-windows-msvc` -100kb for `rustc_driver.dll`
2025-02-07 12:01:57 +01:00
Matthias Krüger
1c794b908b
Rollup merge of #135973 - WaffleLapkin:tail-track-caller-fix, r=compiler-errors
fix tail call checks wrt `#[track_caller]`

Only check the caller + disallow caller having the attribute.

fixes #134336

r? `@compiler-errors`

<sub>apparently there were no tests for `#[track_caller]` before... ooops</sub>
2025-02-07 12:01:56 +01:00
bors
550e035a59 Auto merge of #136450 - compiler-errors:simplify-cast, r=saethlin
Don't reset cast kind without also updating the operand in `simplify_cast` in GVN

Consider this heavily elided segment of the pre-GVN example code that was committed as a test:

```rust
          let _4: *const ();
          let _5: *const [()];
          let mut _6: *const ();
          let _7: *mut ();
          let mut _8: *const [()];
          let mut _9: std::boxed::Box<()>;
          let mut _10: *const ();
          /* ... */
          // Deref a box
          _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
          _4 = copy _10;
          _6 = copy _4;
          // Inlined body of `slice::from_raw_parts`, to turn a unit pointer into a slice-of-unit pointer
          _5 = *const [()] from (copy _6, copy _11);
          _8 = copy _5;
          // Cast the raw slice-of-unit pointer back to a unit pointer
          _7 = copy _8 as *mut () (PtrToPtr);
```

A malformed optimization was changing `_7` (which casted the slice-of-unit ptr to a unit ptr) to:

```
          _7 = copy _5 as *mut () (Transmute);
```

...where `_8` was just replaced with `_5` bc of simple copy propagation, that part is not important... the CastKind changing to Transmute is the important part here.

In #133324, two new functionalities were implemented:
* Peeking through unsized -> sized PtrToPtr casts whose operand is `AggregateKind::RawPtr`, to turn it into PtrToPtr casts of the base of the aggregate. In this case, this allows us to see that the value of `_7` is just a ptr-to-ptr cast of `_6`.
* Folding a PtrToPtr cast of an operand which is a Transmute cast into just a single Transmute, which (theoretically) allows us to treat `_7` as a transmute into `*mut ()` of the base of the cast of `_10`, which is the place projection of `((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>)`.

However, when applying those two subsequent optimizations, we must *not* update the CastKind of the final cast *unless* we also update the operand of the cast, since the operand may no longer make sense with the updated CastKind.

In this case, this is problematic because the type of `_8` is `*const [()]`, but that operand in assignment statement of `_7` does *not* get turned into something like `((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>)` -- **in other words, `try_to_operand` fails** -- because GVN only turns value nodes into locals or consts, not projections of locals. So we fail to update the operand, but we still update the CastKind to Transmute, which means we now are transmuting types of different sizes (a wide pointer and a thin pointer).

r? `@scottmcm` or `@cjgillot`

Fixes #136361
Fixes #135997
2025-02-07 06:26:41 +00:00
Daniel Paoliello
2a6b27444a Remove dead code from rustc_codegen_llvm and the LLVM wrapper 2025-02-06 16:53:52 -08:00
Waffle Lapkin
491599569c
allow+update deref_into_dyn_supertrait
this commit makes `deref_into_dyn_supertrait` lint allow-by-default,
removes future incompatibility (we finally live in a broken world), and
changes the wording in the documentation.

previously documentation erroneously said that it lints against *usage*
of the deref impl, while it actually (since 104742) lints on the impl
itself (oooops, my oversight, should have updated it 2+ years ago...)
2025-02-06 23:44:24 +01:00
Waffle Lapkin
bc1d68e389
adjust a comment
We can't remove `TraitUpcasting` variant, since we need to use the index
in winnowing.
2025-02-06 23:44:24 +01:00
Waffle Lapkin
a970a0d77e
change deref_into_dyn_supertrait lint wording
(so that it doesn't talk about trait upcasting stabilization in the
future tense)
2025-02-06 23:30:23 +01:00
Waffle Lapkin
da9a85a1a6
stabilize feature(trait_upcasting) 2025-02-06 23:30:23 +01:00
Waffle Lapkin
d4914a7719
replace one .map_or(true, ...) with .is_none_or(...) 2025-02-06 23:15:41 +01:00
Matthias Krüger
79e5424e31
Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors
Couple of minor cleanups to the diagnostic infrastructure
2025-02-06 21:56:28 +01:00
Matthias Krüger
3eb1ef836e
Rollup merge of #136580 - bjorn3:miri_fixes, r=lqd
Couple of changes to run rustc in miri

This is not the full set of patches required to run rustc in miri, but it is the fast majority of the changes to rustc itself. There is also a change to the jobserver crate necessary and on arm64 a change to the memchr crate. Running rustc in miri has already found some UB: https://github.com/rust-lang/rust/pull/136579

cc https://github.com/rust-lang/rust/issues/135870#issuecomment-2612470540
2025-02-06 21:56:27 +01:00
Matthias Krüger
3e54c2eb75
Rollup merge of #136219 - yotamofek:pr/hir-cleanup, r=compiler-errors
Misc. `rustc_hir` cleanups 🧹

Each commit stands on its own, but I think all of them make the code a bit cleaner
2025-02-06 21:56:26 +01:00
Matthias Krüger
0fb72ee57c
Rollup merge of #136152 - Urgau:stabilize-map_many_mut, r=joshtriplett
Stabilize `map_many_mut` feature

This PR stabilize `HashMap::get_many_mut` as `HashMap::get_disjoint_mut` and `HashMap::get_many_unchecked_mut` as `HashMap::get_disjoint_unchecked_mut` per FCP.

FCP at https://github.com/rust-lang/rust/issues/97601#issuecomment-2532710423
Fixes #97601
r? libs
2025-02-06 21:56:26 +01:00
Matthias Krüger
ae1410e2d8
Rollup merge of #136069 - yotamofek:next-solver-slice, r=compiler-errors
Simplify slice indexing in next trait solver

Unless I'm missing something:
- no need to explicitly specify the end of the slice as the end of the index range
- the `assert` is redundant since the indexing will panic for the same condition

I think this change simplifies it a bit. Also replaced the `for` loop of `push`es with a call to `extend` with an iterator. Might improve performance since it knows how many elements will be added beforehand and can pre-reserve room?

r? `@compiler-errors` , I think
2025-02-06 21:56:25 +01:00
Matthias Krüger
4b7e55ada3
Rollup merge of #133925 - folkertdev:improve-repr-warnings, r=compiler-errors
disallow `repr()` on invalid items

fixes https://github.com/rust-lang/rust/issues/129606
fixes https://github.com/rust-lang/rust/issues/132391

Disallows `repr()` (so a repr with no arguments) on items where that won't ever make sense.

Also this generates an error when `repr` is used on a trait method and the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first accepts the align attribute on trait methods.

r? `@compiler-errors`

cc `@jdonszelmann` who claimed https://github.com/rust-lang/rust/issues/132391 and generally has been working on attributes
2025-02-06 21:56:24 +01:00
Waffle Lapkin
992e3b4f03
fix tail call checks wrt #[track_caller]
only check the caller + disallow caller having the attr.
2025-02-06 21:06:51 +01:00
Michael Goulet
de7d4a840e Don't reset cast kind without also updating the operand in simplify_cast 2025-02-06 18:39:35 +00:00
bjorn3
b9b2c3affc Stop passing the same resource multiple times when building ParseSess 2025-02-06 17:30:10 +00:00
bjorn3
8a0adec05b Avoid manually producing FatalError in a couple of places 2025-02-06 17:29:15 +00:00
bjorn3
9a833de62a Construct DiagCtxt a bit earlier in build_session 2025-02-06 17:29:15 +00:00
bors
942db6782f Auto merge of #136641 - matthiaskrgr:rollup-lajwje5, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #136073 (Always compute coroutine layout for eagerly emitting recursive layout errors)
 - #136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
 - #136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
 - #136315 (Use short ty string for binop and unop errors)
 - #136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
 - #136435 (Simplify some code for lowering THIR patterns)
 - #136630 (Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-gnu-debug
2025-02-06 17:08:45 +00:00
bors
79f82ad5e8 Auto merge of #136585 - gvozdvmozgu:memchr-eat-until-lexer, r=lcnr
implement `eat_until` leveraging memchr in lexer
2025-02-06 14:19:30 +00:00
Guillaume Gomez
f0966d20ad Add rustc_hir_pretty::item_to_string function 2025-02-06 14:45:28 +01:00
Matthias Krüger
c9635e51b5
Rollup merge of #136435 - Zalathar:thir-pat-stuff, r=Nadrieril
Simplify some code for lowering THIR patterns

I've been playing around with some radically different ways of storing THIR patterns, and while those experiments haven't yet produced a clear win, I have noticed various smaller things in the existing code that can be made a bit nicer.

Some of the more significant changes:
- With a little bit of extra effort (and thoughtful use of Arc), we can completely remove an entire layer of `'pat` lifetimes from the intermediate data structures used for match lowering.
- In several places, lists of THIR patterns were being double-boxed for no apparent reason.
2025-02-06 13:10:00 +01:00
Matthias Krüger
85a9de5d51
Rollup merge of #136393 - oli-obk:pattern-type-lit-oflo-checks, r=compiler-errors
Fix accidentally not emitting overflowing literals lints anymore in patterns

This was regressed in https://github.com/rust-lang/rust/pull/134228 (not in beta yet).

The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code.

So now I've set it up for visitors to be able to directly visit literals and get all literals
2025-02-06 13:09:59 +01:00
Matthias Krüger
c2c4d5ebfb
Rollup merge of #136315 - estebank:long-ty-binop, r=SparrowLii
Use short ty string for binop and unop errors

```
error[E0369]: cannot add `(..., ..., ..., ...)` to `(..., ..., ..., ...)`
  --> $DIR/binop.rs:10:7
   |
LL |     x + x;
   |     - ^ - (..., ..., ..., ...)
   |     |
   |     (..., ..., ..., ...)
   |
   = note: the full name for the type has been written to '$TEST_BUILD_DIR/$FILE.long-type-hash.txt'
   = note: consider using `--verbose` to print the full type name to the console
```
```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = note: the full name for the type has been written to '$TEST_BUILD_DIR/$FILE.long-type-hash.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

CC #135919.
2025-02-06 13:09:59 +01:00
Matthias Krüger
b62f318a3b
Rollup merge of #136311 - compiler-errors:vtable-fixes-2, r=lcnr
Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types

Check for impossible obligations in the `dyn Trait` type we're trying to compute its the vtable upcasting and method call slots.

r? lcnr
2025-02-06 13:09:58 +01:00
Matthias Krüger
62cad970e8
Rollup merge of #136235 - oli-obk:transmuty-pat-tys, r=RalfJung
Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing `0_u32 is 1..`, we now print the default fallback rendering that we also use for invalid bools, chars, ...: `{transmute(0x00000000): (u32) is 1..=}`.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to https://github.com/rust-lang/rust/pull/136176

cc ``@compiler-errors`` ``@scottmcm``

r? ``@RalfJung`` because of the interpreter changes
2025-02-06 13:09:58 +01:00
Matthias Krüger
7ca29360a7
Rollup merge of #136073 - compiler-errors:recursive-coro-always, r=oli-obk
Always compute coroutine layout for eagerly emitting recursive layout errors

Detect recursive coroutine layouts even if we don't detect opaque type recursion in the new solver. This is for two reasons:
1. It helps us detect (bad) recursive async function calls in the new solver, which due to its approach to normalization causes us to not detect this via a recursive RPIT (since the opaques are more eagerly revealed in the opaque body).
    * Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/137.
2. It helps us detect (bad) recursive async functions behind AFITs. See the AFIT test that changed for the old solver too.
3. It also greatly simplifies the recursive impl trait check, since I can remove some jankness around how it handles coroutines.
2025-02-06 13:09:57 +01:00
Zalathar
4385a9e063 Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit 2025-02-06 23:01:29 +11:00
bors
2f92f050e8 Auto merge of #136471 - safinaskar:parallel, r=SparrowLii
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

This is continuation of https://github.com/rust-lang/rust/pull/132282 .

I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement.

There are other possibilities, through.

We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase.

So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge.

cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 )

r? SparrowLii

`@rustbot` label WG-compiler-parallel
2025-02-06 10:50:05 +00:00
Ralf Jung
5934e0afef MIR validation: add comment explaining the limitations of CfgChecker 2025-02-06 11:36:58 +01:00
Jubilee Young
28140e8541 compiler: reorganize rustc_abi to be more internally uniform
General housekeeping:
- Use less reexports from its rustc_target era
- Unify some imports as a result
- Split the Reg(ister) types into their own files

Generally moving stuff around because it makes the crate more consistent.
2025-02-06 01:39:46 -08:00
Jubilee Young
89da3614e5 compiler: make rustc_target have less weird reexports
rustc_target has had a lot of weird reexports for various reasons, but
now we're at a point where we can actually start reducing their number.
We remove weird shadowing-dependent behavior and import directly from
rustc_abi instead of doing weird renaming imports.

This is only incremental progress and does not entirely fix the crate.
2025-02-06 01:39:46 -08:00
Jubilee
c549268a4a
Rollup merge of #136611 - Zalathar:llvm-underscore, r=workingjubilee
cg_llvm: Remove the `mod llvm_` hack, which should no longer be necessary

This re-export was introduced in c76fc3d804, as a workaround for #53912.

In short, there was/is an assumption in some LLVM LTO code that symbol names would not contain `.llvm.`, but legacy symbol mangling would naturally produce that sequence for symbols in a module named `llvm`.

This was later “fixed” by adding a special case to the legacy symbol mangler in #61195, which detects the sequence `llvm` and emits the `m` in an escaped form. As a result, there should no longer be any need to avoid the module name `llvm` in the compiler itself.

(Symbol mangling v0 avoids this problem by not using `.` in the first place, outside of the “vendor-specific suffix”.)
2025-02-05 19:53:54 -08:00
Jubilee
d116ac4b0e
Rollup merge of #136591 - GuillaumeGomez:expr-to-string, r=Urgau
Add `rustc_hir_pretty::expr_to_string` function

It'll allow me to work on a new rustdoc feature. :)

r? `@Urgau`
2025-02-05 19:53:53 -08:00
Jubilee
a9d4b013a2
Rollup merge of #136590 - carolynzech:raw-ptr-kind-internal, r=compiler-errors
Implement RustcInternal for RawPtrKind

Implement `RustcInternal` for `RawPtrKind`. https://github.com/rust-lang/rust/pull/135748 introduced a `Stable` implementation [here](https://github.com/rust-lang/rust/pull/135748/files#diff-60f5e8edf69e04e89ef0c7f576363a91fa141e1db969484cef00063ed39c62e4R235).
2025-02-05 19:53:52 -08:00
Jubilee
736f902581
Rollup merge of #136583 - Jarcho:fn_ctxt2, r=compiler-errors
Only highlight unmatchable parameters at the definition site

Followup to #136497

This generally results more focused messages in the same vein as #99635 (see `test/ui/argument-suggestions/complex.rs`). There are still some cases (e.g. `test/ui/argument-suggestions/permuted_arguments.rs`) where it might be worth highlighting the arguments. This is mitigated by the fact that a suggestion with a suggested rearrangement is given.

r? `@compiler-errors`
2025-02-05 19:53:51 -08:00
Jubilee
ffa67f9c44
Rollup merge of #136573 - oli-obk:document-literal-at-wrong-type-reason, r=compiler-errors
Document why some "type mismatches" exist

Just something I stumbled over and thought to save myself (and maybe others) the research time when encountering it again.
2025-02-05 19:53:50 -08:00
Jubilee
854a710fca
Rollup merge of #136563 - nnethercote:clean-up-Trivials, r=lcnr
Clean up `Trivial*Impls` macros

They're currently quite messy. Details in the individual commit logs.

r? `@lcnr`
2025-02-05 19:53:48 -08:00
Jubilee
1361ef37ff
Rollup merge of #136550 - compiler-errors:rpitit-empty-body, r=oli-obk
Fix `rustc_hidden_type_of_opaques` for RPITITs with no default body

Needed this when debugging something
2025-02-05 19:53:47 -08:00