Remove unnecessary HasLocation implementations

This commit is contained in:
Tad Hardesty 2019-12-07 23:24:30 -08:00
parent fb9d3fc04f
commit bd76179ad2
4 changed files with 10 additions and 39 deletions

View file

@ -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

View file

@ -494,6 +494,10 @@ impl<I> LocationTracker<I> {
at_line_end: true,
}
}
pub fn location(&self) -> Location {
self.location
}
}
impl<I> fmt::Debug for LocationTracker<I> {
@ -506,12 +510,6 @@ impl<I> fmt::Debug for LocationTracker<I> {
}
}
impl<I> HasLocation for LocationTracker<I> {
fn location(&self) -> Location {
self.location
}
}
impl<I: Iterator<Item=io::Result<u8>>> Iterator for LocationTracker<I> {
type Item = Result<u8, DMError>;

View file

@ -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<Include<'ctx>>,
@ -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()
}
}
}

View file

@ -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};