Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver<'db> {
    scopes: Vec<Scope<'db>>,
    module_scope: ModuleItemMap<'db>,
}

Fields§

§scopes: Vec<Scope<'db>>

The stack of scopes, where the inner-most scope is the last item.

When using, you generally want to process the scopes in reverse order, there’s scopes method for that.

§module_scope: ModuleItemMap<'db>

Implementations§

Source§

impl<'db> Resolver<'db>

Source

pub fn resolve_known_trait( &self, db: &dyn SourceDatabase, path: &ModPath, ) -> Option<TraitId>

Resolve known trait from std, like std::futures::Future

Source

pub fn resolve_known_struct( &self, db: &dyn SourceDatabase, path: &ModPath, ) -> Option<StructId>

Resolve known struct from std, like std::boxed::Box

Source

pub fn resolve_known_enum( &self, db: &dyn SourceDatabase, path: &ModPath, ) -> Option<EnumId>

Resolve known enum from std, like std::result::Result

Source

pub fn resolve_module_path_in_items( &self, db: &dyn SourceDatabase, path: &ModPath, ) -> PerNs

Source

pub fn resolve_path_in_type_ns( &self, db: &dyn SourceDatabase, path: &Path, ) -> Option<(TypeNs, Option<usize>, Option<ImportOrExternCrate>)>

Source

pub fn resolve_path_in_type_ns_with_prefix_info( &self, db: &dyn SourceDatabase, path: &Path, ) -> Option<(TypeNs, Option<usize>, Option<ImportOrExternCrate>, ResolvePathResultPrefixInfo, Visibility)>

Source

pub fn resolve_path_in_type_ns_fully( &self, db: &dyn SourceDatabase, path: &Path, ) -> Option<TypeNs>

Source

pub fn resolve_visibility( &self, db: &dyn SourceDatabase, visibility: &RawVisibility, ) -> Option<Visibility>

Source

pub fn resolve_path_in_value_ns( &self, db: &dyn SourceDatabase, path: &Path, hygiene_id: HygieneId, ) -> Option<ResolveValueResult>

Source

fn skip_to_mod<'this, T>( &'this self, f: impl FnMut(&'this ModuleItemMap<'db>) -> Option<T>, ) -> Option<T>

Source

pub fn resolve_path_in_value_ns_with_prefix_info( &self, db: &dyn SourceDatabase, path: &Path, hygiene_id: HygieneId, ) -> Option<(ResolveValueResult, ResolvePathResultPrefixInfo, Visibility)>

Source

pub fn resolve_path_in_value_ns_fully( &self, db: &dyn SourceDatabase, path: &Path, hygiene: HygieneId, ) -> Option<ValueNs>

Source

pub fn resolve_path_as_macro( &self, db: &dyn SourceDatabase, path: &ModPath, expected_macro_kind: Option<MacroSubNs>, ) -> Option<MacrosItem>

Source

pub fn resolve_path_as_macro_def( &self, db: &dyn SourceDatabase, path: &ModPath, expected_macro_kind: Option<MacroSubNs>, ) -> Option<MacroDefId>

Source

pub fn resolve_lifetime(&self, lifetime: &LifetimeRef) -> Option<LifetimeNs>

Source

pub fn names_in_scope( &self, db: &dyn SourceDatabase, ) -> IndexMap<Name, SmallVec<[ScopeDef; 1]>, FxBuildHasher>

Returns a set of names available in the current scope.

Note that this is a somewhat fuzzy concept – internally, the compiler doesn’t necessary follow a strict scoping discipline. Rather, it just tells for each ident what it resolves to.

A good example is something like str::from_utf8. From scopes point of view, this code is erroneous – both str module and str type occupy the same type namespace.

We don’t try to model that super-correctly – this functionality is primarily exposed for completions.

Note that in Rust one name can be bound to several items:

macro_rules! t { () => (()) }
type t = t!();
const t: t = t!();

That’s why we return a multimap.

The shadowing is accounted for: in

ⓘ
let it = 92;
{
    let it = 92;
    $0
}

there will be only one entry for it in the result.

The result is ordered roughly from the innermost scope to the outermost: when the name is introduced in two namespaces in two scopes, we use the position of the first scope.

Source

pub fn extern_crate_decls_in_scope<'a>( &'a self, db: &'a dyn SourceDatabase, ) -> impl Iterator<Item = Name> + 'a

Note: Not to be used directly within hir-def/hir-ty

Source

pub fn extern_crates_in_scope( &self, ) -> impl Iterator<Item = (Name, ModuleId)> + '_

Source

pub fn traits_in_scope(&self, db: &dyn SourceDatabase) -> FxHashSet<TraitId>

Source

pub fn traits_in_scope_from_block_scopes( &self, ) -> impl Iterator<Item = TraitId> + '_

Source

pub fn module(&self) -> ModuleId

Source

pub fn item_scope(&self) -> &ItemScope

Source

pub fn krate(&self) -> Crate

Source

pub fn def_map(&self) -> &DefMap

Source

pub fn top_level_def_map(&self) -> &'db DefMap

Source

pub fn is_visible( &self, db: &dyn SourceDatabase, visibility: Visibility, ) -> bool

Source

pub fn generic_def(&self) -> Option<GenericDefId>

Source

pub fn generic_params(&self) -> Option<&GenericParams>

Source

pub fn all_generic_params( &self, ) -> impl Iterator<Item = (&GenericParams, GenericDefId)>

Source

pub fn expression_store_owner(&self) -> Option<ExpressionStoreOwnerId>

Source

pub fn impl_def(&self) -> Option<ImplId>

Source

pub fn rename_will_conflict_with_another_variable( &self, db: &dyn SourceDatabase, current_name: &Name, current_name_as_path: &ModPath, hygiene_id: HygieneId, new_name: &Symbol, to_be_renamed: BindingId, ) -> Option<BindingId>

Checks if we rename renamed (currently named current_name) to new_name, will the meaning of this reference (that contains current_name path) change from renamed to some another variable (returned as Some).

Source

pub fn rename_will_conflict_with_renamed( &self, db: &dyn SourceDatabase, name: &Name, name_as_path: &ModPath, hygiene_id: HygieneId, to_be_renamed: BindingId, ) -> Option<BindingId>

Checks if we rename renamed to name, will the meaning of this reference (that contains name path) change from some other variable (returned as Some) to renamed.

Source

pub fn update_to_inner_scope( &mut self, db: &'db dyn SourceDatabase, owner: impl Into<ExpressionStoreOwnerId>, expr_id: ExprId, ) -> UpdateGuard

expr_id is required to be an expression id that comes after the top level expression scope in the given resolver

Source

fn update_to_inner_scope_( &mut self, db: &'db dyn SourceDatabase, owner: ExpressionStoreOwnerId, expr_id: ExprId, ) -> UpdateGuard

Source

pub fn reset_to_guard(&mut self, UpdateGuard: UpdateGuard)

Source§

impl<'db> Resolver<'db>

Source

fn scopes(&self) -> impl Iterator<Item = &Scope<'db>>

Source

fn resolve_module_path( &self, db: &dyn SourceDatabase, path: &ModPath, shadow: BuiltinShadowMode, ) -> PerNs

Source

fn item_scope_(&self) -> (&DefMap, &LocalDefMap, ModuleId)

The innermost block scope that contains items or the module scope that contains this resolver.

Source§

impl<'db> Resolver<'db>

Source

fn push_scope(self, scope: Scope<'db>) -> Resolver<'db>

Source

fn push_generic_params_scope( self, db: &'db dyn SourceDatabase, def: GenericDefId, ) -> Resolver<'db>

Source

fn push_block_scope( self, def_map: &'db DefMap, local_def_map: &'db LocalDefMap, module_id: ModuleId, ) -> Resolver<'db>

Source

fn push_expr_scope( self, owner: ExpressionStoreOwnerId, expr_scopes: &'db ExprScopes, scope_id: ScopeId, ) -> Resolver<'db>

Trait Implementations§

Source§

impl<'db> Clone for Resolver<'db>

Source§

fn clone(&self) -> Resolver<'db>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'db> Debug for Resolver<'db>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'db> Freeze for Resolver<'db>

§

impl<'db> RefUnwindSafe for Resolver<'db>

§

impl<'db> Send for Resolver<'db>

§

impl<'db> Sync for Resolver<'db>

§

impl<'db> Unpin for Resolver<'db>

§

impl<'db> UnsafeUnpin for Resolver<'db>

§

impl<'db> UnwindSafe for Resolver<'db>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoBox<dyn Any + Send + Sync> for T
where T: Any + Send + Sync,

§

fn into_box(self) -> Box<dyn Any + Send + Sync>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any + Send> for T
where T: Any + Send,

§

fn into_box(self) -> Box<dyn Any + Send>

Convert self into the appropriate boxed form.
§

impl<T> IntoBox<dyn Any> for T
where T: Any,

§

fn into_box(self) -> Box<dyn Any>

Convert self into the appropriate boxed form.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Lookup<T> for T

§

fn into_owned(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more