From bd76179ad243f8467dd3f4ef85dd82a2c745e3f8 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Sat, 7 Dec 2019 23:24:30 -0800 Subject: [PATCH] Remove unnecessary HasLocation implementations --- src/dreammaker/error.rs | 12 ------------ src/dreammaker/lexer.rs | 10 ++++------ src/dreammaker/preprocessor.rs | 25 +++++-------------------- src/tools/dmm/read.rs | 2 +- 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/dreammaker/error.rs b/src/dreammaker/error.rs index 3f5038ff..37a433ae 100644 --- a/src/dreammaker/error.rs +++ b/src/dreammaker/error.rs @@ -249,18 +249,6 @@ pub trait HasLocation { } } -impl<'a, T: HasLocation> HasLocation for &'a T { - fn location(&self) -> Location { - (**self).location() - } -} - -impl<'a, T: HasLocation> HasLocation for &'a mut T { - fn location(&self) -> Location { - (**self).location() - } -} - // ---------------------------------------------------------------------------- // Error handling diff --git a/src/dreammaker/lexer.rs b/src/dreammaker/lexer.rs index 6feea081..1cd9d760 100644 --- a/src/dreammaker/lexer.rs +++ b/src/dreammaker/lexer.rs @@ -494,6 +494,10 @@ impl LocationTracker { at_line_end: true, } } + + pub fn location(&self) -> Location { + self.location + } } impl fmt::Debug for LocationTracker { @@ -506,12 +510,6 @@ impl fmt::Debug for LocationTracker { } } -impl HasLocation for LocationTracker { - fn location(&self) -> Location { - self.location - } -} - impl>> Iterator for LocationTracker { type Item = Result; diff --git a/src/dreammaker/preprocessor.rs b/src/dreammaker/preprocessor.rs index e50b0916..8f12c1cf 100644 --- a/src/dreammaker/preprocessor.rs +++ b/src/dreammaker/preprocessor.rs @@ -181,15 +181,6 @@ impl<'ctx> Include<'ctx> { } } -impl<'ctx> HasLocation for Include<'ctx> { - fn location(&self) -> Location { - match self { - &Include::File { ref lexer, .. } => lexer.location(), - &Include::Expansion { location, .. } => location, - } - } -} - #[derive(Debug, Default)] struct IncludeStack<'ctx> { stack: Vec>, @@ -213,16 +204,6 @@ impl<'ctx> IncludeStack<'ctx> { } } -impl<'ctx> HasLocation for IncludeStack<'ctx> { - fn location(&self) -> Location { - if let Some(include) = self.stack.last() { - include.location() - } else { - Location::default() - } - } -} - impl<'ctx> Iterator for IncludeStack<'ctx> { type Item = LocatedToken; @@ -313,7 +294,11 @@ pub struct Preprocessor<'ctx> { impl<'ctx> HasLocation for Preprocessor<'ctx> { fn location(&self) -> Location { - self.include_stack.location() + match self.include_stack.stack.last() { + Some(&Include::File { ref lexer, .. }) => lexer.location(), + Some(&Include::Expansion { location, .. }) => location, + None => Location::default() + } } } diff --git a/src/tools/dmm/read.rs b/src/tools/dmm/read.rs index ea7dc28e..6021ebf2 100644 --- a/src/tools/dmm/read.rs +++ b/src/tools/dmm/read.rs @@ -6,7 +6,7 @@ use std::cmp::max; use ndarray::Array3; -use dm::{DMError, Location, HasLocation}; +use dm::{DMError, Location}; use dm::lexer::{LocationTracker, from_utf8_or_latin1}; use super::{Map, Key, KeyType, Prefab};