Skip to main content

luaur_analysis/methods/
constraint_solver_deprecate_d_emplace_constraint_solver.rs

1//! `template<typename T, typename... Args>
2//!  void ConstraintSolver::DEPRECATED_emplace(NotNull<const Constraint> constraint, TypeId ty, Args&&... args)`
3//! (`Analysis/src/ConstraintSolver.cpp:1003-1013`, hand-ported faithfully).
4//!
5//! In C++ the body is `emplaceType<T>(asMutable(ty), args...)` followed by an
6//! unblock. The variant-construction (`Args&&...`) is not expressible through a
7//! Rust generic; callers that need a concrete `T` construct the variant inline
8//! and assign it (see e.g. `bind`'s `TypeVariant::Free(...)` branch). This
9//! method preserves the C++ asserts and the unblock; the `emplaceType<T>`
10//! reinterpret is mirrored via the shared `emplace_type` helper.
11
12use crate::functions::as_mutable_type::as_mutable_type_id;
13use crate::functions::emplace_type::emplace_type;
14use crate::functions::get_type_alt_j::get_type_id;
15use crate::records::blocked_type::BlockedType;
16use crate::records::constraint::Constraint;
17use crate::records::constraint_solver::ConstraintSolver;
18use crate::records::free_type::FreeType;
19use crate::records::pending_expansion_type::PendingExpansionType;
20use crate::type_aliases::type_id::TypeId;
21use luaur_common::macros::luau_assert::LUAU_ASSERT;
22
23impl ConstraintSolver {
24    pub fn deprecate_d_emplace_not_null_constraint_type_id_args_item<T, Args>(
25        &mut self,
26        constraint: *const Constraint,
27        ty: TypeId,
28        _args: Args,
29    ) {
30        // static_assert(!std::is_same_v<T, BoundType>, "cannot use `emplace<BoundType>`! use `bind`");
31
32        LUAU_ASSERT!(unsafe {
33            !get_type_id::<BlockedType>(ty).is_null()
34                || !get_type_id::<FreeType>(ty).is_null()
35                || !get_type_id::<PendingExpansionType>(ty).is_null()
36        });
37
38        let mutable_ty = unsafe { as_mutable_type_id(ty) };
39        let _ = unsafe { emplace_type::<T>(mutable_ty) };
40
41        let location = unsafe { (*constraint).location };
42        self.unblock_type_id_location(ty, location);
43    }
44}