File tree 3 files changed +24
-15
lines changed
3 files changed +24
-15
lines changed Original file line number Diff line number Diff line change 1
1
extern crate evaltrees;
2
- #[ macro_use]
3
2
extern crate failure;
4
3
#[ cfg( not( debug_assertions) ) ]
5
4
#[ macro_use]
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ impl Decl<Ty> {
11
11
arg. collect_vars ( & mut vars) ;
12
12
}
13
13
14
- let mut env = vars. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
14
+ let env = vars. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
15
15
let mut ty = self . aux . reify_in ( & env) ;
16
16
for _ in & env {
17
17
ty = Type :: Forall ( Box :: new ( ty) ) ;
Original file line number Diff line number Diff line change @@ -49,32 +49,42 @@ impl Substitution {
49
49
impl Ty {
50
50
/// Applies a substitution to the type.
51
51
pub fn apply_subst ( & mut self , subst : & Substitution ) {
52
- match self {
53
- Ty :: Func ( l , r) => {
52
+ let new_self = match * self {
53
+ Ty :: Func ( ref mut l , ref mut r) => {
54
54
l. apply_subst ( subst) ;
55
55
r. apply_subst ( subst) ;
56
+ None
56
57
}
57
- Ty :: Int => { }
58
- Ty :: List ( t) => t. apply_subst ( subst) ,
59
- Ty :: Var ( v) => if let Some ( ty) = subst. get ( * v) {
60
- * self = ty;
61
- } ,
58
+ Ty :: Int => None ,
59
+ Ty :: List ( ref mut t) => {
60
+ t. apply_subst ( subst) ;
61
+ None
62
+ }
63
+ Ty :: Var ( v) => subst. get ( v) ,
64
+ } ;
65
+ if let Some ( new_self) = new_self {
66
+ * self = new_self;
62
67
}
63
68
}
64
69
65
70
/// Applies a single replacement to the type.
66
71
pub fn sub ( & mut self , var : SubstVar , ty : & Ty ) {
67
- match self {
72
+ let new_self = match self {
68
73
Ty :: Func ( l, r) => {
69
74
l. sub ( var, ty) ;
70
75
r. sub ( var, ty) ;
76
+ None
71
77
}
72
- Ty :: Int => { }
73
- Ty :: List ( t) => t . sub ( var , ty ) ,
74
- Ty :: Var ( v ) if * v == var => {
75
- * self = ty . clone ( ) ;
78
+ Ty :: Int => None ,
79
+ Ty :: List ( t) => {
80
+ t . sub ( var, ty ) ;
81
+ None
76
82
}
77
- Ty :: Var ( _) => { }
83
+ Ty :: Var ( v) if * v == var => Some ( ty. clone ( ) ) ,
84
+ Ty :: Var ( _) => None ,
85
+ } ;
86
+ if let Some ( new_self) = new_self {
87
+ * self = new_self;
78
88
}
79
89
}
80
90
}
You can’t perform that action at this time.
0 commit comments