about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/imports.rs
AgeCommit message (Collapse)AuthorLines
2023-12-12more clippy::complexity fixesMatthias Krüger-6/+2
redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-11remove some redundant clonesMatthias Krüger-1/+1
2023-12-06Use the glob binding in resolve_rustdoc_path processr0cky-0/+3
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-1/+1
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-1/+1
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-01vis note for no pub reexports glob importbohan-4/+14
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-10-13Format all the let chains in compilerMichael Goulet-19/+21
2023-09-19fix confusing let chain indentation in rustc_resolveEthan Brierley-3/+3
2023-09-13resolve: determined binding after parent module macro expandbohan-7/+2
2023-07-31Rollup merge of #113920 - bvanjoi:fix-81413, r=petrochenkovMatthias Krüger-23/+30
fix(resolve): report unresolved imports firstly Fixes #81413 An easy fix, r? ```@petrochenkov```
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-8/+7
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-20/+94
2023-07-29fix(resolve): report unresolved imports firstlybohan-23/+30
2023-07-25resolve: ensure compile failed when has dummy or ambiguousbohan-8/+8
2023-07-25fix(resolve): skip panic when resolution is dummybohan-1/+4
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-3/+1
2023-07-05resolve: Add comments explaining use of `Interned`Vadim Petrochenkov-0/+2
2023-07-05resolve: Use `Interned` for `Module`Vadim Petrochenkov-6/+6
2023-07-05resolve: Use `Interned` for `Import`Vadim Petrochenkov-29/+20
2023-07-05resolve: Use `Interned` for `NameBinding`Vadim Petrochenkov-28/+25
2023-07-01fix(resolve): skip assertion judgment when `NonModule` is dummybohan-2/+3
2023-06-29resolve: Remove artificial import ambiguity errorsVadim Petrochenkov-17/+6
2023-06-26Rollup merge of #112979 - NotStirred:translatable_diag/resolve_imports, ↵Matthias Krüger-44/+49
r=fee1-dead Rewrite most diagnostics as translatable within resolve/imports
2023-06-25Add translatable diagnostic for import resolution stringsTom Martin-44/+49
Add translatable diagnostic for cannot be reexported error also added for subdiagnostics Add translatable diagnostics for resolve_glob_import errors Add translatable diag for unable to determine import resolution Add translatable diag for is not directly importable
2023-06-24fix: add cfg diagnostic for unresolved import errorbohan-1/+12
2023-06-22Tweak privacy errors to account for reachable itemsEsteban Küber-0/+19
Suggest publicly accessible paths for items in private mod: When encountering a path in non-import situations that are not reachable due to privacy constraints, search for any public re-exports that the user could use instead. Track whether an import suggestion is offering a re-export. When encountering a path with private segments, mention if the item at the final path segment is not publicly accessible at all. Add item visibility metadata to privacy errors from imports: On unreachable imports, record the item that was being imported in order to suggest publicly available re-exports or to be explicit that the item is not available publicly from any path. In order to allow this, we add a mode to `resolve_path` that will not add new privacy errors, nor return early if it encounters one. This way we can get the `Res` corresponding to the final item in the import, which is used in the privacy error machinery.
2023-06-20Revert "Rollup merge of #112758 - bvanjoi:clean-up-resolve, r=petrochenkov"bohan-40/+53
This reverts commit 3b059e0fdbf0257ac4921552781d070e8288233a, reversing changes made to d70be670474c98e62eefc67674b7bb3c7c4f5053.
2023-06-18refactor(resolve): delete `update_resolution` functionbohan-53/+40
2023-06-14fix(resolve): update `shadowed_glob` more precisionbohan-1/+15
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-3/+23
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-05-27Add warn-by-default lint for local binding shadowing exported glob re-export ↵许杰友 Jieyou Xu (Joe)-21/+62
item
2023-05-19Auto merge of #109602 - bvanjoi:fix-issue-109343, r=petrochenkovbors-5/+6
fix(resolve): replace bindings to dummy for unresolved imports close #109343 In #109343, `f` in `pub use f as g` points to: |namespace| binding| |-|-| |type| `external crate f`| |value| `None` | |macro| `None` | When resolve `value_ns` during `resolve_doc_links`, the value of the binding of single_import `pub use f as g` goes to `pub use inner::f`, and since it does not satisfy [!self.is_accessible_from(binding.vis, single_import.parent_scope.module)](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/ident.rs#L971) and returns `Err(Undetermined)`, which eventually goes to `PathResult::Indeterminate => unreachable!`. This PR replace all namespace binding to `dummy_binding` for indeterminate import, so, the bindings of `pub use f as g` had been changed to followings after finalize: |namespace| binding| |-|-| |type| `dummy`| |value| `dummy` | |macro| `dummy` | r?`@petrochenkov`
2023-05-18fix(resolve): only disambiguate binding key during definebohan-2/+2
2023-05-18fix(resolve): replace bindings to dummy for unresolved importsbohan-5/+6
2023-05-04Rollup merge of #110908 - petrochenkov:notagain4, r=compiler-errorsDylan DPC-13/+6
resolve: One more attempt to simplify `module_children` If the next step is performed and `fn module_children_local` is merged with the `module_children` query, then it causes perf regressions, regardless of whether query result feeding is [used](https://perf.rust-lang.org/compare.html?start=43a78029b4f4d92978b8fde0a677ea300b113c41&end=2eb5bcc5068b9d92f74bcb1797da664865d6981d&stat=instructions:u) or [not](https://perf.rust-lang.org/compare.html?start=2fce2290865f012391b8f3e581c3852a248031fa&end=2a33d6cd99481d1712037a79e7d66a8aefadbf72&stat=instructions:u).
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-7/+7
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-05-02resolve: One more attempt to simplify `module_children`Vadim Petrochenkov-13/+6
2023-04-18rustc_metadata: Remove `Span` from `ModChild`Vadim Petrochenkov-7/+1
It can be decoded on demand from regular `def_span` tables. Partially mitigates perf regressions from #109500.
2023-04-12resolve: Pre-compute non-reexport module childrenVadim Petrochenkov-5/+11
Instead of repeating the same logic by walking HIR during metadata encoding. The only difference is that we are no longer encoding `macro_rules` items, but we never currently need them as a part of this list. They can be encoded separately if this need ever arises. `module_reexports` is also un-querified, because I don't see any reasons to make it a query, only overhead.
2023-04-08resolve: Preserve reexport chains in `ModChild`renVadim Petrochenkov-0/+21
This may be potentially useful for - avoiding uses of `hir::ItemKind::Use` - preserving documentation comments on all reexports - preserving and checking stability/deprecation info on reexports - all kinds of diagnostics
2023-03-23Rollup merge of #107880 - jieyouxu:issue-107563, r=petrochenkovMatthias Krüger-1/+31
Lint ambiguous glob re-exports Attempts to fix #107563. We currently already emit errors for ambiguous re-exports when two names are re-exported *specifically*, i.e. not from glob exports. This PR attempts to emit deny-by-default lints for ambiguous glob re-exports.
2023-03-20Lint ambiguous glob re-exports许杰友 Jieyou Xu (Joe)-1/+31
2023-03-19fix: modify the condition that `resolve_imports` stopsbohan-15/+23
2023-03-17resolve: Improve debug impls for `NameBinding`Vadim Petrochenkov-4/+12
Print at least the Some/None/Ok/Err status of the nested bindings if not the bindings themselves.
2023-03-02rustc_middle: Remove trait `DefIdTree`Vadim Petrochenkov-5/+5
This trait was a way to generalize over both `TyCtxt` and `Resolver`, but now `Resolver` has access to `TyCtxt`, so this trait is no longer necessary.
2023-02-22resolve: Remove `ImportResolver`Vadim Petrochenkov-76/+65
It's a trivial wrapper over `Resolver` that doesn't bring any benefits
2023-02-21Use `source_span` query instead of passing the untracked vec aroundOli Scherer-4/+2
2023-02-21Auto merge of #105462 - oli-obk:feeding_full, r=cjgillot,petrochenkovbors-12/+12
give the resolver access to TyCtxt The resolver is now created after TyCtxt is created. Then macro expansion and name resolution are run and the results fed into queries just like before this PR. Since the resolver had (before this PR) mutable access to the `CStore` and the source span table, these two datastructures are now behind a `RwLock`. To ensure that these are not mutated anymore after the resolver is done, a read lock to them is leaked right after the resolver finishes. ### PRs split out of this one and leading up to it: * https://github.com/rust-lang/rust/pull/105423 * https://github.com/rust-lang/rust/pull/105357 * https://github.com/rust-lang/rust/pull/105603 * https://github.com/rust-lang/rust/pull/106776 * https://github.com/rust-lang/rust/pull/106810 * https://github.com/rust-lang/rust/pull/106812 * https://github.com/rust-lang/rust/pull/108032
2023-02-20Stuff a TyCtxt into the ResolverOli Scherer-2/+2