summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-03-25Rollup merge of #138929 - oli-obk:assoc-ctxt-of-trait, r=compiler-errorsMatthias Krüger-5/+0
Visitors track whether an assoc item is in a trait impl or an inherent impl `AssocCtxt::Impl` now contains an `of_trait` field. This allows ast lowering and nameres to not have to track whether we're in a trait impl or an inherent impl.
2025-03-25Rollup merge of #138924 - nnethercote:less-kw-Empty-3, r=compiler-errorsMatthias Krüger-7/+8
Reduce `kw::Empty` usage, part 3 Remove some more `kw::Empty` uses, in support of #137978. r? `@davidtwco`
2025-03-25Track whether an assoc item is in a trait impl or an inherent implOli Scherer-5/+0
2025-03-25Use `Option<Symbol>` in `ModuleKind::Def`.Nicholas Nethercote-7/+8
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/+1
2025-03-19Allow builtin macros to be used more than once.Mara Bos-7/+1
This removes E0773 "A builtin-macro was defined more than once."
2025-03-14resolve: Avoid some unstable iterationVadim Petrochenkov-12/+12
2025-03-12Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, ↵Manish Goregaokar-1/+0
r=onur-ozkan,jieyouxu Use `RUSTC_LINT_FLAGS` more An alternative to the failed #138084. Fixes #138106. r? `````@jieyouxu`````
2025-03-12Disentangle ForwardGenericParamBan and ConstParamTy ribsMichael Goulet-3/+6
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-09Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxuMatthias Krüger-1/+0
Use workspace lints for crates in `compiler/` This is nicer and hopefully less error prone than specifying lints via bootstrap. r? ``@jieyouxu``
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-03-07Pass `Option<Symbol>` to `def_path_data`/`create_def` methods.Nicholas Nethercote-1/+1
It's clearer than using `kw::Empty` to mean `None`.
2025-02-28Introduce `feature(generic_const_parameter_types)`Boxy-4/+4
2025-02-23stabilize extract_ifbendn-1/+0
2025-02-21convert all_macro_rules from hashmap to hashsetklensy-1/+1
2025-02-17Enforce T: Hash for Interned<...>Mark Rousskov-0/+26
This adds panicking Hash impls for several resolver types that don't actually satisfy this condition. It's not obvious to me that rustc_resolve actually upholds the Interned guarantees but fixing that seems pretty hard (the structures have at minimum some interior mutability, so it's not really recursively hashable in place...).
2025-02-08Small resolve refactorAndre Bogus-14/+15
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-12/+13
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.