Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'Display::fmt' instead of 'Error::description', fix warnings #286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,21 @@ impl fmt::Display for LoadingError {
#[cfg(feature = "yaml-load")]
ParseSyntax(ref error, ref filename) => {
if let Some(ref file) = filename {
write!(f, "{}: {}", file, error.description())
write!(f, "{}: {}", file, error)
} else {
error.fmt(f)
}
},
_ => write!(f, "{}", self.description()),
#[cfg(feature = "metadata")]
ParseMetadata(_) => write!(f, "Failed to parse JSON"),
ParseTheme(_) => write!(f, "Invalid syntax theme"),
ReadSettings(_) => write!(f, "Invalid syntax theme settings"),
BadPath => write!(f, "Invalid path"),
}
}
}

impl Error for LoadingError {
fn description(&self) -> &str {
use crate::LoadingError::*;

match *self {
WalkDir(ref error) => error.description(),
Io(ref error) => error.description(),
#[cfg(feature = "yaml-load")]
ParseSyntax(ref error, ..) => error.description(),
#[cfg(feature = "metadata")]
ParseMetadata(_) => "Failed to parse JSON",
ParseTheme(_) => "Invalid syntax theme",
ReadSettings(_) => "Invalid syntax theme settings",
BadPath => "Invalid path",
}
}

fn cause(&self) -> Option<&dyn Error> {
use crate::LoadingError::*;

Expand Down
4 changes: 2 additions & 2 deletions src/parsing/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ impl Scope {
/// It is used internally for turning a scope back into a string.
pub fn atom_at(self, index: usize) -> u16 {
let shifted = if index < 4 {
(self.a >> ((3 - index) * 16))
self.a >> ((3 - index) * 16)
} else if index < 8 {
(self.b >> ((7 - index) * 16))
self.b >> ((7 - index) * 16)
} else {
panic!("atom index out of bounds {:?}", index);
};
Expand Down
23 changes: 7 additions & 16 deletions src/parsing/yaml_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,21 @@ impl fmt::Display for ParseSyntaxError {
use crate::ParseSyntaxError::*;

match *self {
InvalidYaml(_) => write!(f, "Invalid YAML file syntax"),
EmptyFile => write!(f, "Empty file"),
MissingMandatoryKey(_) => write!(f, "Missing mandatory key in YAML file"),
RegexCompileError(ref regex, ref error) =>
write!(f, "Error while compiling regex '{}': {}",
regex, error),
_ => write!(f, "{}", self.description())
InvalidScope(_) => write!(f, "Invalid scope"),
BadFileRef => write!(f, "Invalid file reference"),
MainMissing => write!(f, "Context 'main' is missing"),
TypeMismatch => write!(f, "Type mismatch"),
}
}
}

impl Error for ParseSyntaxError {
fn description(&self) -> &str {
use crate::ParseSyntaxError::*;

match self {
InvalidYaml(_) => "Invalid YAML file syntax",
EmptyFile => "Empty file",
MissingMandatoryKey(_) => "Missing mandatory key in YAML file",
RegexCompileError(_, error) => error.description(),
InvalidScope(_) => "Invalid scope",
BadFileRef => "Invalid file reference",
MainMissing => "Context 'main' is missing",
TypeMismatch => "Type mismatch",
}
}

fn cause(&self) -> Option<&dyn Error> {
use crate::ParseSyntaxError::*;

Expand Down