about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
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.
2023-11-19When encountering struct fn call literal with private fields, suggest all ↵Esteban Küber-0/+1
builders When encountering code like `Box(42)`, suggest `Box::new(42)` and *all* other associated functions that return `-> Box<T>`.
2023-11-16When using existing fn as module, don't claim it doesn't existEsteban Küber-1/+13
Tweak wording of module not found in resolve, when the name exists but belongs to a non-`mod` item. Fix #81232.
2023-11-08rustc: minor changes suggested by clippy perf lints.Nicholas Nethercote-1/+1
2023-10-25Rollup merge of #117009 - fmease:diag-disambig-sugg-crate, r=b-naberMatthias Krüger-14/+44
On unresolved imports, suggest a disambiguated path if necessary to avoid collision with local items Fixes #116970.
2023-10-21on unresolved import disambiguate suggested path if it would collideLeón Orell Valerian Liehr-14/+44
2023-10-20Typo suggestion to change bindings with leading underscoreEsteban Küber-2/+15
When encountering a binding that isn't found but has a typo suggestion for a binding with a leading underscore, suggest changing the binding definition instead of the use place. Fix #60164.
2023-10-13Format all the let chains in compilerMichael Goulet-8/+25
2023-09-28resolve: skip underscore character during candidate lookupbohan-0/+4
2023-09-24fix ICE due to empty span and empty suggestionsRalf Jung-1/+3
2023-09-11Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errorsMatthias Krüger-27/+20
Improve diagnostic for generic params from outer items (E0401) Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples). Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled. Lastly, make E0401 translatable while we're at it. Fixes #115720.
2023-09-10Make E0401 translatableLeón Orell Valerian Liehr-19/+18
2023-09-10Generalize E0401León Orell Valerian Liehr-14/+8
2023-09-07Find lowest span out of use + attrsMichael Goulet-1/+7
2023-08-24resolve: Make bindings for derive helper attributes uniqueVadim Petrochenkov-1/+1
instead of creating them every time such attribute is used
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-31/+29
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-23/+52
2023-07-23fix clippy::useless_formatMatthias Krüger-2/+2
2023-07-19Make it clearer that edition functions are >=, not ==Michael Goulet-5/+5
2023-07-05resolve: Use `Interned` for `Module`Vadim Petrochenkov-9/+6
2023-07-05resolve: Use `Interned` for `Import`Vadim Petrochenkov-12/+12
2023-07-05resolve: Use `Interned` for `NameBinding`Vadim Petrochenkov-11/+11
2023-06-29resolve: Remove artificial import ambiguity errorsVadim Petrochenkov-3/+2
2023-06-22Tweak privacy errors to account for reachable itemsEsteban Küber-28/+64
Suggest publicly accessible paths for items in private mod: When encountering a path in non-import situations that are not reachable due to privacy constraints, search for any public re-exports that the user could use instead. Track whether an import suggestion is offering a re-export. When encountering a path with private segments, mention if the item at the final path segment is not publicly accessible at all. Add item visibility metadata to privacy errors from imports: On unreachable imports, record the item that was being imported in order to suggest publicly available re-exports or to be explicit that the item is not available publicly from any path. In order to allow this, we add a mode to `resolve_path` that will not add new privacy errors, nor return early if it encounters one. This way we can get the `Res` corresponding to the final item in the import, which is used in the privacy error machinery.