difftreelog
style fix clippy warnings
in: master
4 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -81,7 +81,7 @@
#[error(
"syntax error, expected one of {}, got {:?}",
.error.expected,
- .source_code.chars().nth(error.location.offset).map(|c| c.to_string()).unwrap_or("EOF".into())
+ .source_code.chars().nth(error.location.offset).map(|c| c.to_string()).unwrap_or_else(|| "EOF".into())
)]
ImportSyntaxError {
path: Rc<PathBuf>,
crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -419,18 +419,12 @@
use Expr::*;
let LocExpr(expr, loc) = expr;
Ok(match &**expr {
- Literal(LiteralType::This) => Val::Obj(
- context
- .this()
- .clone()
- .ok_or_else(|| CantUseSelfOutsideOfObject)?,
- ),
- Literal(LiteralType::Dollar) => Val::Obj(
- context
- .dollar()
- .clone()
- .ok_or_else(|| NoTopLevelObjectFound)?,
- ),
+ Literal(LiteralType::This) => {
+ Val::Obj(context.this().clone().ok_or(CantUseSelfOutsideOfObject)?)
+ }
+ Literal(LiteralType::Dollar) => {
+ Val::Obj(context.dollar().clone().ok_or(NoTopLevelObjectFound)?)
+ }
Literal(LiteralType::True) => Val::Bool(true),
Literal(LiteralType::False) => Val::Bool(false),
Literal(LiteralType::Null) => Val::Null,
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -87,33 +87,32 @@
error: &LocError,
) -> Result<(), std::fmt::Error> {
writeln!(out, "{}", error.error())?;
- match error.error() {
- Error::ImportSyntaxError {
- path,
- source_code,
- error,
- } => {
- use std::fmt::Write;
- let mut n = self.resolver.resolve(&path);
- let mut offset = error.location.offset;
- let mut is_eof = false;
- if offset >= source_code.len() {
- offset = source_code.len() - 1;
- is_eof = true;
- }
- let mut location = offset_to_location(&source_code, &[offset])
- .into_iter()
- .next()
- .unwrap();
- if is_eof {
- location.column += 1;
- }
-
- write!(n, ":").unwrap();
- print_code_location(&mut n, &location, &location).unwrap();
- write!(out, "{:<p$}{}", "", n, p = self.padding,)?;
+ if let Error::ImportSyntaxError {
+ path,
+ source_code,
+ error,
+ } = error.error()
+ {
+ use std::fmt::Write;
+ let mut n = self.resolver.resolve(path);
+ let mut offset = error.location.offset;
+ let is_eof = if offset >= source_code.len() {
+ offset = source_code.len() - 1;
+ true
+ } else {
+ false
+ };
+ let mut location = offset_to_location(source_code, &[offset])
+ .into_iter()
+ .next()
+ .unwrap();
+ if is_eof {
+ location.column += 1;
}
- _ => {}
+
+ write!(n, ":").unwrap();
+ print_code_location(&mut n, &location, &location).unwrap();
+ write!(out, "{:<p$}{}", "", n, p = self.padding,)?;
}
let file_names = error
.trace()
@@ -196,34 +195,32 @@
error: &LocError,
) -> Result<(), std::fmt::Error> {
writeln!(out, "{}", error.error())?;
- match error.error() {
- Error::ImportSyntaxError {
- path,
+ if let Error::ImportSyntaxError {
+ path,
+ source_code,
+ error,
+ } = error.error()
+ {
+ let mut offset = error.location.offset;
+ if offset >= source_code.len() {
+ offset = source_code.len() - 1;
+ }
+ let mut location = offset_to_location(source_code, &[offset])
+ .into_iter()
+ .next()
+ .unwrap();
+ if location.column >= 1 {
+ location.column -= 1;
+ }
+
+ self.print_snippet(
+ out,
source_code,
- error,
- } => {
- let mut offset = error.location.offset;
- if offset >= source_code.len() {
- offset = source_code.len() - 1;
- }
- let mut location = offset_to_location(&source_code, &[offset])
- .into_iter()
- .next()
- .unwrap();
- if location.column >= 1 {
- location.column -= 1;
- }
-
- self.print_snippet(
- out,
- &source_code,
- &path,
- &location,
- &location,
- "^ syntax error",
- )?;
- }
- _ => {}
+ path,
+ &location,
+ &location,
+ "^ syntax error",
+ )?;
}
let trace = &error.trace();
for item in trace.0.iter() {
@@ -265,7 +262,7 @@
.take(end.line_end_offset - end.line_start_offset)
.collect();
- let origin = self.resolver.resolve(&origin);
+ let origin = self.resolver.resolve(origin);
let snippet = Snippet {
opt: FormatOptions {
color: true,
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth349 for v in arr.iter() {349 for v in arr.iter() {350 out.push_str("---\n");350 out.push_str("---\n");351 out.push_str(&v.manifest(format)?);351 out.push_str(&v.manifest(format)?);352 out.push_str("\n");352 out.push('\n');353 }353 }354 out.push_str("...");354 out.push_str("...");355 }355 }