summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2024-05-30Improve renaming suggestion for names with leading underscoresLucas Scharenbroch-14/+24
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-3/+3
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-6/+0
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-10Remove `ordinalize`.Nicholas Nethercote-14/+0
Some minor (English only) heroics are performed to print error messages like "5th rule of macro `m` is never used". The form "rule #5 of macro `m` is never used" is just as good and much simpler to implement.
2024-05-10Remove `#[macro_use] extern crate tracing` from `rustc_resolve`.Nicholas Nethercote-0/+1
Explicit imports are more standard nowadays and easier to read.
2024-04-29Add raw identifier in a typo suggestionLin Yihai-1/+1
2024-04-13Migrate more diagnosticsJean CASPAR-138/+135
2024-04-13Migrate some diagnosticsJean CASPAR-10/+12
2024-04-13Port build_reduce_graphJeanCASPAR-1/+1
2024-03-27Do not sort `DefId`s in diagnosticsOli Scherer-11/+9
2024-03-12Manual rustfmtOli Scherer-1/+1
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-1/+1
2024-03-06avoid overlapping privacy suggestion for single nested importsbohan-23/+39
2024-03-05Rename `BuiltinLintDiagnostics` as `BuiltinLintDiag`.Nicholas Nethercote-4/+4
Not the dropping of the trailing `s` -- this type describes a single diagnostic and its name should be singular.
2024-03-05Rename `DiagnosticMode` as `DiagMode`.Nicholas Nethercote-19/+16
2024-03-04Rollup merge of #121130 - chenyukang:yukang-fix-121061-macro-later, ↵Matthias Krüger-1/+22
r=matthiaskrgr Suggest moving definition if non-found macro_rules! is defined later Fixes #121061
2024-02-29Rollup merge of #121792 - GuillaumeGomez:improve-suggestion, r=michaelwoeristerGuillaume Gomez-2/+3
Improve renaming suggestion when item starts with underscore Fixes https://github.com/rust-lang/rust/issues/121776. It goes from: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> src/foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider changing it | 1 | enum Foo { | ~~~ ``` to: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider renaming `_Foo` into `Foo` | 1 | enum Foo { | ~~~ error: aborting due to 1 previous error ```
2024-02-29Improve suggestion to rename type starting with underscore to make it more ↵Guillaume Gomez-2/+3
obvious what is actually suggested
2024-02-29Suggest moving if non-found macro_rules! is defined lateryukang-1/+22
2024-02-28Auto merge of #121489 - nnethercote:diag-renaming, r=davidtwcobors-10/+10
Diagnostic renaming Renaming various diagnostic types from `Diagnostic*` to `Diag*`. Part of https://github.com/rust-lang/compiler-team/issues/722. There are more to do but this is enough for one PR. r? `@davidtwco`
2024-02-28Rollup merge of #121226 - chenyukang:yukang-fix-import-alias, r=davidtwcoGuillaume Gomez-1/+11
Fix issues in suggesting importing extern crate paths Fixes #121168 r? ``@petrochenkov``
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-10/+10
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Remove an unnecessary `span_delayed_bug` in `Resolver::valid_res_from_ribs`.Nicholas Nethercote-2/+6
`Resolver::report_error` always emits (this commit makes that clearer), so the `span_delayed_bug` is unnecessary.
2024-02-25Rollup merge of #121060 - clubby789:bool-newtypes, r=cjgillotMatthias Krüger-1/+1
Add newtypes for bool fields/params/return types Fixed all the cases of this found with some simple searches for `*/ bool` and `bool /*`; probably many more
2024-02-25Fix issues in suggesting importing extern crate pathsyukang-1/+11
2024-02-20Add newtype for using the prelude in resolutionclubby789-1/+1
2024-02-19Prefer `DiagnosticBuilder` over `Diagnostic` in diagnostic modifiers.Nicholas Nethercote-8/+8
There are lots of functions that modify a diagnostic. This can be via a `&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type wraps the former and impls `DerefMut`. This commit converts all the `&mut Diagnostic` occurrences to `&mut DiagnosticBuilder`. This is a step towards greatly simplifying `Diagnostic`. Some of the relevant function are made generic, because they deal with both errors and warnings. No function bodies are changed, because all the modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`.
2024-02-18By tracking import use types to check whether it is scope uses or the other ↵surechen-2/+2
situations like module-relative uses, we can do more accurate redundant import checking. fixes #117448 For example unnecessary imports in std::prelude that can be eliminated: ```rust use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly use std::option::Option::None; //~ WARNING the item `None` is imported redundantly ```
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-9/+15
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-06Rollup merge of #119939 - clubby789:static-const-generic-note, r=compiler-errorsMatthias Krüger-1/+9
Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes #109596 Fixes #119936
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-2/+2
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-21exclude unexported macro bindings from extern cratebohan-4/+4
2024-01-15Auto merge of #119610 - Nadrieril:never_pattern_bindings, r=compiler-errorsbors-0/+3
never patterns: Check bindings wrt never patterns Never patterns: - Shouldn't contain bindings since they never match anything; - Don't count when checking that or-patterns have consistent bindings. r? `@compiler-errors`
2024-01-14Special case 'generic param from outer item' message for `Self`clubby789-0/+2
2024-01-14Add note to resolve error about generics from inside static/constclubby789-1/+7
2024-01-13store the segment name when resolution failsbohan-11/+6
2024-01-10Rename consuming chaining methods on `DiagnosticBuilder`.Nicholas Nethercote-3/+3
In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion.
2024-01-10Rename `struct_span_err!` as `struct_span_code_err!`.Nicholas Nethercote-12/+18
Because it takes an error code after the span. This avoids the confusing overlap with the `DiagCtxt::struct_span_err` method, which doesn't take an error code.
2024-01-09Check bindings around never patternsNadrieril-0/+3
2024-01-08Remove all eight `DiagnosticBuilder::*_with_code` methods.Nicholas Nethercote-2/+2
These all have relatively low use, and can be perfectly emulated with a simpler construction method combined with `code` or `code_mv`.
2024-01-08Use chaining in `DiagnosticBuilder` construction.Nicholas Nethercote-5/+4
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-05Rollup merge of #119151 - Jules-Bertholet:no-foreign-doc-hidden-suggest, ↵Matthias Krüger-13/+41
r=davidtwco Hide foreign `#[doc(hidden)]` paths in import suggestions Stops the compiler from suggesting to import foreign `#[doc(hidden)]` paths. ```@rustbot``` label A-suggestion-diagnostics
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-59/+52
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-1/+1
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-20Hide foreign `#[doc(hidden)]` paths in import suggestionsJules Bertholet-13/+41
2023-12-06tip for define macro name after `macro_rules!`bohan-4/+9
2023-12-04Structured `use` suggestion on privacy errorEsteban Küber-1/+86
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
2023-11-23Auto merge of #118065 - estebank:core-not-found-404, r=TaKO8Kibors-0/+9
When failing to import `core`, suggest `std`
2023-11-22When failing to import `core`, suggest `std`Esteban Küber-0/+9
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.