From c3d7885f2f7626565295f996662e24d3a25f2b95 Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:20:27 -0300 Subject: [PATCH] Fix hash.sw, replaced `#![foo]` for #[foo]` While doing this I also updated `forc-fmt` to have a better error message being printed to the stdout Before: ```bash error: Formatting skipped due to error. error: Failed to compile /Users/cr-fuel/projects/fuel/sway/sway-lib-std/src/hash.sw ``` Now: ```bash error: Formatting skipped due to error. error: Failed to compile /Users/cr-fuel/projects/fuel/sway/sway-lib-std/src/hash.sw Cannot format raw hashbang attribute, If this is intended to be a doc comment try using the `//!` syntax instead ``` --- forc-plugins/forc-fmt/src/main.rs | 6 +++++- sway-lib-std/src/hash.sw | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/forc-plugins/forc-fmt/src/main.rs b/forc-plugins/forc-fmt/src/main.rs index a443070a682..1f51938d27a 100644 --- a/forc-plugins/forc-fmt/src/main.rs +++ b/forc-plugins/forc-fmt/src/main.rs @@ -169,7 +169,11 @@ fn format_file( // TODO: Support formatting for incomplete/invalid sway code. // https://github.com/FuelLabs/sway/issues/5012 debug!("{}", err); - bail!("Failed to compile: {:?}", file); + if let Some(file) = file.to_str() { + bail!("Failed to compile {}\n{}", file, err); + } else { + bail!("Failed to compile.\n{}", err); + } } } } diff --git a/sway-lib-std/src/hash.sw b/sway-lib-std/src/hash.sw index 2e09a41187c..50cc573392d 100644 --- a/sway-lib-std/src/hash.sw +++ b/sway-lib-std/src/hash.sw @@ -47,7 +47,7 @@ impl Hasher { self.write(bytes); } - #![inline(never)] + #[inline(never)] pub fn write_str_array(ref mut self, s: S) { __assert_is_str_array::(); let str_size = __size_of_str_array::(); @@ -159,7 +159,7 @@ impl Hash for str { } impl Hash for (A, B) where A: Hash, B: Hash { - #![inline(never)] + #[inline(never)] fn hash(self, ref mut state: Hasher) { self.0.hash(state); self.1.hash(state); @@ -318,7 +318,7 @@ impl Hash for [T; 10] where T: Hash { /// assert(result = 0xa80f942f4112036dfc2da86daf6d2ef6ede3164dd56d1000eb82fa87c992450f); /// } /// ``` -#![inline(never)] +#[inline(never)] pub fn sha256(s: T) -> b256 where T: Hash { let mut hasher = Hasher::new(); s.hash(hasher); @@ -338,7 +338,7 @@ pub fn sha256(s: T) -> b256 where T: Hash { /// assert(result = 0xa80f942f4112036dfc2da86daf6d2ef6ede3164dd56d1000eb82fa87c992450f); /// } /// ``` -#![inline(never)] +#[inline(never)] pub fn sha256_str_array(param: S) -> b256 { __assert_is_str_array::(); let str_size = __size_of_str_array::(); @@ -374,7 +374,7 @@ pub fn sha256_str_array(param: S) -> b256 { /// assert(result = 0x4375c8bcdc904e5f51752581202ae9ae2bb6eddf8de05d5567d9a6b0ae4789ad); /// } /// ``` -#![inline(never)] +#[inline(never)] pub fn keccak256(s: T) -> b256 where T: Hash { let mut hasher = Hasher::new(); s.hash(hasher);