about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
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
2025-01-16Implement `use` associated items of traitsFrank King-1/+5
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-2/+1
Re-export more `rustc_span::symbol` things from `rustc_span`. `rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one. r? `@jieyouxu`
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16update uses of extract_if in the compilerThe 8472-3/+3
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-1/+1
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-11-23Rollup merge of #132949 - clubby789:macro-rules-attr-derive, r=fmease许杰友 Jieyou Xu (Joe)-3/+15
Add specific diagnostic for using macro_rules macro as attribute/derive Fixes #132928
2024-11-22Diagnostic for using macro_rules macro as attr/deriveclubby789-3/+15
2024-11-14Use `for_each_child` in a suitable place.Nicholas Nethercote-7/+5
`for_each_child` exists for this exact pattern.
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-3/+2