Skip to main content

nova_ast/
ty.rs

1//! Type expression AST nodes.
2
3use nova_diagnostics::Spanned;
4
5use crate::Path;
6
7/// A type expression.
8#[derive(Debug, Clone)]
9pub enum Type {
10    /// A named type, possibly with generic arguments: `Vec<Int>`, `String`.
11    Path {
12        path: Path,
13        args: Vec<Spanned<Type>>,
14    },
15    /// A shared reference `&T` or mutable reference `&mut T`.
16    Ref {
17        is_mut: bool,
18        inner: Box<Spanned<Type>>,
19    },
20    /// A raw pointer `*T` or `*mut T` (unsafe only).
21    Ptr {
22        is_mut: bool,
23        inner: Box<Spanned<Type>>,
24    },
25    /// An array / slice type `[T]`.
26    Array(Box<Spanned<Type>>),
27    /// A tuple type `(A, B, C)`. Empty tuple `()` is the unit type.
28    Tuple(Vec<Spanned<Type>>),
29    /// A function type `fn(A, B) -> C`.
30    Fn {
31        params: Vec<Spanned<Type>>,
32        ret: Box<Spanned<Type>>,
33    },
34    /// The optional sugar `T?` (equivalent to `Option<T>`).
35    Optional(Box<Spanned<Type>>),
36    /// A placeholder `_` that tells the compiler to infer the type.
37    Infer,
38}
39
40/// A generic type parameter, e.g. `T: Display + Clone`.
41#[derive(Debug, Clone)]
42pub struct TypeParam {
43    pub name: Spanned<String>,
44    pub bounds: Vec<Spanned<Path>>,
45}