From 3060afd7526fa260416b9049308c4c4b09ad4b9a Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 19 Oct 2021 13:54:32 -0700 Subject: [PATCH] Fix warnings --- schala-lang/language/src/reduced_ast.rs | 2 +- schala-lang/language/src/symbol_table/mod.rs | 17 +++++++---------- .../language/src/symbol_table/resolver.rs | 10 ++++------ .../language/src/symbol_table/symbol_trie.rs | 5 ++--- schala-lang/language/src/symbol_table/tables.rs | 7 ------- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index a0f0859..00bf365 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -17,7 +17,7 @@ use std::str::FromStr; use std::convert::TryFrom; use crate::ast::*; -use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable, FullyQualifiedSymbolName}; +use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable}; use crate::builtin::Builtin; use crate::util::deref_optional_box; diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 9568d7b..31dac84 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use std::fmt; use std::fmt::Write; -use crate::tokenizing::{Location, LineNumber}; +use crate::tokenizing::Location; use crate::ast; use crate::ast::{ItemId, TypeBody, Variant, TypeSingletonName, Signature, Declaration, Statement, StatementKind, ModuleSpecifier}; use crate::typechecking::TypeName; @@ -32,12 +32,6 @@ impl FQSN { v.push(Scope::Name(new_name)); FQSN { scopes: v } } - - fn extend(&self, new_name: String) -> Self { - let mut existing = self.scopes.clone(); - existing.push(Scope::Name(new_name)); - FQSN { scopes: existing } - } } //TODO eventually this should use ItemId's to avoid String-cloning @@ -47,12 +41,14 @@ enum Scope { Name(String) } +#[allow(dead_code)] #[derive(Debug, Clone)] struct DuplicateName { prev_name: FQSN, location: Location } +#[allow(dead_code)] #[derive(Debug)] struct NameSpec { location: Location, @@ -256,7 +252,8 @@ impl SymbolTable { //TODO this should probably return a vector of duplicate name errors fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec) -> Result<(), DuplicateName> { for statement in statements { - let Statement { id, kind, location } = statement; + //TODO I'm not sure if I need to do anything with this ID + let Statement { id: _, kind, location } = statement; let location = *location; match kind { StatementKind::Declaration(Declaration::FuncSig(signature)) => { @@ -290,7 +287,7 @@ impl SymbolTable { StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => { let fq_type = FQSN::from_scope_stack(scope_stack.as_ref(), name.name.as_ref().to_owned()); self.types.register(fq_type, NameSpec { location, kind: TypeKind } )?; - if let Err(errors) = self.add_type_members(id, name, body, mutable, location, scope_stack) { + if let Err(errors) = self.add_type_members(name, body, mutable, location, scope_stack) { return Err(errors[0].clone()); } }, @@ -318,7 +315,7 @@ impl SymbolTable { Ok(()) } - fn add_type_members(&mut self, id: &ItemId, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Result<(), Vec> { + fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Result<(), Vec> { let mut errors = vec![]; let mut register = |fqsn: FQSN, spec: SymbolSpec| { diff --git a/schala-lang/language/src/symbol_table/resolver.rs b/schala-lang/language/src/symbol_table/resolver.rs index a4d0c47..bbdcc80 100644 --- a/schala-lang/language/src/symbol_table/resolver.rs +++ b/schala-lang/language/src/symbol_table/resolver.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use crate::symbol_table::{SymbolTable, ScopeSegment, FullyQualifiedSymbolName, FQSN, Scope}; +use crate::symbol_table::{SymbolTable, FQSN, Scope}; use crate::ast::*; use crate::util::ScopeStack; @@ -65,11 +65,9 @@ impl<'a> ASTVisitor for Resolver<'a> { }; let members = self.symbol_table.symbol_trie.get_children(&prefix); for member in members.into_iter() { - let local_name = match member.scopes.last().unwrap() { - Scope::Name(n) => Rc::new(n.clone()), - _ => panic!("LOL bad"), - }; - self.name_scope_stack.insert(local_name.clone(), member.scopes); + let Scope::Name(n) = member.scopes.last().unwrap(); + let local_name = Rc::new(n.clone()); + self.name_scope_stack.insert(local_name, member.scopes); } }, ImportedNames::LastOfPath => { diff --git a/schala-lang/language/src/symbol_table/symbol_trie.rs b/schala-lang/language/src/symbol_table/symbol_trie.rs index e387c02..68af1a0 100644 --- a/schala-lang/language/src/symbol_table/symbol_trie.rs +++ b/schala-lang/language/src/symbol_table/symbol_trie.rs @@ -11,9 +11,8 @@ impl TrieKey for FQSN { let mut hasher = DefaultHasher::new(); let mut output = vec![]; for segment in self.scopes.iter() { - if let Scope::Name(s) = segment { - s.as_bytes().hash(&mut hasher); - } + let Scope::Name(s) = segment; + s.as_bytes().hash(&mut hasher); output.extend_from_slice(&hasher.finish().to_be_bytes()); } output diff --git a/schala-lang/language/src/symbol_table/tables.rs b/schala-lang/language/src/symbol_table/tables.rs index fd25cdb..cfe0f60 100644 --- a/schala-lang/language/src/symbol_table/tables.rs +++ b/schala-lang/language/src/symbol_table/tables.rs @@ -18,11 +18,4 @@ impl DeclLocations { pub(crate) fn add_location(&mut self, id: &ItemId, loc: Location) { self.map.insert(id.clone(), loc); } - - pub(crate) fn lookup(&self, id: &ItemId) -> Option { - match self.map.get(id) { - Some(loc) => Some(loc.clone()), - None => None - } - } }