From 6a476d19dc87f7736c6678c38b2dacf91f76b88a Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 31 Jan 2019 16:42:49 -0600 Subject: [PATCH] REFACTOR: Improve the typesafety of lookup_sym. It's easier to ensure you don't forget a case if you have to enumerate them all. So don't use the catch all in this match. --- src/build/scope.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/build/scope.rs b/src/build/scope.rs index 2b4f8e6..fcefd92 100644 --- a/src/build/scope.rs +++ b/src/build/scope.rs @@ -134,20 +134,20 @@ impl Scope { } if self.search_curr_val && self.curr_val.is_some() { match self.curr_val.as_ref().unwrap().as_ref() { - &Val::Env(ref fs) => { + Val::Env(ref fs) => { for (name, val) in fs.iter() { if name == &sym.val { return Some(Rc::new(Val::Str(val.clone()))); } } } - &Val::Tuple(ref fs) => match Self::lookup_in_tuple(&sym.pos, &sym.val, fs) { + Val::Tuple(ref fs) => match Self::lookup_in_tuple(&sym.pos, &sym.val, fs) { Ok(v) => return Some(v), Err(_) => { // noop } }, - &Val::List(ref fs) => { + Val::List(ref fs) => { match Self::lookup_in_list(&sym.pos, &Val::Str(sym.val.clone()), fs) { Ok(v) => return Some(v), Err(_) => { @@ -155,7 +155,13 @@ impl Scope { } } } - _ => { + Val::Boolean(_) + | Val::Empty + | Val::Float(_) + | Val::Int(_) + | Val::Module(_) + | Val::Str(_) + | Val::Func(_) => { // noop } };