about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/imports.rs
AgeCommit message (Collapse)AuthorLines
2025-07-23resolve: Make disambiguators for underscore bindings module-localVadim Petrochenkov-13/+25
2025-07-19Revert "resolve: Make disambiguators for underscore bindings module-local"Rémy Rakic-25/+13
This reverts commit 998df3a3e851908afd05c3318f16d99849af5c55.
2025-07-18Rollup merge of #144013 - petrochenkov:disambunder, r=oli-obkMatthias Krüger-13/+25
resolve: Make disambiguators for underscore bindings module-local Disambiguators attached to underscore name bindings (like `const _: u8 = something;`) do not need to be globally unique, they just need to be unique inside the module in which they live, because the bindings in a module are basically kept as `Map<BindingKey, SomeData>`. Also, the specific values of the disambiguators are not important, so a glob import of `const _` may have a different disambiguator than the original `const _` itself. So in this PR the disambiguator is just set to the current number of bindings in the module. This removes one more piece of global mutable state from resolver and unblocks https://github.com/rust-lang/rust/pull/143884.
2025-07-17resolve: Make disambiguators for underscore bindings module-localVadim Petrochenkov-13/+25
2025-07-17Rollup merge of #143550 - petrochenkov:lessmutres, r=lcnrMatthias Krüger-1/+1
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-17Rollup merge of #143856 - mladedav:dm/private-reexport, r=petrochenkovLeón Orell Valerian Liehr-6/+24
Linting public reexport of private dependencies Part of public/private dependencies rust-lang/rust#44663 Partially addresses rust-lang/rust#71043 I'm adding a warning for reexports of private dependencies into `rustc_resolve`. I get that this should not be a warning, but should instead be a lint to be controlled by the feature gate, but I did not figure out how exactly to do that at that point. I tried doing the same thing as is done in `rustc_privacy`, but the linting system is not ready yet as far as I understand the error I got, so I made a warning for now instead. Some guidance on how to emit lints with `dcx` would be appreciated. This also sets the `std_detect` crate as a public dependency of `std` because some macros are reexported from there. I did not check closer, but the other option may be to allow the specific reexports instead.
2025-07-17resolve: Change `&mut Resolver` to `&Resolver` when possibleVadim Petrochenkov-1/+1
2025-07-16resolve: Import `ty::Visibility` everywhereVadim Petrochenkov-4/+5
2025-07-16resolve: Remove trait `ToNameBinding`Vadim Petrochenkov-1/+1
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-3/+0
2025-07-15Implement resolver warnings about reexporting private dependenciesDavid Mládek-2/+23
2025-07-15rustc_resolve: rename `check_hidden_glob_reexports` to `lint_reexports`David Mládek-4/+1
2025-07-13Rollup merge of #143734 - ↵Matthias Krüger-35/+50
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-118/+109
2025-07-12replace binding and shadowed_glob on NameResolution with non_glob_binding ↵b-naber-35/+50
and glob_binding
2025-06-29explain `ImportData::imported_module`bohan-1/+8
2025-06-24Emit a single error when importing a path with `_`Esteban Küber-4/+14
When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`.
2025-06-03resolve: Tweak `private_macro_use` lint to be compatible with upcoming macro ↵Vadim Petrochenkov-1/+3
prelude changes
2025-05-02resolve: Support imports of associated types and glob imports from traitsVadim Petrochenkov-20/+23
2025-04-15Use a dummy ident for a `lint_if_path_starts_with_module` call.Nicholas Nethercote-1/+1
This is pretty weird code. As the `HACK` comment indicates, we push the empty ident here only to make the path longer, so certain checks to occur within `lint_if_path_starts_with_module`. `dummy` is a better choice because it explicitly communicates that the actual value doesn't matter.
2025-04-11Only compute the `DefId` when a diagnostic is definitely emittedOli Scherer-22/+22
2025-04-11Avoid a reverse map that is only used in diagnostics pathsOli Scherer-2/+2
2025-04-01Rollup merge of #138790 - xizheyin:issue-138626, r=compiler-errorsMatthias Krüger-1/+1
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-03-24resolve: Avoid some unstable iteration 2Vadim Petrochenkov-4/+4
2025-03-22Note potential but private items in show_candidatesxizheyin-1/+1
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-26Rollup merge of #137529 - klensy:unused3, r=lcnrLeón Orell Valerian Liehr-5/+3
remove few unused args
2025-02-24cleanup few unused argsklensy-5/+3
2025-02-22Fix binding mode problemsMichael Goulet-9/+9
2025-02-17Enforce T: Hash for Interned<...>Mark Rousskov-0/+13
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-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-6/+9
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08Rustfmtbjorn3-6/+9
2025-02-08Small resolve refactorAndre Bogus-2/+2
2025-01-21rustc_resolve: reduce rightwards drift with `let..else` 👉💨Yotam Ofek-99/+99
2025-01-21rustc_resolve: flatten nested `if`sYotam Ofek-44/+39
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2025-01-16Implement `use` associated items of traitsFrank King-1/+13
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-10Silence `use foo::Bar;` error if `Bar` isn't found in `foo` and `foo.rs` has ↵Esteban Küber-1/+6
parse errors
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-0/+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-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-19/+16
2024-09-12Rollup merge of #130208 - nnethercote:rslv-lifetime, r=petrochenkovMatthias Krüger-34/+38
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-34/+38
`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-11Also fix if in elseMichael Goulet-21/+15
2024-08-10rm `import.used`bohan-3/+2
2024-08-07make `import.vis` is not mutablebohan-27/+26
2024-08-04docs(resolve): more explain about `target`bohan-0/+1
2024-07-31Introduce REDUNDANT_IMPORTS lintMichael Goulet-5/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-20/+20
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-06-25resolve: Tweak some naming around import ambiguitiesVadim Petrochenkov-42/+32