Commit Graph

1294 Commits

Author SHA1 Message Date
Esteban Küber
d48e699b6c Emit fewer errors for incorrect rtn and = -> : typos in bindings
Stash parse errors when pasing rtn that doesn't use `(..)`.
Emit single error on `Foo::bar(qux)` that looks like rtn in incorrect position and suggest `Foo::bar(..)`.
```
error: return type notation not allowed in this position yet
  --> $DIR/let-binding-init-expr-as-ty.rs:18:10
   |
LL | struct K(S::new(()));
   |          ^^^^^^^^^^
   |
help: furthermore, argument types not allowed with return type notation
   |
LL - struct K(S::new(()));
LL + struct K(S::new(..));
   |
```
On incorrect rtn in let binding type for an existing inherent associated function, suggest `:` -> `=` to turn the "type" into a call expression.
```
error: expected type, found associated function call
  --> $DIR/let-binding-init-expr-as-ty.rs:29:12
   |
LL |     let x: S::new(());
   |            ^^^^^^^^^^
   |
help: use `=` if you meant to assign
   |
LL -     let x: S::new(());
LL +     let x = S::new(());
   |
```
2026-03-20 19:33:05 +00:00
Esteban Küber
408066f310 Do not suggest introducing new binding when other suggestions are present 2026-03-15 03:51:25 +00:00
Jonathan Brouwer
77134bd3e2 Rollup merge of #153611 - RalfJung:interp-error-strings, r=oli-obk
interpret: go back to regular string interpolation for error messages

Using the translatable diagnostic infrastructure adds a whole lot of boilerplate which isn't actually useful for const-eval errors, so let's get rid of it. This effectively reverts https://github.com/rust-lang/rust/pull/111677. That PR effectively added 1000 lines and this PR only removes around 600 -- the difference is caused by (a) keeping some of the types around for validation, where we can use them to share error strings and to trigger the extra help for pointer byte shenanigans during CTFE, and (b) this not being a full revert of rust-lang/rust#111677; I am not touching diagnostics outside the interpreter such as all the const-checking code which also got converted to fluent in the same PR.

The last commit does something similar for `LayoutError`, which also helps deduplicate a bunch of error strings. I can make that into a separate PR if you prefer.

r? @oli-obk
Fixes https://github.com/rust-lang/rust/issues/113117
Fixes https://github.com/rust-lang/rust/issues/116764
Fixes https://github.com/rust-lang/rust/issues/112618
2026-03-11 22:05:44 +01:00
Ralf Jung
94361fba3e interpret: go back to regular string interpolation for error messages 2026-03-11 13:53:40 +01:00
Nicholas Nethercote
3399ed3c9a Simplify type_of_opaque.
There is a bunch of complexity supporting the "cannot check whether the
hidden type of opaque type satisfies auto traits" error that shows up in
`tests/ui/impl-trait/auto-trait-leak.rs`. This is an obscure error that
shows up in a single test. If we are willing to downgrade that error
message to a cycle error, we can do the following.

- Simplify the `type_of_opaque` return value.
- Remove the `cycle_stash` query modifier.
- Remove the `CyclePlaceholder` type.
- Remove the `SelectionError::OpaqueTypeAutoTraitLeakageUnknown`
  variant.
- Remove a `FromCycleError` impl.
- Remove `report_opaque_type_auto_trait_leakage`.
- Remove the `StashKey::Cycle` variant.
- Remove the `CycleErrorHandling::Stash` variant.

That's a lot! I think this is a worthwhile trade-off.
2026-03-11 21:54:42 +11:00
Jonathan Brouwer
4af0d1551a Rollup merge of #153641 - nnethercote:mv-Spanned, r=JonathanBrouwer
Move `Spanned`.

It's defined in `rustc_span::source_map` which doesn't make any sense because it has nothing to do with source maps. This commit moves it to the crate root, a more sensible spot for something this basic.

r? @JonathanBrouwer
2026-03-10 22:46:56 +01:00
Nicholas Nethercote
c12ab08c14 Move Spanned.
It's defined in `rustc_span::source_map` which doesn't make any sense
because it has nothing to do with source maps. This commit moves it to
the crate root, a more sensible spot for something this basic.
2026-03-11 06:25:23 +11:00
Guillaume Gomez
744c50315d Add missing Diag::with_span_suggestion_with_style method 2026-03-09 22:18:58 +01:00
Guillaume Gomez
4019a92ca8 Add new rustc_errors::DiagDecorator type 2026-03-09 11:19:53 +01:00
Zalathar
985b41d387 Remove the rustc_data_structures::assert_matches! re-exports 2026-03-08 22:02:23 +11:00
Josh Stone
32bae1353e Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
Jonathan Brouwer
f540b27f90 Rollup merge of #153508 - JonathanBrouwer:improved_eager_format, r=GuillaumeGomez
Clean up the eager formatting API

For https://github.com/rust-lang/rust/issues/151366#event-22181360642

Previously eager formatting worked by throwing the arguments into a diag, formatting, then removing the args again. This is ugly so instead we now just do the formatting completely separately.
This PR has nice commits, so I recommend reviewing commit by commit.

r? @GuillaumeGomez
2026-03-07 01:42:37 +01:00
Jonathan Brouwer
10eb844bac Remove eagerly_format_to_string from DiagCtxt 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
8c87d0761f Remove eagerly_format from DiagCtxt 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
43221b43b6 Remove eagerly_format from Diag 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
828c0c0668 Remove remove_arg from diagnostics 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
c2f1e9d71d Remove stored args from diagnostics 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
2b0552f0cb Add new eager formatting API 2026-03-06 18:52:11 +01:00
Jonathan Brouwer
46cedc33b8 Use eager formatting in #[derive(Subdiagnostic)] 2026-03-06 18:32:54 +01:00
Jonathan Brouwer
8d96e603b1 Preserve the DiagLocation in diag_lint_level 2026-03-06 15:15:43 +01:00
Guillaume Gomez
9dc456a366 Remove usage of LintContext::span_lint in clippy 2026-03-05 23:53:53 +01:00
Jonathan Brouwer
53ef4d297e Rollup merge of #153414 - JonathanBrouwer:translate_cleanup, r=Kivooeo
Rename translation -> formatting

Because there is no translation happening anymore

r? @Kivooeo
2026-03-04 19:30:42 +01:00
Jonathan Brouwer
1500680ba5 Rollup merge of #153401 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Migrationg of `LintDiagnostic` - part 7

Part of https://github.com/rust-lang/rust/issues/153099.

This PR removes the `LintDiagnostic` trait and proc-macro. \o/

r? @JonathanBrouwer
2026-03-04 19:30:40 +01:00
Jonathan Brouwer
1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00
Jonathan Brouwer
d8092147fe Rename translation -> formatting 2026-03-04 17:47:24 +01:00
Guillaume Gomez
7ceb8ea1b0 Remove unused LintDiagnostic trait 2026-03-04 15:16:51 +01:00
Guillaume Gomez
56d636a762 Implement Diagnostic directly on Box<FnOnce...> 2026-03-03 22:14:53 +01:00
Guillaume Gomez
bd538f90fe Remove unused rustc_errors::LintDiagnosticBox trait 2026-03-03 17:21:41 +01:00
Guillaume Gomez
924748717b Implement Diagnostic trait for rustc_errors::DecorateDiagCompat 2026-03-03 17:21:16 +01:00
mu001999
d0a182f485 Remove unused features in compiler 2026-03-02 09:38:04 +08:00
Jonathan Brouwer
51f35d76a2 Pass DiagArgMap instead of FluentArgs into format_diag_message 2026-03-01 10:07:39 +01:00
Jonathan Brouwer
5ade46246e Move DiagArgMap to rustc_error_messages 2026-03-01 10:07:36 +01:00
Jonathan Brouwer
6e8d9c1242 Adjust uses of format_diag_message to remove unwrap 2026-02-28 18:46:53 +01:00
Jonathan Brouwer
5a18412c93 Remove TranslationError 2026-02-28 18:34:17 +01:00
Jonathan Brouwer
66cccfde99 Rollup merge of #147859 - cyrgani:nonfatal-tokenstream-parse, r=petrochenkov,JonathanBrouwer
reduce the amount of panics in `{TokenStream, Literal}::from_str` calls

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/147859)*

Before this PR, calling `TokenStream::from_str` or `Literal::from_str` with an invalid argument would always cause a compile error, even if the `TokenStream` is not used afterwards at all.
This PR changes this so it returns a `LexError` instead in some cases.

This is very theoretically a breaking change, but the doc comment on the impl already says
```
/// NOTE: some errors may cause panics instead of returning `LexError`. We reserve the right to
/// change these errors into `LexError`s later.
```

Fixes some cases of rust-lang/rust#58736.
2026-02-22 11:31:14 +01:00
Jonathan Brouwer
b0cdafbd4a Rollup merge of #152455 - JonathanBrouwer:remove_translation, r=jdonszelmann
Remove the translation `-Z` options and the `Translator` type.

This PR implements MCP https://github.com/rust-lang/compiler-team/issues/967

It is split up into individually reviewable commits, each commit passes tests:

* 6782119567 Removes the translation compiler options from the session
* 8f300d02fe Removes the now empty `Translator` type
* ab715c536f Renames `translate_message` to `format_diag_message`, as the function no longer does any translation
* 8bcbc3f766 Removes a section describing the removed compiler options from the rustc dev guide
2026-02-20 22:00:57 +01:00
Esteban Küber
37684bdfc5 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
Jonathan Brouwer
018a5efcf7 Rename inline_fluent! to msg! 2026-02-14 13:47:52 +01:00
Jonathan Brouwer
f1b935d08f Rollup merge of #152356 - JonathanBrouwer:inline_diag4, r=jdonszelmann
Improve the `inline_fluent!` macro

For https://github.com/rust-lang/rust/issues/151366

This PR turns `inline_fluent!` into a proc macro, so we can run validation on the messages in this macro :)
I started a thread here because I don't like the name of the macro, but that's for a future PR: [#t-compiler > Bikeshed the new &#96;inline_fluent!&#96; macro](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Bikeshed.20the.20new.20.60inline_fluent!.60.20macro/with/572646242)
2026-02-13 13:35:01 +01:00
mu001999
a07f837491 Remove unused features in compiler 2026-02-13 09:25:39 +08:00
cyrgani
f1c80f5988 reduce the amount of panics in {TokenStream, Literal}::from_str calls 2026-02-11 20:09:30 +00:00
Jonathan Brouwer
ab715c536f Rename translate_message to format_diag_message 2026-02-11 17:52:00 +01:00
Jonathan Brouwer
8f300d02fe Remove the Translator type 2026-02-11 17:52:00 +01:00
Lukas Bergdoll
2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
Jonathan Brouwer
6782119567 Remove the translation compiler options 2026-02-10 22:10:22 +01:00
Jonathan Brouwer
ea361287be Remove SubdiagMessage in favour of the identical DiagMessage 2026-02-10 09:13:45 +00:00
Jonathan Brouwer
6eb2a8fa9e Reformat existing error messages 2026-02-09 19:12:22 +01:00
Jonathan Brouwer
81d4214604 Remove fluent tests in rustc_error 2026-02-08 11:06:42 +01:00
Jonathan Brouwer
0db0acd699 Remove the fallback bundle 2026-02-08 11:06:42 +01:00
Jonathan Brouwer
ea8733133c Remove DiagMessage::FluentIdentifier 2026-02-08 10:33:29 +01:00