Skip to content

Commit

Permalink
Appease rust 1.78.0 clippies (#1643)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed May 6, 2024
1 parent 10c6e57 commit 96a1cc8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/abi/anchor.rs
Expand Up @@ -290,7 +290,7 @@ impl TypeManager<'_> {
format!("_{real_name}")
};
let unique_name = self.unique_string(new_other_name);
self.types[idx].name = unique_name.clone();
self.types[idx].name.clone_from(&unique_name);
self.added_names
.insert(unique_name, (idx, other_contract, real_name));
type_name.clone()
Expand Down
12 changes: 6 additions & 6 deletions src/bin/languageserver/mod.rs
Expand Up @@ -1876,7 +1876,7 @@ impl<'a> Builder<'a> {
.hover_overrides
.get(&pt::Loc::File(lookup.0, lookup.1.start, lookup.1.stop))
{
lookup.1.val = msg.clone();
lookup.1.val.clone_from(msg);
}
}

Expand All @@ -1900,7 +1900,7 @@ impl<'a> Builder<'a> {

for val in self.types.values_mut() {
if let Some(path) = defs_to_files.get(&val.def_type) {
val.def_path = path.clone();
val.def_path.clone_from(path);
}
}

Expand Down Expand Up @@ -1948,7 +1948,7 @@ impl<'a> Builder<'a> {
.map(|(_, i)| {
let mut i = i.clone();
if let Some(def_path) = defs_to_files.get(&i.val.def_type) {
i.val.def_path = def_path.clone();
i.val.def_path.clone_from(def_path);
}
i
})
Expand All @@ -1963,7 +1963,7 @@ impl<'a> Builder<'a> {
for val in &mut scope.val {
if let Some(val) = &mut val.1 {
if let Some(def_path) = defs_to_files.get(&val.def_type) {
val.def_path = def_path.clone();
val.def_path.clone_from(def_path);
}
}
}
Expand All @@ -1980,7 +1980,7 @@ impl<'a> Builder<'a> {
{
if def_path.to_str().unwrap() == "" {
if let Some(dp) = defs_to_files.get(def_type) {
*def_path = dp.clone();
def_path.clone_from(dp);
}
}
}
Expand All @@ -1994,7 +1994,7 @@ impl<'a> Builder<'a> {
for def_index in properties.values_mut().flatten() {
if def_index.def_path.to_str().unwrap() == "" {
if let Some(def_path) = defs_to_files.get(&def_index.def_type) {
def_index.def_path = def_path.clone();
def_index.def_path.clone_from(def_path);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/codegen/dispatch/polkadot.rs
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use num_bigint::{BigInt, Sign};
use solang_parser::pt::{FunctionTy, Loc::Codegen};
use std::fmt::{Display, Formatter, Result};

/// On Polkadot, contracts export a `call` and a `deploy` function.
/// The `contracts` pallet will invoke `deploy` on contract instatiation,
Expand All @@ -27,13 +28,12 @@ pub enum DispatchType {
Call,
}

impl ToString for DispatchType {
fn to_string(&self) -> String {
impl Display for DispatchType {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::Deploy => "polkadot_deploy_dispatch",
Self::Call => "polkadot_call_dispatch",
Self::Deploy => f.write_str("polkadot_deploy_dispatch"),
Self::Call => f.write_str("polkadot_call_dispatch"),
}
.into()
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/sema/solana_accounts.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

use std::str::FromStr;
use std::{fmt, str::FromStr};

pub enum BuiltinAccounts {
/// These are the accounts that we can collect from a contract and that Anchor will populate
Expand Down Expand Up @@ -31,10 +31,9 @@ impl BuiltinAccounts {
}
}

impl ToString for BuiltinAccounts {
fn to_string(&self) -> String {
let str = self.as_str();
str.to_string()
impl fmt::Display for BuiltinAccounts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}

Expand Down
22 changes: 10 additions & 12 deletions src/sema/yul/ast.rs
Expand Up @@ -7,7 +7,7 @@ use crate::sema::Recurse;
use num_bigint::BigInt;
use solang_parser::pt;
use solang_parser::pt::{CodeLocation, StorageLocation};
use std::sync::Arc;
use std::{fmt, sync::Arc};

#[derive(Debug, Clone)]
pub struct InlineAssembly {
Expand Down Expand Up @@ -97,17 +97,15 @@ pub enum YulSuffix {
Address,
}

impl ToString for YulSuffix {
fn to_string(&self) -> String {
let name = match self {
YulSuffix::Offset => "offset",
YulSuffix::Slot => "slot",
YulSuffix::Length => "length",
YulSuffix::Selector => "selector",
YulSuffix::Address => "address",
};

name.to_string()
impl fmt::Display for YulSuffix {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
YulSuffix::Offset => f.write_str("offset"),
YulSuffix::Slot => f.write_str("slot"),
YulSuffix::Length => f.write_str("length"),
YulSuffix::Selector => f.write_str("selector"),
YulSuffix::Address => f.write_str("address"),
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/sema/yul/builtin.rs
Expand Up @@ -2,6 +2,7 @@

use crate::Target;
use phf::{phf_map, phf_set};
use std::fmt;

pub struct YulBuiltinPrototype {
pub name: &'static str,
Expand Down Expand Up @@ -258,10 +259,10 @@ impl YulBuiltInFunction {
}
}

impl ToString for YulBuiltInFunction {
fn to_string(&self) -> String {
impl fmt::Display for YulBuiltInFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let prototype = self.get_prototype_info();
prototype.name.to_owned()
f.write_str(prototype.name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sema/yul/expression.rs
Expand Up @@ -576,7 +576,7 @@ fn resolve_suffix_access(
resolved_expr.loc(),
format!(
"the given expression does not support '.{}' suffixes",
suffix_type.to_string()
suffix_type
),
));
}
Expand Down Expand Up @@ -635,7 +635,7 @@ fn resolve_suffix_access(
resolved_expr.loc(),
format!(
"the given expression does not support '.{}' suffixes",
suffix_type.to_string()
suffix_type
),
));
return Err(());
Expand Down
1 change: 1 addition & 0 deletions tests/codegen.rs
Expand Up @@ -33,6 +33,7 @@ fn run_test_for_path(path: &str) {
}

#[derive(Debug)]
#[allow(unused)]
enum Test {
Check(usize, String),
CheckAbsent(usize, String),
Expand Down
12 changes: 7 additions & 5 deletions tests/evm.rs
Expand Up @@ -272,18 +272,20 @@ fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec<String>) {
if !contents.is_empty() {
cache.set_file_contents(&name, contents);
names.push(name);
name = String::new();
}
name = cap.get(1).unwrap().as_str().to_owned();
cap.get(1).unwrap().as_str().clone_into(&mut name);
if name == "////" {
name = "test.sol".to_owned();
"test.sol".clone_into(&mut name);
}
contents = String::new();
} else if let Some(cap) = external_source_delimiter.captures(line) {
let mut name = cap.get(1).unwrap().as_str().to_owned();
if let Some(cap) = equals.captures(&name) {
let filename = cap.get(1).unwrap().as_str();
let mut name = filename.to_owned();
if let Some(cap) = equals.captures(filename) {
let mut ext = path.parent().unwrap().to_path_buf();
ext.push(cap.get(2).unwrap().as_str());
name = cap.get(1).unwrap().as_str().to_owned();
cap.get(1).unwrap().as_str().clone_into(&mut name);
let source = fs::read_to_string(ext).unwrap();
cache.set_file_contents(&name, source);
}
Expand Down
9 changes: 4 additions & 5 deletions tests/polkadot_tests/contracts.rs
Expand Up @@ -248,7 +248,7 @@ fn mangle_function_names_in_abi() {
let _ = runtime.contracts()[0].code.messages["foo_"];
let _ = runtime.contracts()[0].code.messages["foo_uint256_addressArray2Array"];
let _ = runtime.contracts()[0].code.messages["foo_uint8Array2__int256_bool_address"];
assert!(runtime.contracts()[0].code.messages.get("foo").is_none());
assert!(!runtime.contracts()[0].code.messages.contains_key("foo"));
}

#[test]
Expand All @@ -265,12 +265,11 @@ fn mangle_overloaded_function_names_in_abi() {
);

let _ = runtime.contracts()[0].code.messages["foo"];
assert!(runtime.contracts()[0]
assert!(!runtime.contracts()[0]
.code
.messages
.get("foo_bool")
.is_none());
.contains_key("foo_bool"));

let _ = runtime.contracts()[1].code.messages["foo_bool"];
assert!(runtime.contracts()[1].code.messages.get("foo").is_none());
assert!(!runtime.contracts()[1].code.messages.contains_key("foo"));
}

0 comments on commit 96a1cc8

Please sign in to comment.