about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-08-19Auto merge of #145600 - jieyouxu:rollup-jw0bpnt, r=jieyouxubors-1/+4
Rollup of 15 pull requests Successful merges: - rust-lang/rust#145338 (actually provide the correct args to coroutine witnesses) - rust-lang/rust#145429 (Couple of codegen_fn_attrs improvements) - rust-lang/rust#145452 (Do not strip binaries in bootstrap everytime if they are unchanged) - rust-lang/rust#145464 (Stabilize `const_pathbuf_osstring_new` feature) - rust-lang/rust#145474 (Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups) - rust-lang/rust#145486 (Fix `unicode_data.rs` mention message) - rust-lang/rust#145490 (Trace some basic I/O operations in bootstrap) - rust-lang/rust#145493 (remove `should_render` in `PrintAttribute` derive) - rust-lang/rust#145500 (Port must_use to the new target checking) - rust-lang/rust#145505 (Simplify span caches) - rust-lang/rust#145510 (Visit and print async_fut local for async drop.) - rust-lang/rust#145511 (Rust build fails on OpenBSD after using file_lock feature) - rust-lang/rust#145532 (resolve: debug for block module) - rust-lang/rust#145533 (Reorder `lto` options from most to least optimizing) - rust-lang/rust#145537 (Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-17resolve: debug for block modulebohan-1/+4
2025-08-15Detect missing `derive` on unresolved attribute even when not importedEsteban Küber-0/+4
``` error: cannot find attribute `sede` in this scope --> $DIR/missing-derive-3.rs:20:7 | LL | #[sede(untagged)] | ^^^^ | help: the derive macros `Deserialize` and `Serialize` accept the similarly named `serde` attribute | LL | #[serde(untagged)] | + error: cannot find attribute `serde` in this scope --> $DIR/missing-derive-3.rs:14:7 | LL | #[serde(untagged)] | ^^^^^ | note: `serde` is imported here, but it is a crate, not an attribute --> $DIR/missing-derive-3.rs:4:1 | LL | extern crate serde; | ^^^^^^^^^^^^^^^^^^^ help: `serde` is an attribute that can be used by the derive macros `Deserialize` and `Serialize`, you might be missing a `derive` attribute | LL + #[derive(Deserialize, Serialize)] LL | enum B { | ```
2025-08-14Use `default_field_values` in `Resolver`Esteban Küber-30/+17
2025-08-13Auto merge of #144793 - petrochenkov:extprel3, r=davidtwcobors-32/+48
resolve: Split extern prelude into two scopes One scope for `extern crate` items and another for `--extern` options, with the former shadowing the latter. If in a single scope some things can overwrite other things, especially with ad hoc restrictions like `MacroExpandedExternCrateCannotShadowExternArguments`, then it's not really a single scope. So this PR splits `Scope::ExternPrelude` into two cleaner scopes. This is similar to how https://github.com/rust-lang/rust/pull/144131 splits module scope into two scopes for globs and non-globs, but simpler.
2025-08-13resolve: Split extern prelude into two scopesVadim Petrochenkov-32/+48
One for `--extern` options and another for `extern crate` items.
2025-08-12Switch to a bitflags `MacroKinds` to support macros with more than one kindJosh Triplett-5/+5
Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`. Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds. This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`. Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes.
2025-08-10Detect struct construction with private field in field with defaultEsteban Küber-0/+18
When trying to construct a struct that has a public field of a private type, suggest using `..` if that field has a default value. ``` error[E0603]: struct `Priv1` is private --> $DIR/non-exhaustive-ctor.rs:25:39 | LL | let _ = S { field: (), field1: m::Priv1 {} }; | ------ ^^^^^ private struct | | | while setting this field | note: the struct `Priv1` is defined here --> $DIR/non-exhaustive-ctor.rs:14:4 | LL | struct Priv1 {} | ^^^^^^^^^^^^ help: the field `field1` you're trying to set has a default value, you can use `..` to use it | LL | let _ = S { field: (), .. }; | ~~ ```
2025-08-08Rollup merge of #144579 - joshtriplett:mbe-attr, r=petrochenkovTrevor Gross-1/+2
Implement declarative (`macro_rules!`) attribute macros (RFC 3697) This implements [RFC 3697](https://github.com/rust-lang/rust/issues/143547), "Declarative (`macro_rules!`) attribute macros". I would suggest reading this commit-by-commit. This first introduces the feature gate, then adds parsing for attribute rules (doing nothing with them), then adds the ability to look up and apply `macro_rules!` attributes by path, then adds support for local attributes, then adds a test, and finally makes various improvements to errors.
2025-08-08mbe: Handle applying attribute rules with pathsJosh Triplett-1/+2
Add infrastructure to apply an attribute macro given argument tokens and body tokens. Teach the resolver to consider `macro_rules` macros when looking for an attribute via a path. This does not yet handle local `macro_rules` attributes.
2025-08-08Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petrochenkovStuart Cook-21/+111
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-21/+111
2025-08-06Introduce ModernIdent type to unify macro 2.0 hygiene handlingxizheyin-14/+17
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-04Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naberStuart Cook-30/+42
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-07-31resolve: Avoid double table lookup in `extern_prelude_get`Vadim Petrochenkov-22/+29
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-31resolve: Do not add erroneous names to extern preludeVadim Petrochenkov-8/+13
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-1/+1
2025-07-31Move `ResolverOutputs` out of `rustc_middle`.Nicholas Nethercote-2/+7
It's not used in `rustc_middle`, and `rustc_resolve` is a better place for it.
2025-07-29"Cachify" `ExternPreludeEntry.binding` through a `Cell`.LorrensP-2158466-6/+6
2025-07-27split up define into define_extern and define_localLorrensP-2158466-14/+29
2025-07-26resolve: Do not create `NameResolution`s on access unless necessaryVadim Petrochenkov-3/+10
2025-07-24resolve: Remove `Scope::CrateRoot`Vadim Petrochenkov-5/+6
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-0/+3
2025-07-23resolve: Make disambiguators for underscore bindings module-localVadim Petrochenkov-18/+15
2025-07-19Revert "resolve: Make disambiguators for underscore bindings module-local"Rémy Rakic-15/+18
This reverts commit 998df3a3e851908afd05c3318f16d99849af5c55.
2025-07-18Rollup merge of #144059 - LorrensP-2158466:remove-crate-loader, r=petrochenkovMatthias Krüger-16/+10
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-18Rollup merge of #144013 - petrochenkov:disambunder, r=oli-obkMatthias Krüger-18/+15
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-18inline CrateLoader inside of CStoreLorrensP-2158466-16/+10
2025-07-17resolve: Make disambiguators for underscore bindings module-localVadim Petrochenkov-18/+15
2025-07-17Rollup merge of #143550 - petrochenkov:lessmutres, r=lcnrMatthias Krüger-38/+45
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-3/+1
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-3/+3
2025-07-17resolve: Split `module_map` into two maps for local and extern modulesVadim Petrochenkov-13/+29
2025-07-17resolve: Move `self_binding` to `ModuleData`Vadim Petrochenkov-24/+15
2025-07-16resolve: Optimize `fn traits_in_module`Vadim Petrochenkov-7/+6
2025-07-16resolve: Import `ty::Visibility` everywhereVadim Petrochenkov-12/+8
2025-07-16resolve: Remove trait `ToNameBinding`Vadim Petrochenkov-23/+34
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-21/+8
2025-07-15rustc_resolve: rename `check_hidden_glob_reexports` to `lint_reexports`David Mládek-3/+1
2025-07-15Define datastructures for `#[cfg]` attribute, move StrippedCfgItemJonathan Brouwer-1/+1
2025-07-13Rollup merge of #143734 - ↵Matthias Krüger-1/+1
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-0/+7
2025-07-12replace binding and shadowed_glob on NameResolution with non_glob_binding ↵b-naber-1/+1
and glob_binding
2025-07-09Use reference for MacroRulesScopeRef instead of Interned.LorrensP-2158466-1/+1
2025-07-09MacroData in ResolverArenas + split macro_map into extern_macro_map and ↵LorrensP-2158466-5/+19
local_macro_map.
2025-07-06mbe: Change `unused_macro_rules` to a `DenseBitSet`Josh Triplett-1/+2
Now that it only contains indexes, and no other information, a bitset provides a more compact and simpler representation.
2025-07-05mbe: Defer checks for `compile_error!` until reporting an unused macro ruleJosh Triplett-3/+3
The MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This ends up being a net simplification, and reduction in code size.
2025-07-04Auto merge of #143247 - cjgillot:metadata-no-red, r=petrochenkovbors-13/+12
Avoid depending on forever-red DepNode when encoding metadata. Split from https://github.com/rust-lang/rust/pull/114669 for perf r? `@petrochenkov`
2025-07-02Hash resolutions.Camille GILLOT-13/+12
2025-06-25Don't give APITs names with macro expansion placeholder fragments in itMichael Goulet-0/+6