2386 Commits

Author SHA1 Message Date
Stuart Cook
2105044784
Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naber
resolve: Cleanups and micro-optimizations to extern prelude

This is what can be done without changing the structure of `ExternPreludeEntry`, like in https://github.com/rust-lang/rust/pull/144737.

See individual commits for details.
2025-08-04 11:24:39 +10:00
bors
889701db1f Auto merge of #129183 - estebank:cfg-visitor, r=davidtwco
Detect more `cfg`d out items in resolution errors

Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
2025-08-02 05:09:31 +00:00
Esteban Küber
4b24c4bf23 Tweak rendering of cfg'd out item
```
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
  --> $DIR/diagnostics-cross-crate.rs:18:23
   |
LL |     cfged_out::inner::doesnt_exist::hello();
   |                       ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
   |
note: found an item that was configured out
  --> $DIR/auxiliary/cfged_out.rs:6:13
   |
LL |     #[cfg(false)]
   |           ----- the item is gated here
LL |     pub mod doesnt_exist {
   |             ^^^^^^^^^^^^
```
2025-08-01 23:58:15 +00:00
Esteban Küber
77f75f91c5 tiny cleanup 2025-08-01 22:11:45 +00:00
Esteban Küber
adcda6ca9a Detect more cfgd out items in resolution errors
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition.

```
error[E0425]: cannot find function `f` in this scope
  --> $DIR/nested-cfg-attrs.rs:4:13
   |
LL | fn main() { f() }
   |             ^ not found in this scope
   |
note: found an item that was configured out
  --> $DIR/nested-cfg-attrs.rs:2:4
   |
LL | fn f() {}
   |    ^
note: the item is gated here
  --> $DIR/nested-cfg-attrs.rs:1:35
   |
LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))]
   |                                   ^^^^^^^^^^
```
2025-08-01 21:50:36 +00:00
Vadim Petrochenkov
e58e6f857f resolve: Cleanup some uses of extern prelude in diagnostics 2025-07-31 20:35:14 +03:00
Vadim Petrochenkov
73096965fb resolve: Avoid double table lookup in extern_prelude_get
Do not write dummy bindings to extern prelude.
Use more precise `Used::Scope` while recording use and remove now redundant `introduced_by_item` check.
2025-07-31 20:13:13 +03:00
Vadim Petrochenkov
2f7a2fa00f resolve: Do not add erroneous names to extern prelude 2025-07-31 19:47:49 +03:00
Vadim Petrochenkov
cde0374d93 resolve: Clarify extern prelude insertion for extern crate items 2025-07-31 19:20:11 +03:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Nicholas Nethercote
e83c8cb26c Move ResolverOutputs out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_resolve` is a better place
for it.
2025-07-31 11:50:23 +10:00
Jacob Pratt
0912d66c7f
Rollup merge of #144605 - LorrensP-2158466:cache-extern-prelude, r=petrochenkov
Resolve: cachify `ExternPreludeEntry.binding` through a `Cell`

Provides interior mutability to the `binding` field of `ExternPreludeEntry` as this field behaves like a cache. Per [zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion/near/531390914).

A little preparatory work for batched import resolution, which is part of [#gsoc > Project: Parallel Macro Expansion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Parallel.20Macro.20Expansion).

r? `@petrochenkov`
2025-07-29 18:55:20 -04:00
LorrensP-2158466
c39b4479ce "Cachify" ExternPreludeEntry.binding through a Cell. 2025-07-29 15:47:32 +02:00
Camille GILLOT
be9d3bcfed Make resolve_fn_signature responsible for its own rib. 2025-07-29 00:33:21 +00:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
LorrensP-2158466
451a93e2b8 split up define into define_extern and define_local 2025-07-27 12:17:23 +02:00
Vadim Petrochenkov
e82011255b resolve: Do not create NameResolutions on access unless necessary 2025-07-26 00:25:26 +03:00
Vadim Petrochenkov
2c65790160 resolve: Minimize borrow scopes for resolutions 2025-07-26 00:19:12 +03:00
Matthias Krüger
9c257e59c2
Rollup merge of #144368 - petrochenkov:rmrootscope, r=b-naber
resolve: Remove `Scope::CrateRoot`

Use `Scope::Module` with the crate root module inside instead, which should be identical.
This is a simplification by itself, but it will be even larger simplification if something like https://github.com/rust-lang/rust/pull/144131 is implemented, because `Scope::CrateRoot` is also a module with two actual scopes in it (for globs and non-globs).

I also did some renamings for consistency:
- `ScopeSet::AbsolutePath` -> `ScopeSet::ModuleAndExternPrelude`
- `ModuleOrUniformRoot::CrateRootAndExternPrelude` -> `ModuleOrUniformRoot::ModuleAndExternPrelude`
- `is_absolute_path` -> `module_and_extern_prelude`
2025-07-25 11:16:38 +02:00
León Orell Valerian Liehr
456acaa4eb
Rollup merge of #144334 - lolbinarycat:rustdoc-span_of_fragments-revert, r=GuillaumeGomez
rustc_resolve: get rid of unused rustdoc::span_of_fragments_with_expansion

This function can cause false negatives if used incorrectly (usually "do any of the doc fragments come from a macro" is the wrong question to ask), and thus it is unused.

r? `````@GuillaumeGomez`````
2025-07-24 15:08:27 +02:00
Vadim Petrochenkov
9ffa775232 resolve: Remove Scope::CrateRoot
Use `Scope::Module` with the crate root module inside instead, which should be identical.
2025-07-24 15:59:47 +03:00
bors
fc5af18133 Auto merge of #144272 - petrochenkov:disambunder2, r=oli-obk
resolve: Make disambiguators for underscore bindings module-local (take 2)

The difference with https://github.com/rust-lang/rust/pull/144013 can be seen in the second commit.

Now we just keep a separate disambiguator counter in every `Module`, instead of a global counter in `Resolver`.
This will be ok for parallel import resolution because we'll need to lock the module anyway when updating `resolutions` and other fields in it.
And for external modules the disabmiguator could be just passed as an argument to `define_extern`, without using any cells or locks, once https://github.com/rust-lang/rust/pull/143884 lands.

Unblocks https://github.com/rust-lang/rust/pull/143884.
2025-07-24 09:50:20 +00:00
bors
29a58723b0 Auto merge of #144360 - matthiaskrgr:rollup-b6ej0mm, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#144173 (Remove tidy checks for `tests/ui/issues/`)
 - rust-lang/rust#144234 (Fix broken TLS destructors on 32-bit win7)
 - rust-lang/rust#144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - rust-lang/rust#144256 (Don't ICE on non-TypeId metadata within TypeId)
 - rust-lang/rust#144290 (update tests/ui/SUMMARY.md)
 - rust-lang/rust#144292 (mbe: Use concrete type for `get_unused_rule`)
 - rust-lang/rust#144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - rust-lang/rust#144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - rust-lang/rust#144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-23 16:59:13 +00:00
Vadim Petrochenkov
4b557912af resolve: Change the underscore disambiguator to avoid regressions 2025-07-23 16:07:44 +03:00
Vadim Petrochenkov
67b57f69ca resolve: Make disambiguators for underscore bindings module-local 2025-07-23 16:07:44 +03:00
Jonathan Brouwer
a460b46d0f
Ports #[macro_use] and #[macro_escape] to the new attribute parsing infrastructure 2025-07-23 13:33:23 +02:00
binarycat
95de0aaed3 rustc_resolve: get rid of unused rustdoc::span_of_fragments_with_expansion
This function can cause false negatives if used incorrectly
(usually "do any of the doc fragments come from a macro" is
the wrong question to ask), and thus it is unused.
2025-07-22 18:36:09 -05:00
Josh Triplett
551cb9f1f4 mbe: Use concrete type for get_unused_rule
Rather than adding `get_unused_rule` to the `TTMacroExpander` trait, put
it on the concrete `MacroRulesMacroExpander`, and downcast to that type
via `Any` in order to call it.

Suggested-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-07-22 00:36:10 -07:00
bors
0d95920262 Auto merge of #144172 - lqd:revert-144013, r=petrochenkov
Prepare revert of 144013

This is a possible revert for rust-lang/rust#144013 causing issue rust-lang/rust#144168 (imo p-crit) to give us time to figure out a correct fix for rust-lang/rust#144013 without pressure. Feel free to close if it's an easy fix instead: r? `@petrochenkov`
2025-07-19 18:20:39 +00:00
bors
12865ffd0d Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#141076 (fix Zip unsoundness (again))
 - rust-lang/rust#142444 (adding run-make test to autodiff)
 - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner)
 - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia)
 - rust-lang/rust#144083 (miri sleep tests: increase slack)
 - rust-lang/rust#144092 (bootstrap: Detect musl hosts)
 - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT)
 - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`)
 - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling)
 - rust-lang/rust#144115 (fix outdated comment)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-19 11:10:04 +00:00
Rémy Rakic
9613ce02c3 Revert "resolve: Make disambiguators for underscore bindings module-local"
This reverts commit 998df3a3e851908afd05c3318f16d99849af5c55.
2025-07-19 09:30:39 +00:00
xizheyin
c58e0bd093
rename emit_unless to emit_unless_delay
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-19 01:49:19 +08:00
Matthias Krüger
3a3a411980
Rollup merge of #144059 - LorrensP-2158466:remove-crate-loader, r=petrochenkov
Refactor `CrateLoader` into the `CStore`

Removes the `CrateLoader` and moves the code to `CStore`. Now, if you want to use the `CrateLoader`, you can just use `CStore`.

Should we rename `creader.rs` to `cstore.rs`?

r? ``@petrochenkov``
2025-07-18 19:14:46 +02:00
Matthias Krüger
d3bc06ecb4
Rollup merge of #144013 - petrochenkov:disambunder, r=oli-obk
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-18 14:49:20 +02:00
LorrensP-2158466
466d33cb5c inline CrateLoader inside of CStore 2025-07-18 13:16:09 +02:00
xizheyin
848d4a5a38 Remove similar errors about raw underscore lifetime
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18 00:28:09 +08:00
Vadim Petrochenkov
998df3a3e8 resolve: Make disambiguators for underscore bindings module-local 2025-07-17 17:30:30 +03:00
Matthias Krüger
52868368dd
Rollup merge of #143984 - JonathanBrouwer:fix-feature-gate-ice, r=Urgau
Fix ice for feature-gated `cfg` attributes applied to the crate

This PR fixes two fixes:
1. When a feature gated option of the `cfg` attribute is applied to the crate, an ICE would occur because features are not yet available at that stage. This is fixed by ignoring the feature gate at that point, the attribute will later be re-checked (this was already done) when the feature gate is available. Fixes https://github.com/rust-lang/rust/issues/143977
2. Errors and lints on the `cfg` attribute applied to the crate would be produced twice, because of the re-checking. This is fixed by not producing any errors and lints during the first run.

The added regression test checks both problems.
r? ``@jdonszelmann``
2025-07-17 10:41:49 +02:00
Matthias Krüger
52a405b6c9
Rollup merge of #143550 - petrochenkov:lessmutres, r=lcnr
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-17 10:41:44 +02:00
León Orell Valerian Liehr
7a85c5964d
Rollup merge of #143922 - nnethercote:join_path, r=petrochenkov
Improve path segment joining

Currently paths are joined with `::` in many places, in a variety of ways. This PR unifies things.

r? ``@petrochenkov``
2025-07-17 03:58:34 +02:00
León Orell Valerian Liehr
36a362bff5
Rollup merge of #143856 - mladedav:dm/private-reexport, r=petrochenkov
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-17 03:58:33 +02:00
Vadim Petrochenkov
6849f816b1 resolve: Change &mut Resolver to &Resolver when possible 2025-07-17 02:09:01 +03:00
Vadim Petrochenkov
8b8889df25 resolve: Split module_map into two maps for local and extern modules 2025-07-17 02:09:01 +03:00
Vadim Petrochenkov
8d7193973f resolve: Use module_map and get_module less 2025-07-17 02:09:00 +03:00
Vadim Petrochenkov
5d611e5548 resolve: Move self_binding to ModuleData 2025-07-17 02:09:00 +03:00
Nicholas Nethercote
fb7aa9e4fd Improve path segment joining.
There are many places that join path segments with `::` to produce a
string. A lot of these use `join("::")`. Many in rustdoc use
`join_with_double_colon`, and a few use `.joined("..")`. One in Clippy
uses `itertools::join`. A couple of them look for `kw::PathRoot` in the
first segment, which can be important.

This commit introduces `rustc_ast::join_path_{syms,ident}` to do the
joining for everyone. `rustc_ast` is as good a location for these as
any, being the earliest-running of the several crates with a `Path`
type. Two functions are needed because `Ident` printing is more complex
than simple `Symbol` printing.

The commit also removes `join_with_double_colon`, and
`estimate_item_path_byte_length` with it.

There are still a handful of places that join strings with "::" that are
unchanged. They are not that important: some of them are in tests, and
some of them first split a path around "::" and then rejoin with "::".

This fixes one test case where `{{root}}` shows up in an error message.
2025-07-17 08:37:19 +10:00
Vadim Petrochenkov
7f398fd5f6 resolve: Optimize fn traits_in_module 2025-07-16 08:30:48 +03:00
Vadim Petrochenkov
1a9a226058 resolve: Import ty::Visibility everywhere 2025-07-16 08:30:48 +03:00
Vadim Petrochenkov
01b546a19b resolve: Remove trait ToNameBinding 2025-07-16 08:30:44 +03:00