Skip to content

Commit

Permalink
Fix new clippy lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentosal committed Jan 24, 2022
1 parent 8b3e5ff commit 5e82c44
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 69 deletions.
7 changes: 2 additions & 5 deletions forc/src/ops/forc_dep_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ async fn check_tagged_dependency(
if current_release.ne(&latest) {
println!(
"[{}] not up-to-date. Current version: {}, latest: {}",
dependency_name,
current_release.to_string(),
latest.to_string()
dependency_name, current_release, latest
);
} else {
println!(
"[{}] up-to-date. Current version: {}",
dependency_name,
current_release.to_string(),
dependency_name, current_release,
);
}

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ mod tests {
let asm_script = format!("{}", asm);
if asm_script != expected {
println!("{}", prettydiff::diff_lines(&expected, &asm_script));
assert!(false);
panic!();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/control_flow_analysis/flow_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ impl std::fmt::Debug for ControlFlowGraphNode {
ControlFlowGraphNode::OrganizationalDominator(s) => s.to_string(),
ControlFlowGraphNode::ProgramNode(node) => format!("{:?}", node),
ControlFlowGraphNode::EnumVariant { variant_name, .. } => {
format!("Enum variant {}", variant_name.to_string())
format!("Enum variant {}", variant_name)
}
ControlFlowGraphNode::MethodDeclaration { method_name, .. } => {
format!("Method {}", method_name.as_str().to_string())
format!("Method {}", method_name.as_str())
}
ControlFlowGraphNode::StructField {
struct_field_name, ..
} => {
format!("Struct field {}", struct_field_name.as_str().to_string())
format!("Struct field {}", struct_field_name.as_str())
}
};
f.write_str(&text)
Expand Down
3 changes: 1 addition & 2 deletions sway-core/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ impl FnCompiler {
if let Some(ptr) = self
.symbol_map
.get(name)
.map(|local_name| self.function.get_local_ptr(context, local_name))
.flatten()
.and_then(|local_name| self.function.get_local_ptr(context, local_name))
{
Ok(if ptr.is_struct_ptr(context) {
self.current_block.ins(context).get_ptr(ptr)
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/parse_tree/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Literal {
Rule::u8_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U8)
.map_err(|e| {
Expand All @@ -78,7 +78,7 @@ impl Literal {
Rule::u16_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U16)
.map_err(|e| {
Expand All @@ -92,7 +92,7 @@ impl Literal {
Rule::u32_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U32)
.map_err(|e| {
Expand All @@ -106,7 +106,7 @@ impl Literal {
Rule::u64_integer => int_inner
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse()
.map(Literal::U64)
.map_err(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ impl TypedExpression {
let enum_name = enum_name[0].clone();
let namespace = namespace.find_module_relative(module_path);
let namespace = namespace.ok(&mut warnings, &mut errors);
namespace.map(|ns| ns.find_enum(&enum_name)).flatten()
namespace.and_then(|ns| ns.find_enum(&enum_name))
};

// now we can see if this thing is a symbol (typed declaration) or reference to an
Expand Down Expand Up @@ -1644,7 +1644,7 @@ impl TypedExpression {
let enum_name = enum_name[0].clone();
let namespace = namespace.find_module_relative(module_path);
let namespace = namespace.ok(&mut warnings, &mut errors);
namespace.map(|ns| ns.find_enum(&enum_name)).flatten()
namespace.and_then(|ns| ns.find_enum(&enum_name))
};
let mut return_type = None;
let mut owned_enum_variant = None;
Expand Down Expand Up @@ -1794,7 +1794,7 @@ mod tests {
use super::*;

fn do_type_check(expr: Expression, type_annotation: TypeId) -> CompileResult<TypedExpression> {
let mut namespace = create_module();
let namespace = create_module();
let self_type = insert_type(TypeInfo::Unknown);
let build_config = BuildConfig {
file_name: Arc::new("test.sw".into()),
Expand Down
19 changes: 8 additions & 11 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,14 @@ fn find_recursive_call_chain(
))
};
}
decl_dependencies
.get(fn_sym)
.map(|deps_set| {
chain.push(fn_sym_ident.clone());
let result = deps_set.deps.iter().find_map(|dep_sym| {
find_recursive_call_chain(decl_dependencies, dep_sym, fn_span, chain)
});
chain.pop();
result
})
.flatten()
decl_dependencies.get(fn_sym).and_then(|deps_set| {
chain.push(fn_sym_ident.clone());
let result = deps_set.deps.iter().find_map(|dep_sym| {
find_recursive_call_chain(decl_dependencies, dep_sym, fn_span, chain)
});
chain.pop();
result
})
} else {
None
}
Expand Down
20 changes: 10 additions & 10 deletions sway-core/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator<Item = &str> {
if ident.is_empty() {
return None;
}
let index = find_camel_case_word_boundary(ident).unwrap_or_else(|| ident.len());
let index = find_camel_case_word_boundary(ident).unwrap_or(ident.len());
let word = &ident[..index];
ident = &ident[index..];
Some(word)
Expand All @@ -27,7 +27,7 @@ fn camel_case_split_words(ident: &str) -> impl Iterator<Item = &str> {

/// Split an identifier of unknown style into words.
fn split_words(ident: &str) -> impl Iterator<Item = &str> {
ident.split('_').map(camel_case_split_words).flatten()
ident.split('_').flat_map(camel_case_split_words)
}

/// Detect whether an identifier is written in snake_case.
Expand Down Expand Up @@ -72,14 +72,14 @@ pub fn to_snake_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
let mut words = split_words(trimmed);
if let Some(word) = words.next() {
ret.extend(word.chars().map(char::to_lowercase).flatten());
ret.extend(word.chars().flat_map(char::to_lowercase));
for word in words {
ret.push('_');
ret.extend(word.chars().map(char::to_lowercase).flatten());
ret.extend(word.chars().flat_map(char::to_lowercase));
}
}
ret
Expand All @@ -91,14 +91,14 @@ pub fn to_screaming_snake_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
let mut words = split_words(trimmed);
if let Some(word) = words.next() {
ret.extend(word.chars().map(char::to_uppercase).flatten());
ret.extend(word.chars().flat_map(char::to_uppercase));
for word in words {
ret.push('_');
ret.extend(word.chars().map(char::to_uppercase).flatten());
ret.extend(word.chars().flat_map(char::to_uppercase));
}
}
ret
Expand All @@ -110,13 +110,13 @@ pub fn to_upper_camel_case(ident: &str) -> String {
let mut ret = String::with_capacity(ident.len());

let (leading_underscores, trimmed) =
ident.split_at(ident.find(|c| c != '_').unwrap_or_else(|| ident.len()));
ident.split_at(ident.find(|c| c != '_').unwrap_or(ident.len()));
ret.push_str(leading_underscores);
for word in split_words(trimmed) {
let mut chars = word.chars();
if let Some(c) = chars.next() {
ret.extend(c.to_uppercase());
ret.extend(chars.map(char::to_lowercase).flatten());
ret.extend(chars.flat_map(char::to_lowercase));
}
}
ret
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/type_engine/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl TypeInfo {
array_elem_count_pair
.as_str()
.trim()
.replace("_", "")
.replace('_', "")
.parse::<usize>()
// Could probably just .unwrap() here since it will succeed.
.map_or_else(
Expand Down
20 changes: 8 additions & 12 deletions sway-ir/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,14 @@ impl Block {
///
/// Returns `None` if block is empty.
pub fn get_term_inst<'a>(&self, context: &'a Context) -> Option<&'a Instruction> {
context.blocks[self.0]
.instructions
.last()
.map(|val| {
// It's guaranteed to be an instruction value.
if let ValueContent::Instruction(term_inst) = &context.values[val.0] {
Some(term_inst)
} else {
None
}
})
.flatten()
context.blocks[self.0].instructions.last().and_then(|val| {
// It's guaranteed to be an instruction value.
if let ValueContent::Instruction(term_inst) = &context.values[val.0] {
Some(term_inst)
} else {
None
}
})
}

/// Replace a value within this block.
Expand Down
3 changes: 1 addition & 2 deletions sway-ir/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ impl Context {
pub fn get_aggregate_index(&self, aggregate: &Aggregate, field_name: &str) -> Option<u64> {
self.aggregate_symbols
.get(aggregate)
.map(|idx_map| idx_map.get(field_name).copied())
.flatten()
.and_then(|idx_map| idx_map.get(field_name).copied())
}

/// Get a globally unique symbol.
Expand Down
19 changes: 8 additions & 11 deletions sway-ir/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,20 @@ impl Instruction {
Type::Struct(aggregate) => Some(*aggregate),
_otherwise => None,
},
Instruction::ExtractElement { ty, .. } => ty
.get_elem_type(context)
.map(|ty| match ty {
Instruction::ExtractElement { ty, .. } => {
ty.get_elem_type(context).and_then(|ty| match ty {
Type::Array(nested_aggregate) => Some(nested_aggregate),
Type::Struct(nested_aggregate) => Some(nested_aggregate),
_otherwise => None,
})
.flatten(),
}
Instruction::ExtractValue { ty, indices, .. } => {
// This array is a field in a struct or element in an array.
ty.get_field_type(context, indices)
.map(|ty| match ty {
Type::Array(nested_aggregate) => Some(nested_aggregate),
Type::Struct(nested_aggregate) => Some(nested_aggregate),
_otherwise => None,
})
.flatten()
ty.get_field_type(context, indices).and_then(|ty| match ty {
Type::Array(nested_aggregate) => Some(nested_aggregate),
Type::Struct(nested_aggregate) => Some(nested_aggregate),
_otherwise => None,
})
}

// Unknown aggregate instruction. Adding these as we come across them...
Expand Down
3 changes: 1 addition & 2 deletions sway-ir/src/irtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Aggregate {
/// Get the type of (nested) aggregate fields, if found.
pub fn get_field_type(&self, context: &Context, indices: &[u64]) -> Option<Type> {
indices.iter().fold(Some(Type::Struct(*self)), |ty, idx| {
ty.map(|ty| match ty {
ty.and_then(|ty| match ty {
Type::Struct(agg) => context.aggregates[agg.0]
.field_types()
.get(*idx as usize)
Expand All @@ -121,7 +121,6 @@ impl Aggregate {
// Trying to index a non-aggregate.
_otherwise => None,
})
.flatten()
})
}

Expand Down
3 changes: 1 addition & 2 deletions sway-ir/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl Context {
if !last_is_term || num_terms != 1 {
Err(format!(
"Block {} must have single terminator as its last instruction.\n\n{}",
block.label,
self.to_string()
block.label, self
))
} else {
Ok(())
Expand Down

0 comments on commit 5e82c44

Please sign in to comment.