Skip to content

Commit

Permalink
Fixes typos and adds missing trait impls.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jun 5, 2024
1 parent 529445e commit 4893a59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
20 changes: 19 additions & 1 deletion sway-core/src/language/parsed/declaration/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl EqWithEngines for StorageDeclaration {}
impl PartialEqWithEngines for StorageDeclaration {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
self.attributes == other.attributes
&& self.fields.eq(&other.fields, ctx)
&& self.entries.eq(&other.entries, ctx)
&& self.span == other.span
&& self.storage_keyword == other.storage_keyword
}
Expand All @@ -38,6 +38,13 @@ pub struct StorageNamespace {
pub entries: Vec<Box<StorageEntry>>,
}

impl EqWithEngines for StorageNamespace {}
impl PartialEqWithEngines for StorageNamespace {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
self.name.eq(&other.name) && self.entries.eq(&other.entries, ctx)
}
}

#[derive(Debug, Clone)]
pub enum StorageEntry {
Namespace(StorageNamespace),
Expand All @@ -53,6 +60,17 @@ impl StorageEntry {
}
}

impl EqWithEngines for StorageEntry {}
impl PartialEqWithEngines for StorageEntry {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
match (self, other) {
(StorageEntry::Namespace(n1), StorageEntry::Namespace(n2)) => n1.eq(n2, ctx),
(StorageEntry::Field(f1), StorageEntry::Field(f2)) => f1.eq(f2, ctx),
_ => false,
}
}
}

/// An individual field in a storage declaration.
/// A type annotation _and_ initializer value must be provided. The initializer value must be a
/// constant expression. For now, that basically means just a literal, but as constant folding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use fuel_vm::fuel_tx::field;
use sway_error::handler::{ErrorEmitted, Handler};
use sway_types::{BaseIdent, Ident, Named, Spanned};

Expand Down
2 changes: 1 addition & 1 deletion sway-parse/src/item/item_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Parse for StorageEntry {

impl Parse for StorageField {
fn parse(parser: &mut Parser) -> ParseResult<StorageField> {
let name = BaseIdent::dummy(); // Name will be overrided in StorageEntry parse.
let name = BaseIdent::dummy(); // Name will be overridden in StorageEntry parse.
let in_token: Option<InToken> = parser.take();
let mut key_opt: Option<Expr> = None;
if in_token.is_some() {
Expand Down
12 changes: 6 additions & 6 deletions swayfmt/src/items/item_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ impl Format for ItemStorage {
entry: &StorageEntry,
ident_size: usize,
current_ident: usize,
field_lenghts: &mut HashMap<IdentUnique, usize>,
field_lengths: &mut HashMap<IdentUnique, usize>,
) {
if let Some(namespace) = &entry.namespace {
namespace.clone().into_inner().into_iter().for_each(|e| {
collect_field_lengths(
&e.value,
ident_size,
current_ident + ident_size,
field_lenghts,
field_lengths,
)
});
} else if let Some(storage_field) = &entry.field {
field_lenghts.insert(
field_lengths.insert(
storage_field.name.clone().into(),
current_ident + storage_field.name.as_str().len(),
);
Expand All @@ -98,7 +98,7 @@ impl Format for ItemStorage {
formatted_code: &mut FormattedCode,
formatter: &mut Formatter,
entry: &StorageEntry,
field_lenghts: &HashMap<IdentUnique, usize>,
field_lengths: &HashMap<IdentUnique, usize>,
max_valid_field_length: usize,
) -> Result<(), FormatterError> {
if let Some(namespace) = &entry.namespace {
Expand All @@ -112,7 +112,7 @@ impl Format for ItemStorage {
formatted_code,
formatter,
&e.value,
field_lenghts,
field_lengths,
max_valid_field_length,
);
});
Expand All @@ -124,7 +124,7 @@ impl Format for ItemStorage {

// `current_field_length`: the length of the current field that we are
// trying to format.
let current_field_length = field_lenghts
let current_field_length = field_lengths
.get(&storage_field.name.clone().into())
.unwrap()
.clone();
Expand Down

0 comments on commit 4893a59

Please sign in to comment.