about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
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
2023-04-06Label non_exhaustive on privacy errorsMichael Goulet-1/+7
2023-04-01fix clippy::iter_kv_mapMatthias Krüger-3/+3
2023-03-13resolve: Remove `struct_field_names_untracked`Vadim Petrochenkov-2/+5
2023-03-13resolve: Centralize retrieval of items span and item nameVadim Petrochenkov-20/+13
2023-03-13resolve: Partially remove `item_attrs_untracked`Vadim Petrochenkov-8/+4
2023-03-02rustc_middle: Remove trait `DefIdTree`Vadim Petrochenkov-3/+3
This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
2023-02-27diagnostics: avoid querying `associated_item` in the resolverMichael Howell-2/+6
Fixes #108529
2023-02-23Auto merge of #108324 - notriddle:notriddle/assoc-fn-method, ↵bors-2/+2
r=compiler-errors,davidtwco,estebank,oli-obk diagnostics: if AssocFn has self argument, describe as method Discussed in https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/.22associated.20function.22.20vs.20.22method.22/near/329265515 This commit also changes the tooltips on rustdoc intra-doc links targeting methods. For anyone not sure why this is being done, see the Reference definitions of these terms in <https://doc.rust-lang.org/1.67.1/reference/items/associated-items.html#methods> > Associated functions whose first parameter is named `self` are called methods and may be invoked using the [method call operator](https://doc.rust-lang.org/1.67.1/reference/expressions/method-call-expr.html), for example, `x.foo()`, as well as the usual function call notation. In particular, while this means it's technically correct for rustc to refer to a method as an associated function (and there are a few cases where it'll still do so), rustc *must never* use the term "method" to refer to an associated function that does not have a `self` parameter.