Resolver

Struct Resolver 

Source
pub struct Resolver<'db> {
    pub data: ResolverData<'db>,
    pub macro_call_data: Option<Arc<ResolverMacroData<'db>>>,
    pub default_module_allowed: bool,
    pub owning_crate_id: CrateId<'db>,
    pub settings: CrateSettings,
    /* private fields */
}
Expand description

Resolves paths semantically.

Fields§

§data: ResolverData<'db>§macro_call_data: Option<Arc<ResolverMacroData<'db>>>

The resolving context for macro related resolving. Should be Some only if the current code is an expansion of a macro.

§default_module_allowed: bool

If true, allow resolution of path through the module definition, without a modifier. Should be true only within plugin macros generated code, or item macro call generated code.

§owning_crate_id: CrateId<'db>§settings: CrateSettings

Implementations§

Source§

impl<'db> Resolver<'db>

Source

pub fn set_feature_config( &mut self, element_id: &impl LanguageElementId<'db>, syntax: &impl QueryAttrs<'db>, diagnostics: &mut SemanticDiagnostics<'db>, )

Extracts the allowed node from the syntax, and sets it as the allowed features of the resolver.

Source

pub fn extend_feature_config_from_item( &mut self, db: &'db dyn Database, crate_id: CrateId<'db>, diagnostics: &mut SemanticDiagnostics<'db>, item: &impl QueryAttrs<'db>, ) -> FeatureConfigRestore<'db>

Extends the current feature config with the contents of those extracted from the given item, returns the original feature config for restoring it later. IMPORTANT: don’t forget to call restore_feature_config!

Source

pub fn restore_feature_config(&mut self, restore: FeatureConfigRestore<'db>)

Restores the feature config to its state before Self::extend_feature_config_from_item, using the restoration state returned by that method.

Source§

impl<'db> Resolver<'db>

Source

pub fn new( db: &'db dyn Database, module_id: ModuleId<'db>, inference_id: InferenceId<'db>, ) -> Self

Source

pub fn with_data(db: &'db dyn Database, data: ResolverData<'db>) -> Self

Source

pub fn inference(&mut self) -> Inference<'db, '_>

Source

pub fn add_generic_param(&mut self, generic_param_id: GenericParamId<'db>)

Adds a generic param to an existing resolver. This is required since a resolver needs to exist before resolving the generic params, and thus, they are added to the Resolver only after they are resolved.

Source

pub fn set_default_module_allowed(&mut self, default_module_allowed: bool)

Source

pub fn resolve_concrete_path( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, path: impl AsSegments<'db>, item_type: NotFoundItemType, ) -> Maybe<ResolvedConcreteItem<'db>>

Resolves a concrete item, given a path. Guaranteed to result in at most one diagnostic. Item not inside a statement.

Source

pub fn resolve_concrete_path_ex( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, path: impl AsSegments<'db>, item_type: NotFoundItemType, ctx: ResolutionContext<'db, '_>, ) -> Maybe<ResolvedConcreteItem<'db>>

Resolves a concrete item, given a path. Guaranteed to result in at most one diagnostic.

Source

pub fn resolve_generic_path( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, path: impl AsSegments<'db>, item_type: NotFoundItemType, ctx: ResolutionContext<'db, '_>, ) -> Maybe<ResolvedGenericItem<'db>>

Resolves a generic item, given a path. Guaranteed to result in at most one diagnostic.

Source

pub fn resolve_use_path( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, use_path: UsePath<'db>, ctx: ResolutionContext<'db, '_>, ) -> Maybe<ResolvedGenericItem<'db>>

Resolves a generic item from a use statement path.

Useful for resolving paths from use items and statements.

Source

pub fn resolve_generic_path_with_args( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, path: impl AsSegments<'db>, item_type: NotFoundItemType, ctx: ResolutionContext<'db, '_>, ) -> Maybe<ResolvedGenericItem<'db>>

Resolves a generic item, given a concrete item path, while ignoring the generic args. Guaranteed to result in at most one diagnostic.

Source

pub fn determine_base_item_in_local_scope( &mut self, identifier: &TerminalIdentifier<'db>, ) -> Option<ResolvedConcreteItem<'db>>

Determines whether the first identifier of a path is a local item.

Source

pub fn prelude_submodule(&self) -> ModuleId<'db>

Source

pub fn specialize_function( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, stable_ptr: SyntaxStablePtrId<'db>, generic_function: GenericFunctionId<'db>, generic_args: &[GenericArg<'db>], ) -> Maybe<FunctionId<'db>>

Specializes a generic function.

Source

pub fn specialize_type( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, stable_ptr: SyntaxStablePtrId<'db>, generic_type: GenericTypeId<'db>, generic_args: &[GenericArg<'db>], ) -> Maybe<TypeId<'db>>

Specializes a generic type.

Source

pub fn impl_lookup_context(&self) -> ImplLookupContextId<'db>

Returns the current impl lookup context.

Source

pub fn resolve_generic_args( &mut self, diagnostics: &mut SemanticDiagnostics<'db>, substitution: GenericSubstitution<'db>, generic_params: &[GenericParam<'db>], generic_args_syntax: &[GenericArg<'db>], stable_ptr: SyntaxStablePtrId<'db>, ) -> Maybe<Vec<GenericArgumentId<'db>>>

Resolves generic arguments. For each generic argument, if the syntax is provided, it will be resolved by the inference. Otherwise, resolved by type.

Source

pub fn get_arg_syntax_per_param( &self, diagnostics: &mut SemanticDiagnostics<'db>, generic_params: &[GenericParamId<'db>], generic_args_syntax: &[GenericArg<'db>], ) -> Maybe<UnorderedHashMap<GenericParamId<'db>, GenericArgValue<'db>>>

Returns a map of generic param id -> its assigned arg syntax.

Source

pub fn ignore_visibility_checks(&self, module_id: ModuleId<'db>) -> bool

Should visibility checks not actually happen for lookups in this module.

Source

pub fn validate_feature_constraints<T: HasFeatureKind<'db>>( &self, diagnostics: &mut SemanticDiagnostics<'db>, identifier: &TerminalIdentifier<'db>, item_info: &T, )

Validates whether a given item is allowed based on its feature kind. This function checks if the item’s feature kind is allowed in the current configuration. If the item uses an unstable, deprecated, or internal feature that is not permitted, a corresponding diagnostic error is reported.

Source

pub fn is_item_visible( &self, containing_module_id: ModuleId<'db>, item_info: &ModuleItemInfo<'db>, user_module: ModuleId<'db>, ) -> bool

Checks if an item is visible from the current module.

Source

pub fn insert_used_use(&mut self, item_id: ModuleItemId<'db>)

Inserts an item into the used uses set, if it is indeed a use.

Methods from Deref<Target = ResolverData<'db>>§

Source

pub fn clone_with_inference_id( &self, db: &'db dyn Database, inference_id: InferenceId<'db>, ) -> Self

Trait Implementations§

Source§

impl<'db> Deref for Resolver<'db>

Source§

type Target = ResolverData<'db>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Resolver<'_>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> !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<'db, T> DebugDbUpcast<'db, T> for T
where T: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T0, T1, E, TRewriter> SemanticRewriter<(T0, T1), E> for TRewriter
where TRewriter: SemanticRewriter<T0, E> + SemanticRewriter<T1, E>,

Source§

fn internal_rewrite(&mut self, value: &mut (T0, T1)) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<T, E, TRewriter> SemanticRewriter<Box<T>, E> for TRewriter
where TRewriter: SemanticRewriter<T, E>,

Source§

fn internal_rewrite(&mut self, value: &mut Box<T>) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<T, E, TRewriter> SemanticRewriter<Deque<T>, E> for TRewriter
where TRewriter: SemanticRewriter<T, E>,

Source§

fn internal_rewrite(&mut self, value: &mut Deque<T>) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<T, E, TRewriter> SemanticRewriter<Option<T>, E> for TRewriter
where TRewriter: SemanticRewriter<T, E>,

Source§

fn internal_rewrite( &mut self, value: &mut Option<T>, ) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<'a, K, V, E, TRewriter> SemanticRewriter<OrderedHashMap<K, V>, E> for TRewriter
where K: Hash + Eq + LanguageElementId<'a>, V: Clone, TRewriter: SemanticRewriter<V, E>,

Source§

fn internal_rewrite( &mut self, value: &mut OrderedHashMap<K, V>, ) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<T, E, TRewriter, E2> SemanticRewriter<Result<T, E2>, E> for TRewriter
where TRewriter: SemanticRewriter<T, E>,

Source§

fn internal_rewrite( &mut self, value: &mut Result<T, E2>, ) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

Source§

impl<T, E, TRewriter> SemanticRewriter<Vec<T>, E> for TRewriter
where T: Clone, TRewriter: SemanticRewriter<T, E>,

Source§

fn internal_rewrite(&mut self, value: &mut Vec<T>) -> Result<RewriteResult, E>

Source§

fn rewrite(&mut self, value: T) -> Result<T, Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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