Commit graph

1228 commits

Author SHA1 Message Date
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
Zalathar
7ec34defe9 Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11: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
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