From 1ca52346b7299778387499138bfcd2440a907d38 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 17 Nov 2020 11:47:22 +0000 Subject: [PATCH] style: fix clippy warnings --- --- 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, --- 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, --- 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, "{:= 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, "{: 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, --- a/crates/jrsonnet-evaluator/src/val.rs +++ b/crates/jrsonnet-evaluator/src/val.rs @@ -349,7 +349,7 @@ for v in arr.iter() { out.push_str("---\n"); out.push_str(&v.manifest(format)?); - out.push_str("\n"); + out.push('\n'); } out.push_str("..."); } -- gitstuff