Struct rustc_resolve::Resolver[][src]

pub struct Resolver<'a> {
Show 76 fields session: &'a Session, definitions: Definitions, graph_root: &'a ModuleData<'a>, prelude: Option<&'a ModuleData<'a>>, extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'a>>, has_self: FxHashSet<DefId>, field_names: FxHashMap<DefId, Vec<Spanned<Symbol>>>, determined_imports: Vec<&'a Import<'a>>, indeterminate_imports: Vec<&'a Import<'a>>, last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, pat_span_map: NodeMap<Span>, partial_res_map: NodeMap<PartialRes>, import_res_map: NodeMap<PerNS<Option<Res<NodeId>>>>, label_res_map: NodeMap<NodeId>, extern_crate_map: FxHashMap<LocalDefId, CrateNum>, export_map: ExportMap, trait_map: Option<NodeMap<Vec<TraitCandidate>>>, block_map: NodeMap<&'a ModuleData<'a>>, empty_module: &'a ModuleData<'a>, module_map: FxHashMap<LocalDefId, &'a ModuleData<'a>>, extern_module_map: FxHashMap<DefId, &'a ModuleData<'a>>, binding_parent_modules: FxHashMap<PtrKey<'a, NameBinding<'a>>, &'a ModuleData<'a>>, underscore_disambiguator: u32, glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>, visibilities: FxHashMap<LocalDefId, Visibility>, used_imports: FxHashSet<NodeId>, maybe_unused_trait_imports: FxHashSet<LocalDefId>, maybe_unused_extern_crates: Vec<(LocalDefId, Span)>, privacy_errors: Vec<PrivacyError<'a>>, ambiguity_errors: Vec<AmbiguityError<'a>>, use_injections: Vec<UseError<'a>>, macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>, arenas: &'a ResolverArenas<'a>, dummy_binding: &'a NameBinding<'a>, crate_loader: CrateLoader<'a>, macro_names: FxHashSet<Ident>, builtin_macros: FxHashMap<Symbol, BuiltinMacroState>, registered_attrs: FxHashSet<Ident>, registered_tools: FxHashSet<Ident>, macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>, all_macros: FxHashMap<Symbol, Res<NodeId>>, macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>, dummy_ext_bang: Lrc<SyntaxExtension>, dummy_ext_derive: Lrc<SyntaxExtension>, non_macro_attr: Lrc<SyntaxExtension>, local_macro_def_scopes: FxHashMap<LocalDefId, &'a ModuleData<'a>>, ast_transform_scopes: FxHashMap<LocalExpnId, &'a ModuleData<'a>>, unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>, proc_macro_stubs: FxHashSet<LocalDefId>, single_segment_macro_resolutions: Vec<(Ident, MacroKind, ParentScope<'a>, Option<&'a NameBinding<'a>>)>, multi_segment_macro_resolutions: Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>, Option<Res<NodeId>>)>, builtin_attrs: Vec<(Ident, ParentScope<'a>)>, containers_deriving_copy: FxHashSet<LocalExpnId>, invocation_parent_scopes: FxHashMap<LocalExpnId, ParentScope<'a>>, output_macro_rules_scopes: FxHashMap<LocalExpnId, PtrKey<'a, Cell<MacroRulesScope<'a>>>>, helper_attrs: FxHashMap<LocalExpnId, Vec<Ident>>, derive_data: FxHashMap<LocalExpnId, DeriveData>, name_already_seen: FxHashMap<Symbol, Span>, potentially_unused_imports: Vec<&'a Import<'a>>, struct_constructors: DefIdMap<(Res<NodeId>, Visibility, Vec<Visibility>)>, active_features: FxHashSet<Symbol>, lint_buffer: LintBuffer, next_node_id: NodeId, node_id_to_def_id: FxHashMap<NodeId, LocalDefId>, def_id_to_node_id: IndexVec<LocalDefId, NodeId>, placeholder_field_indices: FxHashMap<NodeId, usize>, invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>, next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>, trait_impl_items: FxHashSet<LocalDefId>, legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>, item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>, main_def: Option<MainDefinition>, trait_impls: BTreeMap<DefId, Vec<LocalDefId>>, proc_macros: Vec<NodeId>, confused_type_with_std_module: FxHashMap<Span, Span>,
}
Expand description

The main resolver class.

This is the visitor that walks the whole crate.

Fields

session: &'a Sessiondefinitions: Definitionsgraph_root: &'a ModuleData<'a>prelude: Option<&'a ModuleData<'a>>extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'a>>has_self: FxHashSet<DefId>

N.B., this is used only for better diagnostics, not name resolution itself.

field_names: FxHashMap<DefId, Vec<Spanned<Symbol>>>

Names of fields of an item DefId accessible with dot syntax. Used for hints during error reporting.

determined_imports: Vec<&'a Import<'a>>

All imports known to succeed or fail.

indeterminate_imports: Vec<&'a Import<'a>>

All non-determined imports.

last_import_segment: bool

FIXME: Refactor things so that these fields are passed through arguments and not resolver. We are resolving a last import segment during import validation.

unusable_binding: Option<&'a NameBinding<'a>>

This binding should be ignored during in-module resolution, so that we don’t get “self-confirming” import resolutions during import validation.

pat_span_map: NodeMap<Span>partial_res_map: NodeMap<PartialRes>

Resolutions for nodes that have a single resolution.

import_res_map: NodeMap<PerNS<Option<Res<NodeId>>>>

Resolutions for import nodes, which have multiple resolutions in different namespaces.

label_res_map: NodeMap<NodeId>

Resolutions for labels (node IDs of their corresponding blocks or loops).

extern_crate_map: FxHashMap<LocalDefId, CrateNum>

CrateNum resolutions of extern crate items.

export_map: ExportMaptrait_map: Option<NodeMap<Vec<TraitCandidate>>>block_map: NodeMap<&'a ModuleData<'a>>

A map from nodes to anonymous modules. Anonymous modules are pseudo-modules that are implicitly created around items contained within blocks.

For example, if we have this:

fn f() { fn g() { … } }

There will be an anonymous module created around g with the ID of the entry block for f.

empty_module: &'a ModuleData<'a>

A fake module that contains no definition and no prelude. Used so that some AST passes can generate identifiers that only resolve to local or language items.

module_map: FxHashMap<LocalDefId, &'a ModuleData<'a>>extern_module_map: FxHashMap<DefId, &'a ModuleData<'a>>binding_parent_modules: FxHashMap<PtrKey<'a, NameBinding<'a>>, &'a ModuleData<'a>>underscore_disambiguator: u32glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>

Maps glob imports to the names of items actually imported.

visibilities: FxHashMap<LocalDefId, Visibility>

Visibilities in “lowered” form, for all entities that have them.

used_imports: FxHashSet<NodeId>maybe_unused_trait_imports: FxHashSet<LocalDefId>maybe_unused_extern_crates: Vec<(LocalDefId, Span)>privacy_errors: Vec<PrivacyError<'a>>

Privacy errors are delayed until the end in order to deduplicate them.

ambiguity_errors: Vec<AmbiguityError<'a>>

Ambiguity errors are delayed for deduplication.

use_injections: Vec<UseError<'a>>

use injections are delayed for better placement and deduplication.

macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>

Crate-local macro expanded macro_export referred to by a module-relative path.

arenas: &'a ResolverArenas<'a>dummy_binding: &'a NameBinding<'a>crate_loader: CrateLoader<'a>macro_names: FxHashSet<Ident>builtin_macros: FxHashMap<Symbol, BuiltinMacroState>registered_attrs: FxHashSet<Ident>registered_tools: FxHashSet<Ident>macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>all_macros: FxHashMap<Symbol, Res<NodeId>>macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>dummy_ext_bang: Lrc<SyntaxExtension>dummy_ext_derive: Lrc<SyntaxExtension>non_macro_attr: Lrc<SyntaxExtension>local_macro_def_scopes: FxHashMap<LocalDefId, &'a ModuleData<'a>>ast_transform_scopes: FxHashMap<LocalExpnId, &'a ModuleData<'a>>unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>proc_macro_stubs: FxHashSet<LocalDefId>single_segment_macro_resolutions: Vec<(Ident, MacroKind, ParentScope<'a>, Option<&'a NameBinding<'a>>)>

Traces collected during macro resolution and validated when it’s complete.

multi_segment_macro_resolutions: Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>, Option<Res<NodeId>>)>builtin_attrs: Vec<(Ident, ParentScope<'a>)>containers_deriving_copy: FxHashSet<LocalExpnId>

derive(Copy) marks items they are applied to so they are treated specially later. Derive macros cannot modify the item themselves and have to store the markers in the global context, so they attach the markers to derive container IDs using this resolver table.

invocation_parent_scopes: FxHashMap<LocalExpnId, ParentScope<'a>>

Parent scopes in which the macros were invoked. FIXME: derives are missing in these parent scopes and need to be taken from elsewhere.

output_macro_rules_scopes: FxHashMap<LocalExpnId, PtrKey<'a, Cell<MacroRulesScope<'a>>>>

macro_rules scopes produced by expanding the macro invocations, include all the macro_rules items and other invocations generated by them.

helper_attrs: FxHashMap<LocalExpnId, Vec<Ident>>

Helper attributes that are in scope for the given expansion.

derive_data: FxHashMap<LocalExpnId, DeriveData>

Ready or in-progress results of resolving paths inside the #[derive(...)] attribute with the given ExpnId.

name_already_seen: FxHashMap<Symbol, Span>

Avoid duplicated errors for “name already defined”.

potentially_unused_imports: Vec<&'a Import<'a>>struct_constructors: DefIdMap<(Res<NodeId>, Visibility, Vec<Visibility>)>

Table for mapping struct IDs into struct constructor IDs, it’s not used during normal resolution, only for better error reporting. Also includes of list of each fields visibility

active_features: FxHashSet<Symbol>

Features enabled for this crate.

lint_buffer: LintBuffernext_node_id: NodeIdnode_id_to_def_id: FxHashMap<NodeId, LocalDefId>def_id_to_node_id: IndexVec<LocalDefId, NodeId>placeholder_field_indices: FxHashMap<NodeId, usize>

Indices of unnamed struct or variant fields with unresolved attributes.

invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>

When collecting definitions from an AST fragment produced by a macro invocation ExpnId we know what parent node that fragment should be attached to thanks to this table, and how the impl Trait fragments were introduced.

next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>trait_impl_items: FxHashSet<LocalDefId>

Some way to know that we are in a trait impl in visit_assoc_item. FIXME: Replace with a more general AST map (together with some other fields).

legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>

Amount of lifetime parameters for each item in the crate.

main_def: Option<MainDefinition>trait_impls: BTreeMap<DefId, Vec<LocalDefId>>proc_macros: Vec<NodeId>

A list of proc macro LocalDefIds, written out in the order in which they are declared in the static array generated by proc_macro_harness.

confused_type_with_std_module: FxHashMap<Span, Span>

Implementations

Defines name in namespace ns of module parent to be def if it is not yet defined; otherwise, reports an error.

Walks up the tree of definitions starting at def_id, stopping at the first DefKind::Mod encountered

Combines an error with provided span and emits it.

This takes the error provided, combines it with the span and any additional spans inside the error and emits it.

Lookup typo candidate in scope for a macro or import.

When name resolution fails, this method can be used to look up candidate entities with the expected name. It allows filtering them using the supplied predicate (which should be used to only accept the types of definitions expected, e.g., traits). The lookup spans across all crates.

N.B., the method does not look into imports, but this is not a problem, since we report the definitions (thus, the de-aliased imports).

If the binding refers to a tuple struct constructor with fields, returns the span of its fields.

Attempts to resolve ident in namespaces ns of module. Invariant: if record_used is Some, expansion and import resolution must be complete.

Resolve macro path with error reporting and recovery. Uses dummy syntax extensions for unresolved macros or macros with unexpected resolutions for better error recovery.

Compile the macro into a SyntaxExtension and possibly replace its expander to a pre-defined one for built-in macros.

Runs the function on each namespace.

Entry point to crate resolution.

A generic scope visitor. Visits scopes in order to resolve some identifier in them or perform other actions. If the callback returns Some result, we stop visiting scopes and return it.

This resolves the identifier ident in the namespace ns in the current lexical scope. More specifically, we proceed up the hierarchy of scopes and return the binding for ident in the first scope that defines it (or None if no scopes define it).

A block’s items are above its local variables in the scope hierarchy, regardless of where the items are defined in the block. For example,

fn f() {
   g(); // Since there are no local variables in scope yet, this resolves to the item.
   let g = || {};
   fn g() {}
   g(); // This resolves to the local variable `g` since it shadows the item.
}

Invariant: This must only be called during main resolution, not during import resolution.

This function adds a suggestion to change the binding name of a new import that conflicts with an existing import.

help: you can use `as` to change the binding name of the import
   |
LL | use foo::bar as other_bar;
   |     ^^^^^^^^^^^^^^^^^^^^^

This function adds a suggestion to remove an unnecessary binding from an import that is nested. In the following example, this function will be invoked to remove the a binding in the second use statement:

use issue_52891::a;
use issue_52891::{d, a, e};

The following suggestion will be added:

use issue_52891::{d, a, e};
                     ^-- help: remove unnecessary import

If the nested use contains only one import then the suggestion will remove the entire line.

It is expected that the provided import is nested - this isn’t checked by the function. If this invariant is not upheld, this function’s behaviour will be unexpected as characters expected by span manipulations won’t be present.

Rustdoc uses this to resolve things in a recoverable way. ResolutionError<'a> isn’t something that can be returned because it can’t be made to live that long, and also it’s a private type. Fortunately rustdoc doesn’t need to know the error, just that an error occurred.

Retrieves the span of the given DefId if DefId is in the local crate.

Checks if an expression refers to a function marked with #[rustc_legacy_const_generics] and returns the argument index list from the attribute.

Trait Implementations

Performs the conversion.

Performs the conversion.

This interface is used through the AST→HIR step, to embed full paths into the HIR. After that the resolver is no longer needed as all the relevant information is inline.

Adds a definition with a parent definition.

Obtains resolution for a NodeId with a single resolution.

Obtains per-namespace resolutions for use statement with the given NodeId.

Obtains resolution for a label with the given NodeId.

We must keep the set of definitions up to date as we add nodes that weren’t in the AST. This should only return None during testing. Read more

Does #[derive(...)] attribute with the given ExpnId have built-in Copy inside it?

Resolve paths inside the #[derive(...)] attribute with the given ExpnId.

Take resolutions for paths inside the #[derive(...)] attribute with the given ExpnId back from resolver. Read more

Path resolution logic for #[cfg_accessible(path)].

Decodes the proc-macro quoted span in the specified crate, with the specified id. No caching is performed. Read more

The order of items in the HIR is unrelated to the order of items in the AST. However, we generate proc macro harnesses based on the AST order, and later refer to these harnesses from the HIR. This field keeps track of the order in which we generated proc macros harnesses, so that we can map HIR proc macros items back to their harness items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may be different between compiler versions and platforms. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 2272 bytes