about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/imports.rs
AgeCommit message (Collapse)AuthorLines
2025-08-19Rollup merge of #145166 - makai410:teach-pub-crate, r=lcnr许杰友 Jieyou Xu (Joe)-1/+7
suggest using `pub(crate)` for E0364 - This introduces `vis_span` into `ImportData` for diagnostic purposes. Closes: rust-lang/rust#145140
2025-08-16tidy now installs typos-cli as-needed via cargobinarycat-3/+3
2025-08-14resolve prelude import at `build_reduced_graph` phaseLorrensP-2158466-14/+6
2025-08-13suggest using `pub(crate)` for E0364Makai-1/+7
2025-08-08Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petrochenkovStuart Cook-20/+39
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-20/+39
2025-08-06Introduce ModernIdent type to unify macro 2.0 hygiene handlingxizheyin-5/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-27split up define into define_extern and define_localLorrensP-2158466-10/+9
2025-07-26resolve: Do not create `NameResolution`s on access unless necessaryVadim Petrochenkov-3/+2
2025-07-26resolve: Minimize borrow scopes for `resolutions`Vadim Petrochenkov-33/+30
2025-07-24resolve: Remove `Scope::CrateRoot`Vadim Petrochenkov-4/+4
Use `Scope::Module` with the crate root module inside instead, which should be identical.
2025-07-23resolve: Change the underscore disambiguator to avoid regressionsVadim Petrochenkov-1/+2
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