about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/ident.rs
AgeCommit message (Collapse)AuthorLines
2025-08-14resolve: Restructure `resolve_ident_in_lexical_scope` for better clarityVadim Petrochenkov-42/+37
2025-08-14resolve: Introduce `RibKind::Block`Vadim Petrochenkov-1/+4
to avoid confusing module items, blocks with items, and blocks without items.
2025-08-14resolve: Do not show deprecated helper attributes in typo recommendationsVadim Petrochenkov-5/+0
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-21/+40
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: Split extern prelude into two scopesVadim Petrochenkov-21/+40
One for `--extern` options and another for `extern crate` items.
2025-08-12Switch to a bitflags `MacroKinds` to support macros with more than one kindJosh Triplett-13/+3
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-10Detect struct construction with private field in field with defaultEsteban Küber-1/+18
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-08Rollup merge of #144579 - joshtriplett:mbe-attr, r=petrochenkovTrevor Gross-4/+16
Implement declarative (`macro_rules!`) attribute macros (RFC 3697) This implements [RFC 3697](https://github.com/rust-lang/rust/issues/143547), "Declarative (`macro_rules!`) attribute macros". I would suggest reading this commit-by-commit. This first introduces the feature gate, then adds parsing for attribute rules (doing nothing with them), then adds the ability to look up and apply `macro_rules!` attributes by path, then adds support for local attributes, then adds a test, and finally makes various improvements to errors.
2025-08-08mbe: Handle local `macro_rules` attr resolutionJosh Triplett-4/+16
Teach the resolver to consider `macro_rules` macros when looking for a local attribute. When looking for an attribute and considering a `macro_rules` macro, load the macro in order to see if it has attribute rules. Include a FIXME about tracking multiple macro kinds for a Def instead.
2025-08-07Introduce, implement and use CmResolver.LorrensP-2158466-81/+104
2025-07-26resolve: Do not create `NameResolution`s on access unless necessaryVadim Petrochenkov-2/+7
2025-07-24resolve: Remove `Scope::CrateRoot`Vadim Petrochenkov-43/+29
Use `Scope::Module` with the crate root module inside instead, which should be identical.
2025-07-17resolve: Change `&mut Resolver` to `&Resolver` when possibleVadim Petrochenkov-2/+2
2025-07-17resolve: Move `self_binding` to `ModuleData`Vadim Petrochenkov-1/+1
2025-07-16resolve: Remove trait `ToNameBinding`Vadim Petrochenkov-9/+4
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-3/+3
2025-07-13Rollup merge of #143734 - ↵Matthias Krüger-2/+2
LorrensP-2158466:refactor-resolve-resolution-bindings, r=petrochenkov Refactor resolve resolution bindings This pr does the work asked in https://github.com/rust-lang/rust/pull/142547#issuecomment-3001339385. This part: > move the `(non)_glob_binding` change r? ````@petrochenkov````
2025-07-12merge source and target bindings into single fieldLorrensP-2158466-4/+3
2025-07-12replace binding and shadowed_glob on NameResolution with non_glob_binding ↵b-naber-2/+2
and glob_binding
2025-07-10extract single_import_can_define_name and finalize_glob_module_bindingb-naber-118/+143
2025-06-12Detect when attribute is provided by missing `derive` macroEsteban Küber-0/+1
``` 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-04-09Avoid an empty trait name in impl blocks.Nicholas Nethercote-3/+0
`resolve_ident_in_lexical_scope` checks for an empty name. Why is this necessary? Because `parse_item_impl` can produce an `impl` block with an empty trait name in some cases. This is pretty gross and very non-obvious. This commit avoids the use of the empty trait name. In one case the trait name is instead pulled from `TyKind::ImplTrait`, which prevents the output for `tests/ui/impl-trait/extra-impl-in-trait-impl.rs` from changing. In the other case we just fail the parse and don't try to recover. I think losing error recovery in this obscure case is worth the code cleanup. This change affects `tests/ui/parser/impl-parsing.rs`, which is split in two, and the obsolete `..` syntax cases are removed (they are tested elsewhere).
2025-03-24resolve: Avoid some unstable iteration 2Vadim Petrochenkov-1/+0
2025-03-14resolve: Avoid some unstable iterationVadim Petrochenkov-0/+1
2025-03-12Disentangle ForwardGenericParamBan and ConstParamTy ribsMichael Goulet-20/+41
2025-02-28Introduce `feature(generic_const_parameter_types)`Boxy-28/+14
2025-02-08Rustfmtbjorn3-22/+35
2025-01-21rustc_resolve: flatten nested `if`sYotam Ofek-51/+47
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-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-29/+53
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-20Store resolution for self and crate root module segmentsMichael Goulet-4/+10
2024-11-14Replace the `restricted_shadowing` boolean argument with an enum.Nicholas Nethercote-12/+22
It makes the code clearer.
2024-11-14Remove two `_ext` methods.Nicholas Nethercote-56/+13
`resolve_ident_in_module` is a very thin wrapper around `resolve_ident_in_module_ext`, and `resolve_ident_in_module_unadjusted` is a very thin wrapper around `resolve_ident_in_module_unadjusted_ext`. The wrappers make the call sites slightly more concise, but I don't think that's worth the extra code and indirection. This commit removes the two wrappers and removes the `_ext` suffixes from the inner methods.
2024-11-14Use an atom comparison for a keyword check.Nicholas Nethercote-1/+3
Instead of a string comparison.
2024-11-13Use iteration instead of indexing to access ribs.Nicholas Nethercote-6/+5
This gives a small but noticeable performance improvement.
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-2/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-43/+30
2024-09-12Rollup merge of #130208 - nnethercote:rslv-lifetime, r=petrochenkovMatthias Krüger-53/+53
Introduce `'ra` lifetime name. `rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'rslv`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`rslv` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`. r? ``@petrochenkov`` cc ``@oli-obk``
2024-09-12Introduce `'ra` lifetime name.Nicholas Nethercote-53/+53
`rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'ra`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`ra` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`.
2024-09-11Simplify some nested if statementsMichael Goulet-6/+6
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-1/+1
2024-08-07make `import.vis` is not mutablebohan-15/+55
2024-07-29Reformat `use` declarations.Nicholas Nethercote-12/+10
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-11Account for `let foo = expr`; to suggest `const foo: Ty = expr;`Esteban Küber-12/+32
2024-06-17mark undetermined if target binding in current ns is not gotbohan-9/+16
2024-06-07mark binding undetermined if target name exist and not obtainedbohan-5/+5
2024-06-04resolve: mark it undetermined if single import is not has any bindingsbohan-2/+27
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-1/+1
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-8/+5
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.