2496 Commits

Author SHA1 Message Date
bors
6906167e01 Auto merge of #148193 - camsteffen:remove-qpath-langitem, r=cjgillot
Remove `QPath::LangItem`

Closes rust-lang/rust#115178.

r? cjgillot
2025-10-30 10:04:21 +00:00
bors
907705abea Auto merge of #148208 - camsteffen:assign-desugar-span, r=wesleywiser
Remove unused `AssignDesugar` span
2025-10-29 01:59:52 +00:00
Cameron Steffen
a45c6dd2c0 Remove AssignDesugar span 2025-10-28 11:18:58 -05:00
bors
df984edf44 Auto merge of #147083 - dianne:non-extended-indices, r=matthewjasper
Do not lifetime-extend array/slice indices

When lowering non-overloaded indexing operations to MIR, this uses the temporary lifetime of the index expression for the index temporary, rather than applying the temporary lifetime of the indexing operation as a whole to the index.

For example, in
```rust
let x = &xs[i];
```
previously, the temporary containing the result of evaluating `i` would live until the end of the block due to the indexing operation being [lifetime-extended](https://doc.rust-lang.org/nightly/reference/destructors.html#temporary-lifetime-extension). Under this PR, the index temporary only lives to the end of the `let` statement because it uses the more precise temporary lifetime of the index expression.

I don't think this will affect semantics in an observable way, but the more precise `StorageDead` placement may slightly improve analysis/codegen performance.

r? mir
2025-10-28 03:02:00 +00:00
Cameron Steffen
ead5e120a5 Remove QPath::LangItem 2025-10-27 21:19:38 -05:00
Camille Gillot
5dfbf67f94 Replace NullOp::SizeOf and NullOp::AlignOf by lang items. 2025-10-23 00:38:28 +00:00
yukang
4a886add5c Fix ICE in pattern matching with generic const array length errors 2025-10-16 19:15:32 +08:00
bors
ff6dc928c5 Auto merge of #142390 - cjgillot:mir-liveness, r=davidtwco
Perform unused assignment and unused variables lints on MIR.

Rebase of https://github.com/rust-lang/rust/pull/101500

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

The first commit moves detection of uninhabited types from the current liveness pass to MIR building.

In order to keep the same level of diagnostics, I had to instrument MIR a little more:
- keep for which original local a guard local is created;
- store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern.

I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas.

Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.
2025-10-12 13:00:04 +00:00
bors
3be68033b6 Auto merge of #145513 - beepster4096:erasedereftemps, r=saethlin,cjgillot
Validate CopyForDeref and DerefTemps better and remove them from runtime MIR

(split from my WIP rust-lang/rust#145344)

This PR:
- Removes `Rvalue::CopyForDeref` and `LocalInfo::DerefTemp` from runtime MIR
    - Using a new mir pass `EraseDerefTemps`
    - `CopyForDeref(x)` is turned into `Use(Copy(x))`
    - `DerefTemp` is turned into `Boring`
        - Not sure if this part is actually necessary, it made more sense in rust-lang/rust#145344 with `DerefTemp` storing actual data that I wanted to keep from having to be kept in sync with the rest of the body in runtime MIR
- Checks in validation that `CopyForDeref` and `DerefTemp` are only used together
- Removes special handling for `CopyForDeref` from many places
- Removes `CopyForDeref` from `custom_mir` reverting rust-lang/rust#111587
    - In runtime MIR simple copies can be used instead
    - In post cleanup analysis MIR it was already wrong to use due to the lack of support for creating `DerefTemp` locals
    - Possibly this should be its own PR?
 - Adds an argument to `deref_finder` to avoid creating new `DerefTemp`s and `CopyForDeref` in runtime MIR.
     - Ideally we would just avoid making intermediate derefs instead of fixing it at the end of a pass / during shim building
 - Removes some usages of `deref_finder` that I found out don't actually do anything

r? oli-obk
2025-10-12 02:34:20 +00:00
Camille GILLOT
ca0379d6cd Diagnose liveness on MIR. 2025-10-11 20:50:21 +00:00
Camille GILLOT
89191084d5 Correct binding scope when building MIR. 2025-10-11 20:50:20 +00:00
Camille GILLOT
f2535764d4 Introduce VarBindingIntroduction. 2025-10-11 20:50:20 +00:00
Camille GILLOT
9df2003860 Record for each MIR local where it has been introduced. 2025-10-11 20:50:20 +00:00
Camille GILLOT
5620c82e53 Report uninhabited call return types on MIR. 2025-10-11 20:50:20 +00:00
beepster4096
2da55cdb2c remove copyforderef from custom_mir
it did not create DerefTemp locals when used, so it was never actually correct.
2025-10-10 20:30:19 -07:00
Camille Gillot
b7c2b3dc80 Remove StatementKind::Deinit. 2025-10-10 12:57:24 +00:00
Stuart Cook
9ace0de26b Rollup merge of #147489 - chenyukang:yukang-prefer-repeat-n, r=Kivooeo,oli-obk
Prefer to use repeat_n over repeat().take()

More from https://github.com/rust-lang/rust/pull/147464, but batch processed with `ast-grep` to find and replace.

second commit add notes for library: affaf532f9

r? ``@RalfJung``
2025-10-09 18:43:26 +11:00
yukang
1654cce210 prefer to use repeat_n over repeat and take 2025-10-09 01:24:55 +08:00
Matthias Krüger
193a28d9b4 Rollup merge of #144006 - dianne:match-ergonomics-jargon, r=Nadrieril
clarify wording of match ergonomics diagnostics (`rust_2024_incompatible_pat` lint and error)

Partially addresses rust-lang/rust#143557:
- Uses different wording than the Edition Guide chapter, to hopefully stand alone a bit better. Instead of referring to the "default binding mode", it now talks about what can't be written "within elided reference patterns". I ended up going with "elided" instead of "implicit" in hope that it reads bit less like it should behave the same as an explicit reference pattern, but I'm not totally happy with that wording.
- The explanatory note still points to where the default binding mode was introduced, but only refers to its effect, not what we call it. How that relates to the rest of the diagnostic may still be a bit of a puzzle, but hopefully it isn't too much of one? It also doesn't make sense anymore for the case of `&` written under a by-ref binding mode, so I've left the note out in that case (but kept the label). It's more cramped, but talking about binding modes would feel like a non-sequitur for the error about `&` patterns without further explanation.
- Links to the stable version of the Edition Guide instead of the nightly version. It looks like almost every link to the Edition Guide in diagnostics is to the nightly version, presumably for the same reason as here: the diagnostics were added before the new Edition was stabilized, then never updated. I'll make a separate PR to clean up the others.

This only changes the diagnostic messages, not the code suggestion or the Edition Guide.

r? `@Nadrieril` or reassign
2025-10-08 15:39:25 +02:00
dianne
ec99e3eca2 clarify wording of match ergonomics diagnostics 2025-10-08 02:12:24 -07:00
Matthias Krüger
5f03328084 Rollup merge of #147442 - folkertdev:thir-print-c-variadic, r=fmease
c-variadic: fix thir-print for `...` without a pattern

tracking issue: https://github.com/rust-lang/rust/issues/44930
fixes https://github.com/rust-lang/rust/issues/147409

r? `@fmease`
2025-10-07 17:42:15 +02:00
Folkert de Vries
0a3f1d5b98 c-variadic: fix thir-print for ... without a pattern 2025-10-07 16:00:39 +02:00
bors
42b384ec0d Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnr
Turn ProjectionElem::Subtype into CastKind::Subtype

I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.)

The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant.

cc rust-lang/rust#112651, rust-lang/rust#133258

r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2025-10-02 01:54:48 +00:00
Matthias Krüger
6059195875 Rollup merge of #141469 - Kivooeo:remove-usnsafegate, r=compiler-errors
Allow `&raw [mut | const]` for union field in safe code

fixes rust-lang/rust#141264

r? ``@Veykril``

Unresolved questions:

- [x] Any edge cases?
- [x] How this works with rust-analyzer (because all I've did is prevent compiler from emitting error in `&raw` context) (rust-lang/rust-analyzer#19867)
- [x] Should we allow `addr_of!` and `addr_of_mut!` as well? In current version they both (`&raw` and `addr_of!`) are allowed (They are the same)
- [x] Is chain of union fields is a safe? (Yes)
2025-09-28 18:13:11 +02:00
Matthias Krüger
4eddf645bf Rollup merge of #146745 - helldawg:master, r=workingjubilee
Clarified error note for usize range matching

Fixes rust-lang/rust#146476

This is kinda rough, but it gets the point across a little better and stays short.
2025-09-28 09:15:23 +02:00
dianne
c0dc979549 do not lifetime-extend array/slice indices
When lowering non-overloaded indexing operations to MIR, this uses the
temporary lifetime of the index expression for the index, rather than
applying the temporary lifetime of the indexing operation as a whole to
the index.
2025-09-26 20:14:57 -07:00
Marijn Schouten
fc703ec5c8 fix doc comments to be more standard 2025-09-26 09:25:56 +00:00
beepster4096
aa5a21450a ProjectionElem::Subtype -> CastKind::Subtype 2025-09-26 01:25:26 -07:00
helldawg
7e58c91105 usize/isize range matching error clarification 2025-09-25 18:15:04 +03:00
Ding Xiang Fei
b77de834c0 mark THIR use as candidate for constness check 2025-09-25 01:54:25 +08:00
Ding Xiang Fei
a86f140727 do not materialise X in [X; 0] when X is unsizing a const 2025-09-25 01:54:23 +08:00
Camille Gillot
53b91ea87f Remove Rvalue::Len. 2025-09-16 22:23:19 +00:00
Boxy
332d8d6235 Driveby fixes 2025-09-09 14:49:16 +02:00
Boxy
e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
Nicholas Nethercote
301655eafe Revert introduction of [workspace.dependencies].
This was done in #145740 and #145947. It is causing problems for people
using r-a on anything that uses the rustc-dev rustup package, e.g. Miri,
clippy.

This repository has lots of submodules and subtrees and various
different projects are carved out of pieces of it. It seems like
`[workspace.dependencies]` will just be more trouble than it's worth.
2025-09-02 19:12:54 +10:00
bors
154037ffb8 Auto merge of #144783 - folkertdev:loop-match-diverging-loop, r=SparrowLii
fix `#[loop_match]` on diverging loop

tracking issue: https://github.com/rust-lang/rust/issues/132306

fixes https://github.com/rust-lang/rust/issues/144492
fixes https://github.com/rust-lang/rust/issues/144493

fixes https://github.com/rust-lang/rust/issues/144781

this generated invalid MIR before. issue https://github.com/rust-lang/rust/issues/143806 still has an issue where we assign `state = state` which is invalid in MIR. Fixing that problem is tricky, so I'd like to do that separately.

r? `@bjorn3`
2025-09-01 14:42:07 +00:00
Nicholas Nethercote
5ce3797073 Introduce MirDumper and MirWriter.
MIR dumping is a mess. There are lots of functions and entry points,
e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`,
`dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is
never called without `dump_enabled` first being checked, but there is no
mechanism for ensuring this and it's hard to tell if it is satisfied on
all paths. (`dump_enabled` is checked twice on some paths, however!)

This commit introduces `MirWriter`, which controls the MIR writing, and
encapsulates the `extra_data` closure and `options`. Two existing
functions are now methods of this type. It sets reasonable defaults,
allowing the removal of many `|_, _| Ok(())` closures.

The commit also introduces `MirDumper`, which is layered on top of
`MirWriter`, and which manages the creation of the dump files,
encapsulating pass names, disambiguators, etc. Four existing functions
are now methods of this type.
- `MirDumper::new` will only succeed if dumps are enabled, and will
  return `None` otherwise, which makes it impossible to dump when you
  shouldn't.
- It also sets reasonable defaults for various things like
  disambiguators, which means you no longer need to specify them in many
  cases. When they do need to be specified, it's now done via setter
  methods.
- It avoids some repetition. E.g. `dump_nll_mir` previously specifed the
  pass name `"nll"` four times and the disambiguator `&0` three times;
  now it specifies them just once, to put them in the `MirDumper`.
- For Polonius, the `extra_data` closure can now be specified earlier,
  which avoids having to pass some arguments through some functions.
2025-09-01 09:19:03 +10:00
Nicholas Nethercote
d7faa5630d Avoid unnecessary mut-ness for various closures. 2025-09-01 08:52:34 +10:00
Kivooeo
23f1767c80 allow taking address to union field 2025-08-31 17:23:32 +00:00
Nicholas Nethercote
ce02d34b2f Add rustc_apfloat to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
Nicholas Nethercote
200f56d605 Add itertools to [workspace.dependencies]. 2025-08-27 14:21:21 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Jacob Pratt
45d5109ad8 Rollup merge of #145573 - veluca93:unsafe-force-target-feature, r=davidtwco
Add an experimental unsafe(force_target_feature) attribute.

This uses the feature gate for https://github.com/rust-lang/rust/issues/143352, but is described in https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to the experiment.
2025-08-22 22:00:51 -04:00
Luca Versari
291da71b2a Add an experimental unsafe(force_target_feature) attribute.
This uses the feature gate for
https://github.com/rust-lang/rust/issues/143352, but is described in
https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to
the experiment.
2025-08-22 01:26:26 +02:00
Jacob Pratt
cd0972f6f5 Rollup merge of #144780 - bjorn3:mir_build_debug, r=matthewjasper
Add a method to dump MIR in the middle of MIR building

This makes it easier to debug issues with MIR building by inserting dump_for_debugging calls around the suspected code responsible for the bad MIR.
2025-08-21 17:57:50 -04:00
Michael Goulet
6a088fd584 Defer tail call ret ty equality to check_tail_calls 2025-08-19 20:16:19 +00:00
Stuart Cook
d92e1fe8d7 Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmann
Port `#[custom_mir(..)]` to the new attribute system

r? ``````````@jdonszelmann``````````
2025-08-18 15:31:10 +10:00
Sasha Pourcelot
51bccdd1ab Port #[custom_mir(..)] to the new attribute system 2025-08-15 11:19:29 +02:00
bors
ba412a6e70 Auto merge of #145423 - Zalathar:rollup-9jtefpl, r=Zalathar
Rollup of 21 pull requests

Successful merges:

 - rust-lang/rust#118087 (Add Ref/RefMut try_map method)
 - rust-lang/rust#122661 (Change the desugaring of `assert!` for better error output)
 - rust-lang/rust#142640 (Implement autodiff using intrinsics)
 - rust-lang/rust#143075 (compiler: Allow `extern "interrupt" fn() -> !`)
 - rust-lang/rust#144865 (Fix tail calls to `#[track_caller]` functions)
 - rust-lang/rust#144944 (E0793: Clarify that it applies to unions as well)
 - rust-lang/rust#144947 (Fix description of unsigned `checked_exact_div`)
 - rust-lang/rust#145004 (Couple of minor cleanups)
 - rust-lang/rust#145005 (strip prefix of temporary file names when it exceeds filesystem name length limit)
 - rust-lang/rust#145012 (Tail call diagnostics to include lifetime info)
 - rust-lang/rust#145065 (resolve: Introduce `RibKind::Block`)
 - rust-lang/rust#145120 (llvm: Accept new LLVM lifetime format)
 - rust-lang/rust#145189 (Weekly `cargo update`)
 - rust-lang/rust#145235 (Minor `[const]` tweaks)
 - rust-lang/rust#145275 (fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute)
 - rust-lang/rust#145322 (Resolve the prelude import in `build_reduced_graph`)
 - rust-lang/rust#145331 (Make std use the edition 2024 prelude)
 - rust-lang/rust#145369 (Do not ICE on private type in field of unresolved struct)
 - rust-lang/rust#145378 (Add `FnContext` in parser for diagnostic)
 - rust-lang/rust#145389 ([rustdoc] Revert "rustdoc search: prefer stable items in search results")
 - rust-lang/rust#145392 (coverage: Remove intermediate data structures from mapping creation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-15 09:13:10 +00:00
Stuart Cook
711034f7a1 Rollup merge of #145012 - Kivooeo:fun-problem-fun-fix, r=compiler-errors
Tail call diagnostics to include lifetime info

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

r? ```@WaffleLapkin``` ```@compiler-errors```
2025-08-15 16:16:35 +10:00