Struct rustc_resolve::late::LateResolutionVisitor [−][src]
struct LateResolutionVisitor<'a, 'b, 'ast> {
r: &'b mut Resolver<'a>,
parent_scope: ParentScope<'a>,
ribs: PerNS<Vec<Rib<'a>>>,
label_ribs: Vec<Rib<'a, NodeId>>,
current_trait_ref: Option<(&'a ModuleData<'a>, TraitRef)>,
diagnostic_metadata: DiagnosticMetadata<'ast>,
in_func_body: bool,
}
Fields
r: &'b mut Resolver<'a>
parent_scope: ParentScope<'a>
The module that represents the current item scope.
ribs: PerNS<Vec<Rib<'a>>>
The current set of local scopes for types and values. FIXME #4948: Reuse ribs to avoid allocation.
label_ribs: Vec<Rib<'a, NodeId>>
The current set of local scopes, for labels.
current_trait_ref: Option<(&'a ModuleData<'a>, TraitRef)>
The trait that the current context can refer to.
diagnostic_metadata: DiagnosticMetadata<'ast>
Fields used to add information to diagnostic errors.
in_func_body: bool
State used to know whether to ignore resolution errors for function bodies.
In particular, rustdoc uses this to avoid giving errors for cfg()
items.
In most cases this will be None
, in which case errors will always be reported.
If it is true
, then it will be updated when entering a nested function or trait body.
Implementations
pub(crate) fn smart_resolve_report_errors(
&mut self,
path: &[Segment],
span: Span,
source: PathSource<'_>,
res: Option<Res<NodeId>>
) -> (DiagnosticBuilder<'a>, Vec<ImportSuggestion>)
pub(crate) fn smart_resolve_report_errors(
&mut self,
path: &[Segment],
span: Span,
source: PathSource<'_>,
res: Option<Res<NodeId>>
) -> (DiagnosticBuilder<'a>, Vec<ImportSuggestion>)
Handles error reporting for smart_resolve_path_fragment
function.
Creates base error and amends it with one short label and possibly some longer helps/notes.
fn get_single_associated_item(
&mut self,
path: &[Segment],
span: Span,
source: &PathSource<'_>,
filter_fn: &impl Fn(Res<NodeId>) -> bool
) -> Option<TypoSuggestion>
fn restrict_assoc_type_in_where_clause(
&mut self,
span: Span,
err: &mut DiagnosticBuilder<'_>
) -> bool
fn restrict_assoc_type_in_where_clause(
&mut self,
span: Span,
err: &mut DiagnosticBuilder<'_>
) -> bool
Given where <T as Bar>::Baz: String
, suggest where T: Bar<Baz = String>
.
Check if the source is call expression and the first argument is self
. If true,
return the span of whole call and the span for all arguments expect the first one (self
).
fn smart_resolve_context_dependent_help(
&mut self,
err: &mut DiagnosticBuilder<'a>,
span: Span,
source: PathSource<'_>,
res: Res<NodeId>,
path_str: &str,
fallback_label: &str
) -> bool
fn smart_resolve_context_dependent_help(
&mut self,
err: &mut DiagnosticBuilder<'a>,
span: Span,
source: PathSource<'_>,
res: Res<NodeId>,
path_str: &str,
fallback_label: &str
) -> bool
Provides context-dependent help for errors reported by the smart_resolve_path_fragment
function.
Returns true
if able to provide context-dependent help.
pub(crate) fn find_similarly_named_assoc_item(
&mut self,
ident: Symbol,
kind: &AssocItemKind
) -> Option<Symbol>
pub(crate) fn find_similarly_named_assoc_item(
&mut self,
ident: Symbol,
kind: &AssocItemKind
) -> Option<Symbol>
Given the target ident
and kind
, search for the similarly named associated item
in self.current_trait_ref
.
fn lookup_assoc_candidate<FilterFn>(
&mut self,
ident: Ident,
ns: Namespace,
filter_fn: FilterFn
) -> Option<AssocSuggestion> where
FilterFn: Fn(Res<NodeId>) -> bool,
fn lookup_typo_candidate(
&mut self,
path: &[Segment],
ns: Namespace,
filter_fn: &impl Fn(Res<NodeId>) -> bool,
span: Span
) -> Option<TypoSuggestion>
Only used in a specific case of type ascription suggestions
fn type_ascription_suggestion(
&self,
err: &mut DiagnosticBuilder<'_>,
base_span: Span
) -> bool
fn suggest_using_enum_variant(
&mut self,
err: &mut DiagnosticBuilder<'a>,
source: PathSource<'_>,
def_id: DefId,
span: Span
)
fn suggest_using_enum_variant(
&mut self,
err: &mut DiagnosticBuilder<'a>,
source: PathSource<'_>,
def_id: DefId,
span: Span
)
Adds a suggestion for using an enum’s variant when an enum is used instead.
fn resolve_ident_in_lexical_scope(
&mut self,
ident: Ident,
ns: Namespace,
record_used_id: Option<NodeId>,
path_span: Span
) -> Option<&'a NameBinding<'a>>
fn resolve_path(
&mut self,
path: &[Segment],
opt_ns: Option<Namespace>,
record_used: bool,
path_span: Span,
crate_lint: CrateLint
) -> PathResult<'a>
Do some work
within a new innermost rib of the given kind
in the given namespace (ns
).
Searches the current set of local scopes for labels. Returns the NodeId
of the resolved
label and reports an error if the label is not found or is unreachable.
Determine whether or not a label from the rib_index
th label rib is reachable.
fn with_generic_param_rib<'c, F>(
&'c mut self,
generics: &'c Generics,
kind: RibKind<'a>,
f: F
) where
F: FnOnce(&mut Self),
fn with_constant_rib(
&mut self,
is_repeat: IsRepeatExpr,
is_trivial: bool,
item: Option<(Ident, ConstantItemKind)>,
f: impl FnOnce(&mut Self)
)
fn with_current_self_item<T>(
&mut self,
self_item: &Item,
f: impl FnOnce(&mut Self) -> T
) -> T
When evaluating a trait
use its associated types’ idents for suggestions in E0412.
This is called to resolve a trait reference from an impl
(i.e., impl Trait for Foo
).
fn resolve_implementation(
&mut self,
generics: &'ast Generics,
opt_trait_reference: &'ast Option<TraitRef>,
self_type: &'ast Ty,
item_id: NodeId,
impl_items: &'ast [P<AssocItem>]
)
fn check_trait_item<F>(
&mut self,
ident: Ident,
kind: &AssocItemKind,
ns: Namespace,
span: Span,
err: F
) where
F: FnOnce(Ident, &str, Option<Symbol>) -> ResolutionError<'_>,
build a map from pattern identifiers to binding-info’s. this is done hygienically. This could arise for a macro that expands into an or-pattern where one ‘x’ was from the user and one ‘x’ came from the macro.
fn check_consistent_bindings(
&mut self,
pats: &[P<Pat>]
) -> Vec<FxHashMap<Ident, BindingInfo>>
fn check_consistent_bindings(
&mut self,
pats: &[P<Pat>]
) -> Vec<FxHashMap<Ident, BindingInfo>>
Checks that all of the arms in an or-pattern have exactly the same set of bindings, with the same binding modes for each.
Check the consistency of the outermost or-patterns.
Arising from source
, resolve a top level pattern.
fn resolve_pattern(
&mut self,
pat: &'ast Pat,
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>
)
fn resolve_pattern_inner(
&mut self,
pat: &Pat,
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>
)
fn resolve_pattern_inner(
&mut self,
pat: &Pat,
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>
)
Resolve bindings in a pattern. This is a helper to resolve_pattern
.
bindings
A stack of sets of bindings accumulated.
In each set, PatBoundCtx::Product
denotes that a found binding in it should
be interpreted as re-binding an already bound binding. This results in an error.
Meanwhile, PatBound::Or
denotes that a found binding in the set should result
in reusing this binding rather than creating a fresh one.
When called at the top level, the stack must have a single element
with PatBound::Product
. Otherwise, pushing to the stack happens as
or-patterns (p_0 | ... | p_n
) are encountered and the context needs
to be switched to PatBoundCtx::Or
and then PatBoundCtx::Product
for each p_i
.
When each p_i
has been dealt with, the top set is merged with its parent.
When a whole or-pattern has been dealt with, the thing happens.
See the implementation and fresh_binding
for more details.
fn fresh_binding(
&mut self,
ident: Ident,
pat_id: NodeId,
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>
) -> Res<NodeId>
fn innermost_rib_bindings(
&mut self,
ns: Namespace
) -> &mut FxHashMap<Ident, &'a NameBinding<'a>>
fn try_resolve_as_non_binding(
&mut self,
pat_src: PatternSource,
pat: &Pat,
bm: BindingMode,
ident: Ident,
has_sub: bool
) -> Option<Res<NodeId>>
fn smart_resolve_path(
&mut self,
id: NodeId,
qself: Option<&QSelf>,
path: &Path,
source: PathSource<'ast>
)
fn smart_resolve_path_fragment(
&mut self,
id: NodeId,
qself: Option<&QSelf>,
path: &[Segment],
span: Span,
source: PathSource<'ast>,
crate_lint: CrateLint
) -> PartialRes
A wrapper around Resolver::report_error
.
This doesn’t emit errors for function bodies if this is rustdoc.
If we’re actually rustdoc then avoid giving a name resolution error for cfg()
items.
fn resolve_qpath_anywhere(
&mut self,
id: NodeId,
qself: Option<&QSelf>,
path: &[Segment],
primary_ns: Namespace,
span: Span,
defer_to_typeck: bool,
crate_lint: CrateLint
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>>
Handles paths that may refer to associated items.
Trait Implementations
Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
fn visit_enum_def(
&mut self,
enum_definition: &'ast EnumDef,
generics: &'ast Generics,
item_id: NodeId,
Span
)
Auto Trait Implementations
impl<'a, 'b, 'ast> !RefUnwindSafe for LateResolutionVisitor<'a, 'b, 'ast>
impl<'a, 'b, 'ast> !Send for LateResolutionVisitor<'a, 'b, 'ast>
impl<'a, 'b, 'ast> !Sync for LateResolutionVisitor<'a, 'b, 'ast>
impl<'a, 'b, 'ast> Unpin for LateResolutionVisitor<'a, 'b, 'ast> where
'a: 'b,
impl<'a, 'b, 'ast> !UnwindSafe for LateResolutionVisitor<'a, 'b, 'ast>
Blanket Implementations
Layout
Note: Most layout information is completely unstable and may even differ between compilations. 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: 520 bytes