Skip to content

Commit 5acd1fa

Browse files
author
Nathan Ringo
committed
1 parent 44bd8b6 commit 5acd1fa

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/bin/cli/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
extern crate evaltrees;
2-
#[macro_use]
32
extern crate failure;
43
#[cfg(not(debug_assertions))]
54
#[macro_use]

src/typeck/reify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Decl<Ty> {
1111
arg.collect_vars(&mut vars);
1212
}
1313

14-
let mut env = vars.into_iter().collect::<Vec<_>>();
14+
let env = vars.into_iter().collect::<Vec<_>>();
1515
let mut ty = self.aux.reify_in(&env);
1616
for _ in &env {
1717
ty = Type::Forall(Box::new(ty));

src/typeck/subst.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,42 @@ impl Substitution {
4949
impl Ty {
5050
/// Applies a substitution to the type.
5151
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) => {
5454
l.apply_subst(subst);
5555
r.apply_subst(subst);
56+
None
5657
}
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;
6267
}
6368
}
6469

6570
/// Applies a single replacement to the type.
6671
pub fn sub(&mut self, var: SubstVar, ty: &Ty) {
67-
match self {
72+
let new_self = match self {
6873
Ty::Func(l, r) => {
6974
l.sub(var, ty);
7075
r.sub(var, ty);
76+
None
7177
}
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
7682
}
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;
7888
}
7989
}
8090
}

0 commit comments

Comments
 (0)