Procházet zdrojové kódy

Rust 1.84.1 clippies and remove temporary files (#1714)

Signed-off-by: Sean Young <sean@mess.org>
Sean Young před 9 měsíci
rodič
revize
d13e944d79

+ 3 - 2
.gitignore

@@ -3,8 +3,9 @@ Cargo.lock
 /target
 **/*.rs.bk
 *.ll
-tests/.tmp*
-tests/create_me/
+/tests/.tmp*
+/tests/create_me/
+/test_snapshots/
 
 .helix/
 .vscode/

+ 2 - 2
fmt/src/comments.rs

@@ -117,7 +117,7 @@ impl CommentWithMetadata {
                     // line has something
                     // check if the last comment after code was a postfix comment
                     if last_comment
-                        .map_or(false, |last| last.loc.end() > code_end && !last.is_prefix())
+                        .is_some_and(|last| last.loc.end() > code_end && !last.is_prefix())
                     {
                         // get the indent size of the next item of code
                         let next_indent_len = src[comment.loc().end()..]
@@ -434,7 +434,7 @@ impl std::iter::FusedIterator for CommentStateCharIndices<'_> {}
 /// An Iterator over characters in a string slice which are not a apart of comments
 pub struct NonCommentChars<'a>(CommentStateCharIndices<'a>);
 
-impl<'a> Iterator for NonCommentChars<'a> {
+impl Iterator for NonCommentChars<'_> {
     type Item = char;
 
     #[inline]

+ 9 - 9
fmt/src/formatter.rs

@@ -89,7 +89,7 @@ impl Context {
     pub(crate) fn is_constructor_function(&self) -> bool {
         self.function
             .as_ref()
-            .map_or(false, |f| matches!(f.ty, FunctionTy::Constructor))
+            .is_some_and(|f| matches!(f.ty, FunctionTy::Constructor))
     }
 }
 
@@ -348,7 +348,7 @@ impl<'a, W: Write> Formatter<'a, W> {
                 };
 
                 self.find_next_line(start_from)
-                    .map_or(false, |loc| loc >= end_at)
+                    .is_some_and(|loc| loc >= end_at)
             }
         }
     }
@@ -549,7 +549,7 @@ impl<'a, W: Write> Formatter<'a, W> {
     fn write_doc_block_line(&mut self, comment: &CommentWithMetadata, line: &str) -> Result<()> {
         if line.trim().starts_with('*') {
             let line = line.trim().trim_start_matches('*');
-            let needs_space = line.chars().next().map_or(false, |ch| !ch.is_whitespace());
+            let needs_space = line.chars().next().is_some_and(|ch| !ch.is_whitespace());
             write!(self.buf(), " *{}", if needs_space { " " } else { "" })?;
             self.write_comment_line(comment, line)?;
             self.write_whitespace_separator(true)?;
@@ -1797,7 +1797,7 @@ impl<'a, W: Write> Formatter<'a, W> {
 }
 
 // Traverse the Solidity Parse Tree and write to the code formatter
-impl<'a, W: Write> Visitor for Formatter<'a, W> {
+impl<W: Write> Visitor for Formatter<'_, W> {
     type Error = FormatterError;
 
     #[instrument(name = "source", skip(self))]
@@ -1862,7 +1862,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
         )?;
 
         // EOF newline
-        if self.last_char().map_or(true, |char| char != '\n') {
+        if self.last_char() != Some('\n') {
             writeln!(self.buf())?;
         }
 
@@ -3268,7 +3268,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
 
                 // we can however check if the contract `is` the `base`, this however also does
                 // not cover all cases
-                let is_contract_base = self.context.contract.as_ref().map_or(false, |contract| {
+                let is_contract_base = self.context.contract.as_ref().is_some_and(|contract| {
                     contract.base.iter().any(|contract_base| {
                         contract_base
                             .name
@@ -3292,7 +3292,7 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
                         .content
                         .chars()
                         .next()
-                        .map_or(false, |c| c.is_lowercase());
+                        .is_some_and(|c| c.is_lowercase());
                     if is_lowercase && base_or_modifier.content.ends_with("()") {
                         base_or_modifier
                             .content
@@ -3904,14 +3904,14 @@ struct Transaction<'f, 'a, W> {
     comments: Comments,
 }
 
-impl<'f, 'a, W> std::ops::Deref for Transaction<'f, 'a, W> {
+impl<'a, W> std::ops::Deref for Transaction<'_, 'a, W> {
     type Target = Formatter<'a, W>;
     fn deref(&self) -> &Self::Target {
         self.fmt
     }
 }
 
-impl<'f, 'a, W> std::ops::DerefMut for Transaction<'f, 'a, W> {
+impl<W> std::ops::DerefMut for Transaction<'_, '_, W> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         self.fmt
     }

+ 3 - 3
fmt/src/solang_ext/loc.rs

@@ -12,19 +12,19 @@ pub trait CodeLocationExt {
     fn loc(&self) -> pt::Loc;
 }
 
-impl<'a, T: ?Sized + CodeLocationExt> CodeLocationExt for &'a T {
+impl<T: ?Sized + CodeLocationExt> CodeLocationExt for &'_ T {
     fn loc(&self) -> pt::Loc {
         (**self).loc()
     }
 }
 
-impl<'a, T: ?Sized + CodeLocationExt> CodeLocationExt for &'a mut T {
+impl<T: ?Sized + CodeLocationExt> CodeLocationExt for &'_ mut T {
     fn loc(&self) -> pt::Loc {
         (**self).loc()
     }
 }
 
-impl<'a, T: ?Sized + ToOwned + CodeLocationExt> CodeLocationExt for Cow<'a, T> {
+impl<T: ?Sized + ToOwned + CodeLocationExt> CodeLocationExt for Cow<'_, T> {
     fn loc(&self) -> pt::Loc {
         (**self).loc()
     }

+ 3 - 3
fmt/src/string.rs

@@ -43,7 +43,7 @@ impl<'a> QuoteStateCharIndices<'a> {
     }
 }
 
-impl<'a> Iterator for QuoteStateCharIndices<'a> {
+impl Iterator for QuoteStateCharIndices<'_> {
     type Item = (QuoteState, usize, char);
     fn next(&mut self) -> Option<Self::Item> {
         let (idx, ch) = self.iter.next()?;
@@ -73,14 +73,14 @@ impl<'a> Iterator for QuoteStateCharIndices<'a> {
 /// An iterator over the indices of quoted string locations
 pub struct QuotedRanges<'a>(QuoteStateCharIndices<'a>);
 
-impl<'a> QuotedRanges<'a> {
+impl QuotedRanges<'_> {
     pub fn with_state(mut self, state: QuoteState) -> Self {
         self.0 = self.0.with_state(state);
         self
     }
 }
 
-impl<'a> Iterator for QuotedRanges<'a> {
+impl Iterator for QuotedRanges<'_> {
     type Item = (char, usize, usize);
     fn next(&mut self) -> Option<Self::Item> {
         let (quote, start) = loop {

+ 1 - 1
src/bin/cli/test.rs

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 
-#[cfg(test)]
+#![cfg(test)]
 
 mod tests {
     use crate::{cli, options_arg, Cli, Commands};

+ 3 - 3
src/codegen/revert.rs

@@ -281,7 +281,7 @@ pub(super) fn require(
                         FormatArg::StringLiteral,
                         Expression::BytesLiteral {
                             loc: Loc::Codegen,
-                            ty: Type::Bytes(error_string.as_bytes().len() as u8),
+                            ty: Type::Bytes(error_string.len() as u8),
                             value: error_string.as_bytes().to_vec(),
                         },
                     ),
@@ -350,7 +350,7 @@ pub(super) fn revert(
                             FormatArg::StringLiteral,
                             Expression::BytesLiteral {
                                 loc: Codegen,
-                                ty: Type::Bytes(error_string.as_bytes().len() as u8),
+                                ty: Type::Bytes(error_string.len() as u8),
                                 value: error_string.as_bytes().to_vec(),
                             },
                         ),
@@ -412,7 +412,7 @@ pub(super) fn string_to_expr(string: String) -> Expression {
             FormatArg::StringLiteral,
             Expression::BytesLiteral {
                 loc: Loc::Codegen,
-                ty: Type::Bytes(string.as_bytes().len() as u8),
+                ty: Type::Bytes(string.len() as u8),
                 value: string.as_bytes().to_vec(),
             },
         )],

+ 1 - 1
src/codegen/strength_reduce/mod.rs

@@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
 use std::convert::TryInto;
 use value::{get_max_signed, get_max_unsigned, is_single_constant, Value};
 
-/**
+/*
   Strength Reduce optimization pass - replace expensive arithmetic operations with cheaper ones
 
   Currently implemented:

+ 3 - 3
src/codegen/strength_reduce/reaching_values.rs

@@ -89,8 +89,8 @@ pub(super) fn reaching_values(
 /// changes in the set.
 /// There is a discussion to improve this function: https://github.com/hyperledger-solang/solang/issues/934
 fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool {
-    return if let Some(existing) = map.get_mut(&var_no) {
-        if existing.iter().next().map_or(false, |v| v.all_unknown()) {
+    if let Some(existing) = map.get_mut(&var_no) {
+        if existing.iter().next().is_some_and(|v| v.all_unknown()) {
             // If we already think it is unknown, nothing can improve on that
             false
         } else if let Some(v) = set.iter().find(|v| v.all_unknown()) {
@@ -138,7 +138,7 @@ fn update_map(var_no: usize, set: &HashSet<Value>, map: &mut Variables) -> bool
         }
 
         true
-    };
+    }
 }
 
 /// For a given instruction, calculate the new reaching values

+ 1 - 1
src/codegen/subexpression_elimination/available_expression_set.rs

@@ -12,7 +12,7 @@ use std::cell::RefCell;
 use std::collections::{HashMap, HashSet};
 use std::rc::Rc;
 
-impl<'a, 'b: 'a> AvailableExpressionSet<'a> {
+impl<'a> AvailableExpressionSet<'a> {
     /// Deep clone a set
     pub fn deep_clone(&self) -> AvailableExpressionSet<'a> {
         let mut new_set = AvailableExpressionSet {

+ 2 - 3
src/emit/binary.rs

@@ -909,8 +909,7 @@ impl<'a> Binary<'a> {
     pub(crate) fn llvm_type(&self, ty: &Type, ns: &Namespace) -> BasicTypeEnum<'a> {
         emit_context!(self);
         if ty.is_builtin_struct() == Some(StructType::AccountInfo) {
-            return self
-                .context
+            self.context
                 .struct_type(
                     &[
                         byte_ptr!().as_basic_type_enum(),             // SolPubkey *
@@ -925,7 +924,7 @@ impl<'a> Binary<'a> {
                     ],
                     false,
                 )
-                .as_basic_type_enum();
+                .as_basic_type_enum()
         } else {
             match ty {
                 Type::Bool => BasicTypeEnum::IntType(self.context.bool_type()),

+ 1 - 1
src/emit/math.rs

@@ -446,7 +446,7 @@ pub(super) fn multiply<'a, T: TargetRuntime<'a> + ?Sized>(
                 .build_int_truncate(res.into_int_value(), left.get_type(), "")
                 .unwrap()
         } else {
-            return call_mul32_without_ovf(bin, l, r, o, mul_bits, mul_ty, left.get_type());
+            call_mul32_without_ovf(bin, l, r, o, mul_bits, mul_ty, left.get_type())
         }
     } else if !unchecked {
         build_binary_op_with_overflow_check(

+ 1 - 1
src/sema/format.rs

@@ -248,7 +248,7 @@ impl<'a> FormatIterator<'a> {
     }
 }
 
-impl<'a> Iterator for FormatIterator<'a> {
+impl Iterator for FormatIterator<'_> {
     type Item = (pt::Loc, char);
 
     fn next(&mut self) -> Option<Self::Item> {

+ 1 - 1
src/sema/mutability.rs

@@ -70,7 +70,7 @@ struct StateCheck<'a> {
     data_account: DataAccountUsage,
 }
 
-impl<'a> StateCheck<'a> {
+impl StateCheck<'_> {
     fn value(&mut self, loc: &pt::Loc) {
         self.check_level(loc, Access::Value);
         self.required_access.increase_to(Access::Value);

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 151
test_snapshots/soroban_testcases/storage/counter.1.json


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 224
test_snapshots/soroban_testcases/storage/different_storage_types.1.json


+ 3 - 3
tests/solana.rs

@@ -440,7 +440,7 @@ struct SyscallContext<'a> {
     pub remaining: u64,
 }
 
-impl<'a> ContextObject for SyscallContext<'a> {
+impl ContextObject for SyscallContext<'_> {
     fn trace(&mut self, _state: [u64; 12]) {}
 
     fn consume(&mut self, amount: u64) {
@@ -453,7 +453,7 @@ impl<'a> ContextObject for SyscallContext<'a> {
     }
 }
 
-impl<'a> SyscallContext<'a> {
+impl SyscallContext<'_> {
     pub fn heap_verify(&self) {
         const VERBOSE: bool = false;
 
@@ -1647,7 +1647,7 @@ struct VmFunction<'a, 'b> {
     data_account: Option<usize>,
 }
 
-impl<'a, 'b> VmFunction<'a, 'b> {
+impl<'b> VmFunction<'_, 'b> {
     fn accounts(&mut self, accounts: Vec<(&str, Account)>) -> &mut Self {
         let accounts = accounts.into_iter().collect::<HashMap<&str, Account>>();
         let mut metas: Vec<AccountMeta> = Vec::new();

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů