git.delta.rocks / jrsonnet / refs/commits / 45caf79f1ab3

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2021-01-25parent: #0d591aa.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,8 +1,8 @@
 use crate::{
 	equals,
 	error::{Error::*, Result},
-	parse_args, primitive_equals, push, throw,
-	with_state, ArrValue, Context, FuncVal, LazyVal, Val,
+	parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, FuncVal, LazyVal,
+	Val,
 };
 use format::{format_arr, format_obj};
 use jrsonnet_interner::IStr;
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -139,7 +139,7 @@
 	e: Option<&ExprLocation>,
 	frame_desc: impl FnOnce() -> String,
 	f: impl FnOnce() -> Result<T>,
- ) -> Result<T> {
+) -> Result<T> {
 	push(e, frame_desc, f)
 }
 
@@ -340,11 +340,17 @@
 	pub fn with_tla(&self, val: Val) -> Result<Val> {
 		self.run_in_state(|| {
 			Ok(match val {
-				Val::Func(func) => push(None, || "during TLA call".to_owned(), || Ok(func.evaluate_map(
-					self.create_default_context()?,
-					&self.settings().tla_vars,
-					true,
-				)?))?,
+				Val::Func(func) => push(
+					None,
+					|| "during TLA call".to_owned(),
+					|| {
+						Ok(func.evaluate_map(
+							self.create_default_context()?,
+							&self.settings().tla_vars,
+							true,
+						)?)
+					},
+				)?,
 				v => v,
 			})
 		})
modifiedcrates/jrsonnet-evaluator/src/trace/location.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/trace/location.rs
1#[derive(Clone, PartialEq, Debug)]2pub struct CodeLocation {3	pub offset: usize,45	pub line: usize,6	pub column: usize,78	pub line_start_offset: usize,9	pub line_end_offset: usize,10}1112pub fn offset_to_location(file: &str, offsets: &[usize]) -> Vec<CodeLocation> {13	if offsets.is_empty() {14		return vec![];15	}16	let mut line = 1;17	let mut column = 1;18	let max_offset = *offsets.iter().max().unwrap();1920	let mut offset_map = offsets21		.iter()22		.enumerate()23		.map(|(pos, offset)| (*offset, pos))24		.collect::<Vec<_>>();25	offset_map.sort_by_key(|v| v.0);26	offset_map.reverse();2728	let mut out = vec![29		CodeLocation {30			offset: 0,31			column: 0,32			line: 0,33			line_start_offset: 0,34			line_end_offset: 035		};36		offsets.len()37	];38	let mut with_no_known_line_ending = vec![];39	let mut this_line_offset = 0;40	for (pos, ch) in file.chars().enumerate().chain(std::iter::once((file.len(), ' '))) {41		column += 1;42		match offset_map.last() {43			Some(x) if x.0 == pos => {44				let out_idx = x.1;45				with_no_known_line_ending.push(out_idx);46				out[out_idx].offset = pos;47				out[out_idx].line = line;48				out[out_idx].column = column;49				out[out_idx].line_start_offset = this_line_offset;50				offset_map.pop();51			}52			_ => {}53		}54		if ch == '\n' {55			line += 1;56			column = 1;5758			for idx in with_no_known_line_ending.drain(..) {59				out[idx].line_end_offset = pos;60			}61			this_line_offset = pos + 1;6263			if pos == max_offset + 1 {64				break;65			}66		}67	}68	let file_end = file.chars().count();69	for idx in with_no_known_line_ending {70		out[idx].line_end_offset = file_end;71	}7273	out74}7576#[cfg(test)]77pub mod tests {78	use super::{offset_to_location, CodeLocation};7980	#[test]81	fn test() {82		assert_eq!(83			offset_to_location(84				"hello world\n_______________________________________________________",85				&[0, 14]86			),87			vec![88				CodeLocation {89					offset: 0,90					line: 1,91					column: 2,92					line_start_offset: 0,93					line_end_offset: 11,94				},95				CodeLocation {96					offset: 14,97					line: 2,98					column: 4,99					line_start_offset: 12,100					line_end_offset: 67101				}102			]103		)104	}105}
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -118,18 +118,24 @@
 			.trace()
 			.0
 			.iter()
-			.map(|el| el.location.as_ref().map(|l| {
-				use std::fmt::Write;
-				let mut resolved_path = self.resolver.resolve(&l.0);
-				// TODO: Process all trace elements first
-				let location = evaluation_state
-					.map_source_locations(&l.0, &[l.1, l.2]);
-				write!(resolved_path, ":").unwrap();
-				print_code_location(&mut resolved_path, &location[0], &location[1]).unwrap();
-				resolved_path
-			}))
+			.map(|el| {
+				el.location.as_ref().map(|l| {
+					use std::fmt::Write;
+					let mut resolved_path = self.resolver.resolve(&l.0);
+					// TODO: Process all trace elements first
+					let location = evaluation_state.map_source_locations(&l.0, &[l.1, l.2]);
+					write!(resolved_path, ":").unwrap();
+					print_code_location(&mut resolved_path, &location[0], &location[1]).unwrap();
+					resolved_path
+				})
+			})
 			.collect::<Vec<_>>();
-		let align = file_names.iter().flatten().map(|e| e.len()).max().unwrap_or(0);
+		let align = file_names
+			.iter()
+			.flatten()
+			.map(|e| e.len())
+			.max()
+			.unwrap_or(0);
 		for (i, (el, file)) in error.trace().0.iter().zip(file_names).enumerate() {
 			if i != 0 {
 				writeln!(out)?;
@@ -162,8 +168,9 @@
 				writeln!(out)?;
 			}
 			let desc = &item.desc;
-			if let Some (source) = &item.location {
-				let start_end = evaluation_state.map_source_locations(&source.0, &[source.1, source.2]);
+			if let Some(source) = &item.location {
+				let start_end =
+					evaluation_state.map_source_locations(&source.0, &[source.1, source.2]);
 
 				write!(
 					out,
@@ -174,11 +181,7 @@
 					start_end[0].column,
 				)?;
 			} else {
-				write!(
-					out,
-					"    at {}",
-					desc,
-				)?;
+				write!(out, "    at {}", desc,)?;
 			}
 		}
 		Ok(())
@@ -230,7 +233,8 @@
 		for item in trace.0.iter() {
 			let desc = &item.desc;
 			if let Some(source) = &item.location {
-				let start_end = evaluation_state.map_source_locations(&source.0, &[source.1, source.2]);
+				let start_end =
+					evaluation_state.map_source_locations(&source.0, &[source.1, source.2]);
 				self.print_snippet(
 					out,
 					&evaluation_state.get_source(&source.0).unwrap(),
modifiedcrates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -16,8 +16,8 @@
 		match $value {
 			$match(v) => v,
 			_ => unreachable!(),
-		}
-	}}
+			}
+		}};
 }
 
 #[derive(Debug, Error, Clone)]