Skip to main content

DefKind

Enum DefKind 

Source
#[non_exhaustive]
pub enum DefKind {
Show 15 variants Module, Fn, Const, Global, Record { unit: bool, }, Sum, Class { mixin: bool, }, Interface, Alias, AssocType, Variant { unit: bool, }, Extern, Prim, Local, Err,
}
Expand description

What kind of definition a resolution names, as far as scoping cares.

It decides which syntactic namespaces may name the definition (the table of HIR spec §3.3), whether a path may continue through it (Vec::new), and whether a bare identifier pattern matches it rather than binding.

§Examples

use hir_lang::Ns;
use resolve_lang::DefKind;

assert!(DefKind::Fn.fits(Ns::Value));
assert!(!DefKind::Fn.fits(Ns::Type));
assert!(DefKind::Record { unit: false }.is_prefix());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Module

A module (or a whole unit’s root module).

§

Fn

A function.

§

Const

A constant.

§

Global

A global variable.

§

Record

A record; unit for a record with no fields (struct Unit;).

Fields

§unit: bool

The record has the unit shape.

§

Sum

A sum.

§

Class

A class; mixin for a PHP trait.

Fields

§mixin: bool

The class is a mixin (never instantiated).

§

Interface

An interface.

§

Alias

A type alias.

§

AssocType

An associated type.

§

Variant

A sum variant; unit for a variant with no fields.

Fields

§unit: bool

The variant has the unit shape.

§

Extern

A host or standard-library symbol.

§

Prim

A primitive type.

§

Local

A local binder (a variable, parameter, or generic parameter). Paths name binders through Res::Local; this kind appears in diagnostics.

§

Err

An error item (already reported).

Implementations§

Source§

impl DefKind

Source

pub const fn of_item(kind: &ItemKind) -> Option<Self>

The kind of a HIR item, or None for items that name nothing resolvable (impl, imports, mixin uses).

§Examples
use hir_lang::{ItemKind, RecordDef, Shape};
use resolve_lang::DefKind;

let unit = ItemKind::Record(RecordDef { shape: Shape::Unit, ..RecordDef::default() });
assert_eq!(DefKind::of_item(&unit), Some(DefKind::Record { unit: true }));
Source

pub const fn fits(self, ns: Ns) -> bool

Whether a fully resolved path in syntactic namespace ns may name a definition of this kind (HIR spec §3.3).

§Examples
use hir_lang::Ns;
use resolve_lang::DefKind;

assert!(DefKind::Variant { unit: true }.fits(Ns::Pattern));
assert!(DefKind::Module.fits(Ns::Import));
assert!(!DefKind::Module.fits(Ns::Value));
assert!(DefKind::Prim.fits(Ns::Type));
Source

pub const fn is_prefix(self) -> bool

Whether a path may continue past a definition of this kind, leaving the rest to type-directed or module resolution (a resolved prefix).

§Examples
use resolve_lang::DefKind;

assert!(DefKind::Sum.is_prefix());
assert!(!DefKind::Fn.is_prefix());
assert!(!DefKind::Variant { unit: false }.is_prefix());
Source

pub const fn is_pattern_constant(self) -> bool

Whether a bare identifier pattern naming this definition matches it (a constant, a unit variant, a unit record) instead of binding.

§Examples
use resolve_lang::DefKind;

assert!(DefKind::Const.is_pattern_constant());
assert!(!DefKind::Variant { unit: false }.is_pattern_constant());
Source

pub const fn name(self) -> &'static str

A short lowercase name, for messages.

§Examples
use resolve_lang::DefKind;

assert_eq!(DefKind::Fn.name(), "function");

Trait Implementations§

Source§

impl Clone for DefKind

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 Copy for DefKind

Source§

impl Debug for DefKind

Source§

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

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

impl Eq for DefKind

Source§

impl Hash for DefKind

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DefKind

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DefKind

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.