Skip to main content

luaur_analysis/records/
unifiable.rs

1/// Port of `Luau::Unifiable::Error<Id>` from `Analysis/include/Luau/Unifiable.h`.
2/// An error type with an optional "synthetic" stand-in TypeId for presentation.
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4pub struct Error<Id> {
5    pub index: i32,
6    /// Optional synthetic TypeId used to communicate the error to the user.
7    pub synthetic: Option<Id>,
8}
9
10impl<Id: Copy> Error<Id> {
11    pub fn new() -> Self {
12        static NEXT_INDEX: core::sync::atomic::AtomicI32 = core::sync::atomic::AtomicI32::new(0);
13        Self {
14            index: NEXT_INDEX.fetch_add(1, core::sync::atomic::Ordering::Relaxed),
15            synthetic: None,
16        }
17    }
18
19    pub fn with_synthetic(synthetic: Id) -> Self {
20        static NEXT_INDEX: core::sync::atomic::AtomicI32 = core::sync::atomic::AtomicI32::new(0);
21        Self {
22            index: NEXT_INDEX.fetch_add(1, core::sync::atomic::Ordering::Relaxed),
23            synthetic: Some(synthetic),
24        }
25    }
26}