1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use sway_types::{Ident, Span};
use crate::{language::ty::*, type_system::*};
#[derive(Clone, Debug)]
pub struct TyVariableDeclaration {
pub name: Ident,
pub body: TyExpression,
pub mutability: VariableMutability,
pub return_type: TypeId,
pub type_ascription: TypeId,
pub type_ascription_span: Option<Span>,
}
impl EqWithTypeEngine for TyVariableDeclaration {}
impl PartialEqWithTypeEngine for TyVariableDeclaration {
fn eq(&self, other: &Self, type_engine: &TypeEngine) -> bool {
self.name == other.name
&& self.body.eq(&other.body, type_engine)
&& self.mutability == other.mutability
&& type_engine
.look_up_type_id(self.return_type)
.eq(&type_engine.look_up_type_id(other.return_type), type_engine)
&& type_engine.look_up_type_id(self.type_ascription).eq(
&type_engine.look_up_type_id(other.type_ascription),
type_engine,
)
}
}
impl CopyTypes for TyVariableDeclaration {
fn copy_types_inner(&mut self, type_mapping: &TypeMapping, type_engine: &TypeEngine) {
self.return_type.copy_types(type_mapping, type_engine);
self.type_ascription.copy_types(type_mapping, type_engine);
self.body.copy_types(type_mapping, type_engine)
}
}
impl ReplaceSelfType for TyVariableDeclaration {
fn replace_self_type(&mut self, type_engine: &TypeEngine, self_type: TypeId) {
self.return_type.replace_self_type(type_engine, self_type);
self.type_ascription
.replace_self_type(type_engine, self_type);
self.body.replace_self_type(type_engine, self_type)
}
}