about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
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-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.
2023-06-19Remove unreachable and untested suggestion for invalid span enum derive(Default)Tom Martin-9/+5
2023-06-18Add translatable diagnostic for various strings in ↵Tom Martin-9/+11
resolve::unresolved_macro_suggestions
2023-06-18Add translatable diagnostic for changing import bindingTom Martin-8/+3
2023-06-14s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedListThe 8472-1/+1
2023-06-10Make "consider importing" consistent for macrosMu001999-2/+7
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-8/+61
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-2/+2
2023-05-20Rollup merge of #111652 - clubby789:self-import-improvement, r=compiler-errorsDylan DPC-1/+11
Better diagnostic for `use Self::..` Fixes #111627 cc `@petrochenkov,` you might have thoughts on a better way to handle this (https://github.com/rust-lang/rust/issues/63720#issuecomment-591597466)
2023-05-18fix(resolve): only disambiguate binding key during definebohan-2/+3
2023-05-16Better diagnostic for `use Self::..`clubby789-1/+11
2023-05-14Revert "Validate resolution for SelfCtor too."Camille GILLOT-1/+1
This reverts commit 83453408a0ce91b9e3d3ae6e7f117b1fd28b487d.
2023-05-11Improve error for `self: Box<self>`clubby789-0/+3
2023-05-05improve diagnostics and bless testsBoxy-9/+10
2023-05-04Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkovMatthias Krüger-1/+1
Validate resolution for SelfCtor too. Fixes https://github.com/rust-lang/rust/issues/89868 r? `@petrochenkov`
2023-05-03Validate resolution for SelfCtor too.Camille GILLOT-1/+1
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-25/+25
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-04-17Rollup merge of #110404 - matthiaskrgr:mapmap, r=NilstriebMatthias Krüger-6/+4
fix clippy::toplevel_ref_arg and ::manual_map r? ``@Nilstrieb``
2023-04-16fix clippy::toplevel_ref_arg and ::manual_mapMatthias Krüger-6/+4
2023-04-16use matches! macro in more placesMatthias Krüger-9/+11
2023-04-06Make span a bit betterMichael Goulet-1/+13