Skip to main content

ResolvedUnit

Struct ResolvedUnit 

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

One resolved unit.

§Examples

use hir_lang::Builder;
use intern_lang::Interner;

let mut b = Builder::new();
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
assert_eq!(res.units().len(), 1);
assert!(res.units()[0].hir().validate().is_ok());

Implementations§

Source§

impl ResolvedUnit

Source

pub fn id(&self) -> UnitId

The unit’s id.

§Examples
use hir_lang::{Builder, UnitId};
use intern_lang::Interner;

let mut b = Builder::for_unit(UnitId::new(4));
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
assert_eq!(res.units()[0].id(), UnitId::new(4));
Source

pub fn name(&self) -> Option<Name>

The root name other units reached this unit by, if it had one.

§Examples
use hir_lang::Builder;
use intern_lang::Interner;

let mut b = Builder::new();
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
assert!(res.units()[0].name().is_none());
Source

pub fn hir(&self) -> &Hir

The resolved HIR: every resolvable path’s slot is filled through hir-lang’s checked setters, so it is still a valid Hir.

§Examples
use hir_lang::Builder;
use intern_lang::Interner;

let mut b = Builder::new();
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
assert_eq!(res.units()[0].hir().root(), root);
Source

pub fn into_hir(self) -> Hir

Takes the resolved HIR.

§Examples
use hir_lang::Builder;
use intern_lang::Interner;

let mut b = Builder::new();
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
let (units, _, _) = res.into_parts();
let hir = units.into_iter().next().unwrap().into_hir();
assert!(hir.validate().is_ok());
Source

pub fn members(&self, class: ItemId) -> Option<&[ClassMember]>

The effective members of a class or interface item (its own members plus what its mixins contribute), sorted by namespace, then by name (symbol order, not spelling). None for other items.

§Examples
use hir_lang::{Builder, ClassDef, Item, ItemKind, Name};
use intern_lang::Interner;

let mut names = Interner::new();
let mut b = Builder::new();
let body = b.block(&[], None);
let m = b.func(Name::new(names.intern("m")), &[], body);
let items = b.list(&[m]);
let class = b.item(Item::new(Some(Name::new(names.intern("C"))), ItemKind::Class(ClassDef { items, ..ClassDef::default() })));
let root = b.module(None, &[class]);
let res = resolve_lang::resolve(b.finish(root)?, &names)?;
assert_eq!(res.units()[0].members(class).map(<[_]>::len), Some(1));
Source

pub fn ident_binds(&self, pat: PatId) -> Option<bool>

For a Pat::Ident pattern: Some(true) if it binds its binder, Some(false) if its path named a constant, unit variant, or unit record (it matches that value). None for other patterns.

§Examples
use hir_lang::{Builder, PatId};
use intern_lang::Interner;

let mut b = Builder::new();
let root = b.module(None, &[]);
let res = resolve_lang::resolve(b.finish(root)?, &Interner::new())?;
assert_eq!(res.units()[0].ident_binds(PatId::from_index(0).unwrap()), None);

Trait Implementations§

Source§

impl Clone for ResolvedUnit

Source§

fn clone(&self) -> Self

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 Debug for ResolvedUnit

Source§

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

Formats the value using the given formatter. 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> 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.

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> 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 = !

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.