Skip to content

Commit

Permalink
swayfmt: fix indentation after where in fn (#5468) (#5578)
Browse files Browse the repository at this point in the history
## Description
This is a small fix to match the indentation for opening brace after a
where clause is seen. This should fix #5468

cc: @Braqzen 

The change is near trivial.
## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] 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.
- [ ] 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: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent ccb129f commit cdb82e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sway-lib-std/src/storage/storage_map.sw
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
pub fn insert(self, key: K, value: V)
where
K: Hash,
{
{
let key = sha256((key, self.field_id));
write::<V>(key, 0, value);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ where
pub fn get(self, key: K) -> StorageKey<V>
where
K: Hash,
{
{
StorageKey::<V>::new(
sha256((key, self.field_id)),
0,
Expand Down Expand Up @@ -129,7 +129,7 @@ where
pub fn remove(self, key: K) -> bool
where
K: Hash,
{
{
let key = sha256((key, self.slot));
clear::<V>(key, 0)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ where
pub fn try_insert(self, key: K, value: V) -> Result<V, StorageMapError<V>>
where
K: Hash,
{
{
let key = sha256((key, self.field_id));

let val = read::<V>(key, 0);
Expand Down
3 changes: 2 additions & 1 deletion swayfmt/src/items/item_fn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl CurlyBrace for ItemFn {
let open_brace = Delimiter::Brace.as_open_char();
match formatter.shape.code_line.has_where_clause {
true => {
write!(line, "{open_brace}")?;
let indent_str = formatter.indent_to_str()?;
write!(line, "{indent_str}{open_brace}")?;
formatter.shape.code_line.update_where_clause(false);
}
false => {
Expand Down
34 changes: 34 additions & 0 deletions swayfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2903,3 +2903,37 @@ pub fn from_be_bytes(bytes: [u8; 32]) -> Self {
"#,
);
}

#[test]
fn impl_func_where() {
check(
r#"library;
impl<K, V> Foo<Bar<K, V>>
where
K: Hash,
{
pub fn baz(self, _: K, _: V)
where
K: Hash,
{
debug();
}
}
"#,
r#"library;
impl<K, V> Foo<Bar<K, V>>
where
K: Hash,
{
pub fn baz(self, _: K, _: V)
where
K: Hash,
{
debug();
}
}
"#,
);
}

0 comments on commit cdb82e2

Please sign in to comment.