1196 Commits

Author SHA1 Message Date
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
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
yukang
0006737ca1 Fix the typo error caused span ice 2025-11-09 16:11:32 +08:00
Marijn Schouten
244eef6d2b a few small clippy fixes 2025-11-07 19:57:52 +00:00
bors
c5e283b0d2 Auto merge of #148188 - Muscraft:annotate-snippets-default-on-nightly, r=estebank
feat: Use annotate-snippets by default on nightly

This PR switches the default renderer to use `annotate-snippets` on nightly, but does not affect stable. This is part of the ongoing effort to use `annotate-snippets` to render all diagnostics.

[MCP](https://github.com/rust-lang/compiler-team/issues/937)

Note: This contains the test change from rust-lang/rust#148004, without the change to the default emitter.

rust-lang/rust#59346
rust-lang/rust-project-goals#123

r? `@davidtwco`
2025-11-06 11:45:06 +00:00
Scott Schafer
9cb7deb0b5
refactor: Make short a field on HumanReadableErrorType varinants 2025-11-05 09:01:07 -07:00
Scott Schafer
4748d92a95
feat: Always use annotate-snippets for Unicode output 2025-11-05 09:01:07 -07:00
Scott Schafer
a75bd03fb9
fix: Respect HumanReadableErrorType::AnnotateSnippet 2025-11-05 09:01:07 -07:00
Scott Schafer
37bb0c262a
chore: Make AnnotateSnippetEmitter match revert of "all spans must be disjoint" 2025-11-05 09:01:07 -07:00
Scott Schafer
457cbb06a1
chore: Update annotate-snippets to 0.12.8 2025-11-05 09:00:58 -07:00
bjorn3
973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
Matthias Krüger
e3dbcdf753
Rollup merge of #148004 - Muscraft:only-single-line-item-attributes, r=estebank
fix: Only special case single line item attribute suggestions

`rustc` currently special cases suggestions to add [`#[derive(_)]\n` and other attributes](dc1feabef2/compiler/rustc_errors/src/emitter.rs (L2288C36-L2288C72)), to add more context to the suggestions.

> // The suggestion adds an entire line of code, ending on a newline, so we'll also
> // print the *following* line, to provide context of what we're advising people to
> // do. Otherwise you would only see contextless code that can be confused for
> // already existing code, despite the colors and UI elements.
> // We special case `#[derive(_)]\n` and other attribute suggestions, because those
> // are the ones where context is most useful.

This special case is a bit broad at the moment and applies to suggestions just to add an attribute, as well as suggestions that contain an attribute and other code, i.e.
```rust
#[derive(Clone)]
```
and
```rust
#[cfg(not(test))]
impl Default for NewWithCfg {
    fn default() -> Self {
        Self::new()
    }
}
```

In the latter case, adding a line for context after the suggestion doesn't provide much benefit. Example:
![temp](https://github.com/user-attachments/assets/6859b400-aa99-4c1b-9eb0-0cd67ae35bf9)

This PR makes it so that this special case only applies to suggestions that just add an attribute and nothing else. This will also make `rustc`'s output match `annotate-snippets`.
2025-11-03 21:20:22 +01:00
Esteban Küber
1d860902f6 When a trait isn't implemented, but another similar impl is found, point at it:
```
error[E0277]: the trait bound `u32: Trait` is not satisfied
  --> $DIR/trait_objects_fail.rs:26:9
   |
LL |     foo(&10_u32);
   |         ^^^^^^^ the trait `Trait` is not implemented for `u32`
   |
help: the trait `Trait<12>` is not implemented for `u32`
      but trait `Trait<2>` is implemented for it
  --> $DIR/trait_objects_fail.rs:7:1
   |
LL | impl Trait<2> for u32 {}
   | ^^^^^^^^^^^^^^^^^^^^^
   = note: required for the cast from `&u32` to `&dyn Trait`
```

Pointing at the `impl` definition that *could* apply given a different self type is particularly useful when it has a blanket self type, as it might not be obvious and is not trivially greppable:

```
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
  --> $DIR/issue-62742.rs:4:5
   |
LL |     WrongImpl::foo(0i32);
   |     ^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Raw<_>` is not implemented for `RawImpl<_>`
      but trait `Raw<[_]>` is implemented for it
  --> $DIR/issue-62742.rs:29:1
   |
LL | impl<T> Raw<[T]> for RawImpl<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `SafeImpl`
  --> $DIR/issue-62742.rs:33:35
   |
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
   |                                   ^^^^^^ required by this bound in `SafeImpl`
```
2025-10-31 20:38:31 +00:00
Scott Schafer
73515c787a
fix: Only special case single line item attribute suggestions 2025-10-29 19:21:23 -06:00
Scott Schafer
354b9779bf
chore: Update to the latest annotate-snippets 2025-10-24 12:50:19 -06:00
Rémy Rakic
a2b48332ba Revert "Auto merge of #146121 - Muscraft:filter-suggestion-parts, r=petrochenkov"
This reverts commit 99317ef14d0be42fa4039eea7c5ce50cb4e9aee7, reversing
changes made to 9cd272dc85320e85a8c83a1a338870de52c005f3.
2025-10-23 18:18:35 +00:00
Scott Schafer
c7f014ddc6
fix: Don't add diff symbol to unchanged lines 2025-10-22 15:30:57 -06:00
bors
dc1feabef2 Auto merge of #147207 - Muscraft:anstyle-anstream, r=davidtwco
refactor: Move to anstream + anstyle for styling

`rustc` uses [`termcolor`](https://crates.io/crates/termcolor) for styling and writing, while `annotate-snippets` uses [`anstyle`](https://crates.io/crates/anstyle) for styling and currently writes directly to a `String`. When rendering directly to a terminal, there isn't/shouldn't be any differences. Still, there are differences in the escape sequences, which leads to slightly different output in JSON and SVG tests. As part of my work to have `rustc` use `annotate-snippets`, and to reduce the test differences between the two, I switched `rustc` to use `anstlye` and [`anstream`](https://crates.io/crates/anstream) for styling and writing.

The first commit migrates to `anstyle` and `anstream` and notably does not change the output. This is because it includes extra formatting to ensure that `anstyle` + `anstream` match the current output exactly. Most of this code is unnecessary, as it adds redundant resets or uses 256-color (8-bit) when it could be using 4-bit color. The subsequent commits remove this extra formatting while maintaining the correct output when rendered.

[Zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/annotate-snippets.20hurdles)
2025-10-22 16:22:51 +00:00
Scott Schafer
5aedef17f9
chore: Remove unneeded ansi escape resets from output 2025-10-20 12:13:26 -06:00
Scott Schafer
a484119046
refactor: Use plain ansi colors for output 2025-10-20 12:13:26 -06:00
Scott Schafer
926d4535cd
refactor: Move to anstream + anstyle for styling 2025-10-20 12:13:25 -06:00
relaxcn
ad67c9d581 fix: Use untrimmed line numbers for trimmed suggestions 2025-10-19 23:58:04 +08:00
Matthias Krüger
f64703ce7a
Rollup merge of #147354 - chenyukang:yukang-fix-147070-wrong-highlight-span, r=estebank
Fix wrong span for hightlight for duplicated diff lines

Fixes rust-lang/rust#147070

From comments: https://github.com/rust-lang/rust/issues/147070#issuecomment-3368593144
The lightlight row for diff must at least 2.

r? `@estebank`
2025-10-07 07:04:17 +02:00
yukang
231c39545e Fix wrong span for hightlight for duplicated diff lines 2025-10-07 02:45:11 +00:00
Scott Schafer
9c6897bd07
test: Subtract code_offset from width for ui_testing 2025-10-02 05:45:16 -06:00
Scott Schafer
b307a1146b
fix: Filter suggestion parts that match existing code 2025-09-04 17:42:13 -06:00
Scott Schafer
f196f50d66
chore: Remove redundant disjoint spans assert 2025-09-04 17:42:13 -06:00
Scott Schafer
81557349be
refactor: Move assert for disjoint substitution spans 2025-09-04 17:42:13 -06:00
Stuart Cook
584832843d
Rollup merge of #146120 - smoelius:patch-3, r=lqd
Correct typo in `rustc_errors` comment
2025-09-04 10:01:59 +10:00
Samuel Moelius
5e9b655e70
Correct typo in rustc_errors comment 2025-09-02 08:43:34 -04: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
Stuart Cook
2246dda682
Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol
Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml`

Following on from rust-lang/rust#145740.

r? `@Kobzol`
2025-08-29 12:54:12 +10:00
Stuart Cook
2fae59ac96
Rollup merge of #144864 - Muscraft:no-source-fixes, r=jieyouxu
No source fixes

This PR started as a fix for a rendering bug that [got noticed in #143661](https://github.com/rust-lang/rust/pull/143661#discussion_r2199109530), but turned into a fix for any rendering bugs related to files with no source.
- Don't add an end column separator after a file with no source
- Add column separator before secondary messages with no source
- Render continuation between no source labels

Before
```
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   │             ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
   ╰╴
note: constructor is not visible here due to private fields
   ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL
   │
   ╰ note: private field
   │
   ╰ note: private field
```

After
```
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   │             ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╰╴
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
note: constructor is not visible here due to private fields
   ╭▸ $SRC_DIR/alloc/src/boxed.rs:LL:COL
   │
   ├ note: private field
   │
   ╰ note: private field
```

Note: This PR also makes it so `rustc` and `annotate-snippets` match in these cases
2025-08-28 23:10:34 +10:00
Nicholas Nethercote
daf6fe2c1b Add serde_json to [workspace.dependencies]. 2025-08-28 20:10:54 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Scott Schafer
2bd47d2646
fix: Render continuation between no source labels 2025-08-26 15:15:17 -06:00
Scott Schafer
93d16c5100
fix: Add col separator before secondary messages with no source 2025-08-26 15:15:17 -06:00
Scott Schafer
8835ea854e
fix: Don't add an end column separator after a file with no source 2025-08-26 15:15:17 -06:00
Jana Dönszelmann
4b35cde904
Support lints in early attribute parsing 2025-08-24 09:14:49 +02:00
Jana Dönszelmann
3bf6144461
Allow errors to be emitted as fatal during attribute parsing 2025-08-24 09:14:49 +02:00
Josh Triplett
c99320156d Refactor lint buffering to avoid requiring a giant enum
Lint buffering currently relies on a giant enum `BuiltinLintDiag`
containing all the lints that might potentially get buffered. In
addition to being an unwieldy enum in a central crate, this also makes
`rustc_lint_defs` a build bottleneck: it depends on various types from
various crates (with a steady pressure to add more), and many crates
depend on it.

Having all of these variants in a separate crate also prevents detecting
when a variant becomes unused, which we can do with a dedicated type
defined and used in the same crate.

Refactor this to use a dyn trait, to allow using `LintDiagnostic` types
directly.

This requires boxing, but all of this is already on the slow path
(emitting an error).

Because the existing `BuiltinLintDiag` requires some additional types in
order to decorate some variants, which are only available later in
`rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn
LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-22 01:59:56 -07:00
Josh Triplett
f3c8b7ad40 Split rustc_hir_id out of rustc_hir
Some crates depend on `rustc_hir` but only want `HirId` and similar id
types. `rustc_hir` is a heavy dependency, since it pulls in
`rustc_target`. Split these types out into their own crate
`rustc_hir_id`.

This allows `rustc_errors` to drop its direct dependency on `rustc_hir`.

(`rustc_errors` still depends on `rustc_hir` indirectly through
`rustc_lint_defs`; a subsequent commit will fix that.)
2025-08-20 15:01:13 -07:00
Josh Triplett
b65fab6299 Move IntoDiagArg earlier in the dependency chains
`rustc_errors` depends on numerous crates, solely to implement its
`IntoDiagArg` trait on types from those crates. Many crates depend on
`rustc_errors`, and it's on the critical path.

We can't swap things around to make all of those crates depend on
`rustc_errors` instead, because `rustc_errors` would end up in
dependency cycles.

Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far
fewer dependencies, and then have most of these crates depend on
`rustc_error_messages`.

This allows `rustc_errors` to drop dependencies on several crates,
including the large `rustc_target`.

(This doesn't fully reduce dependency chains yet, as `rustc_errors`
still depends on `rustc_hir` which depends on `rustc_target`. That will
get fixed in a subsequent commit.)
2025-08-20 15:01:13 -07:00