Commit Graph

304479 Commits

Author SHA1 Message Date
Nathaniel McCallum 8dfd6b8ec2 fix a constness ordering bug in rustfmt
Normally, changes to rustfmt go into the separate repo. But, in
this case, the bug is introduced in a local change and therefore
isn't present in the rustfmt repo.
2025-09-01 08:55:25 -04:00
bors 84a1747022 Auto merge of #146077 - Zalathar:rollup-l7ip5yi, r=Zalathar
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#145468 (dedup recip, powi, to_degrees, and to_radians float tests)
 - rust-lang/rust#145643 (coverage: Build an "expansion tree" and use it to unexpand raw spans)
 - rust-lang/rust#145754 (fix(lexer): Don't require frontmatters to be escaped with indented fences)
 - rust-lang/rust#146060 (fixup nix dev shell again)
 - rust-lang/rust#146068 (compiletest: Capture panic messages via a custom panic hook)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-01 07:44:42 +00:00
Stuart Cook 92bc467f36 Rollup merge of #146068 - Zalathar:panic-hook, r=jieyouxu
compiletest: Capture panic messages via a custom panic hook

Currently, output-capture of panic messages relies on special cooperation between `#![feature(internal_output_capture)]` and the default panic hook. That's a problem if we want to perform our own output capture, because the default panic hook won't know about our custom output-capture mechanism.

We can work around that by installing a custom panic hook that prints equivalent panic messages to a buffer instead.

The custom hook is always installed, but delegates to the default panic hook unless a panic-capture buffer has been installed on the current thread. A panic-capture buffer is only installed on compiletest test threads (by the executor), and only if output-capture is enabled.

---

Right now this PR doesn't provide any particular concrete benefits. But it will be essential as part of further efforts to replace compiletest's use of `#![feature(internal_output_capture)]` with our own output-capture mechanism.

r? jieyouxu
2025-09-01 17:35:05 +10:00
Stuart Cook 325bb43f55 Rollup merge of #146060 - WaffleLapkin:fixup-nix-dev-shell-again, r=Noratrieb
fixup nix dev shell again

r? Noratrieb
2025-09-01 17:35:04 +10:00
Stuart Cook 0972fd9d41 Rollup merge of #145754 - epage:escape, r=SparrowLii
fix(lexer): Don't require frontmatters to be escaped with indented fences

The RFC only limits hyphens at the beginning of lines and not if they are indented or embedded in other content.

Sticking to that approach was confirmed by the T-lang liason at https://github.com/rust-lang/rust/issues/141367#issuecomment-3202217544

There is a regression in error message quality which I'm leaving for someone if they feel this needs improving.

Tracking issue: rust-lang/rust#136889

Fixes rust-lang/rust#141367
2025-09-01 17:35:04 +10:00
Stuart Cook 88c254f8d4 Rollup merge of #145643 - Zalathar:tree, r=SparrowLii
coverage: Build an "expansion tree" and use it to unexpand raw spans

Historically and currently, coverage instrumentation assumes that all of a function's spans are in the same file and have the same syntax context. The spans extracted directly from MIR don't satisfy that assumption, so there is an “unexpansion” step that walks up each span's expansion-call-site tree to find a suitable span in the same context as the function's body span.

(That unexpansion step is what allows us to have somewhat reasonable coverage instrumentation for macros like `println!`, and for syntax like `for` and `?` that undergo desugaring expansion.)

The current unexpansion code mostly works fine in that “flat” single-file single-context world. But it's not suitable for incremental work towards proper expansion-aware coverage instrumentation, which would allow a function's coverage spans to encompass multiple expansion contexts and multiple files.

This PR therefore replaces the current unexpansion code with a more sophisticated system that uses the raw MIR spans to reconstruct an “expansion tree”, and then uses that tree to help perform most of the unexpansion work.

Building the tree is “overkill” for current unexpansion needs (though it does give some minor edge-case improvements), but my hope is that having the explicit tree available will be a big help when taking the next steps towards proper expansion-region support.
2025-09-01 17:35:03 +10:00
Stuart Cook 1d520e2694 Rollup merge of #145468 - karolzwolak:float-tests-dedup, r=tgross35
dedup recip, powi, to_degrees, and to_radians float tests

Deduplicates recip, powi, to_degrees, and to_radians float tests.
I had to fiddle and slightly increase the tolerances for a few comparisons, so maybe not all of the tests are worth deduplicating.

Part of rust-lang/rust#141726.
Best reviewed commit-by-commit.

r? `@tgross35`
2025-09-01 17:35:02 +10:00
bors be4e9b77ab Auto merge of #146072 - Zalathar:rollup-0svnrfe, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#145421 (`dump_mir` cleanups)
 - rust-lang/rust#145968 (Add `Bound::copied`)
 - rust-lang/rust#146004 (resolve: Refactor `struct ExternPreludeEntry`)
 - rust-lang/rust#146042 (Detect negative literal inferred to unsigned integer)
 - rust-lang/rust#146046 (Suggest method name with maybe ty mismatch)
 - rust-lang/rust#146051 (Change std f32 test to pass under Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-01 04:37:39 +00:00
Zalathar e7519c63b0 Capture panic messages via a custom panic hook 2025-09-01 13:12:39 +10:00
Stuart Cook 0dbd8e68b1 Rollup merge of #146051 - LorrensP-2158466:miri-libstd-fix, r=RalfJung
Change std f32 test to pass under Miri

Adds `APPROX_DELTA` to 2 tests of `f32::log` reported in [#miri > Miri test-libstd Failure (2025-08)](https://rust-lang.zulipchat.com/#narrow/channel/269128-miri/topic/Miri.20test-libstd.20Failure.20.282025-08.29).

I changed 2 lines, the first one is the actual failure. The second one is precautionary.
2025-09-01 12:42:28 +10:00
Stuart Cook eed52596ab Rollup merge of #146046 - chenyukang:yukang-fix-method-exists-for-ret-ty-error, r=estebank
Suggest method name with maybe ty mismatch

Fixes rust-lang/rust#146008

I think it's ok to suggest method name even when the return ty mismatch, since we only reporting in `Applicability::MaybeIncorrect`, user may add `()` and continue to fix following errors.

r? ```@estebank```
2025-09-01 12:42:27 +10:00
Stuart Cook 142ad69698 Rollup merge of #146042 - estebank:issue-83413, r=lcnr
Detect negative literal inferred to unsigned integer

```
error[E0277]: the trait bound `usize: Neg` is not satisfied
  --> $DIR/negative-literal-infered-to-unsigned.rs:2:14
   |
LL |     for x in -5..5 {
   |              ^^ the trait `Neg` is not implemented for `usize`
   |
help: consider specifying an integer type that can be negative
   |
LL |     for x in -5isize..5 {
   |                +++++
```

Applying this suggestion will always end up in another E0308 error at the point where the unsigned inference comes from, which should help with understanding what the actual problem is.

Fix rust-lang/rust#83413.
2025-09-01 12:42:26 +10:00
Stuart Cook 5adc0fe0e2 Rollup merge of #146004 - petrochenkov:epentry, r=nnethercote
resolve: Refactor `struct ExternPreludeEntry`

Avoid impossible combinations of fields and apply the first part of https://github.com/rust-lang/rust/pull/144737 (do not resolve erroneous entries repeatedly, keep them as `PendingBinding::Ready(None)` instead).
2025-09-01 12:42:26 +10:00
Stuart Cook 0fa8265b3c Rollup merge of #145968 - connortsui20:bound-copied, r=joboet
Add `Bound::copied`

Tracking Issue: https://github.com/rust-lang/rust/issues/145966

Some questions:

- [x] Should I update the documentation for `cloned` to actual used a `Clone` type instead of an integer?
- [x] I removed the `must_use` since this is a cheap copy, does that make sense?
2025-09-01 12:42:25 +10:00
Stuart Cook d17b3fb220 Rollup merge of #145421 - nnethercote:dump_mir-cleanups, r=davidtwco
`dump_mir` cleanups

I found this code hard to read, so I cleaned it up. Details in individual commits.

r? ``@davidtwco``
2025-09-01 12:42:25 +10:00
bors 828e45ad11 Auto merge of #145663 - Kobzol:bootstrap-test, r=jieyouxu
Enforce in bootstrap that test must have stage at least 1 (except for compiletest)

This PR cleans up a bunch of test steps and adds metadata to them. I didn't yet touch the most complicated step (`CompileTest`), I'm leaving that for another PR.

Testing anything on stage 0 is only possible for compiletest and with `build.allow-compiletest-stage0`. Testing anything else on stage 0 will either produce a nice error or crash with a stage being subtracted below zero.

r? `@jieyouxu`

try-job: dist-x86_64-linux
try-job: aarch64-gnu
try-job: arm-android
try-job: `x86_64-gnu-llvm-20*`
try-job: `x86_64-msvc-*`
try-job: aarch64-apple
try-job: test-various
2025-09-01 01:30:27 +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 2d21c13405 Indent some functions.
This commit exists purely to simplify reviewing: these functions will
become methods in the next commit. This commit indents them so that the
next commit is more readable.
2025-09-01 08:52:34 +10:00
Nicholas Nethercote d3e2c93498 Use trait object references for closures.
The dynamic dispatch cost doesn't matter for MIR dumping, which is
perf-insensitive. And it's necessary for the next commit, which will
store some `extra_data` closures in a struct.
2025-09-01 08:52:34 +10:00
Nicholas Nethercote d7faa5630d Avoid unnecessary mut-ness for various closures. 2025-09-01 08:52:34 +10:00
Nicholas Nethercote 3a0d0be586 Inline and remove dump_mir_for_pass.
The code is more readable without it.
2025-09-01 08:52:33 +10:00
Nicholas Nethercote 7ea882d4c4 Inline and remove dump_matched_mir_node.
It has a single call site.
2025-09-01 08:52:33 +10:00
Esteban Küber ea2daa33c8 Split ObligationCauseCode::BinOp for unops to UnOp 2025-08-31 21:13:12 +00:00
bors 07d246fc6d Auto merge of #146038 - notriddle:polarity, r=GuillaumeGomez
rustdoc-search: split function inverted index by input/output

Fixes rust-lang/rust#146015

With a patch applied to count the number of unifications, and running the query `Option<T>, (T -> U) -> Option<U>`

before: performed unifyFunctionType on 17484 functions
after: performed unifyFunctionType on 3055 functions

preview:
https://notriddle.com/rustdoc-html-demo-12/polarity/doc/std/index.html
https://notriddle.com/rustdoc-html-demo-12/polarity/compiler-doc/rustc_hir/index.html
2025-08-31 20:28:35 +00:00
Karol Zwolak 9028efcf2e dedup to_radians float test 2025-08-31 18:20:49 +02:00
bors f73bcd50a4 Auto merge of #146053 - joboet:split-paths-regression, r=Mark-Simulacrum
std: fix `SplitPaths` regression

Fixes rust-lang/rust#146045 by defining the TAIT more precisely, ensuring that `'a` does not need to be live on drop.
2025-08-31 16:19:09 +00:00
Karol Zwolak c81a8a89ee dedup to_degrees float test 2025-08-31 18:19:05 +02:00
Waffle Lapkin 43e535947b fixup nix dev shell again 2025-08-31 18:17:50 +02:00
Karol Zwolak e10e6d78ac dedup powi float test 2025-08-31 18:16:00 +02:00
bors 564ee21912 Auto merge of #146052 - matthiaskrgr:rollup-cfxx9m6, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144443 (Make target pointer width in target json an integer)
 - rust-lang/rust#145174 (Ensure consistent drop for panicking drop in hint::select_unpredictable)
 - rust-lang/rust#145592 (Fix format string grammar in docs and improve alignment error message for rust-lang/rust#144023)
 - rust-lang/rust#145931 (Clarify that align_offset overaligns)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-31 11:53:54 +00:00
joboet 6d8d952e48 std: fix SplitPaths regression 2025-08-31 13:46:52 +02:00
Matthias Krüger e3881cb587 Rollup merge of #145931 - gonzalobg:patch-1, r=nagisa
Clarify that align_offset overaligns

The current documentation is not clear whether adding `a` to a pointer overaligns (align up) or underaligns (align down).

It should say this explicitly.

cc `@nagisa`
2025-08-31 13:40:36 +02:00
Matthias Krüger e5f96e3b43 Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnr
Fix format string grammar in docs and improve alignment error message for #144023

This PR improves error messages and documentation for format strings involving alignment and formatting traits.

Highlights:

- Clearer error messages for invalid alignment specifiers (e.g., `{0:#X>18}`), showing the expected `<`, `^`, or `>` and a working example:

    println!("{0:>#18X}", value);

- Updated UI test `format-alignment-hash.rs` to reflect the improved error output.
- Documentation clarification: ensures examples correctly show how width, alignment, and traits like `x`, `X`, `#` combine.

Motivation:
Previously, using `#` with alignment and width produced confusing errors. This PR guides users on the correct syntax and provides actionable examples.

Testing:
- Built the compiler (`./x build`)
- Blessed and ran UI tests (`./x. test src/test/ui/fmt/format-alignment-hash.rs --bless`)
- Verified full test suite passes (`./x test`)

Issue: rust-lang/rust#144023
2025-08-31 13:40:35 +02:00
Matthias Krüger 59a645ac25 Rollup merge of #145174 - 197g:issue-145148-select-unpredictable-drop, r=joboet
Ensure consistent drop for panicking drop in hint::select_unpredictable

There are a few alternatives to the implementation. The principal problem is that the selected value must be owned (in the sense of having a drop flag of sorts) when the unselected value is dropped, such that panic unwind goes through the drop of both. This ownership must then be passed on in return when the drop went smoothly.

The basic way of achieving this is by extracting the selected value first, at the cost of relying on the optimizer a little more for detecting the copy as constructing the return value despite having a place in the body. Unfortunately, that causes LLVM to discard the !unpredictable annotation (for some reason that is beyond my comprehension of LLVM).

<details>
<summary>Extract from the build log showing an unannotated select being used</summary>

```
2025-08-09T16:51:06.8790764Z            39: define noundef i64 `@test_int2(i1` noundef zeroext %p, i64 noundef %a, i64 noundef %b) unnamed_addr #0 personality ptr `@rust_eh_personality` {
2025-08-09T16:51:06.8791368Z check:47'0                                  X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
2025-08-09T16:51:06.8791700Z            40: start:
2025-08-09T16:51:06.8791858Z check:47'0     ~~~~~~~
2025-08-09T16:51:06.8792043Z            41:  %ret.i = select i1 %p, i64 %a, i64 %b
2025-08-09T16:51:06.8792293Z check:47'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-08-09T16:51:06.8792686Z check:47'1               ?                             possible intended match
2025-08-09T16:51:06.8792946Z            42:  ret i64 %ret.i
2025-08-09T16:51:06.8793127Z check:47'0     ~~~~~~~~~~~~~~~~
```

</details>

So instead, this PR includes a guard to drop the selected `MaybeUnit<T>` which is active only for the section where the unselected value is dropped. That leaves the code for selecting the result intact leading to the expected ir. That complicates the 'unselection' process a little bit since we require _both_ values as a result of that intrinsic call. Since the arguments alias, this portion as well as the drop guard uses raw pointers.

Closes: rust-lang/rust#145148
Prior: rust-lang/rust#139977
2025-08-31 13:40:35 +02:00
Matthias Krüger 0e28b4201a Rollup merge of #144443 - WaffleLapkin:integer-target-pointer-width, r=Noratrieb
Make target pointer width in target json an integer

r? Noratrieb
cc `@RalfJung` (https://github.com/rust-lang/rust/pull/142352/files#r2230380120)

try-job: x86_64-rust-for-linux
2025-08-31 13:40:34 +02:00
bors 1bc901e0ca Auto merge of #146039 - Mark-Simulacrum:fix-bolt-path, r=Kobzol
Use absolute path to llvm-bolt, merge-fdata rather than PATH

This unconditionally uses the provided LLVM toolchain's BOLT. I'm not sure that makes sense, but since we don't build BOLT as part of Rust's build of LLVM today, it's probably the right option for now.

This avoids breaking the build on not being able to find the llvm-bolt executable.
2025-08-31 08:45:55 +00:00
LorrensP-2158466 cfba491e67 fix 2025-08-31 10:03:49 +02:00
Michael Howell 6ef0bfdb5c rustdoc-search: improve concurrency at type search 2025-08-30 20:20:18 -07:00
bors 64a99db105 Auto merge of #145582 - estebank:issue-107806, r=chenyukang
Detect missing `if let` or `let-else`

During `let` binding parse error and encountering a block, detect if there is a likely missing `if` or `else`:

```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
  --> $DIR/missing-if-let-or-let-else.rs:14:25
   |
LL |     let Some(x) = foo() {
   |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator
   |
help: you might have meant to use `if let`
   |
LL |     if let Some(x) = foo() {
   |     ++
help: alternatively, you might have meant to use `let else`
   |
LL |     let Some(x) = foo() else {
   |                         ++++
```

Fix rust-lang/rust#107806.
2025-08-31 03:00:54 +00:00
yukang 263766bcc2 suggest method name with maybe ty mismatch 2025-08-31 10:55:14 +08:00
bors cd60c60d9f Auto merge of #146043 - tgross35:rollup-hdumq5v, r=tgross35
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#144964 (std: clarify `OpenOptions` error for create without write access)
 - rust-lang/rust#146030 (Fix `sys::process::windows::tests::test_thread_handle` spurious failure)
 - rust-lang/rust#146035 (Update `browser-ui-test` version to `0.21.3`)
 - rust-lang/rust#146036 (Use move_file for rename in tracing)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-30 23:51:29 +00:00
Trevor Gross 7185ec6056 Rollup merge of #146036 - Mark-Simulacrum:rust-1, r=Kobzol
Use move_file for rename in tracing

This avoids panicking when the source and destination are on different filesystems.
2025-08-30 18:49:50 -05:00
Trevor Gross 226517e55f Rollup merge of #146035 - GuillaumeGomez:update-browser-ui-test, r=GuillaumeGomez
Update `browser-ui-test` version to `0.21.3`

I cannot test it locally because of this bug:

```
error: couldn't generate documentation: failed to read column from disk: data consumer error: missing field `unknown number` at line 1 column 8
  |
  = note: failed to create or modify "build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/search.index/entry/": failed to read column from disk: data consumer error: missing field `unknown number` at line 1 column 8
```

So I'll iterate through CI checks I guess.

r? ghost
2025-08-30 18:49:49 -05:00
Trevor Gross b86c601a71 Rollup merge of #146030 - ChrisDenton:wait-timeout, r=tgross35
Fix `sys::process::windows::tests::test_thread_handle` spurious failure

Instead of sleeping, wait for the process to finish so that we can be sure it's done. We use a timeout because otherwise this test can be stuck indefinitely if it fails (unfortunately std doesn't currently have a way to wait with a timeout so a manual OS API call is necessary).

I also changed the test to run `whoami` and pipe the output to null so that it doesn't clutter up the test output.

Fixes rust-lang/rust#146024
2025-08-30 18:49:49 -05:00
Trevor Gross 9489339118 Rollup merge of #144964 - 0xdeafbeef:fix-open-options, r=ibraheemdev
std: clarify `OpenOptions` error for create without write access

Fixes rust-lang/rust#140621
2025-08-30 18:49:48 -05:00
Esteban Küber 18a36bccf5 Detect negative literal inferred to unsigned integer
```
error[E0277]: the trait bound `usize: Neg` is not satisfied
  --> $DIR/negative-literal-infered-to-unsigned.rs:2:14
   |
LL |     for x in -5..5 {
   |              ^^ the trait `Neg` is not implemented for `usize`
   |
help: consider specifying an integer type that can be negative
   |
LL |     for x in -5isize..5 {
   |                +++++
```
2025-08-30 23:28:58 +00:00
Mark Rousskov 199d2d4615 Use absolute path to llvm-bolt, merge-fdata rather than PATH
This unconditionally uses the provided LLVM toolchain's BOLT. I'm not
sure that makes sense, but since we don't build BOLT as part of Rust's
build of LLVM today, it's probably the right option for now.

This avoids breaking the build on not being able to find the llvm-bolt
executable.
2025-08-30 18:47:23 -04:00
Michael Howell 0becce400b rustdoc-search: split function inverted index by input/output
With a patch applied to count the number of unifications,
and running the query `Option<T>, (T -> U) -> Option<U>`

before: performed unifyFunctionType on 17484 functions
after: performed unifyFunctionType on 3055 functions
2025-08-30 12:22:33 -07:00
Esteban Küber 3af81cf0b7 review comment: move Visitor 2025-08-30 18:42:07 +00:00
Chris Denton 3516e25eed Fix spurious test timeout 2025-08-30 18:07:09 +00:00