about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-01-27Use identifiers in diagnostics more oftenMichael Goulet-7/+7
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2025-01-16Implement `use` associated items of traitsFrank King-4/+7
2024-12-22Fix spacing of markdown code block fences in compiler rustdocDavid Tolnay-1/+4
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-14Don't make a def id for impl_trait_in_bindingsMichael Goulet-0/+1
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-0/+6
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-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-1/+1
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-1/+1
2024-11-28always create `DefId`s when lowering anon-constslcnr-13/+0
2024-11-14Remove `Resolver::empty_disambiguator`.Nicholas Nethercote-6/+0
It was added in #115367 for anonymous ADTs. Those changes were then reverted in #131045, but `empty_disambiguator` was left behind, perhaps by mistake. It seems to be unnecessary.
2024-11-14Tweak a `resolutions` loop.Nicholas Nethercote-6/+5
In this case field access is more concise and easier to read than destructuring, and it matches how other similar loops are done elsewhere.
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-3/+3
2024-10-20Stop relying on hashmap iteration for unused macro rules armsNoratrieb-1/+2
2024-10-03rustdoc: prevent ctors from resolvingMichael Howell-1/+3
2024-10-03Handle `rustc_metadata` cases of `rustc::potential_query_instability` lintismailarilik-2/+2
2024-10-02Handle `rustc-hir-analysis` cases of `rustc::potential_query_instability` lintismailarilik-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-6/+6
2024-09-21Handle macro calls in anon const def creation take 2Boxy-0/+5
2024-09-13Auto merge of #129137 - camelid:lazy-def-macro-const, r=BoxyUwUbors-3/+25
Fix anon const def-creation when macros are involved Fixes #128016. Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The long-term fix for this is to delay the creation of defs for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, doing this uncovers a pre-existing bug with opaque types that is quite involved to fix (see #129023). In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`. r? `@BoxyUwU`
2024-09-12Fix anon const def-creation when macros are involvedNoah Lev-3/+25
Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The ideal long-term fix for this is a bit unclear. One option is to delay def creation for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, this approach has some downsides as well, and the best approach is yet to be determined. In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`.
2024-09-12Introduce `'ra` lifetime name.Nicholas Nethercote-143/+144
`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-08-29Add `warn(unreachable_pub)` to `rustc_resolve`.Nicholas Nethercote-0/+1
2024-08-10rm `import.used`bohan-5/+7
2024-08-08rm `declared_features` field in resolverbohan-5/+0
2024-08-07make `import.vis` is not mutablebohan-1/+2
2024-07-31Rollup merge of #123813 - compiler-errors:redundant-lint, r=petrochenkovMatthias Krüger-2/+2
Add `REDUNDANT_IMPORTS` lint for new redundant import detection Defaults to Allow for now. Stacked on #123744 to avoid merge conflict, but much easier to review all as one. r? petrochenkov
2024-07-31Introduce REDUNDANT_IMPORTS lintMichael Goulet-2/+2
2024-07-29Structured suggestion for `extern crate foo` when `foo` isn't resolved in importEsteban Küber-0/+6
When encountering a name in an import that could have come from a crate that wasn't imported, use a structured suggestion to suggest `extern crate foo;` pointing at the right place in the crate. When encountering `_` in an import, do not suggest `extern crate _;`. ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ maybe a missing crate `spam`? | help: consider importing the `spam` crate | LL + extern crate spam; | ```
2024-07-29Reformat `use` declarations.Nicholas Nethercote-20/+24
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-5/+6
2024-07-08Rollup merge of #127431 - oli-obk:feed_item_attrs, r=compiler-errors许杰友 Jieyou Xu (Joe)-5/+13
Use field ident spans directly instead of the full field span in diagnostics on local fields This improves diagnostics and avoids having to store the `DefId`s of fields
2024-07-06Use field ident spans directly instead of the full field span in diagnostics ↵Oli Scherer-5/+13
on local fields
2024-07-06out_of_scope_macro_calls: Detect calls inside attributes more preciselyVadim Petrochenkov-2/+3
2024-06-28Change RTN to use .. againMichael Goulet-0/+1
2024-06-25resolve: Tweak some naming around import ambiguitiesVadim Petrochenkov-6/+8
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-1/+13
2024-05-29Rollup merge of #125381 - estebank:issue-96799, r=petrochenkov许杰友 Jieyou Xu (Joe)-1/+3
Silence some resolve errors when there have been glob import errors When encountering `use foo::*;` where `foo` fails to be found, and we later encounter resolution errors, we silence those later errors. A single case of the above, for an *existing* import on a big codebase would otherwise have a huge number of knock-down spurious errors. Ideally, instead of a global flag to silence all subsequent resolve errors, we'd want to introduce an unnameable binding in the appropriate rib as a sentinel when there's a failed glob import, so when we encounter a resolve error we can search for that sentinel and if found, and only then, silence that error. The current approach is just a quick proof of concept to iterate over. Partially address #96799.
2024-05-28Silence some resolve errors when there have been glob import errorsEsteban Küber-1/+3
When encountering `use foo::*;` where `foo` fails to be found, and we later encounter resolution errors, we silence those later errors. A single case of the above, for an *existing* import on a big codebase would otherwise have a huge number of knock-down spurious errors. Ideally, instead of a global flag to silence all subsequent resolve errors, we'd want to introduce an unameable binding in the appropriate rib as a sentinel when there's a failed glob import, so when we encounter a resolve error we can search for that sentinel and if found, and only then, silence that error. The current approach is just a quick proof of concept to iterate over. Partially address #96799.
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-1/+1
2024-05-21Convert uses of BuiltinLintDiag::Normal to custom variantsXiretza-3/+7
This ensures all diagnostic messages are created at diagnostic emission time, making them translatable.
2024-05-10Remove unused `derive(Clone)` on `MacroData`.Nicholas Nethercote-1/+0
2024-05-10Remove `#[macro_use] extern crate tracing` from `rustc_resolve`.Nicholas Nethercote-9/+5
Explicit imports are more standard nowadays and easier to read.
2024-05-10Remove unnecessary `allow` attribute.Nicholas Nethercote-6/+7
The `#[allow(rustdoc:private_intra_doc_links)]` isn't necessary. Also sort them, as is done in other files like `compiler/rustc_errors/src/lib.rs`.
2024-04-26Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-deadJacob Pratt-2/+2
`rustc_builtin_macros` cleanups Some improvements I found while looking over this code. r? ``@fee1-dead``
2024-04-26Introduce `DeriveResolution`.Nicholas Nethercote-2/+2
Making this a proper struct, and giving its fields names, makes things easier to understand.
2024-04-23delegation: Support async, const, extern "ABI" and C-variadic functionsVadim Petrochenkov-10/+6
Also allow `impl Trait` in delegated functions. The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created.
2024-04-17consistency rename: language item -> lang itemRalf Jung-1/+1
2024-04-11Silence unused_imports lint for redundant importsMichael Goulet-1/+1
2024-03-28remove `def_id_to_node_id` in ast loweringbohan-1/+0