From 09c5300ac581a413324551a78100b15dd0ff4180 Mon Sep 17 00:00:00 2001 From: arty Date: Tue, 17 Dec 2024 17:33:38 -0800 Subject: [PATCH] fmt+clippy --- src/classic/clvm/__type_compatibility__.rs | 2 +- src/classic/clvm/serialize.rs | 4 +- src/classic/clvm/sexp.rs | 4 +- .../clvm_tools/stages/stage_2/optimize.rs | 62 +++++++++---------- src/classic/platform/mod.rs | 4 +- src/compiler/evaluate.rs | 2 +- src/compiler/mod.rs | 2 +- src/compiler/sexp.rs | 2 +- src/compiler/stackvisit.rs | 4 +- src/util/mod.rs | 2 +- 10 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/classic/clvm/__type_compatibility__.rs b/src/classic/clvm/__type_compatibility__.rs index f25696dcc..75f481b10 100644 --- a/src/classic/clvm/__type_compatibility__.rs +++ b/src/classic/clvm/__type_compatibility__.rs @@ -22,7 +22,7 @@ pub fn char_to_string(ch: char) -> String { } pub fn vec_to_string(r: &[u8]) -> String { - return String::from_utf8_lossy(r).as_ref().to_string(); + String::from_utf8_lossy(r).as_ref().to_string() } /** diff --git a/src/classic/clvm/serialize.rs b/src/classic/clvm/serialize.rs index a9f57c24a..949c1c185 100644 --- a/src/classic/clvm/serialize.rs +++ b/src/classic/clvm/serialize.rs @@ -91,7 +91,7 @@ impl<'a> SExpToBytesIterator<'a> { } } -impl<'a> Iterator for SExpToBytesIterator<'a> { +impl Iterator for SExpToBytesIterator<'_> { type Item = Vec; fn next(&mut self) -> Option { @@ -281,6 +281,6 @@ pub fn atom_from_stream<'a>( if blob.length() != size as usize { return Err(EvalErr(NodePtr::NIL, "bad encoding".to_string())); } - return allocator.new_atom(blob.data()); + allocator.new_atom(blob.data()) }) } diff --git a/src/classic/clvm/sexp.rs b/src/classic/clvm/sexp.rs index 84f69725a..5ea82ea4a 100644 --- a/src/classic/clvm/sexp.rs +++ b/src/classic/clvm/sexp.rs @@ -202,7 +202,7 @@ pub fn to_sexp_type(allocator: &mut Allocator, value: CastableType) -> Result Err(EvalErr(NodePtr::NIL, "stack empty".to_string())), Some(top) => match top.borrow() { CastableType::CLVMObject(o) => Ok(*o), @@ -211,7 +211,7 @@ pub fn to_sexp_type(allocator: &mut Allocator, value: CastableType) -> Result Bytes { diff --git a/src/classic/clvm_tools/stages/stage_2/optimize.rs b/src/classic/clvm_tools/stages/stage_2/optimize.rs index c7fdce417..4d254d981 100644 --- a/src/classic/clvm_tools/stages/stage_2/optimize.rs +++ b/src/classic/clvm_tools/stages/stage_2/optimize.rs @@ -165,7 +165,7 @@ pub fn cons_q_a_optimizer( let matched = match_sexp(allocator, cons_q_a_optimizer_pattern, r, HashMap::new()); - return match ( + match ( matched.as_ref().and_then(|t1| t1.get("args").copied()), matched.as_ref().and_then(|t1| t1.get("sexp").copied()), ) { @@ -177,7 +177,7 @@ pub fn cons_q_a_optimizer( } } _ => Ok(r), - }; + } } fn cons_pattern(allocator: &mut Allocator) -> NodePtr { @@ -521,41 +521,35 @@ fn path_optimizer( let first_match = match_sexp(allocator, first_atom_pattern, r, HashMap::new()); let rest_match = match_sexp(allocator, rest_atom_pattern, r, HashMap::new()); - return m! { - match (first_match, rest_match) { - (Some(first), _) => { - match first. - get("atom"). - and_then(|a| atom(allocator, *a).ok()). - map(|atom| number_from_u8(&atom)) - { - Some(atom) => { - let node = - NodePath::new(Some(atom)). - add(NodePath::new(None).first()); - allocator.new_atom(node.as_path().data()) - }, - _ => { Ok(r) } + match (first_match, rest_match) { + (Some(first), _) => { + match first + .get("atom") + .and_then(|a| atom(allocator, *a).ok()) + .map(|atom| number_from_u8(&atom)) + { + Some(atom) => { + let node = NodePath::new(Some(atom)).add(NodePath::new(None).first()); + allocator.new_atom(node.as_path().data()) } - }, - (_, Some(rest)) => { - match rest. - get("atom"). - and_then(|a| atom(allocator, *a).ok()). - map(|atom| number_from_u8(&atom)) - { - Some(atom) => { - let node = - NodePath::new(Some(atom)). - add(NodePath::new(None).rest()); - allocator.new_atom(node.as_path().data()) - }, - _ => { Ok(r) } + _ => Ok(r), + } + } + (_, Some(rest)) => { + match rest + .get("atom") + .and_then(|a| atom(allocator, *a).ok()) + .map(|atom| number_from_u8(&atom)) + { + Some(atom) => { + let node = NodePath::new(Some(atom)).add(NodePath::new(None).rest()); + allocator.new_atom(node.as_path().data()) } - }, - _ => Ok(r) + _ => Ok(r), + } } - }; + _ => Ok(r), + } } fn quote_pattern_1(allocator: &mut Allocator) -> NodePtr { diff --git a/src/classic/platform/mod.rs b/src/classic/platform/mod.rs index 72ead7d4f..47d3fcf38 100644 --- a/src/classic/platform/mod.rs +++ b/src/classic/platform/mod.rs @@ -11,9 +11,9 @@ impl ArgumentValueConv for PathJoin { fn convert(&self, arg: &str) -> Result { let mut p = PathBuf::new(); p.push(arg); - return Ok(ArgumentValue::ArgString( + Ok(ArgumentValue::ArgString( None, p.as_path().to_str().unwrap().to_string(), - )); + )) } } diff --git a/src/compiler/evaluate.rs b/src/compiler/evaluate.rs index 866bcd07e..21c636d5c 100644 --- a/src/compiler/evaluate.rs +++ b/src/compiler/evaluate.rs @@ -49,7 +49,7 @@ trait VisitedInfoAccess { fn insert_function(&mut self, name: Vec, body: Rc); } -impl<'info> VisitedInfoAccess for VisitedMarker<'info, VisitedInfo> { +impl VisitedInfoAccess for VisitedMarker<'_, VisitedInfo> { fn get_function(&mut self, name: &[u8]) -> Option> { if let Some(ref mut info) = self.info { info.functions.get(name).cloned() diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index 0b8351392..3920a884d 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -267,7 +267,7 @@ impl<'a> CompileContextWrapper<'a> { /// Drop CompileContextWrapper reverts the contained objects back to the ones /// owned by the caller. -impl<'a> Drop for CompileContextWrapper<'a> { +impl Drop for CompileContextWrapper<'_> { fn drop(&mut self) { self.switch(); } diff --git a/src/compiler/sexp.rs b/src/compiler/sexp.rs index eee39c7b5..c426b0800 100644 --- a/src/compiler/sexp.rs +++ b/src/compiler/sexp.rs @@ -367,7 +367,7 @@ fn list_no_parens(a: &SExp, b: &SExp) -> String { } pub fn decode_string(v: &[u8]) -> String { - return String::from_utf8_lossy(v).as_ref().to_string(); + String::from_utf8_lossy(v).as_ref().to_string() } pub fn printable(a: &[u8], quoted: bool) -> bool { diff --git a/src/compiler/stackvisit.rs b/src/compiler/stackvisit.rs index 32ba9e677..276191cf2 100644 --- a/src/compiler/stackvisit.rs +++ b/src/compiler/stackvisit.rs @@ -51,7 +51,7 @@ impl<'info, T> VisitedMarker<'info, T> { } } -impl<'info, T> Unvisit for VisitedMarker<'info, T> { +impl Unvisit for VisitedMarker<'_, T> { fn give_back(&mut self, info: Option>) { self.info = info; } @@ -66,7 +66,7 @@ impl<'info, T> Unvisit for VisitedMarker<'info, T> { } // When dropped, the info box is handed back. -impl<'info, T> Drop for VisitedMarker<'info, T> { +impl Drop for VisitedMarker<'_, T> { fn drop(&mut self) { let mut info = None; swap(&mut self.info, &mut info); diff --git a/src/util/mod.rs b/src/util/mod.rs index d075b9aba..8988c5c60 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -40,7 +40,7 @@ where } pub fn skip_leading(s: &str, dash: &str) -> String { - return s.graphemes(true).skip_while(|ch| dash == *ch).collect(); + s.graphemes(true).skip_while(|ch| dash == *ch).collect() } pub fn collapse(r: Result) -> A {