Skip to content

Commit

Permalink
Fix clippy warnings for Rust 1.84.0 (#6877)
Browse files Browse the repository at this point in the history
## Description

Fix clippy warnings for Rust 1.84.0
  • Loading branch information
tritao authored Feb 3, 2025
1 parent 8c5afa3 commit 9df66ce
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl DapServer {
});
if let Some(existing_bp) = existing_breakpoints
.iter()
.find(|bp| bp.line.map_or(false, |line| line == source_bp.line))
.find(|bp| (bp.line == Some(source_bp.line)))
{
Breakpoint {
verified,
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-migrate/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) struct MutProgramInfo<'a> {
pub engines: &'a Engines,
}

impl<'a> ProgramInfo<'a> {
impl ProgramInfo<'_> {
pub(crate) fn as_mut(&mut self) -> MutProgramInfo {
MutProgramInfo {
lexed_program: &mut self.lexed_program,
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-migrate/src/modifying/storage_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ToInKey for Expr {
}
}

impl<'a> Modifier<'a, StorageField> {
impl Modifier<'_, StorageField> {
pub(crate) fn with_in_key<K: ToInKey>(&mut self, key: K) -> &mut Self {
// If the `in` token already exists, just replace the key and leave the `in`
// token as is. Place the key after the `in` token.
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
if !val
.get_type(self.context)
.and_then(|val_ty| key.get_type(self.context).map(|key_ty| (val_ty, key_ty)))
.map_or(false, |(val_ty, key_ty)| {
.is_some_and(|(val_ty, key_ty)| {
val_ty.is_ptr(self.context) && key_ty.is_ptr(self.context)
})
{
Expand Down Expand Up @@ -1958,7 +1958,7 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
if !store_val
.get_type(self.context)
.and_then(|val_ty| key.get_type(self.context).map(|key_ty| (val_ty, key_ty)))
.map_or(false, |(val_ty, key_ty)| {
.is_some_and(|(val_ty, key_ty)| {
val_ty.is_uint64(self.context) && key_ty.is_ptr(self.context)
})
{
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/fuel/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl FuelAsmBuilder<'_, '_> {
// XXX val.get_type() should be a pointer if it's not meant to be loaded.
if val
.get_type(self.context)
.map_or(false, |t| self.is_copy_type(&t))
.is_some_and(|t| self.is_copy_type(&t))
{
self.cur_bytecode.push(Op {
opcode: either::Either::Left(VirtualOp::LW(
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'cfg> ControlFlowGraph<'cfg> {
connections_count
.get(n)
.cloned()
.map_or(false, |count| count > 1)
.is_some_and(|count| count > 1)
}
}
ControlFlowGraphNode::FunctionParameter {
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<'cfg> ControlFlowGraph<'cfg> {
connections_count
.get(n)
.cloned()
.map_or(false, |count| count > 0)
.is_some_and(|count| count > 0)
}
_ => false,
}
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl<'eng> FnCompiler<'eng> {
if val
.value
.get_type(context)
.map_or(false, |ty| ty.is_ptr(context))
.is_some_and(|ty| ty.is_ptr(context))
{
let load_val = self.current_block.append(context).load(val.value);
TerminatorValue::new(load_val, context)
Expand Down Expand Up @@ -2540,7 +2540,7 @@ impl<'eng> FnCompiler<'eng> {

let ptr_as_int = if ref_value
.get_type(context)
.map_or(false, |ref_value_type| ref_value_type.is_ptr(context))
.is_some_and(|ref_value_type| ref_value_type.is_ptr(context))
{
// We are dereferencing a reference variable and we got a pointer to it.
// To get the address the reference is pointing to we need to load the value.
Expand Down Expand Up @@ -4262,7 +4262,7 @@ impl<'eng> FnCompiler<'eng> {
let init_type = self.engines.te().get_unaliased(init_expr.return_type);
if initializer_val
.get_type(context)
.map_or(false, |ty| ty.is_ptr(context))
.is_some_and(|ty| ty.is_ptr(context))
&& (init_type.is_copy_type() || init_type.is_reference())
{
// It's a pointer to a copy type, or a reference behind a pointer. We need to dereference it.
Expand Down
15 changes: 6 additions & 9 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ pub(crate) fn is_ty_module_cache_up_to_date(
) -> bool {
let cache = engines.qe().module_cache.read();
let key = ModuleCacheKey::new(path.clone(), include_tests);
cache.get(&key).map_or(false, |entry| {
entry.typed.as_ref().map_or(false, |typed| {
cache.get(&key).is_some_and(|entry| {
entry.typed.as_ref().is_some_and(|typed| {
// Check if the cache is up to date based on file versions
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.map_or(false, |tv| v <= tv))
version.map_or(true, |v| typed.version.is_some_and(|tv| v <= tv))
});

// If the cache is up to date, recursively check all dependencies
Expand All @@ -472,7 +472,7 @@ pub(crate) fn is_parse_module_cache_up_to_date(
) -> bool {
let cache = engines.qe().module_cache.read();
let key = ModuleCacheKey::new(path.clone(), include_tests);
cache.get(&key).map_or(false, |entry| {
cache.get(&key).is_some_and(|entry| {
// Determine if the cached dependency information is still valid
let cache_up_to_date = build_config
.and_then(|x| x.lsp_mode.as_ref())
Expand All @@ -498,7 +498,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.map_or(false, |ev| v <= ev))
version.map_or(true, |v| entry.parsed.version.is_some_and(|ev| v <= ev))
},
);

Expand Down Expand Up @@ -601,10 +601,7 @@ pub fn parsed_to_ast(
experimental,
);

let mut typed_program = match typed_program_opt {
Ok(typed_program) => typed_program,
Err(e) => return Err(e),
};
let mut typed_program = typed_program_opt?;

check_should_abort(handler, retrigger_compilation.clone()).map_err(|error| {
TypeCheckFailed {
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 @@ -211,7 +211,7 @@ impl QueryEngine {
pub fn clear_module(&mut self, source_id: &SourceId) {
self.function_cache
.write()
.retain(|(ident, _), _| ident.span().source_id().map_or(true, |id| id != source_id));
.retain(|(ident, _), _| (ident.span().source_id() != Some(source_id)));
}

/// Removes all data associated with the `program_id` from the function cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,7 @@ where
}

fn encompasses_all(&self, others: &[Range<T>]) -> bool {
others
.iter()
.map(|other| self.encompasses(other))
.all(|x| x)
others.iter().all(|other| self.encompasses(other))
}

/// Checks to see if two ranges are within ± 1 of one another. There are 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,7 @@ impl ty::TyExpression {
Self::type_check_deref(handler, ctx.by_ref(), expr, span)
}
};
let mut typed_expression = match res {
Ok(r) => r,
Err(e) => return Err(e),
};
let mut typed_expression = res?;

// if the return type cannot be cast into the annotation type then it is a type error
ctx.unify_with_type_annotation(handler, typed_expression.return_type, &expr_span);
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/semantic_analysis/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl ty::TyModule {

// Create a cache key and get the module cache
let path = engines.se().get_path(source_id);
let include_tests = build_config.map_or(false, |x| x.include_tests);
let include_tests = build_config.is_some_and(|x| x.include_tests);
let key = ModuleCacheKey::new(path.clone().into(), include_tests);
let cache = engines.qe().module_cache.read();
cache.get(&key).and_then(|entry| {
Expand Down Expand Up @@ -475,7 +475,7 @@ impl ty::TyModule {
.and_then(|lsp| lsp.file_versions.get(&path).copied())
.flatten();

let include_tests = build_config.map_or(false, |x| x.include_tests);
let include_tests = build_config.is_some_and(|x| x.include_tests);
let key = ModuleCacheKey::new(path.clone().into(), include_tests);
engines.qe().update_typed_module_cache_entry(
&key,
Expand Down
7 changes: 1 addition & 6 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,7 @@ impl TraitMap {
for key in keys {
let vec = &self.trait_impls[key];
for entry in vec {
if entry
.key
.trait_decl_span
.as_ref()
.map_or(false, |span| span == &trait_decl_span)
{
if entry.key.trait_decl_span.as_ref() == Some(&trait_decl_span) {
let trait_map_vec =
if let Some(trait_map_vec) = trait_map.trait_impls.get_mut(key) {
trait_map_vec
Expand Down
5 changes: 1 addition & 4 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,7 @@ impl TypeInfo {
engines,
error_msg_span,
);
let name = match name {
Ok(name) => name,
Err(e) => return Err(e),
};
let name = name?;
format!("a[{};{}]", name, length.val())
}
RawUntypedPtr => "rawptr".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/analysis/dominator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn compute_dom_tree(
// "p" may not be reachable, and hence not in dom_tree.
po.block_to_po
.get(p)
.map_or(false, |p_po| *p_po > po.block_to_po[b])
.is_some_and(|p_po| *p_po > po.block_to_po[b])
})
.cloned()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/analysis/memory_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn get_symbols(context: &Context, val: Value, gep_only: bool) -> ReferredSymbols
}
}

if !val.get_type(context).map_or(false, |t| t.is_ptr(context)) {
if !val.get_type(context).is_some_and(|t| t.is_ptr(context)) {
return ReferredSymbols::new(true, IndexSet::default());
}

Expand Down
2 changes: 1 addition & 1 deletion sway-ir/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Block {
/// Those instructions are: [InstOp::Ret], [FuelVmInstruction::Retd],
/// [FuelVmInstruction::JmpMem], and [FuelVmInstruction::Revert]).
pub fn is_terminated_by_return_or_revert(&self, context: &Context) -> bool {
self.get_terminator(context).map_or(false, |i| {
self.get_terminator(context).is_some_and(|i| {
matches!(
i,
Instruction {
Expand Down
8 changes: 4 additions & 4 deletions sway-ir/src/optimize/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn combine_cmp(context: &mut Context, function: &Function) -> bool {
},
);

candidate.map_or(false, |(inst_val, block, cn_replace)| {
candidate.is_some_and(|(inst_val, block, cn_replace)| {
// Replace this `cmp` instruction with a constant.
inst_val.replace(
context,
Expand Down Expand Up @@ -240,7 +240,7 @@ fn combine_binary_op(context: &mut Context, function: &Function) -> bool {
);

// Replace this binary op instruction with a constant.
candidate.map_or(false, |(inst_val, block, new_value)| {
candidate.is_some_and(|(inst_val, block, new_value)| {
inst_val.replace(context, ValueDatum::Constant(new_value));
block.remove_instruction(context, inst_val);
true
Expand Down Expand Up @@ -282,7 +282,7 @@ fn remove_useless_binary_op(context: &mut Context, function: &Function) -> bool
},
);

candidate.map_or(false, |(block, old_value, new_value)| {
candidate.is_some_and(|(block, old_value, new_value)| {
let replace_map = FxHashMap::from_iter([(old_value, new_value)]);
function.replace_values(context, &replace_map, None);

Expand Down Expand Up @@ -324,7 +324,7 @@ fn combine_unary_op(context: &mut Context, function: &Function) -> bool {
);

// Replace this unary op instruction with a constant.
candidate.map_or(false, |(inst_val, block, new_value)| {
candidate.is_some_and(|(inst_val, block, new_value)| {
inst_val.replace(context, ValueDatum::Constant(new_value));
block.remove_instruction(context, inst_val);
true
Expand Down
13 changes: 7 additions & 6 deletions sway-ir/src/optimize/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,13 @@ fn candidate_symbols(context: &Context, function: Function) -> FxHashSet<Symbol>
}
continue;
}
if combine_indices(context, *ptr).map_or(false, |indices| {
indices.iter().any(|idx| !idx.is_constant(context))
}) || ptr.match_ptr_type(context).is_some_and(|pointee_ty| {
super::target_fuel::is_demotable_type(context, &pointee_ty)
&& !matches!(inst.op, InstOp::MemCopyVal { .. })
}) {
if combine_indices(context, *ptr)
.is_some_and(|indices| indices.iter().any(|idx| !idx.is_constant(context)))
|| ptr.match_ptr_type(context).is_some_and(|pointee_ty| {
super::target_fuel::is_demotable_type(context, &pointee_ty)
&& !matches!(inst.op, InstOp::MemCopyVal { .. })
})
{
candidates.remove(syms.iter().next().unwrap());
}
}
Expand Down
4 changes: 2 additions & 2 deletions sway-ir/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ impl InstructionVerifier<'_, '_> {
let val_ty = value
.get_type(self.context)
.ok_or(IrError::VerifyBitcastUnknownSourceType)?;
if self.type_bit_size(&val_ty).map_or(false, |sz| sz > 64)
|| self.type_bit_size(ty).map_or(false, |sz| sz > 64)
if self.type_bit_size(&val_ty).is_some_and(|sz| sz > 64)
|| self.type_bit_size(ty).is_some_and(|sz| sz > 64)
{
Err(IrError::VerifyBitcastBetweenInvalidTypes(
val_ty.as_string(self.context),
Expand Down
6 changes: 3 additions & 3 deletions sway-lsp/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ pub fn parse_lexed_program(
.map(|path| {
item.span()
.source_id()
.map_or(false, |id| ctx.engines.se().get_path(id) == *path)
.is_some_and(|id| ctx.engines.se().get_path(id) == *path)
})
.unwrap_or(true)
};
Expand Down Expand Up @@ -562,7 +562,7 @@ fn parse_ast_to_tokens(
.map(|path| {
node.span
.source_id()
.map_or(false, |id| ctx.engines.se().get_path(id) == *path)
.is_some_and(|id| ctx.engines.se().get_path(id) == *path)
})
.unwrap_or(true)
};
Expand Down Expand Up @@ -597,7 +597,7 @@ fn parse_ast_to_typed_tokens(
.map(|path| {
node.span
.source_id()
.map_or(false, |id| ctx.engines.se().get_path(id) == *path)
.is_some_and(|id| ctx.engines.se().get_path(id) == *path)
})
.unwrap_or(true)
};
Expand Down
7 changes: 2 additions & 5 deletions sway-lsp/src/core/token_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,8 @@ impl<'a> TokenMap {

/// Remove all tokens for the given file from the token map.
pub fn remove_tokens_for_file(&self, path_to_remove: &PathBuf) {
self.0.retain(|key, _value| {
key.path
.as_ref()
.map_or(true, |path| path != path_to_remove)
});
self.0
.retain(|key, _value| (key.path.as_ref() != Some(path_to_remove)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sway-parse/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn lex_commented(
let not_is_single_underscore = character != '_'
|| l.stream
.peek()
.map_or(false, |(_, next)| next.is_xid_continue());
.is_some_and(|(_, next)| next.is_xid_continue());
if not_is_single_underscore {
// Consume until we hit other than `XID_CONTINUE`.
while l.stream.next_if(|(_, c)| c.is_xid_continue()).is_some() {}
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn check_test_forc_tomls(all_tests_dir: &Path) -> Result<()> {
.and_then(|t| {
t.values().find(|v| {
v.get("package")
.map_or(false, |p| p.as_str().unwrap_or_default() == lib_name)
.is_some_and(|p| p.as_str().unwrap_or_default() == lib_name)
})
})
{
Expand Down Expand Up @@ -216,7 +216,7 @@ fn check_test_forc_tomls(all_tests_dir: &Path) -> Result<()> {
} else if path.is_file()
&& path
.file_name()
.map(|f| f.to_ascii_lowercase() == "forc.toml")
.map(|f| f.eq_ignore_ascii_case("forc.toml"))
.unwrap_or(false)
{
forc_tomls.push(path.to_path_buf());
Expand Down

0 comments on commit 9df66ce

Please sign in to comment.