Skip to main content

Definitions

Struct Definitions 

Source
pub struct Definitions { /* private fields */ }
Expand description

The item-level namespaces of a whole program (one or more modules).

defs and DefIds are global; name lookups are module-relative — a name is resolved in the scope of the module that owns the item currently being checked (see Definitions::module_of).

Implementations§

Source§

impl Definitions

Source

pub fn defs(&self) -> &[Def]

All collected definitions, indexable by DefId.0.

Source

pub fn def(&self, id: DefId) -> &Def

Look up a definition by id.

Source

pub fn module_of(&self, item_index: usize) -> ModuleId

The module that owns the item at item_index in the merged file.

Source

pub fn module_count(&self) -> usize

Number of modules in the program.

Source

pub fn module_name(&self, module: ModuleId) -> &str

The name of a module.

Source

pub fn resolve_value(&self, module: ModuleId, name: &str) -> Option<Res>

Resolve a name in value position, relative to module.

Source

pub fn resolve_type(&self, module: ModuleId, name: &str) -> Option<DefId>

Resolve a name in type position, relative to module.

Source

pub fn resolve_trait(&self, module: ModuleId, name: &str) -> Option<DefId>

Resolve a name in trait position, relative to module.

Source

pub fn methods( &self, ) -> impl Iterator<Item = (DefId, usize, usize, MethodOwner)> + '_

Iterate all method definitions as (DefId, item_index, method_index, owner).

Source

pub fn functions(&self) -> impl Iterator<Item = (DefId, usize)> + '_

Iterate all function definitions as (DefId, item_index).

Source

pub fn extern_functions( &self, ) -> impl Iterator<Item = (DefId, usize, usize)> + '_

Iterate all extern function declarations as (DefId, item_index, fn_index) (fn_index into the extern block’s items).

Source§

impl Definitions

Source

pub fn names_in_scope(&self, module: ModuleId) -> Vec<(String, ScopeEntry)>

Every name module can see, in all three namespaces:

  • its own items;
  • its imports;
  • the builtins;
  • std’s glob-imported names.

A module binds each name once per namespace, so a std name the module shadows appears once, as the module’s own. The result is sorted by name, then values, types and traits, for a stable order.

Source§

impl Definitions

Source

pub fn importable(&self, module: ModuleId) -> &[(String, ModuleId)]

The modules module could import, by the name an import writes (spec 3.4b §4.6).

Source

pub fn exported(&self, module: ModuleId, name: &str) -> Exported

What module exports under name.

Source

pub fn same_package(&self, a: ModuleId, b: ModuleId) -> bool

Whether a and b are modules of one package. A loose program’s modules are.

Source

pub fn bound_outside_std(&self, module: ModuleId, name: &str) -> Exported

What module binds name to, in each namespace, other than through std’s glob (plan decision 8): a binding equal to some std module’s export of that name came through it. Builtins are bound outside std.

Source

pub fn is_std_module(&self, module: ModuleId) -> bool

Whether module is one of the implicit std modules.

Source

pub fn owned(&self, module: ModuleId) -> bool

Whether a fix may edit module (spec 3.4b §3.1; plan decision 19): it is the root package’s, whose key is 0, or a loose program’s, and not std’s.

Trait Implementations§

Source§

impl Debug for Definitions

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Definitions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.