pub struct Scope<'scope, 'db> {
span: Span<'db>,
chain: ScopeChain<'scope, 'db>,
}Expand description
Name resolution scope, used when converting types/function-bodies etc into symbols.
Fields§
§span: Span<'db>§chain: ScopeChain<'scope, 'db>Implementations§
Source§impl<'scope, 'db> Scope<'scope, 'db>
impl<'scope, 'db> Scope<'scope, 'db>
Sourcepub(crate) fn new(db: &'db dyn Db, span: Span<'db>) -> Self
pub(crate) fn new(db: &'db dyn Db, span: Span<'db>) -> Self
A base scope containing only the primitive names.
Sourcepub(crate) fn with_link<'scope1>(
self,
link: impl Into<ScopeChainKind<'scope1, 'db>>,
) -> Scope<'scope1, 'db>where
'scope: 'scope1,
pub(crate) fn with_link<'scope1>(
self,
link: impl Into<ScopeChainKind<'scope1, 'db>>,
) -> Scope<'scope1, 'db>where
'scope: 'scope1,
Extend this scope with another link in the name resolution chain
pub fn span(&self) -> Span<'db>
Sourcefn with_prelude(
self,
db: &'db dyn Db,
span: Span<'db>,
crate_source: Krate,
) -> Self
fn with_prelude( self, db: &'db dyn Db, span: Span<'db>, crate_source: Krate, ) -> Self
Extend this scope with the prelude from a crate.
Crates can define a module named prelude.
Sourcepub fn push_link(&mut self, kind: impl Into<ScopeChainKind<'scope, 'db>>)
pub fn push_link(&mut self, kind: impl Into<ScopeChainKind<'scope, 'db>>)
Extend this scope with another link in the name resolution chain
Sourcepub fn aggregate(&self) -> Option<SymAggregate<'db>>
pub fn aggregate(&self) -> Option<SymAggregate<'db>>
Return the innermost class in scope (if any).
Sourcepub(crate) fn resolve_name(
&self,
db: &'db dyn Db,
id: Identifier<'db>,
span: Span<'db>,
) -> Errors<NameResolution<'db>>
pub(crate) fn resolve_name( &self, db: &'db dyn Db, id: Identifier<'db>, span: Span<'db>, ) -> Errors<NameResolution<'db>>
Resolve identifier id (found at span) in the scope.
Reports errors if nothing is found and returns Err(Reported).
Sourcepub fn generic_sym_in_scope(
&self,
db: &'db dyn Db,
sym: SymVariable<'db>,
) -> bool
pub fn generic_sym_in_scope( &self, db: &'db dyn Db, sym: SymVariable<'db>, ) -> bool
True if sym is in scope.
Sourcepub fn into_bound_value<B>(self, db: &'db dyn Db, value: B::LeafTerm) -> Bwhere
B: BoundTerm<'db>,
pub fn into_bound_value<B>(self, db: &'db dyn Db, value: B::LeafTerm) -> Bwhere
B: BoundTerm<'db>,
Given a value of type T that was resolved against this scope,
creates a bound version like Binder<T> or Binder<Binder<T>>
where all variables defined in scope are contained in these binders.
Each inner binding level in the output binds the symbols from one binding level in the scope. The outermost binding level in the output then binds all remaining symbols.
Example: Given a scope that has three levels like
Classbinding[A, B]Functionbinding[C, D]- Local variables binding
[x, y]
if we produce a Binder<'db, Binder<'db, T>>, then the result would be
- an outer
Binder<Binder<T>>binds[A, B, C, D]that contains…- an inner
Binder<T>binding[x, y]that contains…- the
Tvalue referencingA,B,C,D,x, andy
- the
- an inner
§Panics
If the target type B requires more binding levels than are present in scope.
Sourcepub fn all_binders(&self) -> Vec<Vec<SymVariable<'db>>>
pub fn all_binders(&self) -> Vec<Vec<SymVariable<'db>>>
Convert self into a vec-of-vecs containing the bound generic symbols
in outermost-to-innermost order. e.g. if you have class[type A] { fn foo[type B]() },
this will return [[A], [B]].
Trait Implementations§
impl<'scope, 'db> Eq for Scope<'scope, 'db>
impl<'scope, 'db> StructuralPartialEq for Scope<'scope, 'db>
Auto Trait Implementations§
impl<'scope, 'db> Freeze for Scope<'scope, 'db>
impl<'scope, 'db> !RefUnwindSafe for Scope<'scope, 'db>
impl<'scope, 'db> Send for Scope<'scope, 'db>
impl<'scope, 'db> Sync for Scope<'scope, 'db>
impl<'scope, 'db> Unpin for Scope<'scope, 'db>
impl<'scope, 'db> UnsafeUnpin for Scope<'scope, 'db>
impl<'scope, 'db> !UnwindSafe for Scope<'scope, 'db>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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