#[non_exhaustive]pub enum DefKind {
}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
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;).
Sum
A sum.
Class
A class; mixin for a PHP trait.
Interface
An interface.
Alias
A type alias.
AssocType
An associated type.
Variant
A sum variant; unit for a variant with no fields.
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
impl DefKind
Sourcepub const fn of_item(kind: &ItemKind) -> Option<Self>
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 }));Sourcepub const fn fits(self, ns: Ns) -> bool
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));Sourcepub const fn is_prefix(self) -> bool
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());Sourcepub const fn is_pattern_constant(self) -> bool
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());