Commit graph

1221 commits

Author SHA1 Message Date
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
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
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 99317ef14d, reversing
changes made to 9cd272dc85.
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