Commit Graph

271044 Commits

Author SHA1 Message Date
Michael Howell
86da4be47f rustdoc: use a trie for name-based search
Preview and profiler results
----------------------------

Here's some quick profiling in Firefox done on the rust compiler docs:

- Before: https://share.firefox.dev/3UPm3M8
- After: https://share.firefox.dev/40LXvYb

Here's the results for the node.js profiler:

- https://notriddle.com/rustdoc-html-demo-15/trie-perf/index.html

Here's a copy that you can use to try it out. Compare it with [the nightly].
Try typing `typecheckercontext` one character at a time, slowly.

- https://notriddle.com/rustdoc-html-demo-15/compiler-doc-trie/index.html

[the nightly]: https://doc.rust-lang.org/nightly/nightly-rustc/

The fuzzy match algo is based on [Fast String Correction with
Levenshtein-Automata] and the corresponding implementation code in [moman]
and [Lucene]; the bit-packing representation comes from Lucene, but the
actual matcher is more based on `fsc.py`. As suggested in the paper, a
trie is used to represent the FSA dictionary.

The same trie is used for prefix matching. Substring matching is done with a
side table of three-character[^1] windows that point into the trie.

[Fast String Correction with Levenshtein-Automata]: https://github.com/tpn/pdfs/blob/master/Fast%20String%20Correction%20with%20Levenshtein-Automata%20(2002)%20(10.1.1.16.652).pdf
[Lucene]: https://fossies.org/linux/lucene/lucene/core/src/java/org/apache/lucene/util/automaton/Lev1TParametricDescription.java
[moman]: https://gitlab.com/notriddle/moman-rustdoc

User-visible changes
--------------------

I don't expect anybody to notice anything, but it does cause two changes:

- Substring matches, in the middle of a name, only apply if there's three
  or more characters in the search query.
- Levenshtein distance limit now maxes out at two. In the old version,
  the limit was w/3, so you could get looser matches for queries with
  9 or more characters[^1] in them.

[^1]: technically utf-16 code units
2024-11-13 12:04:46 -07:00
iximeow
a54d6ad039
Delete tests/codegen/fmt_int_no_panic.rs
this test was included for demonstrative and discussion purposes but does not test what its name alleges - in fact it does not test much of value at all!

as mentioned in this comment, https://github.com/rust-lang/rust/pull/122770#issuecomment-2474256965 , writing a correct test for this codegen outcome is difficult (partially because the public interface to std::fmt intentionally includes an #[inline(never)] function!), so to test this correctly will require more than i can offer in 122770.
2024-11-13 09:50:00 -08:00
lcnr
117038197d actually test next solver 2024-11-13 18:44:13 +01:00
Guillaume Gomez
7a8257dc47 Add regression test for #131901 2024-11-13 16:56:40 +01:00
Guillaume Gomez
d9aac8cfce Fix duplicated footnote IDs 2024-11-13 16:56:18 +01:00
León Orell Valerian Liehr
9016711bf1
rustdoc: Treat decl macros like other items 2024-11-13 16:03:57 +01:00
Christopher Berner
0df3ef4435 Fix compilation error on Solaris due to flock usage
PR 130999 added the file_lock feature, but libc does not define
flock() for the Solaris platform leading to a compilation error.

Additionally, I went through all the Tier 2 platforms and read through
their documentation to see whether flock was implemented. This turned up
5 more Unix platforms where flock is not supported, even though it may
exist in the libc crate.
2024-11-13 06:53:19 -08:00
许杰友 Jieyou Xu (Joe)
29889cca42 Unvacation 2024-11-13 21:35:46 +08:00
Kirill Podoprigora
81f6105851 Address review 2024-11-13 15:31:07 +02:00
clubby789
1136bbf066 Trim extra space when suggesting removing bad let 2024-11-13 13:19:13 +00:00
Kirill Podoprigora
98a71766b8 Add `exact-llvm-major-version` directive 2024-11-13 15:05:31 +02:00
bors
a00df61387 Auto merge of #132556 - clubby789:cargo-update, r=Mark-Simulacrum
Add licenses + run `cargo update`

Replaces #131311
```
compiler & tools dependencies:
     Locking 86 packages to latest compatible versions
    Updating anstream v0.6.15 -> v0.6.17
    Updating anstyle v1.0.8 -> v1.0.10
    Updating anstyle-lossy v1.1.2 -> v1.1.3
    Updating anstyle-parse v0.2.5 -> v0.2.6
    Updating anstyle-query v1.1.1 -> v1.1.2
    Updating anstyle-svg v0.1.5 -> v0.1.7
    Updating anstyle-wincon v3.0.4 -> v3.0.6
    Updating anyhow v1.0.89 -> v1.0.92
    Updating arrayref v0.3.7 -> v0.3.9
    Updating blake3 v1.5.2 -> v1.5.4
    Updating bytes v1.7.2 -> v1.8.0
    Updating cc v1.1.23 -> v1.1.34
    Updating clap v4.5.18 -> v4.5.20
    Updating clap_builder v4.5.18 -> v4.5.20
    Updating clap_complete v4.5.29 -> v4.5.36
    Updating colorchoice v1.0.2 -> v1.0.3
    Updating constant_time_eq v0.3.0 -> v0.3.1
    Updating curl v0.4.46 -> v0.4.47
    Updating curl-sys v0.4.76+curl-8.10.1 -> v0.4.77+curl-8.10.1
    Updating derive_builder v0.20.1 -> v0.20.2
    Updating derive_builder_core v0.20.1 -> v0.20.2
    Updating derive_builder_macro v0.20.1 -> v0.20.2
      Adding foldhash v0.1.3
    Updating futures v0.3.30 -> v0.3.31
    Updating futures-channel v0.3.30 -> v0.3.31
    Updating futures-core v0.3.30 -> v0.3.31
    Updating futures-executor v0.3.30 -> v0.3.31
    Updating futures-io v0.3.30 -> v0.3.31
    Updating futures-macro v0.3.30 -> v0.3.31
    Updating futures-sink v0.3.30 -> v0.3.31
    Updating futures-task v0.3.30 -> v0.3.31
    Updating futures-util v0.3.30 -> v0.3.31
    Updating gimli v0.31.0 -> v0.31.1
      Adding hashbrown v0.15.0
    Updating indexmap v2.5.0 -> v2.6.0
    Updating js-sys v0.3.70 -> v0.3.72
    Updating libc v0.2.159 -> v0.2.161
    Updating libm v0.2.8 -> v0.2.11
    Updating object v0.36.4 -> v0.36.5
    Updating once_cell v1.19.0 -> v1.20.2
    Removing once_map v0.4.19
    Updating openssl-sys v0.9.103 -> v0.9.104
    Updating pathdiff v0.2.1 -> v0.2.2
    Updating pest v2.7.13 -> v2.7.14
    Updating pest_derive v2.7.13 -> v2.7.14
    Updating pest_generator v2.7.13 -> v2.7.14
    Updating pest_meta v2.7.13 -> v2.7.14
    Updating pin-project-lite v0.2.14 -> v0.2.15
    Updating proc-macro2 v1.0.86 -> v1.0.89
    Updating redox_syscall v0.5.6 -> v0.5.7
    Updating regex v1.10.6 -> v1.11.1
    Updating regex-automata v0.4.7 -> v0.4.8
    Updating regex-syntax v0.8.4 -> v0.8.5
    Updating rinja v0.3.4 -> v0.3.5
    Updating rinja_derive v0.3.4 -> v0.3.5
    Updating rinja_parser v0.3.4 -> v0.3.5
    Updating rustix v0.38.37 -> v0.38.38
    Updating rustversion v1.0.17 -> v1.0.18
    Updating schannel v0.1.24 -> v0.1.26
    Updating serde v1.0.210 -> v1.0.214
    Updating serde_derive v1.0.210 -> v1.0.214
    Updating serde_json v1.0.128 -> v1.0.132
    Updating syn v2.0.79 -> v2.0.87
    Updating tar v0.4.42 -> v0.4.43
    Updating terminal_size v0.3.0 -> v0.4.0
    Updating thiserror v1.0.64 -> v1.0.66
    Updating thiserror-impl v1.0.64 -> v1.0.66
    Updating tokio v1.40.0 -> v1.41.0
    Updating ucd-trie v0.1.6 -> v0.1.7
    Updating unicase v2.7.0 -> v2.8.0
    Updating unicode-bidi v0.3.15 -> v0.3.17
    Updating unicode-properties v0.1.2 -> v0.1.3
    Updating uuid v1.10.0 -> v1.11.0
    Updating wasi-preview1-component-adapter-provider v24.0.0 -> v24.0.1 (latest: v25.0.1)
    Updating wasm-bindgen v0.2.93 -> v0.2.95
    Updating wasm-bindgen-backend v0.2.93 -> v0.2.95
    Updating wasm-bindgen-macro v0.2.93 -> v0.2.95
    Updating wasm-bindgen-macro-support v0.2.93 -> v0.2.95
    Updating wasm-bindgen-shared v0.2.93 -> v0.2.95
    Updating wasm-encoder v0.219.0 -> v0.219.1
    Updating wasm-metadata v0.219.0 -> v0.219.1
    Removing wasmparser v0.219.0
      Adding wasmparser v0.218.0 (latest: v0.219.1)
      Adding wasmparser v0.219.1
    Updating wast v219.0.0 -> v219.0.1
    Updating wat v1.219.0 -> v1.219.1
    Updating wit-component v0.219.0 -> v0.219.1
    Updating wit-parser v0.219.0 -> v0.219.1

library dependencies:
     Locking 5 packages to latest compatible versions
    Updating compiler_builtins v0.1.136 -> v0.1.138
    Updating dlmalloc v0.2.6 -> v0.2.7
    Updating object v0.36.4 -> v0.36.5
    Updating windows-sys v0.52.0 -> v0.59.0

rustbook dependencies:
    Updating anstream v0.6.15 -> v0.6.17
    Updating anstyle v1.0.8 -> v1.0.10
    Updating anstyle-parse v0.2.5 -> v0.2.6
    Updating anstyle-query v1.1.1 -> v1.1.2
    Updating anstyle-wincon v3.0.4 -> v3.0.6
    Updating anyhow v1.0.89 -> v1.0.92
    Updating cc v1.1.22 -> v1.1.34
    Updating clap v4.5.18 -> v4.5.20
    Updating clap_builder v4.5.18 -> v4.5.20
    Updating clap_complete v4.5.29 -> v4.5.36
    Updating colorchoice v1.0.2 -> v1.0.3
    Updating hashbrown v0.14.5 -> v0.15.0
    Updating indexmap v2.5.0 -> v2.6.0
    Updating js-sys v0.3.70 -> v0.3.72
    Updating libc v0.2.159 -> v0.2.161
    Updating once_cell v1.19.0 -> v1.20.2
    Updating pathdiff v0.2.1 -> v0.2.2
    Updating pest v2.7.13 -> v2.7.14
    Updating pest_derive v2.7.13 -> v2.7.14
    Updating pest_generator v2.7.13 -> v2.7.14
    Updating pest_meta v2.7.13 -> v2.7.14
    Updating proc-macro2 v1.0.86 -> v1.0.89
    Updating redox_syscall v0.5.6 -> v0.5.7
    Updating regex v1.10.6 -> v1.11.1
    Updating regex-automata v0.4.7 -> v0.4.8
    Updating regex-syntax v0.8.4 -> v0.8.5
    Updating rustix v0.38.37 -> v0.38.38
    Updating serde v1.0.210 -> v1.0.214
    Updating serde_derive v1.0.210 -> v1.0.214
    Updating serde_json v1.0.128 -> v1.0.132
    Updating syn v2.0.79 -> v2.0.87
    Updating terminal_size v0.3.0 -> v0.4.0
    Updating thiserror v1.0.64 -> v1.0.66
    Updating thiserror-impl v1.0.64 -> v1.0.66
    Updating ucd-trie v0.1.6 -> v0.1.7
    Updating unicase v2.7.0 -> v2.8.0
    Updating unicode-bidi v0.3.15 -> v0.3.17
    Updating wasm-bindgen v0.2.93 -> v0.2.95
    Updating wasm-bindgen-backend v0.2.93 -> v0.2.95
    Updating wasm-bindgen-macro v0.2.93 -> v0.2.95
    Updating wasm-bindgen-macro-support v0.2.93 -> v0.2.95
    Updating wasm-bindgen-shared v0.2.93 -> v0.2.95
    Removing windows-sys v0.48.0
    Removing windows-targets v0.48.5
    Removing windows_aarch64_gnullvm v0.48.5
    Removing windows_aarch64_msvc v0.48.5
    Removing windows_i686_gnu v0.48.5
    Removing windows_i686_msvc v0.48.5
    Removing windows_x86_64_gnu v0.48.5
    Removing windows_x86_64_gnullvm v0.48.5
    Removing windows_x86_64_msvc v0.48.5
```
2024-11-13 12:57:09 +00:00
clubby789
812daed7a8 Run cargo update and update licenses 2024-11-13 12:22:10 +00:00
klensy
cdd948cbc0 fix clippy warns on windows (not checked by CI) 2024-11-13 15:08:49 +03:00
klensy
dad667b6ac fix tests 2024-11-13 15:08:47 +03:00
Pietro Albini
3c6841725c define all the clippy lints we check in CI in a step 2024-11-13 15:07:04 +03:00
Pietro Albini
6729186908 store the lint levels in the clippy structs themselves 2024-11-13 15:07:03 +03:00
Ralf Jung
9760983353 check_consts: fix error requesting feature gate when that gate is not actually needed 2024-11-13 12:03:16 +01:00
bors
65b3877488 Auto merge of #132872 - onur-ozkan:reapply-132772, r=jieyouxu
Reland #132772: use `download-rustc="if-unchanged"` as a global default

Relands https://github.com/rust-lang/rust/pull/132772 with the fix.

r? jieyouxu (knows the context).
2024-11-13 08:54:51 +00:00
Ralf Jung
c00d64250b const_panic: don't wrap it in a separate function 2024-11-13 09:53:42 +01:00
bors
ec239b888f Auto merge of #132886 - fmease:rustdoc-perf-clean-middle-args, r=GuillaumeGomez
[perf] rustdoc: Perform less work when cleaning middle::ty parenthesized generic args

CC #132697. I presume the perf regression it caused (if real) boils down to query invocation overhead, namely of `def_kind` & `trait_def` as we don't seem to be decoding more often from the crate metadata.

I won't try the obvious and reduce the amount of query calls by threading information via params as that would render the code awkward.

So instead I'm simply trying to attack some low-hanging fruits in the vicinity.

---

Previously, we would `clean_middle_generic_args` *unconditionally* inside `clean_middle_generic_args_with_constraints` even though we didn't actually use its result for parenthesized generic args (`Trait(...) -> ...`).

Now, we only call `clean_middle_generic_args` when necessary. Lastly, I've simplified `clean_middle_generic_args_with_constraints`.

---

r? ghost
2024-11-13 06:07:27 +00:00
Rain
fb3edb2fc7 [illumos] use pipe2 to create anonymous pipes
pipe2 allows the newly-created pipe to atomically be CLOEXEC.

pipe2 was added to illumos a long time ago:
5dbfd19ad5.
I've verified that this change passes all tests.
2024-11-13 05:48:06 +00:00
onur-ozkan
db12ccd88e disable precompiled rustc for "library" and "compiler" profiles
There is an ongoing discussion about this on Zulip and for now we
want to keep these disabled.

Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.60download-rustc.20.3D.20'if-unchanged'.60.20for.20.60compiler.60.20profile.3F

Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-11-13 08:21:22 +03:00
onur-ozkan
508e81fc18 handle channel info before handling git info
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-11-13 08:21:19 +03:00
onur-ozkan
1837f6f5b1 Reapply "Rollup merge of #132772 - onur-ozkan:download-rustc-default, r=jieyouxu"
This reverts commit c0cee4e36b.
2024-11-13 08:21:03 +03:00
bors
44f233f251 Auto merge of #132883 - LaihoE:vectorized_is_sorted, r=thomcc
vectorize slice::is_sorted

Benchmarks using u32 slices:
| len | New | Old |
|--------|----------------------|----------------------|
| 2      | 1.1997 ns           | 889.23 ps           |
| 4      | 1.6479 ns           | 1.5396 ns           |
| 8      | 2.5764 ns           | 2.5633 ns           |
| 16     | 5.4750 ns           | 4.7421 ns           |
| 32     | 11.344 ns           | 8.4634 ns           |
| 64     | 12.105 ns           | 18.104 ns           |
| 128    | 17.263 ns           | 33.185 ns           |
| 256    | 29.465 ns           | 60.928 ns           |
| 512    | 48.926 ns           | 116.19 ns           |
| 1024   | 85.274 ns           | 237.91 ns           |
| 2048   | 160.94 ns           | 469.53 ns           |
| 4096   | 311.60 ns           | 911.43 ns           |
| 8192   | 615.89 ns           | 2.2316 µs           |
| 16384  | 1.2619 µs           | 3.4871 µs           |
| 32768  | 2.5245 µs           | 6.9947 µs           |
| 65536  | 5.2254 µs           | 15.212 µs           |

Seems to be a bit slower on small N but much faster on large N.

Godbolt: https://rust.godbolt.org/z/Txn5MdfKn
2024-11-13 03:43:59 +00:00
bors
242f20dc1e Auto merge of #132972 - matthiaskrgr:rollup-456osr7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #132702 (CFI: Append debug location to CFI blocks)
 - #132851 (Update the doc comment of `ASCII_CASE_MASK`)
 - #132948 (stabilize const_unicode_case_lookup)
 - #132950 (Use GNU ld on m68k-unknown-linux-gnu)
 - #132962 (triagebot: add codegen reviewers)
 - #132966 (stabilize const_option_ext)
 - #132970 (Add tracking issue number to unsigned_nonzero_div_ceil feature)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-13 01:00:17 +00:00
maxcabrajac
a7ac8bfc22 format 2024-11-12 21:57:25 -03:00
Catherine Flores
b829d53c19
New lint: unnecessary_map_or (#11796)
Closes https://github.com/rust-lang/rust-clippy/issues/10118

This lint checks `map_or` method calls to check if they can be
consolidated down to something simpler and/or more readable.

For example, the code
```rs
let x = Some(5);
x.map_or(false, |n| n == 5)
```

can be rewritten as
```rs
let x = Some(5);
x == Some(5)
```

In addition, when the closure is more complex, the code can be altered
from, say,
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.map_or(false, |n| n == [5])
```
into
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.is_some_and(|n| n == [5])
```

This lint also considers cases where the `map_or` can be chained with
other method calls, and accommodates accordingly by adding extra
parentheses as needed to the suggestion.

changelog: add new lint `unnecessary_map_or`
2024-11-13 00:08:36 +00:00
Jacherr
89210d7c5a new lint unnecessary_map_or 2024-11-12 23:00:26 +00:00
Matthias Krüger
d83de7e0c5
Rollup merge of #132970 - tyilo:nonzero-u-div-ceil-issue, r=tgross35
Add tracking issue number to unsigned_nonzero_div_ceil feature

Tracking issue: #132968
2024-11-12 23:26:46 +01:00
Matthias Krüger
ae5c00f053
Rollup merge of #132966 - RalfJung:const_option_ext, r=jhpratt
stabilize const_option_ext

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

FCP passed in that issue.
2024-11-12 23:26:45 +01:00
Matthias Krüger
b952f2ee4f
Rollup merge of #132962 - workingjubilee:add-codegen-reviewers, r=saethlin
triagebot: add codegen reviewers

Discussed with `@saethlin` off-sides
2024-11-12 23:26:45 +01:00
Matthias Krüger
f7e40680b5
Rollup merge of #132950 - knickish:m68k_gnu_ld, r=workingjubilee
Use GNU ld on m68k-unknown-linux-gnu

LLD does not really support the M68k architecture yet, specify `m68k-linux-gnu-ld` as the linker for the platform
2024-11-12 23:26:44 +01:00
Matthias Krüger
978f592539
Rollup merge of #132948 - RalfJung:const_unicode_case_lookup, r=Noratrieb
stabilize const_unicode_case_lookup

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

See there for t-libs-api FCP
2024-11-12 23:26:43 +01:00
Matthias Krüger
5419f41f9a
Rollup merge of #132851 - chansuke:update-comment, r=thomcc
Update the doc comment of `ASCII_CASE_MASK`

Revived and continued the work from https://github.com/rust-lang/rust/pull/120282.

the original [branch](https://github.com/mahmudsudo/rust-1/tree/patch-1) was deleted, i created a new branch to carry the changes forward
2024-11-12 23:26:42 +01:00
Matthias Krüger
bd79fe7a94
Rollup merge of #132702 - 1c3t3a:issue-132615, r=rcvalle
CFI: Append debug location to CFI blocks

Currently we're not appending debug locations to the inserted CFI blocks. This shows up in #132615 and #100783. This change fixes that by passing down the debug location to the CFI type-test generation and appending it to the blocks.

Credits also belong to `@jakos-sec` who worked with me on this.
2024-11-12 23:26:41 +01:00
bors
b420d923cf Auto merge of #132870 - Noratrieb:inline-int-parsing, r=tgross35
`#[inline]` integer parsing functions

This improves the performance of `str::parse` into integers.

Before:
```
compare          fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ std                         │               │               │               │         │
   ├─ 328920585  10.23 ns      │ 24.8 ns       │ 10.34 ns      │ 10.48 ns      │ 100     │ 25600
   ├─ 3255       8.551 ns      │ 8.59 ns       │ 8.551 ns      │ 8.56 ns       │ 100     │ 25600
   ╰─ 5          7.847 ns      │ 7.887 ns      │ 7.847 ns      │ 7.853 ns      │ 100     │ 25600
```

After:
```
compare          fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ std                         │               │               │               │         │
   ├─ 328920585  8.316 ns      │ 23.7 ns       │ 8.355 ns      │ 8.491 ns      │ 100     │ 25600
   ├─ 3255       4.566 ns      │ 4.588 ns      │ 4.586 ns      │ 4.576 ns      │ 100     │ 51200
   ╰─ 5          2.877 ns      │ 3.697 ns      │ 2.896 ns      │ 2.945 ns      │ 100     │ 102400
```

Benchmark:
```rust
fn std(input: &str) -> Result<u64, ParseIntError> {
    input.parse()
}
```
2024-11-12 22:24:50 +00:00
Asger Hautop Drewsen
19843dbcb4 Add tracking issue number to unsigned_nonzero_div_ceil feature 2024-11-12 22:36:54 +01:00
Boxy
6dad074907 Handle infer vars in anon consts on stable 2024-11-12 21:36:42 +00:00
Luca Versari
295cffc4b4 ABI checks: add support for tier2 arches
See #131800 for the data collection behind this change.

Also adds a test that exercise the "empty list of features" path.
2024-11-12 22:34:31 +01:00
Maybe Lapkin
db0740446b
Don't trigger never type lint in a delegation test 2024-11-12 22:23:01 +01:00
klensy
acea108b90 fix REGISTRY_USERNAME to reuse cache between auto and pr jobs 2024-11-13 00:21:37 +03:00
Zachary S
e0c1c8bc50 Make CloneToUninit dyn-compatible 2024-11-12 15:08:41 -06:00
kirk
d3768ea81f use gnu ld for m68k target 2024-11-12 20:48:30 +00:00
Ralf Jung
324d059962 stabilize const_option_ext 2024-11-12 21:42:15 +01:00
Ben Kimock
f6e913b259 Querify MonoItem collection 2024-11-12 14:48:10 -05:00
Jubilee Young
048824b773 triagebot: add codegen reviewers 2024-11-12 11:29:42 -08:00
bors
f7273e0044 Auto merge of #132954 - matthiaskrgr:rollup-x3rww9h, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #131831 (extend the "if-unchanged" logic for compiler builds)
 - #132541 (Proper support for cross-crate recursive const stability checks)
 - #132657 (AIX: add run-make support)
 - #132901 (Warn about invalid `mir-enable-passes` pass names)
 - #132923 (Triagebot: Consolidate the T-compiler ad hoc assignment groups)
 - #132938 (Make precise capturing suggestion machine-applicable only if it has no APITs)
 - #132947 (clarify `must_produce_diag` ICE for debugging)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-12 18:04:27 +00:00
Matthias Krüger
f00a31c44d
Rollup merge of #132947 - lqd:trimmed-ice, r=compiler-errors
clarify `must_produce_diag` ICE for debugging

We have a sanity check to ensure the expensive `trimmed_def_paths` functions are called only when producing diagnostics, and not e.g. on the happy path. The panic often happens IME during development because of randomly printing stuff, causing an ICE if no diagnostics were also emitted.

I have this change locally but figured it could be useful to others, so this PR clarifies the message when this happens during development.

The output currently looks like this by default; it's a bit confusing with words missing:

```
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:628:17:
must_produce_diag: `trimmed_def_paths` called but no diagnostics emitted; `with_no_trimmed_paths` for debugging. called at: disabled backtrace
stack backtrace:
   0:     0x7ffff79570f6 - std::backtrace_rs::backtrace::libunwind::trace::h33576c57327a3cea
                               at .../library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7ffff79570f6 - std::backtrace_rs::backtrace::trace_unsynchronized::h7972a09393b420db
                               at .../library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ffff79570f6 - std::sys::backtrace::_print_fmt::hae8c5bbfbf7a8322
                               at .../library/std/src/sys/backtrace.rs:66:9
   3:     0x7ffff79570f6 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1fd6a7a210f5b535
...
```

The new output mentions how to get more information and locate where the `with_no_trimmed_paths` call needs to be added.

1. By default, backtraces are disabled:
```
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:642:17:
`trimmed_def_paths` called, diagnostics were expected but none were emitted. Use `with_no_trimmed_paths` for debugging. Backtraces are currently disabled: set `RUST_BACKTRACE=1` and re-run to see where it happened.
stack backtrace:
   0:     0x7ffff79565f6 - std::backtrace_rs::backtrace::libunwind::trace::h33576c57327a3cea
...
```

2. With backtraces enabled:
```
thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:642:17:
`trimmed_def_paths` called, diagnostics were expected but none were emitted. Use `with_no_trimmed_paths` for debugging. This happened in the following `must_produce_diag` call's backtrace:
   0: <rustc_errors::DiagCtxtHandle>::set_must_produce_diag
             at .../compiler/rustc_errors/src/lib.rs:1133:58
   1: <rustc_session::session::Session>::record_trimmed_def_paths
             at .../compiler/rustc_session/src/session.rs:327:9
   2: rustc_middle::ty::print::pretty::trimmed_def_paths
             at .../compiler/rustc_middle/src/ty/print/pretty.rs:3351:5
...
```

A `\n` could be added here or there, but it didn't matter much whenever I hit this case with the new message.
2024-11-12 18:11:07 +01:00