about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2025-08-15Detect missing `derive` on unresolved attribute even when not importedEsteban Küber-27/+3
``` error: cannot find attribute `sede` in this scope --> $DIR/missing-derive-3.rs:20:7 | LL | #[sede(untagged)] | ^^^^ | help: the derive macros `Deserialize` and `Serialize` accept the similarly named `serde` attribute | LL | #[serde(untagged)] | + error: cannot find attribute `serde` in this scope --> $DIR/missing-derive-3.rs:14:7 | LL | #[serde(untagged)] | ^^^^^ | note: `serde` is imported here, but it is a crate, not an attribute --> $DIR/missing-derive-3.rs:4:1 | LL | extern crate serde; | ^^^^^^^^^^^^^^^^^^^ help: `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`, you might be missing a `derive` attribute | LL + #[derive(Deserialize, Serialize)] LL | enum B { | ```
2025-08-14Do not ICE on private type in field of unresolved structEsteban Küber-3/+3
2025-08-14resolve: Improve code reuse in typo candidate collectionVadim Petrochenkov-7/+18
2025-08-14resolve: Do not show deprecated helper attributes in typo recommendationsVadim Petrochenkov-22/+1
Remove one FIXME, addressing it does not reduce the hacky-ness much, and the logic is going to be removed anyway together with the `legacy_derive_helpers` deprecation lint.
2025-08-14resolve: Do not call `resolve_macro_path` from late resolutionVadim Petrochenkov-1/+1
`maybe_resolve_path` is less precise in corner cases, but it's only used for diagnostics and error recovery, so it's good enough.
2025-08-13Auto merge of #144793 - petrochenkov:extprel3, r=davidtwcobors-3/+12
resolve: Split extern prelude into two scopes One scope for `extern crate` items and another for `--extern` options, with the former shadowing the latter. If in a single scope some things can overwrite other things, especially with ad hoc restrictions like `MacroExpandedExternCrateCannotShadowExternArguments`, then it's not really a single scope. So this PR splits `Scope::ExternPrelude` into two cleaner scopes. This is similar to how https://github.com/rust-lang/rust/pull/144131 splits module scope into two scopes for globs and non-globs, but simpler.
2025-08-13resolve: Improve diagnostics for ambiguities in extern preludeVadim Petrochenkov-2/+9
2025-08-13resolve: Split extern prelude into two scopesVadim Petrochenkov-1/+3
One for `--extern` options and another for `extern crate` items.
2025-08-12Detect and report macro kind mismatches early, and more preciselyJosh Triplett-9/+13
This eliminates the case in `failed_to_match_macro` to check for a function-like invocation of a macro with no function-like rules. Instead, macro kind mismatches now result in an unresolved macro, and we detect this case in `unresolved_macro_suggestions`, which now carefully distinguishes between a kind mismatch and other errors. This also handles cases of forward-referenced attributes and cyclic attributes. Expand test coverage to include all of these cases.
2025-08-12Switch to a bitflags `MacroKinds` to support macros with more than one kindJosh Triplett-9/+19
Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`. Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds. This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`. Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes.
2025-08-10review commentsEsteban Küber-48/+80
2025-08-10Detect struct construction with private field in field with defaultEsteban Küber-2/+58
When trying to construct a struct that has a public field of a private type, suggest using `..` if that field has a default value. ``` error[E0603]: struct `Priv1` is private --> $DIR/non-exhaustive-ctor.rs:25:39 | LL | let _ = S { field: (), field1: m::Priv1 {} }; | ------ ^^^^^ private struct | | | while setting this field | note: the struct `Priv1` is defined here --> $DIR/non-exhaustive-ctor.rs:14:4 | LL | struct Priv1 {} | ^^^^^^^^^^^^ help: the field `field1` you're trying to set has a default value, you can use `..` to use it | LL | let _ = S { field: (), .. }; | ~~ ```
2025-08-09remove `P`Deadbeef-2/+1
2025-08-08Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petrochenkovStuart Cook-33/+33
Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution. This pr introduces a `CmResolver`, a wrapper around the main resolver which gives out mutable access given a condition. `CmResolver` only allows mutation when we’re not in speculative import resolution. This ensures we can’t accidentally mutate the resolver during this process, which is important as we move towards a batched resolution algorithm. This also changes functions that are used during speculative import resolution to take a `CmResolver` instead of a `&mut Resolver`. Also introduces a new kind of "smart pointer" which has the behaviour described above: ```rust /// A wrapper around a mutable reference that conditionally allows mutable access. pub(crate) struct RefOrMut<'a, T> { p: &'a mut T, mutable: bool, } type CmResolver<'r, 'ra, 'tcx> = RefOrMut<'r, Resolver<'ra, 'tcx>>; ``` r? petrochenkov
2025-08-07Introduce, implement and use CmResolver.LorrensP-2158466-33/+33
2025-08-06Introduce ModernIdent type to unify macro 2.0 hygiene handlingxizheyin-8/+10
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-04Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naberStuart Cook-2/+2
resolve: Cleanups and micro-optimizations to extern prelude This is what can be done without changing the structure of `ExternPreludeEntry`, like in https://github.com/rust-lang/rust/pull/144737. See individual commits for details.
2025-08-02Auto merge of #129183 - estebank:cfg-visitor, r=davidtwcobors-13/+12
Detect more `cfg`d out items in resolution errors Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ```
2025-08-01Tweak rendering of cfg'd out itemEsteban Küber-9/+6
``` error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-cross-crate.rs:18:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | #[cfg(false)] | ----- the item is gated here LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ ```
2025-08-01tiny cleanupEsteban Küber-8/+5
2025-08-01Detect more `cfg`d out items in resolution errorsEsteban Küber-5/+10
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ```
2025-07-31resolve: Cleanup some uses of extern prelude in diagnosticsVadim Petrochenkov-2/+2
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-7/+3
2025-07-27split up define into define_extern and define_localLorrensP-2158466-2/+2
2025-07-26resolve: Do not create `NameResolution`s on access unless necessaryVadim Petrochenkov-2/+1
2025-07-26resolve: Minimize borrow scopes for `resolutions`Vadim Petrochenkov-3/+2
2025-07-24resolve: Remove `Scope::CrateRoot`Vadim Petrochenkov-5/+0
Use `Scope::Module` with the crate root module inside instead, which should be identical.
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`