Skip to content

Commit

Permalink
feat: remove linter warnings by applying cargo clippy (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoks authored Mar 28, 2024
1 parent e7af20b commit 9810e8e
Show file tree
Hide file tree
Showing 70 changed files with 252 additions and 248 deletions.
2 changes: 1 addition & 1 deletion language/evm/exec-utils/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn solc(
/// compiled bytecode. If `return_optimized_yul` is true, also return the textual representation
/// of optimized Yul.
pub fn solc_yul(source: &str, return_optimized_yul: bool) -> Result<(Vec<u8>, Option<String>)> {
let mut prog = Command::new(&solc_path()?);
let mut prog = Command::new(solc_path()?);
prog.arg("--optimize").arg("--strict-assembly").arg("--bin");
if return_optimized_yul {
prog.arg("--ir-optimized");
Expand Down
3 changes: 1 addition & 2 deletions language/evm/move-to-yul/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a> Context<'a> {
.unwrap_or_else(|_| PathBuf::from("."))
.to_string_lossy()
.to_string()
+ &std::path::MAIN_SEPARATOR.to_string();
+ std::path::MAIN_SEPARATOR_STR;
if file_path.starts_with(&current_dir) {
file_path[current_dir.len()..].to_string()
} else {
Expand Down Expand Up @@ -255,7 +255,6 @@ impl<'a> Context<'a> {
pub fn derive_contracts(&self) -> Vec<Contract> {
self.env
.get_modules()
.into_iter()
.filter_map(|ref m| {
if is_evm_contract_module(m) {
Some(self.extract_contract(m))
Expand Down
2 changes: 1 addition & 1 deletion language/evm/move-to-yul/src/dispatcher_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Generator {
}
if !attributes::is_create_fun(fun) || self.storage_type.is_none() {
// If this is not a creator which returns a storage value, add return types.
types.extend(fun.get_return_types().into_iter())
types.extend(fun.get_return_types())
}
types.into_iter().all(|ty| !ty.is_reference())
}
Expand Down
2 changes: 1 addition & 1 deletion language/move-analyzer/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn identifiers(buffer: &str, symbols: &Symbols, path: &PathBuf) -> Vec<Completio
}

let mut ids = HashSet::new();
while lexer.peek() != Tok::EOF {
while lexer.peek() != Tok::Eof {
// Some tokens, such as "phantom", are contextual keywords that are only reserved in
// certain contexts. Since for now this language server doesn't analyze semantic context,
// tokens such as "phantom" are always present in keyword suggestions. To avoid displaying
Expand Down
26 changes: 21 additions & 5 deletions language/move-analyzer/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use crate::{
use anyhow::{anyhow, Result};
use codespan_reporting::files::SimpleFiles;
use crossbeam::channel::Sender;
use derivative::*;
use im::ordmap::OrdMap;
use lsp_server::{Request, RequestId};
use lsp_types::{
Expand Down Expand Up @@ -167,17 +166,34 @@ struct StructDef {
field_defs: Vec<FieldDef>,
}

#[derive(Derivative, Debug, Clone, PartialEq, Eq)]
#[derivative(PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FunctionDef {
name: Symbol,
start: Position,
attrs: Vec<String>,
#[derivative(PartialOrd = "ignore")]
#[derivative(Ord = "ignore")]
ident_type: IdentType,
}

impl Ord for FunctionDef {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
if self.name.ne(&other.name) {
self.name.partial_cmp(&other.name).unwrap()
} else if self.start.ne(&other.start) {
self.start.partial_cmp(&other.start).unwrap()
} else if self.attrs.ne(&other.attrs) {
self.attrs.partial_cmp(&other.attrs).unwrap()
} else {
std::cmp::Ordering::Equal
}
}
}

impl PartialOrd for FunctionDef {
fn partial_cmp(&self, other: &FunctionDef) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

/// Module-level definitions
#[derive(Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
pub struct ModuleDefs {
Expand Down
2 changes: 1 addition & 1 deletion language/move-binary-format/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {

#[test]
fn test_buf_reader() {
let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7];
let in_buf = [0, 1, 2, 3, 4, 5, 6, 7];
let mut reader = Cursor::new(&in_buf[..]);
let mut buf = [];
assert_eq!(reader.read(&mut buf).unwrap(), 0);
Expand Down
18 changes: 9 additions & 9 deletions language/move-binary-format/src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,9 @@ fn load_ability_set(
AbilitySetPosition::FunctionTypeParameters
| AbilitySetPosition::StructTypeParameters => {
let set = match DeprecatedKind::from_u8(byte)? {
DeprecatedKind::ALL => AbilitySet::EMPTY,
DeprecatedKind::COPYABLE => AbilitySet::EMPTY | Ability::Copy | Ability::Drop,
DeprecatedKind::RESOURCE => AbilitySet::EMPTY | Ability::Key,
DeprecatedKind::All => AbilitySet::EMPTY,
DeprecatedKind::Copyable => AbilitySet::EMPTY | Ability::Copy | Ability::Drop,
DeprecatedKind::Resource => AbilitySet::EMPTY | Ability::Key,
};
Ok(match pos {
AbilitySetPosition::StructHandle => unreachable!(),
Expand Down Expand Up @@ -1688,17 +1688,17 @@ impl DeprecatedNominalResourceFlag {
#[allow(non_camel_case_types)]
#[repr(u8)]
enum DeprecatedKind {
ALL = 0x1,
COPYABLE = 0x2,
RESOURCE = 0x3,
All = 0x1,
Copyable = 0x2,
Resource = 0x3,
}

impl DeprecatedKind {
fn from_u8(value: u8) -> BinaryLoaderResult<DeprecatedKind> {
match value {
0x1 => Ok(DeprecatedKind::ALL),
0x2 => Ok(DeprecatedKind::COPYABLE),
0x3 => Ok(DeprecatedKind::RESOURCE),
0x1 => Ok(DeprecatedKind::All),
0x2 => Ok(DeprecatedKind::Copyable),
0x3 => Ok(DeprecatedKind::Resource),
_ => Err(PartialVMError::new(StatusCode::UNKNOWN_ABILITY)),
}
}
Expand Down
9 changes: 2 additions & 7 deletions language/move-binary-format/src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,14 @@ pub struct FieldDefinition {

/// `Visibility` restricts the accessibility of the associated entity.
/// - For function visibility, it restricts who may call into the associated function.
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "fuzzing"), derive(proptest_derive::Arbitrary))]
#[cfg_attr(any(test, feature = "fuzzing"), proptest(no_params))]
#[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary))]
#[repr(u8)]
pub enum Visibility {
/// Accessible within its defining module only.
#[default]
Private = 0x0,
/// Accessible by any module or script outside of its declaring module.
Public = 0x1,
Expand All @@ -436,12 +437,6 @@ impl Visibility {
pub const DEPRECATED_SCRIPT: u8 = 0x2;
}

impl Default for Visibility {
fn default() -> Self {
Visibility::Private
}
}

impl core::convert::TryFrom<u8> for Visibility {
type Error = ();

Expand Down
2 changes: 1 addition & 1 deletion language/move-binary-format/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<'a, T: ModuleAccess> LocalsSignatureView<'a, T> {
let parameters = self.parameters();
SignatureTokenView::new(
self.function_def_view.module,
if (index as usize) < parameters.len() {
if index < parameters.len() {
&parameters[index]
} else {
&self.additional_locals()[index - parameters.len()]
Expand Down
9 changes: 5 additions & 4 deletions language/move-bytecode-verifier/src/struct_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> StructDefGraphBuilder<'a> {
token: &SignatureToken,
) -> PartialVMResult<()> {
use SignatureToken as T;
Ok(match token {
match token {
T::Bool
| T::U8
| T::U16
Expand All @@ -127,21 +127,22 @@ impl<'a> StructDefGraphBuilder<'a> {
if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) {
neighbors
.entry(cur_idx)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(*struct_def_idx);
}
}
T::StructInstantiation(sh_idx, inners) => {
if let Some(struct_def_idx) = self.handle_to_def.get(sh_idx) {
neighbors
.entry(cur_idx)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(*struct_def_idx);
}
for t in inners {
self.add_signature_token(neighbors, cur_idx, t)?
}
}
})
}
Ok(())
}
}
2 changes: 1 addition & 1 deletion language/move-command-line-common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum ParsedType {
}

impl Display for TypeToken {
fn fmt<'f>(&self, formatter: &mut fmt::Formatter<'f>) -> Result<(), fmt::Error> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let s = match *self {
TypeToken::Whitespace => "[whitespace]",
TypeToken::Ident => "[identifier]",
Expand Down
2 changes: 1 addition & 1 deletion language/move-command-line-common/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ParsableValue for () {
}

impl Display for ValueToken {
fn fmt<'f>(&self, formatter: &mut fmt::Formatter<'f>) -> Result<(), fmt::Error> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let s = match self {
ValueToken::Number => "[num]",
ValueToken::NumberTyped => "[num typed]",
Expand Down
6 changes: 3 additions & 3 deletions language/move-compiler/src/cfgir/absint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use super::cfg::CFG;
use super::cfg::Cfg;
use crate::{diagnostics::Diagnostics, hlir::ast::*};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -83,7 +83,7 @@ pub trait AbstractInterpreter: TransferFunctions {
/// Analyze procedure local@function_view starting from pre-state local@initial_state.
fn analyze_function(
&mut self,
cfg: &dyn CFG,
cfg: &dyn Cfg,
initial_state: Self::State,
) -> (BTreeMap<Label, Self::State>, Diagnostics) {
let mut inv_map: InvariantMap<Self::State> = InvariantMap::new();
Expand Down Expand Up @@ -151,7 +151,7 @@ pub trait AbstractInterpreter: TransferFunctions {

fn execute_block(
&mut self,
cfg: &dyn CFG,
cfg: &dyn Cfg,
pre_state: &Self::State,
block_lbl: Label,
) -> (Self::State, Diagnostics) {
Expand Down
8 changes: 4 additions & 4 deletions language/move-compiler/src/cfgir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
// CFG
//**************************************************************************************************

pub trait CFG {
pub trait Cfg {
fn successors(&self, label: Label) -> &BTreeSet<Label>;

fn predecessors(&self, label: Label) -> &BTreeSet<Label>;
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'a> BlockCFG<'a> {
}
}

impl<'a> CFG for BlockCFG<'a> {
impl<'a> Cfg for BlockCFG<'a> {
fn successors(&self, label: Label) -> &BTreeSet<Label> {
self.successor_map.get(&label).unwrap()
}
Expand Down Expand Up @@ -549,7 +549,7 @@ impl<'a> ReverseBlockCFG<'a> {
for terminal_predecessor in &end_blocks {
forward_successors
.entry(*terminal_predecessor)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(terminal);
}
forward_predecessor.insert(terminal, end_blocks);
Expand Down Expand Up @@ -623,7 +623,7 @@ impl<'a> Drop for ReverseBlockCFG<'a> {
}
}

impl<'a> CFG for ReverseBlockCFG<'a> {
impl<'a> Cfg for ReverseBlockCFG<'a> {
fn successors(&self, label: Label) -> &BTreeSet<Label> {
self.successor_map.get(&label).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion language/move-compiler/src/cfgir/liveness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod state;

use super::{
absint::*,
cfg::{BlockCFG, ReverseBlockCFG, CFG},
cfg::{BlockCFG, Cfg, ReverseBlockCFG},
locals,
};
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion language/move-compiler/src/cfgir/optimize/inline_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::{
cfgir::{
ast::remap_labels,
cfg::{BlockCFG, CFG},
cfg::{BlockCFG, Cfg},
},
hlir::ast::{BasicBlocks, Command_, FunctionSignature, Label, SingleType},
parser::ast::Var,
Expand Down
2 changes: 1 addition & 1 deletion language/move-compiler/src/cfgir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<'env> Context<'env> {
// Returns the blocks inserted in insertion ordering
pub fn finish_blocks(&mut self) -> (Label, BasicBlocks, Vec<(Label, BlockInfo)>) {
self.next_label = None;
let start = mem::replace(&mut self.start, None);
let start = self.start.take();
let blocks = mem::take(&mut self.blocks);
let block_ordering = mem::take(&mut self.block_ordering);
let block_info = mem::take(&mut self.block_info);
Expand Down
24 changes: 12 additions & 12 deletions language/move-compiler/src/command_line/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ enum PassResult {
Expansion(expansion::ast::Program),
Naming(naming::ast::Program),
Typing(typing::ast::Program),
HLIR(hlir::ast::Program),
CFGIR(cfgir::ast::Program),
Hlir(hlir::ast::Program),
Cfgir(cfgir::ast::Program),
Compilation(Vec<AnnotatedCompiledUnit>, /* warnings */ Diagnostics),
}

Expand Down Expand Up @@ -394,8 +394,8 @@ ast_stepped_compilers!(
),
(PASS_NAMING, naming, Naming, at_naming, new_at_naming),
(PASS_TYPING, typing, Typing, at_typing, new_at_typing),
(PASS_HLIR, hlir, HLIR, at_hlir, new_at_hlir),
(PASS_CFGIR, cfgir, CFGIR, at_cfgir, new_at_cfgir)
(PASS_HLIR, hlir, Hlir, at_hlir, new_at_hlir),
(PASS_CFGIR, cfgir, Cfgir, at_cfgir, new_at_cfgir)
);

impl<'a> SteppedCompiler<'a, PASS_COMPILATION> {
Expand Down Expand Up @@ -458,11 +458,11 @@ pub fn construct_pre_compiled_lib<Paths: Into<Symbol>, NamedAddress: Into<Symbol
assert!(typing.is_none());
typing = Some(tprog.clone())
}
PassResult::HLIR(hprog) => {
PassResult::Hlir(hprog) => {
assert!(hlir.is_none());
hlir = Some(hprog.clone());
}
PassResult::CFGIR(cprog) => {
PassResult::Cfgir(cprog) => {
assert!(cfgir.is_none());
cfgir = Some(cprog.clone());
}
Expand Down Expand Up @@ -728,8 +728,8 @@ impl PassResult {
PassResult::Expansion(_) => PASS_EXPANSION,
PassResult::Naming(_) => PASS_NAMING,
PassResult::Typing(_) => PASS_TYPING,
PassResult::HLIR(_) => PASS_HLIR,
PassResult::CFGIR(_) => PASS_CFGIR,
PassResult::Hlir(_) => PASS_HLIR,
PassResult::Cfgir(_) => PASS_CFGIR,
PassResult::Compilation(_, _) => PASS_COMPILATION,
}
}
Expand Down Expand Up @@ -794,23 +794,23 @@ fn run(
run(
compilation_env,
pre_compiled_lib,
PassResult::HLIR(hprog),
PassResult::Hlir(hprog),
until,
result_check,
)
}
PassResult::HLIR(hprog) => {
PassResult::Hlir(hprog) => {
let cprog = cfgir::translate::program(compilation_env, pre_compiled_lib, hprog);
compilation_env.check_diags_at_or_above_severity(Severity::NonblockingError)?;
run(
compilation_env,
pre_compiled_lib,
PassResult::CFGIR(cprog),
PassResult::Cfgir(cprog),
until,
result_check,
)
}
PassResult::CFGIR(cprog) => {
PassResult::Cfgir(cprog) => {
let compiled_units =
to_bytecode::translate::program(compilation_env, pre_compiled_lib, cprog);
compilation_env.check_diags_at_or_above_severity(Severity::NonblockingError)?;
Expand Down
Loading

0 comments on commit 9810e8e

Please sign in to comment.