Commit graph

23042 commits

Author SHA1 Message Date
Stuart Cook
8461682729
Rollup merge of #151384 - pm-tokenstream-tests, r=Kivooeo
add basic `TokenStream` api tests

There were none so far. Especially helpful for rust-lang/rust#130856.
2026-01-20 18:00:11 +11:00
Stuart Cook
8221b5e622
Rollup merge of #151375 - terminal_width_independence, r=lqd
Fix terminal  width dependent tests

[#t-compiler > What is -Zui-testing=no and why are we using it](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/What.20is.20-Zui-testing.3Dno.20and.20why.20are.20we.20using.20it/with/568842970)

See zulip thread. I've verified locally that this lets me run the ui test suite without problems even with a very thin terminal 😆
2026-01-20 18:00:10 +11:00
Stuart Cook
0a5d1e8059
Rollup merge of #151255 - fix-rustdoc-ice-reexported-deprecated-note, r=lolbinarycat
rustdoc: Fix ICE when deprecated note is not resolved on the correct `DefId`

Supersedes https://github.com/rust-lang/rust/pull/151237.
Follow-up of rust-lang/rust#151120.

The `span` overlapping approach wasn't good enough so instead we now check if the reexport itself has the `deprecated` attribute, and if so, we resolve the path to the reexport `DefId`, otherwise we resolve it on the reexported item's `DefId`.

cc @Zalathar
r? @lolbinarycat
2026-01-20 18:00:10 +11:00
Stuart Cook
88df8fd3ef
Rollup merge of #151091 - hide-deprecated-items, r=lolbinarycat
Add new "hide deprecated items" setting in rustdoc

This PR adds a new JS setting which allows the JS to hide deprecated items. This is especially useful for crates like `std` which accumulates deprecated items but never removes them.

Nicely enough, the "deprecation" information was already in the search index, meaning I didn't need to change anything there. Before this PR, it was only used to make the deprecated items rank lower. Well now it's also used to generate an extra CSS class, allowing the JS setting to work.

This is taking over https://github.com/rust-lang/rust/pull/149551.

This feature got approved by the rustdoc team in the [meeting of december](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2025-12-08/near/562553156).

You can give it a try [here](https://rustdoc.crud.net/imperio/hide-deprecated-items/foo/index.html).

r? @lolbinarycat
2026-01-20 18:00:09 +11:00
Stuart Cook
1262ff906b
Rollup merge of #150288 - offload-bench-fix, r=ZuseZ4
Add scalar support for offload

This PR adds scalar support to the offload feature. The scalar management has two main parts:

On the host side, each scalar arg is casted to `ix` type, zero extended to `i64` and passed to the kernel like that.
On the device, the each scalar arg (`i64` at that point), is truncated to `ix` and then casted to the original type.

r? @ZuseZ4
2026-01-20 18:00:08 +11:00
Zalathar
1f423a6e42 coverage: Add a test for macros that only contain other macros 2026-01-20 13:29:09 +11:00
Guillaume Gomez
aef8112b26 Add test for search results of not yet deprecated search items
Improve the `perform-search` goml function to work when search is already open
2026-01-19 23:14:09 +01:00
cyrgani
60e488ec07 add basic TokenStream api tests 2026-01-19 21:46:52 +00:00
Marcelo Domínguez
307a4fcdf8 Add scalar support for both host and device 2026-01-19 22:28:42 +01:00
Guillaume Gomez
9f965bcf76 Add rustdoc GUI test to ensure that the "hide deprecated items" setting is working as expected 2026-01-19 21:37:15 +01:00
Jonathan Brouwer
0833ace2fd
Rollup merge of #151361 - test-issue-61463, r=lqd
add test for issue 61463

A test for the issue where the variable meta is mistakenly treated as a reserved keyword.

close rust-lang/rust#61463
2026-01-19 20:53:25 +01:00
Jonathan Brouwer
8c5e10bb11
Rollup merge of #151249 - fix/151238, r=petrochenkov
Parse ident with allowing recovery when trying to diagnose

Fixes rust-lang/rust#151238

rust-lang/rust#146978 made parsing ident not always allowed-recovery ([change](https://github.com/rust-lang/rust/pull/146978/changes#diff-ef8d6186dc7fb1d03a71446d0c9e6cc9e72158ec6896703dcf05686ee7dc83fcL469-R469)), so when matching macro with `NoopTracker`, which has `Recovery::Forbidden`, ICE happens when trying to parse kw as ident and then unwraping it.

This PR introduces a new method for parsing ident with allowing recovery when trying to diagnose. Then errors will behave like previous.

r? @petrochenkov
2026-01-19 20:53:24 +01:00
Jonathan Brouwer
1968df85fb
Rollup merge of #151171 - issue-141436, r=davidtwco
Do not recover from `Trait()` if generic list is unterminated

If we encounter `fn foo<T: Trait()`, the recovery logic would it as if `Trait` was intended to use the Fn-like trait syntax, but if we don't know for certain that we've parsed a full trait bound (`fn foo<T: Trait()>`), we bail from the recovery as more likely there could have been a missing closing `>` and the `(` corresponds to the start of the fn parameter list.

Fix rust-lang/rust#141436.
2026-01-19 20:53:23 +01:00
Jonathan Brouwer
8a22babce9
Rollup merge of #150895 - rustc_colored_explain, r=Kivooeo
rustc_errors: Add (heuristic) Syntax Highlighting for `rustc --explain`

This PR adds a feature that enables `rustc --explain <error>` to have syntax highlighted code blocks. Due to performance, size and complexity constraints, the highlighter is very heuristc, relying on conventions for capitalizations and such to infer what an identifier represents. The details for the implementation are specified below.
# Changes
1. Change `term::entrypoint` to `term::entrypoint_with_formatter`, which takes an optional third argument, which is a function pointer to a formatter. ([compiler/rustc_errors/src/markdown/mod.rs](https://github.com/rust-lang/rust/compare/main...JayanAXHF:rust:rustc_colored_explain?expand=1#diff-a6e139cadbc2e6922d816eb08f9e2c7b48304d09e6588227e2b70215c4f0725c))
2. Change `MdStream::write_anstream_buf` to be a wrapper around a new function, `MdStream::write_anstream_buf_with_formatter`, which takes a function pointer to a formatter. ([compiler/rustc_errors/src/markdown/mod.rs](https://github.com/rust-lang/rust/compare/main...JayanAXHF:rust:rustc_colored_explain?expand=1#diff-a6e139cadbc2e6922d816eb08f9e2c7b48304d09e6588227e2b70215c4f0725c))
3. Change [`compiler/rustc_driver_impl/src/lib.rs`](https://github.com/rust-lang/rust/compare/main...JayanAXHF:rust:rustc_colored_explain?expand=1#diff-39877a2556ea309c89384956740d5892a59cef024aa9473cce16bbdd99287937) to call `MdStream::write_anstream_buf_with_formatter` instead of `MdStream::write_anstream_buf`.
4. Add a `compiler/rustc_driver_impl/src/highlighter.rs` file, which contains the actual syntax highlighter.

# Implementation Details
1. The highlighter starts from the `highlight` function defined in `compiler/rustc_driver_impl/src/highlighter.rs`. It creates a new instance of the `Highlighter` struct, and calls its `highlight_rustc_lexer` function to start highlighting.
2. The `highlight_rustc_lexer` function uses `rustc_lexer` to lex the code into `Token`s. `rustc_lexer` was chosen since it preserves the newlines after scanning.
3. Based on the kind of token (`TokenKind`), we color the corresponding lexeme.
## Highlighter Implementation
### Identifiers
1. All identifiers that match a (non-exhaustive and minimal) list of keywords are coloured magenta.
2. An identifier that begins with a capital letter is assumed as a type. There is no distinction between a `Trait` and a type, since that would involve name resolution, and the parts of `rustc` that perform name resolution on code do not preserve the original formatting. (An attempt to use `rustc_parse`'s lexer and `TokenStream` was made, which was then printed with the pretty printer, but failed to preserve the formatting and was generally more complex to work with)
3. An identifier that is immediately followed by a parenthesis is recognized as a function identifier, and coloured blue.
## Literals
5. A `String` literal (or its corresponding `Raw`, `C` and `Byte` versions) is colored green.
6. All other literals are colored bright red (orange-esque)
## Everything Else

Everything else is colored bright white and dimmed, to create a grayish colour.

---
# Demo
<img width="1864" height="2136" alt="image" src="https://github.com/user-attachments/assets/b17d3a71-e641-4457-be85-5e5b1cea2954" />

<caption> Command: <code>rustc --explain E0520</code> </caption>

---
This description was not generated by an LLM (:p)

cc: @bjorn3
2026-01-19 20:53:21 +01:00
Jonathan Brouwer
958d1f907b
Rollup merge of #150879 - remove_diag_lints, r=Kivooeo
Remove the diagnostic lints

Removes the `untranslatable_diagnostic` and `diagnostic_outside_of_impl` lints
These lints are allowed for a while already. Per https://github.com/rust-lang/compiler-team/issues/959, we no longer want to enforce struct diagnostics for all usecases, so this is no longer useful.

r? @Kivooeo
I recommend reviewing commit by commit (also feel free to wait with reviewing until the MCP is accepted)

@rustbot +S-blocked
Blocked by https://github.com/rust-lang/compiler-team/issues/959
2026-01-19 20:53:20 +01:00
Jonathan Brouwer
619f1378ed
Rollup merge of #148623 - trimmed-paths, r=davidtwco
Ignore `#[doc(hidden)]` items when computing trimmed paths for printing

The `trimmed_def_paths` query examines all items in the current crate, and all pub items in immediate-dependency crates (including the standard library), to see which item names are unique and can therefore be printed unambiguously as a bare name without a module path.

Currently that query has no special handling for `#[doc(hidden)]` items, which has two consequences:
- Hidden names can be considered unique, and will therefore be printed without a path, making it hard to find where that name is defined (since it normally isn't listed in documentation).
- Hidden names can conflict with visible names that would otherwise be considered unique, causing diagnostics to mysteriously become more verbose based on internal details of other crates.

This PR therefore makes the `trimmed_def_paths` query ignore external-crate items that are `#[doc(hidden)]`, along with their descendants.

As a result, hidden item names are never considered unique for trimming, and no longer interfere with visible item names being considered unique.

---
- Fixes https://github.com/rust-lang/rust/issues/148387.
2026-01-19 20:53:19 +01:00
Boxy
8a573580f8 Fix terminal dependent tests 2026-01-19 18:54:02 +00:00
Jonathan Brouwer
0fa5589e0a
Remove obsolote diagnostic tests 2026-01-19 17:40:42 +01:00
Jonathan Brouwer
0ee7d96253
Remove all allows for diagnostic_outside_of_impl and untranslatable_diagnostic throughout the codebase
This PR was mostly made by search&replacing
2026-01-19 17:39:49 +01:00
JayanAXHF
67c45b739a feat: added syntax highlighting for code blocks in rustc --explain
This commit adds a heuristics-based syntax highlighter for the `rustc
--explain` command. It uses `rsutc_lexer`'s lexer to parse input in
tokens, and matches on them to determine their color.
2026-01-19 17:44:24 +05:30
KaiTomotake
eeed3376e2
add test program
A test for the issue where the variable meta is mistakenly treated as a reserved keyword.
2026-01-19 19:49:07 +09:00
bors
158ae9ee50 Auto merge of #151360 - JonathanBrouwer:rollup-UpAM1gc, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#151071 (Generate openmp metadata)
 - rust-lang/rust#151302 (add lint test)
 - rust-lang/rust#151338 (Factor out diagnostic slug checking from `DiagnosticDerive` )
 - rust-lang/rust#151354 (ci: Move lockfile updates to a script)

r? @ghost
2026-01-19 09:40:32 +00:00
Jonathan Brouwer
d2375c2edf
Rollup merge of #151338 - factor_slug, r=Kivooeo
Factor out diagnostic slug checking from `DiagnosticDerive`

Doing some cleanup work in preparation for https://github.com/rust-lang/compiler-team/issues/959

r? @Kivooeo
2026-01-19 08:31:32 +01:00
Jonathan Brouwer
3f01ca0f54
Rollup merge of #151302 - add-lint-test, r=lqd
add lint test

closes rust-lang/rust#138069, which was already fixed.
2026-01-19 08:31:32 +01:00
Jonathan Brouwer
a56e2d3037
Rollup merge of #151071 - gen-openmp-metadata, r=nnethercote
Generate openmp metadata

LLVM has an openmp-opt pass, which is part of the default O3 pipeline.
The pass bails if we don't have a global called openmp, so let's generate it if people enable our experimental offload feature. openmp is a superset of the offload feature, so they share optimizations.
In follow-up PRs I'll start verifying that LLVM optimizes Rust the way we want it.

r? compiler
2026-01-19 08:31:31 +01:00
bors
53b6f89be2 Auto merge of #151352 - Zalathar:rollup-nUIzD3P, r=Zalathar
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#151080 (fix(build-manifest): enable docs target fallback for `rustc-docs`)
 - rust-lang/rust#151328 (Fix capitalization of diag messages)
 - rust-lang/rust#151341 (miri subtree update)
 - rust-lang/rust#151349 (Add myself to the review rotation)

r? @ghost
2026-01-19 06:22:30 +00:00
Stuart Cook
82db63b7ca
Rollup merge of #151328 - diag-case, r=Urgau
Fix capitalization of diag messages

Per https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide
> Error, Warning, Note, and Help messages start with a lowercase letter and do not end with punctuation.
2026-01-19 15:28:02 +11:00
bors
3d087e6044 Auto merge of #150309 - dianqk:ssa-range, r=cjgillot
New MIR Pass: SsaRangePropagation

As an alternative to https://github.com/rust-lang/rust/pull/150192.

Introduces a new pass that propagates the known ranges of SSA locals.
We can know the ranges of SSA locals at some locations for the following code:
```rust
fn foo(a: u32) {
  let b = a < 9;
  if b {
    let c = b; // c is true since b is whitin the range [1, 2)
    let d = a < 8; // d is true since b whitin the range [0, 9)
  }
}
```

This PR only implements a trivial range: we know one value on switch, assert, and assume.
2026-01-19 03:04:55 +00:00
mu001999
3713512217 Parse ident with allowing recovery when trying to recover in diagnosing 2026-01-19 10:08:45 +08:00
Zalathar
2df2c72d7a Ignore #[doc(hidden)] items when computing trimmed paths 2026-01-19 12:27:27 +11:00
Zalathar
3327a92b43 Add some tests for trimmed paths in diagnostics 2026-01-19 12:27:27 +11:00
KaiTomotake
3a8b57715f
add lint test
Co-authored-by: Redddy <midzy0228@gmail.com>
2026-01-19 08:59:44 +09:00
Jonathan Brouwer
f5a1fc75ad
Update uitests 2026-01-18 22:41:00 +01:00
Jonathan Brouwer
7ec4a8e798
Update uitests 2026-01-18 22:36:39 +01:00
bors
9b37157ece Auto merge of #151339 - JonathanBrouwer:rollup-DYrRtnq, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#151287 (Reorganizing `tests/ui/issues` 15 tests [2/N] )
 - rust-lang/rust#151309 (fix: thread creation failed on the wasm32-wasip1-threads target.)
 - rust-lang/rust#151335 (Port rustc allocator attributes to attribute parser)

r? @ghost
2026-01-18 21:30:40 +00:00
Jonathan Brouwer
5a96067a65
Rollup merge of #151287 - m15t, r=Kivooeo
Reorganizing `tests/ui/issues` 15 tests [2/N]

part of https://github.com/rust-lang/rust/issues/133895

r? Kivooeo
2026-01-18 21:43:44 +01:00
bors
0a3cd3b6b6 Auto merge of #151325 - JonathanBrouwer:rollup-YoCcqTr, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#150767 (Allow invoking all help options at once)
 - rust-lang/rust#150886 (Added mGCA related tests)
 - rust-lang/rust#151245 (Explicitly list crate level attrs)
 - rust-lang/rust#151268 (Fix ICE on inconsistent import resolution with macro-attributed extern crate)
 - rust-lang/rust#151275 (Normalize type_const items even with feature `generic_const_exprs`)
 - rust-lang/rust#151288 (Use `find_attr` instead of `attr::contains_name` in `lower_const_item_rhs`)
 - rust-lang/rust#151321 (Port #![no_main] to the attribute parser.)

r? @ghost
2026-01-18 18:08:26 +00:00
Jonathan Brouwer
3c2c533d2e
Rollup merge of #151321 - no_main-attr, r=JonathanBrouwer
Port #![no_main] to the attribute parser.

Tracking issue: https://github.com/rust-lang/rust/issues/131229

r? @JonathanBrouwer
2026-01-18 18:26:06 +01:00
Jonathan Brouwer
4df80b1976
Rollup merge of #151288 - fix/151250, r=BoxyUwU
Use `find_attr` instead of `attr::contains_name` in `lower_const_item_rhs`

Fixes rust-lang/rust#151250

`attr::contains_name` uses `AttributeExt::name()` to filter, but for `hir::Attribute::Parsed`, this method will return `None`, and then `attr::contains_name` will return `false` here. So that the previous logic cannot work as expected.

r? @BoxyUwU
2026-01-18 18:26:06 +01:00
Jonathan Brouwer
9f49af87cb
Rollup merge of #151275 - fix/151251, r=BoxyUwU
Normalize type_const items even with feature `generic_const_exprs`

Fixes rust-lang/rust#151251

With feature `generic_const_exprs` enabled, consts with `#[type_const]` won't be normalized even if they need. Then ICE happens when CTFE tries to evaluate such const without body.

Fix this by normalizing such consts even with feature `generic_const_exprs` enabled.

r? @BoxyUwU
2026-01-18 18:26:06 +01:00
Jonathan Brouwer
85d2cf32f1
Rollup merge of #151268 - ice-inconsistent-resolution-151213, r=mati865
Fix ICE on inconsistent import resolution with macro-attributed extern crate

Fixes rust-lang/rust#151213 using issue_145575_hack_applied in the same way as in rust-lang/rust#149860.
2026-01-18 18:26:04 +01:00
Jonathan Brouwer
57edde388b
Rollup merge of #150886 - mgca-test, r=BoxyUwU
Added mGCA related tests

Add regression tests for subsequent mGCA tasks

edit:

resolve: https://github.com/rust-lang/rust/issues/147415 `tests\ui\const-generics\mgca\size-of-generic-ptr-in-array-len.rs`
resolve: https://github.com/rust-lang/rust/issues/141014 `tests\ui\const-generics\mgca\assoc-const-projection-in-bound.rs`

and crashes: 138226, 138226-2, 149809, 150960
2026-01-18 18:26:03 +01:00
Jonathan Brouwer
05d494faaf
Rollup merge of #150767 - all-help, r=jieyouxu
Allow invoking all help options at once

Implements rust-lang/rust#150442

Help messages are printed in the order they are invoked, but only once (e.g. `--help -C help --help` prints regular help then codegen help).

Lint groups (`-Whelp`) are always printed last due to necessarily coming later in the compiler pipeline.

Adds `help` flags to `-C` and `-Z` to avoid an error in `build_session_options`.

cc @bjorn3 [#t-compiler/major changes > Allow combining &#96;--help -C help -Z help -… compiler-team#954 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Allow.20combining.20.60--help.20-C.20help.20-Z.20help.20-.E2.80.A6.20compiler-team.23954/near/564358190) - this currently maintains the behaviour of unrecognized options always failing-fast, as this happens within `getopt`s parsing, before we can even check if help options are present.
2026-01-18 18:26:03 +01:00
Oscar Bray
ea77786cdb Port #![no_main] to the attribute parser. 2026-01-18 16:50:49 +00:00
bors
2b112efccc Auto merge of #149484 - ogoffart:fix-68838, r=petrochenkov
Supress some lookup errors if a module contains `compile_error!`

The problem is that when a macro expand to `compile_error!` because its input is malformed, the actual error message from the `compile_error!` might be hidden in a long list of other messages about using items that should have otherwise been generated by the macro.

So suppress error about missing items in that module.

Fixes rust-lang/rust#68838
2026-01-18 14:50:15 +00:00
Olivier Goffart
f3e73dced1 Supress some lookup errors if a module contains compile_error!
The problem is that when a macro expand to `compile_error!` because
its input is malformed, the actual error message from the
`compile_error!` might be hidden in a long list of other messages about
using items that should have otherwise been generated by the macro.

So suppress error about missing items in that module.

Fixes issue 68838
2026-01-18 14:37:57 +01:00
Jacob Pratt
80db7158af
Rollup merge of #151235 - type-info-rename-bits, r=oli-obk
Change field `bit_width: usize` to `bits: u32` in type info

Follow-up https://github.com/rust-lang/rust/pull/151123#discussion_r2698418929. Quotes:

@Skgland:
> > I'm not sure whether we should use `usize` or `u64` here to represent the bit width.
>
> My expectation would be `u32` matching the associated `{u,i}N::BITS`[^1][^2][^3] constant that already exists on the integer types.
>
> [^1]: https://doc.rust-lang.org/std/primitive.i8.html#associatedconstant.BITS
> [^2]: https://doc.rust-lang.org/std/primitive.i128.html#associatedconstant.BITS
> [^3]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.BITS

@SpriteOvO:
> I found some [previous discussions](https://github.com/rust-lang/rust/pull/76492#issuecomment-700516940) regarding the type of `::BITS` constant. And during the stabilization of `::BITS`, the choice of `u32` affected some ecosystem crates (#81654), but soon after, these crates all accepted the `u32` type.
>
> So I think it makes sense to keep the type consistent with `::BITS` here. Then I'd also like to change the name from `bit_width` to `bits`, also for consistency.

r? @oli-obk
2026-01-18 03:16:46 -05:00
Jacob Pratt
0331284ffc
Rollup merge of #150955 - yukang-fix-149889-unused-assign, r=fee1-dead
Underscore-prefixed bindings are explicitly allowed to be unused

Fixes rust-lang/rust#149889
2026-01-18 03:16:45 -05:00
mu001999
db9f9e6501 Use find_attr instead of attr::contains_name in lower_const_item_rhs 2026-01-18 13:38:19 +08:00
tuturuu
2c7969a0cd
add metadata and bless moved tests 2026-01-18 06:23:47 +01:00