Skip to content

Commit a9100ab

Browse files
committed
refactor: fix clippy warnings
1 parent d349b9e commit a9100ab

27 files changed

Lines changed: 185 additions & 174 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ mutable_key_type = "allow"
150150
redundant_pub_crate = "allow"
151151
# Sometimes code is fancier without that
152152
manual_let_else = "allow"
153+
# Something is broken about that lint, can't be allowed for
154+
# codegenerated-stdlib block
155+
similar_names = "allow"
153156

154157
#[profile.test]
155158
#opt-level = 1

cmds/jrsonnet-fmt/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dprint_core::formatting::{PrintOptions, PrintItems};
1+
use dprint_core::formatting::{PrintItems, PrintOptions};
22
use indoc::indoc;
33

44
use crate::Printable;

cmds/jrsonnet/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn main_catch(opts: Opts) -> bool {
153153
if let Error::Evaluation(e) = e {
154154
let mut out = String::new();
155155
trace.write_trace(&mut out, &e).expect("format error");
156-
eprintln!("{out}")
156+
eprintln!("{out}");
157157
} else {
158158
eprintln!("{e}");
159159
}

crates/jrsonnet-cli/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use jrsonnet_evaluator::{
1010
stack::{limit_stack_depth, StackDepthLimitOverrideGuard},
1111
FileImportResolver,
1212
};
13-
use jrsonnet_gcmodule::with_thread_object_space;
13+
use jrsonnet_gcmodule::{with_thread_object_space, ObjectSpace};
1414
pub use manifest::*;
1515
pub use stdlib::*;
1616
pub use tla::*;
@@ -88,7 +88,7 @@ pub struct LeakSpace(PhantomData<()>);
8888

8989
impl Drop for LeakSpace {
9090
fn drop(&mut self) {
91-
with_thread_object_space(|s| s.leak())
91+
with_thread_object_space(ObjectSpace::leak);
9292
}
9393
}
9494

@@ -102,6 +102,6 @@ impl Drop for GcStatsPrinter {
102102
let collected = jrsonnet_gcmodule::collect_thread_cycles();
103103
eprintln!("Collected: {collected}");
104104
}
105-
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
105+
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked());
106106
}
107107
}

crates/jrsonnet-cli/src/stdlib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ impl FromStr for ExtStr {
3939

4040
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
4141
match s.find('=') {
42-
Some(idx) => Ok(ExtStr {
42+
Some(idx) => Ok(Self {
4343
name: s[..idx].to_owned(),
4444
value: s[idx + 1..].to_owned(),
4545
}),
46-
None => Ok(ExtStr {
46+
None => Ok(Self {
4747
name: s.to_owned(),
4848
value: std::env::var(s).or(Err("missing env var"))?,
4949
}),
@@ -109,16 +109,16 @@ impl StdOpts {
109109
return Ok(None);
110110
}
111111
let ctx = ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
112-
for ext in self.ext_str.iter() {
112+
for ext in &self.ext_str {
113113
ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
114114
}
115-
for ext in self.ext_str_file.iter() {
115+
for ext in &self.ext_str_file {
116116
ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
117117
}
118-
for ext in self.ext_code.iter() {
118+
for ext in &self.ext_code {
119119
ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
120120
}
121-
for ext in self.ext_code_file.iter() {
121+
for ext in &self.ext_code_file {
122122
ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
123123
}
124124
Ok(Some(ctx))

crates/jrsonnet-evaluator/src/arr/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl ArrValue {
4242
Self::new(EagerArray(values))
4343
}
4444

45-
pub fn repeated(data: ArrValue, repeats: usize) -> Option<Self> {
45+
pub fn repeated(data: Self, repeats: usize) -> Option<Self> {
4646
Some(Self::new(RepeatedArray::new(data, repeats)?))
4747
}
4848

@@ -70,7 +70,7 @@ impl ArrValue {
7070
Ok(Self::eager(out))
7171
}
7272

73-
pub fn extended(a: ArrValue, b: ArrValue) -> Self {
73+
pub fn extended(a: Self, b: Self) -> Self {
7474
// TODO: benchmark for an optimal value, currently just a arbitrary choice
7575
const ARR_EXTEND_THRESHOLD: usize = 100;
7676

crates/jrsonnet-evaluator/src/function/arglike.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ pub enum TlaArg {
6161
impl ArgLike for TlaArg {
6262
fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result<Thunk<Val>> {
6363
match self {
64-
TlaArg::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
65-
TlaArg::Code(code) => Ok(if tailstrict {
64+
Self::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
65+
Self::Code(code) => Ok(if tailstrict {
6666
Thunk::evaluated(evaluate(ctx, code)?)
6767
} else {
6868
Thunk::new(EvaluateThunk {
6969
ctx,
7070
expr: code.clone(),
7171
})
7272
}),
73-
TlaArg::Val(val) => Ok(Thunk::evaluated(val.clone())),
74-
TlaArg::Lazy(lazy) => Ok(lazy.clone()),
73+
Self::Val(val) => Ok(Thunk::evaluated(val.clone())),
74+
Self::Lazy(lazy) => Ok(lazy.clone()),
7575
}
7676
}
7777
}

crates/jrsonnet-evaluator/src/function/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl FuncVal {
237237

238238
pub fn evaluate_trivial(&self) -> Option<Val> {
239239
match self {
240-
FuncVal::Normal(n) => n.evaluate_trivial(),
240+
Self::Normal(n) => n.evaluate_trivial(),
241241
_ => None,
242242
}
243243
}

crates/jrsonnet-evaluator/src/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
use fs::File;
1111
use jrsonnet_gcmodule::Trace;
1212
use jrsonnet_interner::IBytes;
13-
use jrsonnet_parser::{SourceDirectory, SourceFile, SourcePath, SourceFifo};
13+
use jrsonnet_parser::{SourceDirectory, SourceFifo, SourceFile, SourcePath};
1414

1515
use crate::{
1616
bail,

crates/jrsonnet-evaluator/src/integrations/serde.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616

1717
impl<'de> Deserialize<'de> for Val {
18-
fn deserialize<D>(deserializer: D) -> Result<Val, D::Error>
18+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1919
where
2020
D: serde::Deserializer<'de>,
2121
{
@@ -155,10 +155,10 @@ impl Serialize for Val {
155155
S: serde::Serializer,
156156
{
157157
match self {
158-
Val::Bool(v) => serializer.serialize_bool(*v),
159-
Val::Null => serializer.serialize_none(),
160-
Val::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
161-
Val::Num(n) => {
158+
Self::Bool(v) => serializer.serialize_bool(*v),
159+
Self::Null => serializer.serialize_none(),
160+
Self::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
161+
Self::Num(n) => {
162162
if n.fract() == 0.0 {
163163
let n = *n as i64;
164164
serializer.serialize_i64(n)
@@ -167,8 +167,8 @@ impl Serialize for Val {
167167
}
168168
}
169169
#[cfg(feature = "exp-bigint")]
170-
Val::BigInt(b) => b.serialize(serializer),
171-
Val::Arr(arr) => {
170+
Self::BigInt(b) => b.serialize(serializer),
171+
Self::Arr(arr) => {
172172
let mut seq = serializer.serialize_seq(Some(arr.len()))?;
173173
for (i, element) in arr.iter().enumerate() {
174174
let mut serde_error = None;
@@ -190,7 +190,7 @@ impl Serialize for Val {
190190
}
191191
seq.end()
192192
}
193-
Val::Obj(obj) => {
193+
Self::Obj(obj) => {
194194
let mut map = serializer.serialize_map(Some(obj.len()))?;
195195
for (field, value) in obj.iter(
196196
#[cfg(feature = "exp-preserve-order")]
@@ -215,7 +215,7 @@ impl Serialize for Val {
215215
}
216216
map.end()
217217
}
218-
Val::Func(_) => Err(S::Error::custom("tried to manifest function")),
218+
Self::Func(_) => Err(S::Error::custom("tried to manifest function")),
219219
}
220220
}
221221
}
@@ -248,9 +248,9 @@ impl SerializeSeq for IntoVecValSerializer {
248248
type Ok = Val;
249249
type Error = JrError;
250250

251-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
251+
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
252252
where
253-
T: Serialize,
253+
T: ?Sized + Serialize,
254254
{
255255
let value = value.serialize(IntoValSerializer)?;
256256
self.data.push(value);
@@ -272,9 +272,9 @@ impl SerializeTuple for IntoVecValSerializer {
272272
type Ok = Val;
273273
type Error = JrError;
274274

275-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
275+
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
276276
where
277-
T: Serialize,
277+
T: ?Sized + Serialize,
278278
{
279279
SerializeSeq::serialize_element(self, value)
280280
}
@@ -287,9 +287,9 @@ impl SerializeTupleVariant for IntoVecValSerializer {
287287
type Ok = Val;
288288
type Error = JrError;
289289

290-
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
290+
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
291291
where
292-
T: Serialize,
292+
T: ?Sized + Serialize,
293293
{
294294
SerializeSeq::serialize_element(self, value)
295295
}
@@ -302,9 +302,9 @@ impl SerializeTupleStruct for IntoVecValSerializer {
302302
type Ok = Val;
303303
type Error = JrError;
304304

305-
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
305+
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
306306
where
307-
T: Serialize,
307+
T: ?Sized + Serialize,
308308
{
309309
SerializeSeq::serialize_element(self, value)
310310
}
@@ -607,7 +607,7 @@ impl Serializer for IntoValSerializer {
607607
}
608608

609609
impl Val {
610-
pub fn from_serde(v: impl Serialize) -> Result<Val, JrError> {
610+
pub fn from_serde(v: impl Serialize) -> Result<Self, JrError> {
611611
v.serialize(IntoValSerializer)
612612
}
613613
}

0 commit comments

Comments
 (0)