Explorar o código

Updates for rust 1.50.0

Signed-off-by: Sean Young <sean@mess.org>
Sean Young %!s(int64=4) %!d(string=hai) anos
pai
achega
bc0af604af

+ 2 - 2
.github/workflows/test.yml

@@ -12,8 +12,8 @@ jobs:
         run: rustup default stable
       - name: Run cargo fmt
         run: cargo fmt --all -- --check
-      - name: Run cargo clippy --tests --bins
-        run: cargo clippy -- -D warnings
+      - name: Run cargo clippy
+        run: cargo clippy --tests --bins -- -D warnings
 
   linux:
     name: Linux

+ 4 - 1
src/abi/ethereum.rs

@@ -80,7 +80,10 @@ pub fn gen_abi(contract_no: usize, ns: &Namespace) -> Vec<ABI> {
         .filter_map(|function_no| {
             let func = &ns.functions[*function_no];
 
-            if matches!(func.visibility, pt::Visibility::Public(_) | pt::Visibility::External(_)) {
+            if matches!(
+                func.visibility,
+                pt::Visibility::Public(_) | pt::Visibility::External(_)
+            ) {
                 Some(ABI {
                     name: func.name.to_owned(),
                     mutability: func.print_mutability(),

+ 1 - 3
src/codegen/strength_reduce.rs

@@ -737,9 +737,7 @@ fn transfer(instr: &Instr, vars: &mut Variables, ns: &Namespace) {
 /// Other types (e.g. bytes) is not relevant for strength reduce. Bools are only
 /// tracked so we can following branching after integer compare.
 fn track(ty: &Type) -> bool {
-    matches!(ty,
-        Type::Uint(_) | Type::Int(_) | Type::Bool | Type::Value
-    )
+    matches!(ty, Type::Uint(_) | Type::Int(_) | Type::Bool | Type::Value)
 }
 
 #[derive(Eq, Hash, Debug, Clone, PartialEq)]

+ 1 - 1
src/emit/mod.rs

@@ -3599,7 +3599,7 @@ pub trait TargetRuntime<'a> {
 
                                 if dest.is_pointer_value()
                                     && !(v.ty.is_reference_type()
-                                        || matches!(v.ty, ast::Type::ExternalFunction{ .. }))
+                                        || matches!(v.ty, ast::Type::ExternalFunction { .. }))
                                 {
                                     contract.builder.build_store(dest.into_pointer_value(), val);
                                 } else {

+ 14 - 18
src/parser/lexer.rs

@@ -534,7 +534,7 @@ impl<'input> Lexer<'input> {
         start: usize,
         end: usize,
         ch: char,
-    ) -> Option<Result<(usize, Token<'input>, usize), LexicalError>> {
+    ) -> Result<(usize, Token<'input>, usize), LexicalError> {
         if ch == '0' {
             if let Some((_, 'x')) = self.chars.peek() {
                 // hex number
@@ -543,10 +543,10 @@ impl<'input> Lexer<'input> {
                 let mut end = match self.chars.next() {
                     Some((end, ch)) if ch.is_ascii_hexdigit() => end,
                     Some((_, _)) => {
-                        return Some(Err(LexicalError::MissingNumber(start, start + 1)));
+                        return Err(LexicalError::MissingNumber(start, start + 1));
                     }
                     None => {
-                        return Some(Err(LexicalError::EndofFileInHex(start, self.input.len())));
+                        return Err(LexicalError::EndofFileInHex(start, self.input.len()));
                     }
                 };
 
@@ -558,11 +558,7 @@ impl<'input> Lexer<'input> {
                     self.chars.next();
                 }
 
-                return Some(Ok((
-                    start,
-                    Token::HexNumber(&self.input[start..=end]),
-                    end + 1,
-                )));
+                return Ok((start, Token::HexNumber(&self.input[start..=end]), end + 1));
             }
         }
 
@@ -591,13 +587,13 @@ impl<'input> Lexer<'input> {
             }
 
             if exp_start > end {
-                return Some(Err(LexicalError::MissingExponent(start, self.input.len())));
+                return Err(LexicalError::MissingExponent(start, self.input.len()));
             }
         }
 
         let exp = &self.input[exp_start..=end];
 
-        Some(Ok((start, Token::Number(base, exp), end + 1)))
+        Ok((start, Token::Number(base, exp), end + 1))
     }
 
     fn string(
@@ -605,7 +601,7 @@ impl<'input> Lexer<'input> {
         token_start: usize,
         string_start: usize,
         quote_char: char,
-    ) -> Option<Result<(usize, Token<'input>, usize), LexicalError>> {
+    ) -> Result<(usize, Token<'input>, usize), LexicalError> {
         let mut end;
 
         let mut last_was_escape = false;
@@ -622,18 +618,18 @@ impl<'input> Lexer<'input> {
                     last_was_escape = false;
                 }
             } else {
-                return Some(Err(LexicalError::EndOfFileInString(
+                return Err(LexicalError::EndOfFileInString(
                     token_start,
                     self.input.len(),
-                )));
+                ));
             }
         }
 
-        Some(Ok((
+        Ok((
             token_start,
             Token::StringLiteral(&self.input[string_start..end]),
             end + 1,
-        )))
+        ))
     }
 
     fn next(&mut self) -> Option<Result<(usize, Token<'input>, usize), LexicalError>> {
@@ -664,7 +660,7 @@ impl<'input> Lexer<'input> {
 
                                 self.chars.next();
 
-                                return self.string(start, start + 8, quote_char);
+                                return Some(self.string(start, start + 8, quote_char));
                             }
                             _ => (),
                         }
@@ -742,7 +738,7 @@ impl<'input> Lexer<'input> {
                     };
                 }
                 Some((start, quote_char @ '"')) | Some((start, quote_char @ '\'')) => {
-                    return self.string(start, start + 1, quote_char);
+                    return Some(self.string(start, start + 1, quote_char));
                 }
                 Some((start, '/')) => {
                     match self.chars.peek() {
@@ -827,7 +823,7 @@ impl<'input> Lexer<'input> {
                     }
                 }
                 Some((start, ch)) if ch.is_ascii_digit() => {
-                    return self.parse_number(start, start, ch)
+                    return Some(self.parse_number(start, start, ch))
                 }
                 Some((i, ';')) => return Some(Ok((i, Token::Semicolon, i + 1))),
                 Some((i, ',')) => return Some(Ok((i, Token::Comma, i + 1))),

+ 4 - 2
src/sema/ast.rs

@@ -203,8 +203,10 @@ impl Function {
 
     /// Is this function accessable externally
     pub fn is_public(&self) -> bool {
-        matches!(self.visibility,
-            pt::Visibility::Public(_) | pt::Visibility::External(_))
+        matches!(
+            self.visibility,
+            pt::Visibility::Public(_) | pt::Visibility::External(_)
+        )
     }
 
     /// Is this function accessable only from same contract

+ 9 - 8
src/sema/expression.rs

@@ -1279,9 +1279,10 @@ pub fn compatible_mutability(
     left: &Option<pt::StateMutability>,
     right: &Option<pt::StateMutability>,
 ) -> bool {
-    matches!((left, right),
-            // only payable is compatible with payable
-            (Some(pt::StateMutability::Payable(_)), Some(pt::StateMutability::Payable(_)))
+    matches!(
+        (left, right),
+        // only payable is compatible with payable
+        (Some(pt::StateMutability::Payable(_)), Some(pt::StateMutability::Payable(_)))
             // default is compatible with anything but pure and view
             | (None, Some(pt::StateMutability::Payable(_))) | (None, None)
             // view is compatible with anything but pure
@@ -1289,8 +1290,7 @@ pub fn compatible_mutability(
             | (Some(pt::StateMutability::View(_)), None)
             | (Some(pt::StateMutability::View(_)), Some(pt::StateMutability::View(_)))
             // pure is compatible with anything
-            | (Some(pt::StateMutability::Pure(_)), _)
-            // everything else is not compatible
+            | (Some(pt::StateMutability::Pure(_)), _) // everything else is not compatible
     )
 }
 
@@ -3782,9 +3782,10 @@ fn assign_expr(
     )?;
     let var_ty = var.ty();
 
-    let resolve_to = if matches!(expr,
-        pt::Expression::AssignShiftLeft(_, _, _) | pt::Expression::AssignShiftRight(_, _, _))
-    {
+    let resolve_to = if matches!(
+        expr,
+        pt::Expression::AssignShiftLeft(_, _, _) | pt::Expression::AssignShiftRight(_, _, _)
+    ) {
         None
     } else {
         Some(var_ty.deref_any())

+ 12 - 2
src/sema/format.rs

@@ -92,8 +92,18 @@ pub fn string_format(
                         ));
                         return Err(());
                     }
-                } else if !matches!(arg_ty, Type::Uint(_) | Type::Int(_) | Type::Bytes(_) | Type::Enum(_) | Type::Address(_) | Type::Contract(_) | Type::String | Type::DynamicBytes | Type::Bool)
-                {
+                } else if !matches!(
+                    arg_ty,
+                    Type::Uint(_)
+                        | Type::Int(_)
+                        | Type::Bytes(_)
+                        | Type::Enum(_)
+                        | Type::Address(_)
+                        | Type::Contract(_)
+                        | Type::String
+                        | Type::DynamicBytes
+                        | Type::Bool
+                ) {
                     diagnostics.push(Diagnostic::error(
                         arg.loc(),
                         String::from(

+ 7 - 5
src/sema/types.rs

@@ -1018,12 +1018,14 @@ impl Type {
     /// compatible with ethereum solidity. Opinions on whether other types should be
     /// allowed be storage are welcome.
     pub fn can_have_data_location(&self) -> bool {
-        matches!(self,
+        matches!(
+            self,
             Type::Array(_, _)
-            | Type::Struct(_)
-            | Type::Mapping(_, _)
-            | Type::String
-            | Type::DynamicBytes)
+                | Type::Struct(_)
+                | Type::Mapping(_, _)
+                | Type::String
+                | Type::DynamicBytes
+        )
     }
 
     /// Is this a reference to contract storage?

+ 4 - 1
src/sema/variables.rs

@@ -159,7 +159,10 @@ pub fn var_decl(
             return None;
         }
     } else if ty.contains_internal_function(ns)
-        && matches!(visibility, pt::Visibility::Public(_) | pt::Visibility::External(_))
+        && matches!(
+            visibility,
+            pt::Visibility::Public(_) | pt::Visibility::External(_)
+        )
     {
         ns.diagnostics.push(Diagnostic::error(
             s.ty.loc(),

+ 2 - 2
tests/codegen.rs

@@ -71,7 +71,7 @@ fn testcase(path: PathBuf) {
 
         match checks.get(current_check) {
             Some(Test::Check(needle)) => {
-                if line.find(needle).is_some() {
+                if line.contains(needle) {
                     current_check += 1;
                 }
             }
@@ -84,7 +84,7 @@ fn testcase(path: PathBuf) {
         }
 
         if let Some(Test::Fail(needle)) = fails.get(current_fail) {
-            if line.find(needle).is_some() {
+            if line.contains(needle) {
                 current_fail += 1;
             }
         }