Skip to content

Commit

Permalink
Apply new clippy suggestions from new clippy update (FuelLabs#4259)
Browse files Browse the repository at this point in the history
## Description

This PR applies new clippy suggestions from a new clippy update.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: emilyaherbert <[email protected]>
  • Loading branch information
emilyaherbert and emilyaherbert authored Mar 9, 2023
1 parent 6dedd55 commit 264e4ec
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 45 deletions.
1 change: 0 additions & 1 deletion forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ impl TestResult {
let file_str = fs::read_to_string(&*file_path)?;
let line_number = file_str[..span_start]
.chars()
.into_iter()
.filter(|&c| c == '\n')
.count();
Ok(TestDetails {
Expand Down
17 changes: 7 additions & 10 deletions sway-core/src/ir_generation/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ pub fn serialize_to_storage_slots(
// Return a list of `StorageSlot`s
// First get the keys then get the values
(0..(ir_type_size_in_bytes(context, ty) + 31) / 32)
.into_iter()
.map(|i| add_to_b256(get_storage_key(ix, indices), i))
.zip((0..packed.len() / 4).into_iter().map(|i| {
.zip((0..packed.len() / 4).map(|i| {
Bytes32::new(
Vec::from_iter((0..4).into_iter().flat_map(|j| *packed[4 * i + j]))
Vec::from_iter((0..4).flat_map(|j| *packed[4 * i + j]))
.try_into()
.unwrap(),
)
Expand Down Expand Up @@ -178,11 +177,9 @@ pub fn serialize_to_words(constant: &Constant, context: &Context, ty: &Type) ->
ConstantValue::Uint(n) if ty.is_uint(context) => {
vec![Bytes8::new(n.to_be_bytes())]
}
ConstantValue::B256(b) if ty.is_b256(context) => Vec::from_iter(
(0..4)
.into_iter()
.map(|i| Bytes8::new(b[8 * i..8 * i + 8].try_into().unwrap())),
),
ConstantValue::B256(b) if ty.is_b256(context) => {
Vec::from_iter((0..4).map(|i| Bytes8::new(b[8 * i..8 * i + 8].try_into().unwrap())))
}
ConstantValue::String(s) if ty.is_string(context) => {
// Turn the bytes into serialized words (Bytes8).
let mut s = s.clone();
Expand All @@ -191,9 +188,9 @@ pub fn serialize_to_words(constant: &Constant, context: &Context, ty: &Type) ->
assert!(s.len() % 8 == 0);

// Group into words
Vec::from_iter((0..s.len() / 8).into_iter().map(|i| {
Vec::from_iter((0..s.len() / 8).map(|i| {
Bytes8::new(
Vec::from_iter((0..8).into_iter().map(|j| s[8 * i + j]))
Vec::from_iter((0..8).map(|j| s[8 * i + j]))
.try_into()
.unwrap(),
)
Expand Down
9 changes: 2 additions & 7 deletions sway-core/src/language/purity.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// The purity of a function is related to its access of contract storage. If a function accesses
/// or could potentially access contract storage, it is [Purity::Impure]. If a function does not utilize any
/// any accesses (reads _or_ writes) of storage, then it is [Purity::Pure].
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, Default)]
pub enum Purity {
#[default]
Pure,
Reads,
Writes,
Expand Down Expand Up @@ -33,12 +34,6 @@ impl Purity {
}
}

impl Default for Purity {
fn default() -> Self {
Purity::Pure
}
}

/// Utility to find the union of purities. To 'promote' Reads to Writes we want ReadsWrites, and
/// the same for Writes to Reads.
pub fn promote_purity(from: Purity, to: Purity) -> Purity {
Expand Down
2 changes: 0 additions & 2 deletions sway-core/src/language/ty/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ impl CollectTypesMetadata for TyProgram {
for module in std::iter::once(&self.root).chain(
self.root
.submodules_recursive()
.into_iter()
.map(|(_, submod)| &submod.module),
) {
for node in module.all_nodes.iter() {
Expand Down Expand Up @@ -400,7 +399,6 @@ impl CollectTypesMetadata for TyProgram {
for module in std::iter::once(&self.root).chain(
self.root
.submodules_recursive()
.into_iter()
.map(|(_, submod)| &submod.module),
) {
for node in module.all_nodes.iter() {
Expand Down
9 changes: 2 additions & 7 deletions sway-core/src/language/ty/variable_mutability.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use crate::language::Visibility;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub enum VariableMutability {
// mutable
Mutable,
// referenceable + mutable
RefMutable,
// immutable
#[default]
Immutable,
}

impl Default for VariableMutability {
fn default() -> Self {
VariableMutability::Immutable
}
}

impl VariableMutability {
pub fn new_from_ref_mut(is_reference: bool, is_mutable: bool) -> VariableMutability {
if is_reference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ fn type_check_impl_method(
unconstrained_type_parameters_in_this_function
.difference(&unconstrained_type_parameters_in_the_type)
.cloned()
.into_iter()
.map(|x| x.thing)
.collect::<Vec<_>>();
impl_method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ impl ConstructorFactory {
PatStack::from(
all_variants
.difference(&variant_tracker)
.into_iter()
.map(|x| {
Pattern::Enum(EnumPattern {
enum_name: enum_name.to_string(),
Expand Down
9 changes: 2 additions & 7 deletions sway-core/src/semantic_analysis/ast_node/mode.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Default)]
pub enum Mode {
ImplAbiFn,
#[default]
NonAbi,
}

impl Default for Mode {
fn default() -> Self {
Mode::NonAbi
}
}
3 changes: 1 addition & 2 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ impl TraitMap {
.value
.values()
.cloned()
.into_iter()
.flat_map(|item| match item {
ty::TyTraitItem::Fn(decl_ref) => Some(decl_ref),
})
Expand Down Expand Up @@ -701,7 +700,7 @@ impl TraitMap {
if &map_trait_name == trait_name
&& are_equal_minus_dynamic_types(engines, type_id, e.key.type_id)
{
let mut trait_items = e.value.values().cloned().into_iter().collect::<Vec<_>>();
let mut trait_items = e.value.values().cloned().collect::<Vec<_>>();
items.append(&mut trait_items);
}
}
Expand Down
9 changes: 2 additions & 7 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ impl<T: PartialEqWithEngines> PartialEqWithEngines for VecSet<T> {
}

/// Type information without an associated value, used for type inferencing and definition.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub enum TypeInfo {
#[default]
Unknown,
/// Represents a type parameter.
///
Expand Down Expand Up @@ -370,12 +371,6 @@ impl OrdWithEngines for TypeInfo {
}
}

impl Default for TypeInfo {
fn default() -> Self {
TypeInfo::Unknown
}
}

impl DisplayWithEngines for TypeInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>, engines: Engines<'_>) -> fmt::Result {
use TypeInfo::*;
Expand Down

0 comments on commit 264e4ec

Please sign in to comment.