//! This module describes hir-level representation of expressions. //! //! This representation is: //! //! 1. Identity-based. Each expression has an `id`, so we can distinguish //! between different `1` in `1 + 1`. //! 2. Independent of syntax. Though syntactic provenance information can be //! attached separately via id-based side map. //! 3. Unresolved. Paths are stored as sequences of names, and not as defs the //! names refer to. //! 4. Desugared. There's no `if let`. //! //! See also a neighboring `body` module. pub mod format_args; pub mod generics; pub mod type_ref; use std::fmt; use hir_expand::{MacroDefId, name::Name}; use intern::Symbol; use la_arena::Idx; use rustc_apfloat::ieee::{Half as f16, Quad as f128}; use syntax::ast; use type_ref::TypeRefId; use crate::{ BlockId, builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}, expr_store::{ HygieneId, path::{GenericArgs, Path}, }, type_ref::{Mutability, Rawness}, }; pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp}; pub type BindingId = Idx; pub type ExprId = Idx; pub type PatId = Idx; // FIXME: Encode this as a single u32, we won't ever reach all 32 bits especially given these counts // are local to the body. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum ExprOrPatId { ExprId(ExprId), PatId(PatId), } impl ExprOrPatId { pub fn as_expr(self) -> Option { match self { Self::ExprId(v) => Some(v), _ => None, } } pub fn is_expr(&self) -> bool { matches!(self, Self::ExprId(_)) } pub fn as_pat(self) -> Option { match self { Self::PatId(v) => Some(v), _ => None, } } pub fn is_pat(&self) -> bool { matches!(self, Self::PatId(_)) } } stdx::impl_from!(ExprId, PatId for ExprOrPatId); #[derive(Debug, Clone, Eq, PartialEq)] pub struct Label { pub name: Name, } pub type LabelId = Idx