Commit graph

1238 commits

Author SHA1 Message Date
Jonathan Brouwer
8927aa5738
Add inline syntax for diagnostic messages 2026-02-01 11:11:59 +01:00
Jacob Pratt
4a983e0900
Rollup merge of #151439 - Mark-Simulacrum:bootstrap-bump, r=nnethercote
Bump bootstrap compiler to 1.94

https://forge.rust-lang.org/release/process.html#default-branch-bootstrap-update-tuesday
2026-01-22 00:37:43 -05:00
Mark Rousskov
3dc7a1f33b Bump stage0 2026-01-21 20:03:56 -05:00
bjorn3
3ccabc6a8d Remove old error emitter
This completes the transition to annotate-snippets
2026-01-21 12:14:51 +00:00
Jacob Pratt
2206d935f7
Rollup merge of #149209 - lto_refactors8, r=jackh726
Move LTO to OngoingCodegen::join

This will make it easier to in the future move all this code to link_binary.

Follow up to https://github.com/rust-lang/rust/pull/147810
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-01-21 02:04:01 -05:00
Jonathan Brouwer
e8c3dd36f8
Rollup merge of #151326 - translated, r=davidtwco
Remove `DiagMessage::Translated` in favour of `DiagMessage::Str`

This variant did not seem to be meaningfully different from `DiagMessage::Str`.
Am I missing something or was this just an oversight?

r? @davidtwco
2026-01-19 20:53:24 +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
f50f5dc494
Remove all usages of #[rustc_lint_diagnostics] 2026-01-19 17:39:54 +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
Zalathar
7ec34defe9 Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
Jonathan Brouwer
ec787b07fd
Remove DiagMessage::Translated in favour of DiagMessage::Str 2026-01-18 18:30:11 +01:00
Kivooeo
84f2854bc3 remove fixme & update stderr files 2025-12-16 13:23:48 +00:00
Kivooeo
6d6068f6c5 stabilize annotate-snippet as default formatter 2025-12-16 11:20:27 +00:00
bors
8188f6c808 Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +00:00
Urgau
8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Matthias Krüger
215d7b661e
Rollup merge of #148717 - estebank:macro-spans-2, r=petrochenkov
Point at span within local macros even when error happens in nested external macro

Address issue noticed at https://users.rust-lang.org/t/error-message-does-not-specify-where-in-macro/135157/1. On errors occurring within a macro expansion, point at the innermost local macro expansion point.

```
error[E0308]: mismatched types
  --> $DIR/macro-span-caller-replacement.rs:5:17
   |
LL |             s = format!("{arg}");
   |                 ^^^^^^^^^^^^^^^^ expected `&str`, found `String`
...
LL |     macro_with_format!();
   |     -------------------- in this macro invocation
   |
   = note: this error originates in the macro `format` which comes from the expansion of the macro `macro_with_format` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-12-11 22:09:53 +01:00
Matthias Krüger
bf399241fe
Rollup merge of #146584 - cyrgani:error-codes-macro, r=GuillaumeGomez
remove duplicated columns from `rustc_error_code::error_codes!`

Possible because of rust-lang/rust#146308 ~~, but currently still blocked on the next stage0 bump~~.
2025-12-11 22:09:52 +01:00
Esteban Küber
1bd7934d89 Point at span within local macros even when error happens in nested external macro
```
error[E0308]: mismatched types
  --> $DIR/macro-span-caller-replacement.rs:5:17
   |
LL |             s = format!("{arg}");
   |                 ^^^^^^^^^^^^^^^^ expected `&str`, found `String`
...
LL |     macro_with_format!();
   |     -------------------- in this macro invocation
   |
   = note: this error originates in the macro `format` which comes from the expansion of the macro `macro_with_format` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2025-12-10 19:27:40 +00:00
bors
ba86c0460b Auto merge of #149704 - matthiaskrgr:rollup-u4zhw99, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-06 12:25:12 +00:00
Matthias Krüger
8a6f82efac
Rollup merge of #148814 - bend-n:stabilize_array_windows, r=scottmcm
stabilize `array_windows`

Tracking issue: rust-lang/rust#75027
Closes: rust-lang/rust#75027
FCP completed: https://github.com/rust-lang/rust/issues/75027#issuecomment-3477510526
2025-12-06 09:57:59 +01:00
Jonathan Brouwer
8f59eb0177
Move attribute lints to rustc_lint 2025-12-05 14:22:52 +01:00
bors
eca9d93f90 Auto merge of #149529 - Muscraft:update-annotate-snippets, r=jieyouxu
chore: Update annotate-snippets to 0.12.10

This PR updates `annotate-snippets` to `0.12.10`, which [includes a fix](756366223c/CHANGELOG.md (fixed)) that modifies some test output.
2025-12-02 13:55:16 +00:00
bors
47cd7120d9 Auto merge of #147634 - fmease:mv-var-to-dyn-buf-lints-next, r=jdonszelmann
Move even more early buffered lints to dyn lint diagnostics

Follow-up to https://github.com/rust-lang/rust/pull/145881 and https://github.com/rust-lang/rust/pull/145747.

I originally wanted to migrate most if not the entire rest of the early buffered lints. However, when trying to migrate the buffered lints used by check-cfg I encountered a roadblock. Namely, it depends on `TyCtxt` (well, `Option<TyCtxt>`) which makes it quite hard to migrate (see also https://github.com/rust-lang/rust/pull/147634#issuecomment-3398174584, https://github.com/rust-lang/rust/pull/147634#issuecomment-3398207128 & rust-lang/rust#149215).

So for now, I won't migrate it (maybe rust-lang/rust#149215 will find a solution), nor will I migrate the rest since it's quite tedious to migrate these. I'll leave them for future me.
2025-12-02 07:33:36 +00:00
Scott Schafer
b2b059c20b
chore: Update annotate-snippets to 0.12.10 2025-12-01 18:12:35 -07:00
bendn
919e46f4d4
stabilize [T]::array_windows 2025-12-02 00:37:17 +07:00
Matthias Krüger
ab2cdfc884
Rollup merge of #149433 - scottmcm:delay-layout-ICEs, r=jdonszelmann
Use a delayed bug for this layout ICE

Fixes rust-lang/rust#144501
cc `@matthiaskrgr`
2025-12-01 18:35:11 +01:00
León Orell Valerian Liehr
109e5e5999
Move early buffered lint ambigous-glob-imports to a dyn lint diagnostic 2025-12-01 16:31:53 +01:00
Scott McMurray
673be1b82a Use a delayed bug for this layout ICE
Fixes 144501
2025-11-28 14:49:42 -08:00
Sasha Pourcelot
85e24b0d36 Make the capitalization explicit on keyword misspell error 2025-11-28 20:02:38 +01:00
bjorn3
b13bb4b2da Move LTO to OngoingCodegen::join 2025-11-23 10:33:52 +00:00
bors
c268b39984 Auto merge of #148882 - 20jasper:patch-1, r=nnethercote,Kivooeo
Fix typo in comment in rustc_errors

It seems "CharPose" was a typo since I couldn't find any references to it anywhere else in the codebase
2025-11-23 07:26:56 +00:00
Jacob Asper
548b5d2406
lowercase usize
Co-authored-by: Kivooeo <75776246+Kivooeo@users.noreply.github.com>
2025-11-22 22:25:51 -05:00
Matthias Krüger
d48305fa5b
Rollup merge of #149077 - Muscraft:annotate-snippets-simd, r=davidtwco
feat: Enable annotate-snippets' simd feature

`annotate-snippets` `simd` feature enables the use of `memchr` when searching for `char`/`str`. This should hopefully improve performance when [`annotate-snippets` is passed large `source`](https://github.com/rust-lang/rust/pull/148188#issuecomment-3550280300).
2025-11-22 18:41:22 +01:00
Matthias Krüger
0279cba1f6
Rollup merge of #149065 - Muscraft:annotate-snippets-regressions, r=davidtwco
Address annotate-snippets test differences

When `annotate-snippets` became the default renderer on `nightly`, it came with a few rendering differences. I was not entirely happy with a few of the differences, and after talking with ``@davidtwco`` about them, I decided to address those that seemed like regressions.

r? ``@davidtwco``
2025-11-22 18:41:20 +01:00
mu001999
fc822f8c85 Emit error when using path-segment keyword as cfg pred 2025-11-21 18:48:04 +08:00
Scott Schafer
83485b94a0
fix: Only show one origin for multiline annotations with no source 2025-11-18 19:26:02 -07:00
Scott Schafer
ec17d9ea7c
fix: Sort annotations by line number in AnnotateSnippetEmitter 2025-11-18 19:26:02 -07:00
Scott Schafer
1befb0bac0
fix: Only add extra padding to the first group's last file 2025-11-18 19:26:02 -07:00
Scott Schafer
60427ac5be
feat: Enable annotate-snippets' simd feature 2025-11-18 19:07:18 -07:00
Ralf Jung
bad7d36c33 flush_delayed: add note about stashed diagnostics 2025-11-17 12:09:57 +01:00
Scott Schafer
463c6cea68
chore: Update annotate-snippets to 0.12.9 2025-11-15 14:45:21 -07:00
Stuart Cook
06b18db01b
Rollup merge of #148735 - chenyukang:yukang-fix-ice-148732, r=nnethercote
Fix ICE caused by invalid spans for shrink_file

Fixes rust-lang/rust#148732

There are two issues in this function:
1. the original issue is caused by a typo error, which is fixed in the first commit
2. another different ice(Patch span `7..7` is beyond the end of buffer `0`) will be reported after fixing the first one, is caused by spans cross file boundaries due to macro expansion. It is fixed in the second commit.

r? `@nnethercote`

edited: also fixes rust-lang/rust#148684, added a new testcase for it in the last commit.
2025-11-13 11:57:07 +11:00
Jacob Asper
41e236a0df
Fix typo in comment in rustc_errors
It seems "CharPose" was a typo since I couldn't find any references to it anywhere else in the codebase
2025-11-12 15:26:05 -05:00
yukang
4a2c9a11d5 skip invalid span in error emitter 2025-11-12 17:47:15 +08:00
Scott Schafer
c523b65245
fix(rustdoc): Color doctest errors 2025-11-11 17:23:35 -07:00
bors
2636cb4c13 Auto merge of #148818 - Zalathar:rollup-4vujcg0, r=Zalathar
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#148694 (std: support `RwLock` and thread parking on TEEOS)
 - rust-lang/rust#148712 (Port `cfg_select!` to the new attribute parsing system)
 - rust-lang/rust#148760 (rustc_target: hide TargetOptions::vendor)
 - rust-lang/rust#148771 (IAT: Reinstate early bailout)
 - rust-lang/rust#148775 (Fix a typo in the documentation for the strict_shr function)
 - rust-lang/rust#148779 (Implement DynSend and DynSync for std::panic::Location.)
 - rust-lang/rust#148781 ([rustdoc] Remove unneeded `allow(rustc::potential_query_instability)`)
 - rust-lang/rust#148783 (add test for assoc type norm wf check)
 - rust-lang/rust#148785 (Replace `master` branch references with `main`)
 - rust-lang/rust#148791 (fix "is_closure_like" doc comment)
 - rust-lang/rust#148792 (Prefer to use file.stable_id over file.name from source map)
 - rust-lang/rust#148805 (rustc-dev-guide subtree update)
 - rust-lang/rust#148807 (Document (and test) a problem with `Clone`/`Copy` deriving.)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-11 13:30:50 +00:00
yukang
b1542c92ab Prefer to use file.stable_id over file.name from source map 2025-11-10 10:01:18 +08:00
yukang
725b213606 add regression test for 148684 2025-11-10 09:23:11 +08:00
yukang
8573ee6478 Fix ICE caused by span boundaries due to macro expansion 2025-11-09 16:32:22 +08:00