difftreelog
style fix warnings with nightly clippy
in: master
9 files changed
crates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -9,7 +9,7 @@
use crate::ConfigureState;
-#[derive(PartialEq)]
+#[derive(PartialEq, Eq)]
pub enum TraceFormatName {
Compact,
Explaining,
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -13,20 +13,20 @@
fn into_untyped(value: Self, s: State) -> Result<Val> {
Ok(match value {
- Value::Null => Val::Null,
- Value::Bool(v) => Val::Bool(v),
- Value::Number(n) => Val::Num(n.as_f64().ok_or_else(|| {
+ Self::Null => Val::Null,
+ Self::Bool(v) => Val::Bool(v),
+ Self::Number(n) => Val::Num(n.as_f64().ok_or_else(|| {
RuntimeError(format!("json number can't be represented as jsonnet: {}", n).into())
})?),
- Value::String(s) => Val::Str((&s as &str).into()),
- Value::Array(a) => {
+ Self::String(s) => Val::Str((&s as &str).into()),
+ Self::Array(a) => {
let mut out: Vec<Val> = Vec::with_capacity(a.len());
for v in a {
out.push(Self::into_untyped(v, s.clone())?);
}
Val::Arr(out.into())
}
- Value::Object(o) => {
+ Self::Object(o) => {
let mut builder = ObjValueBuilder::with_capacity(o.len());
for (k, v) in o {
builder
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -17,6 +17,11 @@
clippy::cast_possible_wrap,
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
+ // False positives
+ // https://github.com/rust-lang/rust-clippy/issues/6902
+ clippy::use_self,
+ // https://github.com/rust-lang/rust-clippy/issues/8539
+ clippy::iter_with_drain,
)]
// For jrsonnet-macros
crates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -120,7 +120,7 @@
Ok((out, &str[i..]))
}
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Width {
Star,
Fixed(usize),
@@ -174,7 +174,7 @@
Ok(((), &str[idx..]))
}
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum ConvTypeV {
Decimal,
Octal,
crates/jrsonnet-evaluator/src/stdlib/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs
@@ -3,7 +3,7 @@
throw, State, Val,
};
-#[derive(PartialEq, Clone, Copy)]
+#[derive(PartialEq, Eq, Clone, Copy)]
pub enum ManifestType {
// Applied in manifestification
Manifest,
crates/jrsonnet-evaluator/src/trace/location.rsdiffbeforeafterboth1#[allow(clippy::module_name_repetitions)]2#[derive(Clone, PartialEq, Debug)]3pub struct CodeLocation {4 pub offset: usize,56 pub line: usize,7 pub column: usize,89 pub line_start_offset: usize,10 pub line_end_offset: usize,11}1213#[allow(clippy::module_name_repetitions)]14pub fn location_to_offset(mut file: &str, mut line: usize, column: usize) -> Option<usize> {15 let mut offset = 0;16 while line > 1 {17 let pos = file.find('\n')?;18 offset += pos + 1;19 file = &file[pos + 1..];20 line -= 1;21 }22 offset += column - 1;23 Some(offset)24}2526#[allow(clippy::module_name_repetitions)]27pub fn offset_to_location(file: &str, offsets: &[u32]) -> Vec<CodeLocation> {28 if offsets.is_empty() {29 return vec![];30 }31 let mut line = 1;32 let mut column = 1;33 let max_offset = *offsets.iter().max().expect("offsets is not empty");3435 let mut offset_map = offsets36 .iter()37 .enumerate()38 .map(|(pos, offset)| (*offset, pos))39 .collect::<Vec<_>>();40 offset_map.sort_by_key(|v| v.0);41 offset_map.reverse();4243 let mut out = vec![44 CodeLocation {45 offset: 0,46 column: 0,47 line: 0,48 line_start_offset: 0,49 line_end_offset: 050 };51 offsets.len()52 ];53 let mut with_no_known_line_ending = vec![];54 let mut this_line_offset = 0;55 for (pos, ch) in file56 .chars()57 .enumerate()58 .chain(std::iter::once((file.len(), ' ')))59 {60 column += 1;61 match offset_map.last() {62 Some(x) if x.0 == pos as u32 => {63 let out_idx = x.1;64 with_no_known_line_ending.push(out_idx);65 out[out_idx].offset = pos;66 out[out_idx].line = line;67 out[out_idx].column = column;68 out[out_idx].line_start_offset = this_line_offset;69 offset_map.pop();70 }71 _ => {}72 }73 if ch == '\n' {74 line += 1;75 column = 1;7677 for idx in with_no_known_line_ending.drain(..) {78 out[idx].line_end_offset = pos;79 }80 this_line_offset = pos + 1;8182 if pos == max_offset as usize + 1 {83 break;84 }85 }86 }87 let file_end = file.chars().count();88 for idx in with_no_known_line_ending {89 out[idx].line_end_offset = file_end;90 }9192 out93}9495#[cfg(test)]96pub mod tests {97 use super::{offset_to_location, CodeLocation};9899 #[test]100 fn test() {101 assert_eq!(102 offset_to_location(103 "hello world\n_______________________________________________________",104 &[0, 14]105 ),106 vec![107 CodeLocation {108 offset: 0,109 line: 1,110 column: 2,111 line_start_offset: 0,112 line_end_offset: 11,113 },114 CodeLocation {115 offset: 14,116 line: 2,117 column: 4,118 line_start_offset: 12,119 line_end_offset: 67120 }121 ]122 )123 }124}1#[allow(clippy::module_name_repetitions)]2#[derive(Clone, PartialEq, Eq, Debug)]3pub struct CodeLocation {4 pub offset: usize,56 pub line: usize,7 pub column: usize,89 pub line_start_offset: usize,10 pub line_end_offset: usize,11}1213#[allow(clippy::module_name_repetitions)]14pub fn location_to_offset(mut file: &str, mut line: usize, column: usize) -> Option<usize> {15 let mut offset = 0;16 while line > 1 {17 let pos = file.find('\n')?;18 offset += pos + 1;19 file = &file[pos + 1..];20 line -= 1;21 }22 offset += column - 1;23 Some(offset)24}2526#[allow(clippy::module_name_repetitions)]27pub fn offset_to_location(file: &str, offsets: &[u32]) -> Vec<CodeLocation> {28 if offsets.is_empty() {29 return vec![];30 }31 let mut line = 1;32 let mut column = 1;33 let max_offset = *offsets.iter().max().expect("offsets is not empty");3435 let mut offset_map = offsets36 .iter()37 .enumerate()38 .map(|(pos, offset)| (*offset, pos))39 .collect::<Vec<_>>();40 offset_map.sort_by_key(|v| v.0);41 offset_map.reverse();4243 let mut out = vec![44 CodeLocation {45 offset: 0,46 column: 0,47 line: 0,48 line_start_offset: 0,49 line_end_offset: 050 };51 offsets.len()52 ];53 let mut with_no_known_line_ending = vec![];54 let mut this_line_offset = 0;55 for (pos, ch) in file56 .chars()57 .enumerate()58 .chain(std::iter::once((file.len(), ' ')))59 {60 column += 1;61 match offset_map.last() {62 Some(x) if x.0 == pos as u32 => {63 let out_idx = x.1;64 with_no_known_line_ending.push(out_idx);65 out[out_idx].offset = pos;66 out[out_idx].line = line;67 out[out_idx].column = column;68 out[out_idx].line_start_offset = this_line_offset;69 offset_map.pop();70 }71 _ => {}72 }73 if ch == '\n' {74 line += 1;75 column = 1;7677 for idx in with_no_known_line_ending.drain(..) {78 out[idx].line_end_offset = pos;79 }80 this_line_offset = pos + 1;8182 if pos == max_offset as usize + 1 {83 break;84 }85 }86 }87 let file_end = file.chars().count();88 for idx in with_no_known_line_ending {89 out[idx].line_end_offset = file_end;90 }9192 out93}9495#[cfg(test)]96pub mod tests {97 use super::{offset_to_location, CodeLocation};9899 #[test]100 fn test() {101 assert_eq!(102 offset_to_location(103 "hello world\n_______________________________________________________",104 &[0, 14]105 ),106 vec![107 CodeLocation {108 offset: 0,109 line: 1,110 column: 2,111 line_start_offset: 0,112 line_end_offset: 11,113 },114 CodeLocation {115 offset: 14,116 line: 2,117 column: 4,118 line_start_offset: 12,119 line_end_offset: 67120 }121 ]122 )123 }124}crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -476,43 +476,43 @@
impl Val {
pub const fn as_bool(&self) -> Option<bool> {
match self {
- Val::Bool(v) => Some(*v),
+ Self::Bool(v) => Some(*v),
_ => None,
}
}
pub const fn as_null(&self) -> Option<()> {
match self {
- Val::Null => Some(()),
+ Self::Null => Some(()),
_ => None,
}
}
pub fn as_str(&self) -> Option<IStr> {
match self {
- Val::Str(s) => Some(s.clone()),
+ Self::Str(s) => Some(s.clone()),
_ => None,
}
}
pub const fn as_num(&self) -> Option<f64> {
match self {
- Val::Num(n) => Some(*n),
+ Self::Num(n) => Some(*n),
_ => None,
}
}
pub fn as_arr(&self) -> Option<ArrValue> {
match self {
- Val::Arr(a) => Some(a.clone()),
+ Self::Arr(a) => Some(a.clone()),
_ => None,
}
}
pub fn as_obj(&self) -> Option<ObjValue> {
match self {
- Val::Obj(o) => Some(o.clone()),
+ Self::Obj(o) => Some(o.clone()),
_ => None,
}
}
pub fn as_func(&self) -> Option<FuncVal> {
match self {
- Val::Func(f) => Some(f.clone()),
+ Self::Func(f) => Some(f.clone()),
_ => None,
}
}
crates/jrsonnet-interner/src/inner.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/inner.rs
+++ b/crates/jrsonnet-interner/src/inner.rs
@@ -157,7 +157,7 @@
pub fn ptr_eq(a: &Self, b: &Self) -> bool {
a.0 == b.0
}
- pub fn as_ptr(this: &Self) -> *const u8 {
+ pub const fn as_ptr(this: &Self) -> *const u8 {
// SAFETY: data is initialized
unsafe { this.0.as_ptr().add(mem::size_of::<InnerHeader>()) }
}
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -21,7 +21,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum Visibility {
/// :
Normal,
@@ -60,7 +60,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum UnaryOpType {
Plus,
Minus,
@@ -85,7 +85,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, PartialEq, Trace)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]
pub enum BinaryOpType {
Mul,
Div,
@@ -179,7 +179,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Trace)]
+#[derive(Debug, Clone, PartialEq, Eq, Trace)]
pub enum DestructRest {
/// ...rest
Keep(IStr),
@@ -188,7 +188,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, PartialEq, Trace)]
+#[derive(Debug, Clone, PartialEq, Eq, Trace)]
pub enum Destruct {
Full(IStr),
#[cfg(feature = "exp-destruct")]
@@ -263,7 +263,7 @@
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, PartialEq, Clone, Copy, Trace)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]
pub enum LiteralType {
This,
Super,
@@ -357,7 +357,7 @@
/// file, begin offset, end offset
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Clone, PartialEq, Trace)]
+#[derive(Clone, PartialEq, Eq, Trace)]
#[skip_trace]
#[repr(C)]
pub struct ExprLocation(pub Source, pub u32, pub u32);