about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2025-07-18inline CrateLoader inside of CStoreLorrensP-2158466-1/+2
2025-07-17Rollup merge of #143550 - petrochenkov:lessmutres, r=lcnrMatthias Krüger-19/+27
resolve: Use interior mutability for extern module map Module map for extern modules is a lazily populated cache, it's not *significantly* mutable. If some logic in name resolver is parallelized, then this cache can be populated from any thread, and without affecting results of any speculative resolution. Unblocks https://github.com/rust-lang/rust/pull/143884. This is a part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/with/527348747). cc `@LorrensP-2158466`
2025-07-17resolve: Change `&mut Resolver` to `&Resolver` when possibleVadim Petrochenkov-10/+5
2025-07-17resolve: Split `module_map` into two maps for local and extern modulesVadim Petrochenkov-1/+10
2025-07-17resolve: Use `module_map` and `get_module` lessVadim Petrochenkov-17/+21
2025-07-17Improve path segment joining.Nicholas Nethercote-15/+14
There are many places that join path segments with `::` to produce a string. A lot of these use `join("::")`. Many in rustdoc use `join_with_double_colon`, and a few use `.joined("..")`. One in Clippy uses `itertools::join`. A couple of them look for `kw::PathRoot` in the first segment, which can be important. This commit introduces `rustc_ast::join_path_{syms,ident}` to do the joining for everyone. `rustc_ast` is as good a location for these as any, being the earliest-running of the several crates with a `Path` type. Two functions are needed because `Ident` printing is more complex than simple `Symbol` printing. The commit also removes `join_with_double_colon`, and `estimate_item_path_byte_length` with it. There are still a handful of places that join strings with "::" that are unchanged. They are not that important: some of them are in tests, and some of them first split a path around "::" and then rejoin with "::". This fixes one test case where `{{root}}` shows up in an error message.
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-27/+13
2025-07-15Define attribute parser & config evaluatorJonathan Brouwer-14/+7
2025-07-12replace binding and shadowed_glob on NameResolution with non_glob_binding ↵b-naber-2/+2
and glob_binding
2025-07-09MacroData in ResolverArenas + split macro_map into extern_macro_map and ↵LorrensP-2158466-2/+7
local_macro_map.
2025-07-04Port `#[non_exhaustive]` to the new attribute parsing infrastructureJonathan Brouwer-3/+3
2025-06-27Rollup merge of #142730 - ↵Matthias Krüger-0/+51
bend-n:suggest_declaring_modules_when_file_found_but_module_not_defined, r=petrochenkov suggest declaring modules when file found but module not defined suggests declaring modules when a module is found but not defined, i.e ``` ├── main.rs: `use thing::thang;` └── thing.rs: `struct thang` ``` or ``` ├── main.rs: `use thing::thang;` └── thing └── mod.rs: `struct thang` ``` which currently is just ```rust error[E0432]: unresolved import `yeah` --> src/main.rs:1:1 | 1 | use thing::thang; | ^^^^^ use of unresolved module or unlinked crate `thing` | ``` but now would have this nice help: ```text = help: you may have forgotten to declare the module `thing`. use `mod thing` in this file to declare this module. ```
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-8/+6
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-25suggest declaring modules when file found but module not definedbendn-0/+51
2025-06-12Detect when attribute is provided by missing `derive` macroEsteban Küber-2/+132
``` error: cannot find attribute `empty_helper` in this scope --> $DIR/derive-helper-legacy-limits.rs:17:3 | LL | #[empty_helper] | ^^^^^^^^^^^^ | help: `empty_helper` is an attribute that can be used by the derive macro `Empty`, you might be missing a `derive` attribute | LL + #[derive(Empty)] LL | struct S2; | ``` Look at proc-macro attributes when encountering unknown attribute ``` error: cannot find attribute `sede` in this scope --> src/main.rs:18:7 | 18 | #[sede(untagged)] | ^^^^ | help: the derive macros `Serialize` and `Deserialize` accept the similarly named `serde` attribute | 18 | #[serde(untagged)] | ~~~~~ error: cannot find attribute `serde` in this scope --> src/main.rs:12:7 | 12 | #[serde(untagged)] | ^^^^^ | = note: `serde` is in scope, but it is a crate, not an attribute help: `serde` is an attribute that can be used by the derive macros `Serialize` and `Deserialize`, you might be missing a `derive` attribute | 10 | #[derive(Serialize, Deserialize)] | ```
2025-05-28consider glob imports in cfg suggestionbohan-2/+48
2025-05-17Use `crate::` prefix for root macro suggestionsbohan-1/+1
2025-05-09Suggest stable candidates rather than unstable onesmu001999-6/+68
2025-05-02resolve: Support imports of associated types and glob imports from traitsVadim Petrochenkov-5/+3
2025-04-11Avoid a reverse map that is only used in diagnostics pathsOli Scherer-3/+3
2025-04-10Rename some `name` variables as `ident`.Nicholas Nethercote-4/+8
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
2025-04-01Rollup merge of #138790 - xizheyin:issue-138626, r=compiler-errorsMatthias Krüger-11/+11
Note potential but private items in show_candidates Closes #138626 . We should add potential private items to give ample hints. And for the other seemingly false positive ` pub use crate::one::Foo;` should be kept because we don't know if the user wants to import other module's items or not, and therefore should be given the full option to do so. r? compiler
2025-04-01Auto merge of #138740 - nnethercote:ast-ItemKind-idents, r=fmeasebors-1/+1
Move `ast::Item::ident` into `ast::ItemKind` The follow-up to #138384, which did the same thing for `hir::ItemKind`. r? `@fmease`
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-1/+1
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-04-01Use `sym::dummy` in one more place.Nicholas Nethercote-1/+1
It makes it clearer that the symbol is unused and doesn't matter.
2025-03-25Rollup merge of #138924 - nnethercote:less-kw-Empty-3, r=compiler-errorsMatthias Krüger-1/+1
Reduce `kw::Empty` usage, part 3 Remove some more `kw::Empty` uses, in support of #137978. r? `@davidtwco`
2025-03-25Use `Option<Symbol>` in `ModuleKind::Def`.Nicholas Nethercote-1/+1
This way, `None` represents "crate root without a name" instead of `kw::Empty`. This changes makes it impossible to forget to handle the exceptional case.
2025-03-24resolve: Avoid some unstable iteration 2Vadim Petrochenkov-1/+0
2025-03-22Note potential but private items in show_candidatesxizheyin-11/+11
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-03-14resolve: Avoid some unstable iterationVadim Petrochenkov-10/+5
2025-03-12Disentangle ForwardGenericParamBan and ConstParamTy ribsMichael Goulet-10/+20
2025-03-12Introduce `sym::dummy` and `Ident::dummy`.Nicholas Nethercote-1/+1
The idea is to identify cases of symbols/identifiers that are not expected to be used. There isn't a perfectly sharp line between "dummy" and "not dummy", but I think it's useful nonetheless.
2025-02-28Introduce `feature(generic_const_parameter_types)`Boxy-3/+3
2025-02-26Rollup merge of #137529 - klensy:unused3, r=lcnrLeón Orell Valerian Liehr-7/+2
remove few unused args
2025-02-24Change span field accesses to method callsJana Dönszelmann-1/+1
2025-02-24cleanup few unused argsklensy-7/+2
2025-02-11Rollup merge of #135677 - yotamofek:resolve-cleanups2, r=compiler-errorsMatthias Krüger-7/+8
Small `rustc_resolve` cleanups 1. Don't open-code `Reverse` 2. Use slice patterns where possible
2025-02-08Rustfmtbjorn3-8/+4
2025-01-27Use identifiers in diagnostics more oftenMichael Goulet-1/+1
2025-01-25Auto merge of #133154 - estebank:issue-133137, r=wesleywiserbors-4/+32
Reword resolve errors caused by likely missing crate in dep tree Reword label and add `help`: ``` error[E0432]: unresolved import `some_novel_crate` --> f704.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` | = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml` ``` Fix #133137.
2025-01-24Reword "crate not found" resolve messageEsteban Küber-4/+32
``` error[E0432]: unresolved import `some_novel_crate` --> file.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` ``` On resolve errors where there might be a missing crate, mention `cargo add foo`: ``` error[E0433]: failed to resolve: use of unresolved module or unlinked crate `nope` --> $DIR/conflicting-impl-with-err.rs:4:11 | LL | impl From<nope::Thing> for Error { | ^^^^ use of unresolved module or unlinked crate `nope` | = help: if you wanted to use a crate named `nope`, use `cargo add nope` to add it to your `Cargo.toml` ```
2025-01-21rustc_resolve: don't open-code `Option::filter`Yotam Ofek-4/+1
2025-01-21rustc_resolve: reduce rightwards drift with `let..else` 👉💨Yotam Ofek-195/+199
2025-01-21rustc_resolve: flatten nested `if`sYotam Ofek-69/+58
2025-01-21rustc_resolve: remove unneeded `return`sYotam Ofek-2/+0
2025-01-21use slice patterns for checking for elements of sliceYotam Ofek-5/+6
2025-01-21don't use partial ordering on types that support total orderingYotam Ofek-2/+2
2025-01-20Rollup merge of #135676 - yotamofek:resolve-cleanups, r=BoxyUwU许杰友 Jieyou Xu (Joe)-24/+15
rustc_resolve: use structured fields in traces I think this crate was written before `tracing` was adopted, and was manually writing fields into trace logs instead of using structured fields. I kept function names in the trace messages even though I added `#[instrument]` invocations so that the events will be in named spans, wasn't sure if spans are always printed.
2025-01-20rustc_resolve: use structured fields in tracesYotam Ofek-24/+15
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-3/+3