difftreelog
style fix clippy warnings
in: master
5 files changed
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth1use crate::{2 error::Error::*, map::LayeredHashMap, resolved_lazy_val, FutureWrapper, LazyBinding, LazyVal,3 ObjValue, Result, Val,4};5use jrsonnet_interner::IStr;6use rustc_hash::FxHashMap;7use std::hash::BuildHasherDefault;8use std::{fmt::Debug, rc::Rc};910#[derive(Clone)]11pub struct ContextCreator(pub Context, pub FutureWrapper<FxHashMap<IStr, LazyBinding>>);12impl ContextCreator {13 pub fn create(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<Context> {14 self.0.clone().extend_unbound(15 self.1.clone().unwrap(),16 self.0.dollar().clone().or_else(|| this.clone()),17 this,18 super_obj,19 )20 }21}2223struct ContextInternals {24 dollar: Option<ObjValue>,25 this: Option<ObjValue>,26 super_obj: Option<ObjValue>,27 bindings: LayeredHashMap<LazyVal>,28}29impl Debug for ContextInternals {30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {31 f.debug_struct("Context")32 .field("this", &self.this.as_ref().map(|e| Rc::as_ptr(&e.0)))33 .field("bindings", &self.bindings)34 .finish()35 }36}3738#[derive(Debug, Clone)]39pub struct Context(Rc<ContextInternals>);40impl Context {41 pub fn new_future() -> FutureWrapper<Context> {42 FutureWrapper::new()43 }4445 pub fn dollar(&self) -> &Option<ObjValue> {46 &self.0.dollar47 }4849 pub fn this(&self) -> &Option<ObjValue> {50 &self.0.this51 }5253 pub fn super_obj(&self) -> &Option<ObjValue> {54 &self.0.super_obj55 }5657 pub fn new() -> Self {58 Self(Rc::new(ContextInternals {59 dollar: None,60 this: None,61 super_obj: None,62 bindings: LayeredHashMap::default(),63 }))64 }6566 pub fn binding(&self, name: IStr) -> Result<LazyVal> {67 Ok(self68 .069 .bindings70 .get(&name)71 .cloned()72 .ok_or(VariableIsNotDefined(name))?)73 }74 pub fn into_future(self, ctx: FutureWrapper<Context>) -> Self {75 {76 ctx.0.borrow_mut().replace(self);77 }78 ctx.unwrap()79 }8081 pub fn with_var(self, name: IStr, value: Val) -> Self {82 let mut new_bindings =83 FxHashMap::with_capacity_and_hasher(1, BuildHasherDefault::default());84 new_bindings.insert(name, resolved_lazy_val!(value));85 self.extend(new_bindings, None, None, None)86 }8788 pub fn extend(89 self,90 new_bindings: FxHashMap<IStr, LazyVal>,91 new_dollar: Option<ObjValue>,92 new_this: Option<ObjValue>,93 new_super_obj: Option<ObjValue>,94 ) -> Self {95 match Rc::try_unwrap(self.0) {96 Ok(mut ctx) => {97 // Extended context aren't used by anything else, we can freely mutate it without cloning98 if let Some(dollar) = new_dollar {99 ctx.dollar = Some(dollar);100 }101 if let Some(this) = new_this {102 ctx.this = Some(this);103 }104 if let Some(super_obj) = new_super_obj {105 ctx.super_obj = Some(super_obj);106 }107 if !new_bindings.is_empty() {108 ctx.bindings = ctx.bindings.extend(new_bindings);109 }110 Self(Rc::new(ctx))111 }112 Err(ctx) => {113 let dollar = new_dollar.or_else(|| ctx.dollar.clone());114 let this = new_this.or_else(|| ctx.this.clone());115 let super_obj = new_super_obj.or_else(|| ctx.super_obj.clone());116 let bindings = if new_bindings.is_empty() {117 ctx.bindings.clone()118 } else {119 ctx.bindings.clone().extend(new_bindings)120 };121 Self(Rc::new(ContextInternals {122 dollar,123 this,124 super_obj,125 bindings,126 }))127 }128 }129 }130 pub fn extend_bound(self, new_bindings: FxHashMap<IStr, LazyVal>) -> Self {131 let new_this = self.0.this.clone();132 let new_super_obj = self.0.super_obj.clone();133 self.extend(new_bindings, None, new_this, new_super_obj)134 }135 pub fn extend_unbound(136 self,137 new_bindings: FxHashMap<IStr, LazyBinding>,138 new_dollar: Option<ObjValue>,139 new_this: Option<ObjValue>,140 new_super_obj: Option<ObjValue>,141 ) -> Result<Self> {142 let this = new_this.or_else(|| self.0.this.clone());143 let super_obj = new_super_obj.or_else(|| self.0.super_obj.clone());144 let mut new =145 FxHashMap::with_capacity_and_hasher(new_bindings.len(), BuildHasherDefault::default());146 for (k, v) in new_bindings.into_iter() {147 new.insert(k, v.evaluate(this.clone(), super_obj.clone())?);148 }149 Ok(self.extend(new, new_dollar, this, super_obj))150 }151 #[cfg(feature = "unstable")]152 pub fn into_weak(self) -> WeakContext {153 WeakContext(Rc::downgrade(&self.0))154 }155}156157impl Default for Context {158 fn default() -> Self {159 Self::new()160 }161}162163impl PartialEq for Context {164 fn eq(&self, other: &Self) -> bool {165 Rc::ptr_eq(&self.0, &other.0)166 }167}168169#[cfg(feature = "unstable")]170#[derive(Debug, Clone)]171pub struct WeakContext(std::rc::Weak<ContextInternals>);172#[cfg(feature = "unstable")]173impl WeakContext {174 pub fn upgrade(&self) -> Context {175 Context(self.0.upgrade().expect("context is removed"))176 }177}178#[cfg(feature = "unstable")]179impl PartialEq for WeakContext {180 fn eq(&self, other: &Self) -> bool {181 self.0.ptr_eq(&other.0)182 }183}1use crate::{2 error::Error::*, map::LayeredHashMap, resolved_lazy_val, FutureWrapper, LazyBinding, LazyVal,3 ObjValue, Result, Val,4};5use jrsonnet_interner::IStr;6use rustc_hash::FxHashMap;7use std::hash::BuildHasherDefault;8use std::{fmt::Debug, rc::Rc};910#[derive(Clone)]11pub struct ContextCreator(pub Context, pub FutureWrapper<FxHashMap<IStr, LazyBinding>>);12impl ContextCreator {13 pub fn create(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<Context> {14 self.0.clone().extend_unbound(15 self.1.clone().unwrap(),16 self.0.dollar().clone().or_else(|| this.clone()),17 this,18 super_obj,19 )20 }21}2223struct ContextInternals {24 dollar: Option<ObjValue>,25 this: Option<ObjValue>,26 super_obj: Option<ObjValue>,27 bindings: LayeredHashMap<LazyVal>,28}29impl Debug for ContextInternals {30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {31 f.debug_struct("Context")32 .field("this", &self.this.as_ref().map(|e| Rc::as_ptr(&e.0)))33 .field("bindings", &self.bindings)34 .finish()35 }36}3738#[derive(Debug, Clone)]39pub struct Context(Rc<ContextInternals>);40impl Context {41 pub fn new_future() -> FutureWrapper<Self> {42 FutureWrapper::new()43 }4445 pub fn dollar(&self) -> &Option<ObjValue> {46 &self.0.dollar47 }4849 pub fn this(&self) -> &Option<ObjValue> {50 &self.0.this51 }5253 pub fn super_obj(&self) -> &Option<ObjValue> {54 &self.0.super_obj55 }5657 pub fn new() -> Self {58 Self(Rc::new(ContextInternals {59 dollar: None,60 this: None,61 super_obj: None,62 bindings: LayeredHashMap::default(),63 }))64 }6566 pub fn binding(&self, name: IStr) -> Result<LazyVal> {67 Ok(self68 .069 .bindings70 .get(&name)71 .cloned()72 .ok_or(VariableIsNotDefined(name))?)73 }74 pub fn into_future(self, ctx: FutureWrapper<Self>) -> Self {75 {76 ctx.0.borrow_mut().replace(self);77 }78 ctx.unwrap()79 }8081 pub fn with_var(self, name: IStr, value: Val) -> Self {82 let mut new_bindings =83 FxHashMap::with_capacity_and_hasher(1, BuildHasherDefault::default());84 new_bindings.insert(name, resolved_lazy_val!(value));85 self.extend(new_bindings, None, None, None)86 }8788 pub fn extend(89 self,90 new_bindings: FxHashMap<IStr, LazyVal>,91 new_dollar: Option<ObjValue>,92 new_this: Option<ObjValue>,93 new_super_obj: Option<ObjValue>,94 ) -> Self {95 match Rc::try_unwrap(self.0) {96 Ok(mut ctx) => {97 // Extended context aren't used by anything else, we can freely mutate it without cloning98 if let Some(dollar) = new_dollar {99 ctx.dollar = Some(dollar);100 }101 if let Some(this) = new_this {102 ctx.this = Some(this);103 }104 if let Some(super_obj) = new_super_obj {105 ctx.super_obj = Some(super_obj);106 }107 if !new_bindings.is_empty() {108 ctx.bindings = ctx.bindings.extend(new_bindings);109 }110 Self(Rc::new(ctx))111 }112 Err(ctx) => {113 let dollar = new_dollar.or_else(|| ctx.dollar.clone());114 let this = new_this.or_else(|| ctx.this.clone());115 let super_obj = new_super_obj.or_else(|| ctx.super_obj.clone());116 let bindings = if new_bindings.is_empty() {117 ctx.bindings.clone()118 } else {119 ctx.bindings.clone().extend(new_bindings)120 };121 Self(Rc::new(ContextInternals {122 dollar,123 this,124 super_obj,125 bindings,126 }))127 }128 }129 }130 pub fn extend_bound(self, new_bindings: FxHashMap<IStr, LazyVal>) -> Self {131 let new_this = self.0.this.clone();132 let new_super_obj = self.0.super_obj.clone();133 self.extend(new_bindings, None, new_this, new_super_obj)134 }135 pub fn extend_unbound(136 self,137 new_bindings: FxHashMap<IStr, LazyBinding>,138 new_dollar: Option<ObjValue>,139 new_this: Option<ObjValue>,140 new_super_obj: Option<ObjValue>,141 ) -> Result<Self> {142 let this = new_this.or_else(|| self.0.this.clone());143 let super_obj = new_super_obj.or_else(|| self.0.super_obj.clone());144 let mut new =145 FxHashMap::with_capacity_and_hasher(new_bindings.len(), BuildHasherDefault::default());146 for (k, v) in new_bindings.into_iter() {147 new.insert(k, v.evaluate(this.clone(), super_obj.clone())?);148 }149 Ok(self.extend(new, new_dollar, this, super_obj))150 }151 #[cfg(feature = "unstable")]152 pub fn into_weak(self) -> WeakContext {153 WeakContext(Rc::downgrade(&self.0))154 }155}156157impl Default for Context {158 fn default() -> Self {159 Self::new()160 }161}162163impl PartialEq for Context {164 fn eq(&self, other: &Self) -> bool {165 Rc::ptr_eq(&self.0, &other.0)166 }167}168169#[cfg(feature = "unstable")]170#[derive(Debug, Clone)]171pub struct WeakContext(std::rc::Weak<ContextInternals>);172#[cfg(feature = "unstable")]173impl WeakContext {174 pub fn upgrade(&self) -> Context {175 Context(self.0.upgrade().expect("context is removed"))176 }177}178#[cfg(feature = "unstable")]179impl PartialEq for WeakContext {180 fn eq(&self, other: &Self) -> bool {181 self.0.ptr_eq(&other.0)182 }183}crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -1,6 +1,6 @@
#![cfg_attr(feature = "unstable", feature(stmt_expr_attributes))]
-#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
#![warn(clippy::all, clippy::nursery)]
+#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths, clippy::ptr_arg)]
mod builtin;
mod ctx;
@@ -429,7 +429,7 @@
}
pub fn resolve_file(&self, from: &PathBuf, path: &PathBuf) -> Result<Rc<PathBuf>> {
- Ok(self.settings().import_resolver.resolve_file(from, path)?)
+ self.settings().import_resolver.resolve_file(from, path)
}
pub fn load_file_contents(&self, path: &PathBuf) -> Result<IStr> {
self.settings().import_resolver.load_file_contents(path)
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -173,7 +173,7 @@
pub fn extend_with_field(self, key: IStr, value: ObjMember) -> Self {
let mut new = FxHashMap::with_capacity_and_hasher(1, BuildHasherDefault::default());
new.insert(key, value);
- ObjValue::new(Some(self), Rc::new(new))
+ Self::new(Some(self), Rc::new(new))
}
pub(crate) fn get_raw(&self, key: IStr, real_this: Option<&Self>) -> Result<Option<Val>> {
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::redundant_closure_call)]
+
use peg::parser;
use std::{path::PathBuf, rc::Rc};
mod expr;
crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::redundant_closure_call)]
+
use std::fmt::Display;
#[macro_export]