Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rex4539 committed Feb 10, 2025
1 parent 1fdf630 commit 7644add
Show file tree
Hide file tree
Showing 30 changed files with 108 additions and 111 deletions.
2 changes: 1 addition & 1 deletion forc-pkg/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ fn implicit_std_dep() -> Dependency {

if let Some((_, build_metadata)) = det.tag.as_ref().and_then(|tag| tag.split_once('+')) {
// Nightlies are in the format v<version>+nightly.<date>.<hash>
let rev = build_metadata.split('.').last().map(|r| r.to_string());
let rev = build_metadata.split('.').next_back().map(|r| r.to_string());

// If some revision is available and parsed from the 'nightly' build metadata,
// we always prefer the revision over the tag.
Expand Down
4 changes: 2 additions & 2 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl MemberFilter {
TreeType::Predicate => self.build_predicates,
TreeType::Script => self.build_scripts,
TreeType::Contract => self.build_contracts,
TreeType::Library { .. } => self.build_libraries,
TreeType::Library => self.build_libraries,
},
Err(_) => true,
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ fn validate_dep_manifest(
// Check if the dependency is either a library or a contract declared as a contract dependency
match (&dep_program_type, &dep_edge.kind) {
(TreeType::Contract, DepKind::Contract { salt: _ })
| (TreeType::Library { .. }, DepKind::Library) => {}
| (TreeType::Library, DepKind::Library) => {}
_ => bail!(
"\"{}\" is declared as a {} dependency, but is actually a {}",
dep.name,
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-debug/src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub async fn cmd_step(state: &mut State, mut args: Vec<String>) -> Result<()> {
// Determine whether to enable or disable single stepping
let enable = args
.first()
.map_or(true, |v| !["off", "no", "disable"].contains(&v.as_str()));
.is_none_or(|v| !["off", "no", "disable"].contains(&v.as_str()));

// Call the client
state
Expand Down
8 changes: 4 additions & 4 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ pub fn path_lock<X: AsRef<Path>>(path: X) -> Result<fd_lock::RwLock<File>> {

pub fn program_type_str(ty: &TreeType) -> &'static str {
match ty {
TreeType::Script {} => "script",
TreeType::Contract {} => "contract",
TreeType::Predicate {} => "predicate",
TreeType::Library { .. } => "library",
TreeType::Script => "script",
TreeType::Contract => "contract",
TreeType::Predicate => "predicate",
TreeType::Library => "library",
}
}

Expand Down
2 changes: 1 addition & 1 deletion sway-ast/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl PathType {
self.suffix
.iter()
.map(|s| &s.1)
.last()
.next_back()
.unwrap_or(&self.prefix)
}
}
Expand Down
10 changes: 7 additions & 3 deletions sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_hash::FxHashMap;
use sway_ir::{size_bytes_round_up_to_word_alignment, Constant, ConstantValue, Context, Padding};

use std::{fmt, iter::repeat};
use std::fmt;

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
pub enum EntryName {
Expand Down Expand Up @@ -176,8 +176,12 @@ impl Entry {

let final_padding = self.padding.target_size().saturating_sub(bytes.len());
match self.padding {
Padding::Left { .. } => [repeat(0u8).take(final_padding).collect(), bytes].concat(),
Padding::Right { .. } => [bytes, repeat(0u8).take(final_padding).collect()].concat(),
Padding::Left { .. } => {
[std::iter::repeat_n(0u8, final_padding).collect(), bytes].concat()
}
Padding::Right { .. } => {
[bytes, std::iter::repeat_n(0u8, final_padding).collect()].concat()
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
// XXX not required after we have FuelVM specific verifier.
if !key
.get_type(self.context)
.map_or(true, |key_ty| key_ty.is_ptr(self.context))
.is_none_or(|key_ty| key_ty.is_ptr(self.context))
{
return Err(CompileError::Internal(
"Key value for state clear is not a pointer.",
Expand Down Expand Up @@ -1923,7 +1923,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
// XXX not required after we have FuelVM specific verifier.
if !key
.get_type(self.context)
.map_or(true, |key_ty| key_ty.is_ptr(self.context))
.is_none_or(|key_ty| key_ty.is_ptr(self.context))
{
return Err(CompileError::Internal(
"Key value for state load word is not a pointer.",
Expand Down Expand Up @@ -1993,7 +1993,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {

if stored_val
.get_type(self.context)
.map_or(true, |ty| !self.is_copy_type(&ty))
.is_none_or(|ty| !self.is_copy_type(&ty))
{
Err(CompileError::Internal(
"Attempt to store a non-copy type.",
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/asm_generation/fuel/register_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl RegisterPool {
/// ===============================================================================================
/// 1. create a graph node for every virtual register used.
/// 2. for a MOVE "v <= c" with live_out virtual registers b1, ... bn for v:
/// add edges (v, b_1), ..., (v, b_n) for any b_i different from c.
/// add edges (v, b_1), ..., (v, b_n) for any b_i different from c.
/// 3. for non-MOVE def of virtual register v with live_out virtual registers b_1, ..., b_n:
/// add edges (v, b_1), ..., (v, b_n)
/// add edges (v, b_1), ..., (v, b_n)
///
/// ===============================================================================================
pub(crate) fn create_interference_graph(
Expand Down Expand Up @@ -384,8 +384,8 @@ fn compute_def_use_points(ops: &[Op]) -> FxHashMap<VirtualRegister, (Vec<usize>,
/// 2. Remove node n and all its edges from the graph
/// - This may make some new nodes have fewer than k neighbours which is nice.
/// 3. If some vertex n still has k or more neighbors, then the graph may not be k colorable.
/// We still add it to the stack as is, as a potential spill. When popping, if we still
/// can't colour it, then it becomes an actual spill.
/// We still add it to the stack as is, as a potential spill. When popping, if we still
/// can't colour it, then it becomes an actual spill.
///
/// ===============================================================================================
///
Expand Down
4 changes: 1 addition & 3 deletions sway-core/src/asm_lang/allocated_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,7 @@ impl AllocatedOp {
/* Non-VM Instructions */
BLOB(a) => {
return FuelAsmData::Instructions(
std::iter::repeat(op::NOOP::new().into())
.take(a.value() as usize)
.collect(),
std::iter::repeat_n(op::NOOP::new().into(), a.value() as usize).collect(),
)
}
ConfigurablesOffsetPlaceholder => {
Expand Down
14 changes: 7 additions & 7 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn is_entry_point(node: &TyAstNode, decl_engine: &DeclEngine, tree_type: &TreeTy
_ => false,
}
}
TreeType::Contract | TreeType::Library { .. } => match node {
TreeType::Contract | TreeType::Library => match node {
TyAstNode {
content:
TyAstNodeContent::Declaration(TyDecl::FunctionDecl(FunctionDecl { decl_id })),
Expand Down Expand Up @@ -140,15 +140,15 @@ impl<'cfg> ControlFlowGraph<'cfg> {
connections_count
.get(n)
.cloned()
.map_or(true, |count| count <= 1)
.is_none_or(|count| count <= 1)
}
ControlFlowGraphNode::FunctionParameter { .. } => {
// Consider variables declarations dead when count is not greater than 1
// Function param always has the function pointing to them
connections_count
.get(n)
.cloned()
.map_or(true, |count| count <= 1)
.is_none_or(|count| count <= 1)
}
_ => false,
}
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<'cfg> ControlFlowGraph<'cfg> {
connections_count
.get(n)
.cloned()
.map_or(true, |count| count > 1)
.is_none_or(|count| count > 1)
}
}
ControlFlowGraphNode::ProgramNode {
Expand Down Expand Up @@ -708,7 +708,7 @@ fn connect_struct_declaration<'eng: 'cfg, 'cfg>(
//
// this is important because if the struct is public, you want to be able to signal that all
// fields are accessible by just adding an edge to the struct declaration node
if matches!(tree_type, TreeType::Contract | TreeType::Library { .. })
if matches!(tree_type, TreeType::Contract | TreeType::Library)
&& *visibility == Visibility::Public
{
for (_name, node) in &field_nodes {
Expand Down Expand Up @@ -792,7 +792,7 @@ fn connect_impl_trait<'eng: 'cfg, 'cfg>(
if let Some(trait_entry) = trait_entry.clone() {
matches!(
trait_entry.module_tree_type,
TreeType::Library { .. } | TreeType::Contract
TreeType::Library | TreeType::Contract
)
} else {
// trait_entry not found which means it is an external trait.
Expand All @@ -801,7 +801,7 @@ fn connect_impl_trait<'eng: 'cfg, 'cfg>(
true
}
} else {
matches!(tree_type, TreeType::Library { .. } | TreeType::Contract)
matches!(tree_type, TreeType::Library | TreeType::Contract)
};
if add_edge_to_fn_decl {
graph.add_edge(entry_node, fn_decl_entry_node, "".into());
Expand Down
9 changes: 5 additions & 4 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,11 @@ fn compile_fn(
// Convert the name.
param.name.as_str().into(),
// Convert the type further to a pointer if it's a reference.
param
.is_reference
.then(|| Type::new_ptr(context, ty))
.unwrap_or(ty),
if param.is_reference {
Type::new_ptr(context, ty)
} else {
ty
},
// Convert the span to a metadata index.
md_mgr.span_to_md(context, &param.name.span()),
)
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'eng> FnCompiler<'eng> {
}),
}
}
ty::TyExpressionVariant::Continue { .. } => match self.block_to_continue_to {
ty::TyExpressionVariant::Continue => match self.block_to_continue_to {
// If `self.block_to_continue_to` is not None, then it has been set inside
// a loop and the use of `continue` here is legal, so create a branch
// instruction. Error out otherwise.
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/ir_generation/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub fn serialize_to_storage_slots(
let mut packed = serialize_to_words(constant, context, ty, InByte8Padding::default());
packed.extend(vec![
Bytes8::new([0; 8]);
((packed.len() + 3) / 4) * 4 - packed.len()
packed.len().div_ceil(4) * 4 - packed.len()
]);

assert!(packed.len() % 4 == 0);
Expand All @@ -257,7 +257,7 @@ pub fn serialize_to_storage_slots(
);

let storage_key = get_storage_key(storage_field_names, key, experimental);
(0..(type_size_in_bytes + 31) / 32)
(0..type_size_in_bytes.div_ceil(32))
.map(|i| add_to_b256(storage_key, i))
.zip((0..packed.len() / 4).map(|i| {
Bytes32::new(
Expand Down Expand Up @@ -310,7 +310,7 @@ fn serialize_to_words(
ConstantValue::String(s) if ty.is_string_array(context) => {
// Turn the bytes into serialized words (Bytes8) and right pad it to the word boundary.
let mut s = s.clone();
s.extend(vec![0; ((s.len() + 7) / 8) * 8 - s.len()]);
s.extend(vec![0; s.len().div_ceil(8) * 8 - s.len()]);

assert!(s.len() % 8 == 0);

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/ty/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl TyProgram {
// Some checks that are specific to non-contracts
if kind != parsed::TreeType::Contract {
// impure functions are disallowed in non-contracts
if !matches!(kind, parsed::TreeType::Library { .. }) {
if !matches!(kind, parsed::TreeType::Library) {
for err in disallow_impure_functions(decl_engine, &declarations, &entries) {
handler.emit_err(err);
}
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ pub(crate) fn is_ty_module_cache_up_to_date(
let cache_up_to_date = build_config
.and_then(|x| x.lsp_mode.as_ref())
.and_then(|lsp| lsp.file_versions.get(path.as_ref()))
.map_or(true, |version| {
version.map_or(true, |v| typed.version.is_some_and(|tv| v <= tv))
.is_none_or(|version| {
version.is_none_or(|v| typed.version.is_some_and(|tv| v <= tv))
});

// If the cache is up to date, recursively check all dependencies
Expand Down Expand Up @@ -499,7 +499,7 @@ pub(crate) fn is_parse_module_cache_up_to_date(
// - If there's no cached version (entry.parsed.version is None), the cache is outdated.
// - If there's a cached version, compare them: cache is up-to-date if the LSP file version
// is not greater than the cached version.
version.map_or(true, |v| entry.parsed.version.is_some_and(|ev| v <= ev))
version.is_none_or(|v| entry.parsed.version.is_some_and(|ev| v <= ev))
},
);

Expand Down Expand Up @@ -802,7 +802,7 @@ pub fn compile_to_ast(
};

// If tests are not enabled, exclude them from `parsed_program`.
if build_config.map_or(true, |config| !config.include_tests) {
if build_config.is_none_or(|config| !config.include_tests) {
parsed_program.exclude_tests(engines);
}

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/query_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl QueryEngine {
ident
.span()
.source_id()
.map_or(true, |id| id.program_id() != *program_id)
.is_none_or(|id| id.program_id() != *program_id)
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,9 @@ impl TyImplSelfOrTrait {
);

// Do a topological sort to compute an ordered list of nodes (by function calls).
let sorted = match petgraph::algo::toposort(&sub_graph, None) {
Ok(value) => Some(value),
// If the dependency graph contains cycles, then this means there are recursive
// function calls, which we will report later.
Err(_) => None,
};
let sorted = petgraph::algo::toposort(&sub_graph, None).ok();
// If the dependency graph contains cycles, then this means there are recursive
// function calls, which we will report later.

Ok(sorted)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ where
/// 1. Sort the intervals based on increasing order of starting time.
/// 2. Push the first interval on to a stack.
/// 3. For each interval do the following
/// 3a. If the current interval does not overlap with the stack
/// top, push it.
/// 3b. If the current interval overlaps with stack top (or is within ± 1)
/// and ending time of current interval is more than that of stack top,
/// update stack top with the ending time of current interval.
/// 3a. If the current interval does not overlap with the stack
/// top, push it.
/// 3b. If the current interval overlaps with stack top (or is within ± 1)
/// and ending time of current interval is more than that of stack top,
/// update stack top with the ending time of current interval.
/// 4. At the end stack contains the merged intervals.
fn condense_ranges(
handler: &Handler,
Expand Down
Loading

0 comments on commit 7644add

Please sign in to comment.