git.delta.rocks / jrsonnet / refs/commits / 1ca52346b729

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2020-11-17parent: #db14944.patch.diff
in: master

4 files changed

modifiedcrates/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>,
modifiedcrates/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,
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
87 error: &LocError,87 error: &LocError,
88 ) -> Result<(), std::fmt::Error> {88 ) -> Result<(), std::fmt::Error> {
89 writeln!(out, "{}", error.error())?;89 writeln!(out, "{}", error.error())?;
90 match error.error() {
91 Error::ImportSyntaxError {90 if let Error::ImportSyntaxError {
92 path,91 path,
93 source_code,92 source_code,
94 error,93 error,
95 } => {94 } = error.error()
95 {
96 use std::fmt::Write;96 use std::fmt::Write;
97 let mut n = self.resolver.resolve(&path);97 let mut n = self.resolver.resolve(path);
98 let mut offset = error.location.offset;98 let mut offset = error.location.offset;
99 let mut is_eof = false;99 let is_eof = if offset >= source_code.len() {
100 if offset >= source_code.len() {
101 offset = source_code.len() - 1;100 offset = source_code.len() - 1;
102 is_eof = true;101 true
103 }102 } else {
103 false
104 };
104 let mut location = offset_to_location(&source_code, &[offset])105 let mut location = offset_to_location(source_code, &[offset])
105 .into_iter()106 .into_iter()
106 .next()107 .next()
107 .unwrap();108 .unwrap();
113 print_code_location(&mut n, &location, &location).unwrap();114 print_code_location(&mut n, &location, &location).unwrap();
114 write!(out, "{:<p$}{}", "", n, p = self.padding,)?;115 write!(out, "{:<p$}{}", "", n, p = self.padding,)?;
115 }116 }
116 _ => {}
117 }
118 let file_names = error117 let file_names = error
119 .trace()118 .trace()
120 .0119 .0
196 error: &LocError,195 error: &LocError,
197 ) -> Result<(), std::fmt::Error> {196 ) -> Result<(), std::fmt::Error> {
198 writeln!(out, "{}", error.error())?;197 writeln!(out, "{}", error.error())?;
199 match error.error() {
200 Error::ImportSyntaxError {198 if let Error::ImportSyntaxError {
201 path,199 path,
202 source_code,200 source_code,
203 error,201 error,
204 } => {202 } = error.error()
203 {
205 let mut offset = error.location.offset;204 let mut offset = error.location.offset;
206 if offset >= source_code.len() {205 if offset >= source_code.len() {
207 offset = source_code.len() - 1;206 offset = source_code.len() - 1;
208 }207 }
209 let mut location = offset_to_location(&source_code, &[offset])208 let mut location = offset_to_location(source_code, &[offset])
210 .into_iter()209 .into_iter()
211 .next()210 .next()
212 .unwrap();211 .unwrap();
216215
217 self.print_snippet(216 self.print_snippet(
218 out,217 out,
219 &source_code,218 source_code,
220 &path,219 path,
221 &location,220 &location,
222 &location,221 &location,
223 "^ syntax error",222 "^ syntax error",
224 )?;223 )?;
225 }224 }
226 _ => {}
227 }
228 let trace = &error.trace();225 let trace = &error.trace();
229 for item in trace.0.iter() {226 for item in trace.0.iter() {
230 let desc = &item.desc;227 let desc = &item.desc;
265 .take(end.line_end_offset - end.line_start_offset)262 .take(end.line_end_offset - end.line_start_offset)
266 .collect();263 .collect();
267264
268 let origin = self.resolver.resolve(&origin);265 let origin = self.resolver.resolve(origin);
269 let snippet = Snippet {266 let snippet = Snippet {
270 opt: FormatOptions {267 opt: FormatOptions {
271 color: true,268 color: true,
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- 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("...");
 				}