Skip to content

Commit

Permalink
refactor: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Apr 7, 2024
1 parent d349b9e commit a9100ab
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 174 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ mutable_key_type = "allow"
redundant_pub_crate = "allow"
# Sometimes code is fancier without that
manual_let_else = "allow"
# Something is broken about that lint, can't be allowed for
# codegenerated-stdlib block
similar_names = "allow"

#[profile.test]
#opt-level = 1
Expand Down
2 changes: 1 addition & 1 deletion cmds/jrsonnet-fmt/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dprint_core::formatting::{PrintOptions, PrintItems};
use dprint_core::formatting::{PrintItems, PrintOptions};
use indoc::indoc;

use crate::Printable;
Expand Down
2 changes: 1 addition & 1 deletion cmds/jrsonnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn main_catch(opts: Opts) -> bool {
if let Error::Evaluation(e) = e {
let mut out = String::new();
trace.write_trace(&mut out, &e).expect("format error");
eprintln!("{out}")
eprintln!("{out}");
} else {
eprintln!("{e}");
}
Expand Down
6 changes: 3 additions & 3 deletions crates/jrsonnet-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use jrsonnet_evaluator::{
stack::{limit_stack_depth, StackDepthLimitOverrideGuard},
FileImportResolver,
};
use jrsonnet_gcmodule::with_thread_object_space;
use jrsonnet_gcmodule::{with_thread_object_space, ObjectSpace};
pub use manifest::*;
pub use stdlib::*;
pub use tla::*;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct LeakSpace(PhantomData<()>);

impl Drop for LeakSpace {
fn drop(&mut self) {
with_thread_object_space(|s| s.leak())
with_thread_object_space(ObjectSpace::leak);
}
}

Expand All @@ -102,6 +102,6 @@ impl Drop for GcStatsPrinter {
let collected = jrsonnet_gcmodule::collect_thread_cycles();
eprintln!("Collected: {collected}");
}
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked());
}
}
12 changes: 6 additions & 6 deletions crates/jrsonnet-cli/src/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ impl FromStr for ExtStr {

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.find('=') {
Some(idx) => Ok(ExtStr {
Some(idx) => Ok(Self {
name: s[..idx].to_owned(),
value: s[idx + 1..].to_owned(),
}),
None => Ok(ExtStr {
None => Ok(Self {
name: s.to_owned(),
value: std::env::var(s).or(Err("missing env var"))?,
}),
Expand Down Expand Up @@ -109,16 +109,16 @@ impl StdOpts {
return Ok(None);
}
let ctx = ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
for ext in self.ext_str.iter() {
for ext in &self.ext_str {
ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
}
for ext in self.ext_str_file.iter() {
for ext in &self.ext_str_file {
ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
}
for ext in self.ext_code.iter() {
for ext in &self.ext_code {
ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
}
for ext in self.ext_code_file.iter() {
for ext in &self.ext_code_file {
ctx.add_ext_code(&ext.name as &str, &ext.value as &str)?;
}
Ok(Some(ctx))
Expand Down
4 changes: 2 additions & 2 deletions crates/jrsonnet-evaluator/src/arr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ArrValue {
Self::new(EagerArray(values))
}

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

Expand Down Expand Up @@ -70,7 +70,7 @@ impl ArrValue {
Ok(Self::eager(out))
}

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

Expand Down
8 changes: 4 additions & 4 deletions crates/jrsonnet-evaluator/src/function/arglike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ pub enum TlaArg {
impl ArgLike for TlaArg {
fn evaluate_arg(&self, ctx: Context, tailstrict: bool) -> Result<Thunk<Val>> {
match self {
TlaArg::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
TlaArg::Code(code) => Ok(if tailstrict {
Self::String(s) => Ok(Thunk::evaluated(Val::string(s.clone()))),
Self::Code(code) => Ok(if tailstrict {
Thunk::evaluated(evaluate(ctx, code)?)
} else {
Thunk::new(EvaluateThunk {
ctx,
expr: code.clone(),
})
}),
TlaArg::Val(val) => Ok(Thunk::evaluated(val.clone())),
TlaArg::Lazy(lazy) => Ok(lazy.clone()),
Self::Val(val) => Ok(Thunk::evaluated(val.clone())),
Self::Lazy(lazy) => Ok(lazy.clone()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl FuncVal {

pub fn evaluate_trivial(&self) -> Option<Val> {
match self {
FuncVal::Normal(n) => n.evaluate_trivial(),
Self::Normal(n) => n.evaluate_trivial(),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use fs::File;
use jrsonnet_gcmodule::Trace;
use jrsonnet_interner::IBytes;
use jrsonnet_parser::{SourceDirectory, SourceFile, SourcePath, SourceFifo};
use jrsonnet_parser::{SourceDirectory, SourceFifo, SourceFile, SourcePath};

use crate::{
bail,
Expand Down
36 changes: 18 additions & 18 deletions crates/jrsonnet-evaluator/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

impl<'de> Deserialize<'de> for Val {
fn deserialize<D>(deserializer: D) -> Result<Val, D::Error>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Expand Down Expand Up @@ -155,10 +155,10 @@ impl Serialize for Val {
S: serde::Serializer,
{
match self {
Val::Bool(v) => serializer.serialize_bool(*v),
Val::Null => serializer.serialize_none(),
Val::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
Val::Num(n) => {
Self::Bool(v) => serializer.serialize_bool(*v),
Self::Null => serializer.serialize_none(),
Self::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
Self::Num(n) => {
if n.fract() == 0.0 {
let n = *n as i64;
serializer.serialize_i64(n)
Expand All @@ -167,8 +167,8 @@ impl Serialize for Val {
}
}
#[cfg(feature = "exp-bigint")]
Val::BigInt(b) => b.serialize(serializer),
Val::Arr(arr) => {
Self::BigInt(b) => b.serialize(serializer),
Self::Arr(arr) => {
let mut seq = serializer.serialize_seq(Some(arr.len()))?;
for (i, element) in arr.iter().enumerate() {
let mut serde_error = None;
Expand All @@ -190,7 +190,7 @@ impl Serialize for Val {
}
seq.end()
}
Val::Obj(obj) => {
Self::Obj(obj) => {
let mut map = serializer.serialize_map(Some(obj.len()))?;
for (field, value) in obj.iter(
#[cfg(feature = "exp-preserve-order")]
Expand All @@ -215,7 +215,7 @@ impl Serialize for Val {
}
map.end()
}
Val::Func(_) => Err(S::Error::custom("tried to manifest function")),
Self::Func(_) => Err(S::Error::custom("tried to manifest function")),
}
}
}
Expand Down Expand Up @@ -248,9 +248,9 @@ impl SerializeSeq for IntoVecValSerializer {
type Ok = Val;
type Error = JrError;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
T: Serialize,
T: ?Sized + Serialize,
{
let value = value.serialize(IntoValSerializer)?;
self.data.push(value);
Expand All @@ -272,9 +272,9 @@ impl SerializeTuple for IntoVecValSerializer {
type Ok = Val;
type Error = JrError;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
T: Serialize,
T: ?Sized + Serialize,
{
SerializeSeq::serialize_element(self, value)
}
Expand All @@ -287,9 +287,9 @@ impl SerializeTupleVariant for IntoVecValSerializer {
type Ok = Val;
type Error = JrError;

fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
T: Serialize,
T: ?Sized + Serialize,
{
SerializeSeq::serialize_element(self, value)
}
Expand All @@ -302,9 +302,9 @@ impl SerializeTupleStruct for IntoVecValSerializer {
type Ok = Val;
type Error = JrError;

fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
T: Serialize,
T: ?Sized + Serialize,
{
SerializeSeq::serialize_element(self, value)
}
Expand Down Expand Up @@ -607,7 +607,7 @@ impl Serializer for IntoValSerializer {
}

impl Val {
pub fn from_serde(v: impl Serialize) -> Result<Val, JrError> {
pub fn from_serde(v: impl Serialize) -> Result<Self, JrError> {
v.serialize(IntoValSerializer)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub use jrsonnet_interner::{IBytes, IStr};
#[doc(hidden)]
pub use jrsonnet_macros;
pub use jrsonnet_parser as parser;
use jrsonnet_parser::*;
use jrsonnet_parser::{ExprLocation, LocExpr, ParserSettings, Source, SourcePath};
pub use obj::*;
use stack::check_depth;
pub use tla::apply_tla;
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ thread_local! {
pub struct StackOverflowError;
impl From<StackOverflowError> for ErrorKind {
fn from(_: StackOverflowError) -> Self {
ErrorKind::StackOverflow
Self::StackOverflow
}
}
impl From<StackOverflowError> for Error {
Expand Down
8 changes: 4 additions & 4 deletions crates/jrsonnet-evaluator/src/typed/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ where
};
a.iter()
.map(|r| r.and_then(T::from_untyped))
.collect::<Result<Vec<T>>>()
.collect::<Result<Self>>()
}
}

Expand All @@ -381,7 +381,7 @@ impl<K: Typed + Ord, V: Typed> Typed for BTreeMap<K, V> {
Self::TYPE.check(&value)?;
let obj = value.as_obj().expect("typecheck should fail");

let mut out = BTreeMap::new();
let mut out = Self::new();
if V::wants_lazy() {
for key in obj.fields_ex(
false,
Expand Down Expand Up @@ -623,8 +623,8 @@ impl Typed for IndexableVal {

fn into_untyped(value: Self) -> Result<Val> {
match value {
IndexableVal::Str(s) => Ok(Val::string(s)),
IndexableVal::Arr(a) => Ok(Val::Arr(a)),
Self::Str(s) => Ok(Val::string(s)),
Self::Arr(a) => Ok(Val::Arr(a)),
}
}

Expand Down
28 changes: 14 additions & 14 deletions crates/jrsonnet-evaluator/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
T: ThunkValue<Output = V>,
{
fn from(value: T) -> Self {
Thunk::new(value)
Self::new(value)
}
}

Expand Down Expand Up @@ -221,8 +221,8 @@ pub enum IndexableVal {
impl IndexableVal {
pub fn to_array(self) -> ArrValue {
match self {
IndexableVal::Str(s) => ArrValue::chars(s.chars()),
IndexableVal::Arr(arr) => arr,
Self::Str(s) => ArrValue::chars(s.chars()),
Self::Arr(arr) => arr,
}
}
/// Slice the value.
Expand All @@ -239,7 +239,7 @@ impl IndexableVal {
step: Option<BoundedUsize<1, { i32::MAX as usize }>>,
) -> Result<Self> {
match &self {
IndexableVal::Str(s) => {
Self::Str(s) => {
let mut computed_len = None;
let mut get_len = || {
computed_len.map_or_else(
Expand Down Expand Up @@ -277,7 +277,7 @@ impl IndexableVal {
.into(),
))
}
IndexableVal::Arr(arr) => {
Self::Arr(arr) => {
let get_idx = |pos: Option<i32>, len: usize, default| match pos {
Some(v) if v < 0 => len.saturating_sub((-v) as usize),
Some(v) => (v as usize).min(len),
Expand Down Expand Up @@ -307,7 +307,7 @@ pub enum StrValue {
Tree(Rc<(StrValue, StrValue, usize)>),
}
impl StrValue {
pub fn concat(a: StrValue, b: StrValue) -> Self {
pub fn concat(a: Self, b: Self) -> Self {
// TODO: benchmark for an optimal value, currently just a arbitrary choice
const STRING_EXTEND_THRESHOLD: usize = 100;

Expand All @@ -334,8 +334,8 @@ impl StrValue {
}
}
match self {
StrValue::Flat(f) => f,
StrValue::Tree(_) => {
Self::Flat(f) => f,
Self::Tree(_) => {
let mut buf = String::with_capacity(self.len());
write_buf(&self, &mut buf);
buf.into()
Expand All @@ -344,8 +344,8 @@ impl StrValue {
}
pub fn len(&self) -> usize {
match self {
StrValue::Flat(v) => v.len(),
StrValue::Tree(t) => t.2,
Self::Flat(v) => v.len(),
Self::Tree(t) => t.2,
}
}
pub fn is_empty(&self) -> bool {
Expand All @@ -367,8 +367,8 @@ where
impl Display for StrValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StrValue::Flat(v) => write!(f, "{v}"),
StrValue::Tree(t) => {
Self::Flat(v) => write!(f, "{v}"),
Self::Tree(t) => {
write!(f, "{}", t.0)?;
write!(f, "{}", t.1)
}
Expand Down Expand Up @@ -522,8 +522,8 @@ impl Val {

pub fn into_indexable(self) -> Result<IndexableVal> {
Ok(match self {
Val::Str(s) => IndexableVal::Str(s.into_flat()),
Val::Arr(arr) => IndexableVal::Arr(arr),
Self::Str(s) => IndexableVal::Str(s.into_flat()),
Self::Arr(arr) => IndexableVal::Arr(arr),
_ => bail!(ValueIsNotIndexable(self.value_type())),
})
}
Expand Down
Loading

0 comments on commit a9100ab

Please sign in to comment.