Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneeded Unit Expression Warning From Clippy #2774

Closed
jyhi opened this issue Jan 20, 2022 · 9 comments · Fixed by #2778
Closed

Unneeded Unit Expression Warning From Clippy #2774

jyhi opened this issue Jan 20, 2022 · 9 comments · Fixed by #2778
Labels

Comments

@jyhi
Copy link

jyhi commented Jan 20, 2022

Describe the Bug

wasm-bindgen 0.2.79 released not long ago triggered a workflow error in our repository, which doesn't exist before.

A local run of cargo +nightly clippy -- -Z macro-backtrace with clippy 0.1.60 (5e57faa 2022-01-19) prints the following:

    Checking client-wasm v0.0.1 (/home/user/repo/iota.rs/bindings/wasm/native)
warning: unneeded unit expression
  --> src/address_getter.rs:22:1
   |
22 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = note: `#[warn(clippy::unused_unit)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/address_getter.rs:22:1
   |
22 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/balance_getter.rs:20:1
   |
20 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/client.rs:46:1
   |
46 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/client_builder.rs:28:1
   |
28 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/get_address.rs:16:1
   |
16 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/message_builder.rs:36:1
   |
36 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/message_getter.rs:17:1
   |
17 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/unspent_address_getter.rs:19:1
   |
19 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:22:1
   |
22 | pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ---------------------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen::prelude::__wasm_bindgen_class_marker]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: unneeded unit expression
  --> src/lib.rs:27:1
   |
27 | #[wasm_bindgen(start)]
   | ^^^^^^^^^^^^^^^^^^^^^^ in this procedural macro expansion
   |
  ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-0.2.79/src/lib.rs:9:1
   |
9  | pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
   | ------------------------------------------------------------------------- in this expansion of `#[wasm_bindgen]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit

warning: `client-wasm` (lib) generated 100 warnings (90 duplicates)
    Finished dev [unoptimized + debuginfo] target(s) in 0.77s

Steps to Reproduce

  1. git clone https://github.com/iotaledger/iota.rs
  2. cd iota.rs/bindings/wasm/native
  3. cargo clippy (version of toolchain doesn't actually matter)
  4. See warnings

Expected Behavior

No warning should be given.

Actual Behavior

client-wasm (lib) generated 100 warnings (90 duplicates).

Additional Context

We haven't tried to identify whether this is a problem from our side yet.

@jetli
Copy link

jetli commented Jan 21, 2022

same here, this breaks my CIs

@damianwadley
Copy link

Example input:

    #[wasm_bindgen(js_name = "setTimeout")]
    pub fn set_timeout(&mut self, timeout: u16) -> u16 {
        let old = self.timeout;
        self.timeout = timeout;
        old
    }

Expanded output:

        pub fn set_timeout(&mut self, timeout: u16) -> u16 {
            #[automatically_derived]
            const __wasm_bindgen_generated_StructName_setTimeout__const: () = {
                pub extern "C" fn __wasm_bindgen_generated_StructName_setTimeout(
                    me: u32,
                    arg1: <u16 as wasm_bindgen::convert::FromWasmAbi>::Abi,
                ) -> <u16 as wasm_bindgen::convert::ReturnWasmAbi>::Abi {
                    let _ret = {
                        let mut me = unsafe {
                            < WasmStructName as wasm_bindgen :: convert :: RefMutFromWasmAbi > :: ref_mut_from_abi (me)
                        };
                        let me = &mut *me;
                        let arg1 =
                            unsafe { <u16 as wasm_bindgen::convert::FromWasmAbi>::from_abi(arg1) };
                        me.set_timeout(arg1)
                    };
                    <u16 as wasm_bindgen::convert::ReturnWasmAbi>::return_abi(_ret)
                }
                ()
            };
            let old = self.timeout;
            self.timeout = timeout;
            old
        }

That () line is triggering the warning.

@Razican
Copy link

Razican commented Jan 22, 2022

I can confirm that this error comes with the update from 0.2.78 to 0.2.79.

keiya01 added a commit to keiya01/og_image_writer that referenced this issue Jan 23, 2022
neacsu added a commit to nymtech/nym that referenced this issue Jan 24, 2022
There is an `unused-unit` lint that will fail for now, but this is
regarded as a false positive and should eventualy get fixed:

rustwasm/wasm-bindgen#2774
neacsu added a commit to nymtech/nym that referenced this issue Jan 24, 2022
* Fix wasm client

* Re-enable CI on wasm client

There is an `unused-unit` lint that will fail for now, but this is
regarded as a false positive and should eventualy get fixed:

rustwasm/wasm-bindgen#2774

* The wasm tests would be run under native arch
twifkak added a commit to twifkak/sxg-rs that referenced this issue Jan 25, 2022
Add #[allow(dead_code)] for a field that is only available in feature =
"rust_signer".

Skip wasm-bindgen version 0.2.79 per
rustwasm/wasm-bindgen#2774.
twifkak added a commit to twifkak/sxg-rs that referenced this issue Jan 25, 2022
Add #[allow(dead_code)] for a field that is only available in feature =
"rust_signer".

Skip wasm-bindgen version 0.2.79 per
rustwasm/wasm-bindgen#2774.
zebp added a commit to cloudflare/workers-rs that referenced this issue Jan 25, 2022
Currently wasm-bindgen has an unresolved bug that generates code that
emits a clippy warning. So we'll just pin it until
rustwasm/wasm-bindgen#2774 is fixed
twifkak added a commit to google/sxg-rs that referenced this issue Jan 25, 2022
Add #[allow(dead_code)] for a field that is only available in feature =
"rust_signer".

Skip wasm-bindgen version 0.2.79 per
rustwasm/wasm-bindgen#2774.
jstuczyn added a commit to nymtech/nym that referenced this issue Jan 26, 2022
* Feature-locked unused imports

* Reverted wasam-bindgen to 0.2.78 to temporarily bypass rustwasm/wasm-bindgen#2774

* Reorganised imports
@Razican
Copy link

Razican commented Jan 29, 2022

@alexcrichton would it be possible to release a new version with the fix?

@alexcrichton
Copy link
Contributor

Sorry but no I would prefer to not make a release simply for clippy.

@anonrig
Copy link

anonrig commented Feb 6, 2022

I'm facing a similar issue. As a new developer working on Rust, I thought this was caused by a bug on my side, and sad to see that even though the maintainer acknowledges the issue, he does not prefer to "make a release simply for clippy".

Can you at least point us to a solution/explanation for this?

@tgecho
Copy link

tgecho commented Feb 6, 2022

Can you at least point us to a solution/explanation for this?

As I understand these things (being somewhat new to Rust as well), normally you wouldn't see a warning for code that is in another crate. However in this case it's being caused by something inside macro generated code... which is in a sense actually in your crate. Still not your fault, and still an annoying bummer.

If you want to suppress the warning while waiting for the next release, you should be able to add this to the top of the affected file: #![allow(clippy::unused_unit)]

See https://github.com/rust-lang/rust-clippy#allowingdenying-lints

arctic-hen7 added a commit to framesurge/perseus that referenced this issue Feb 17, 2022
These are caused by rustwasm/wasm-bindgen#2774 while we wait for a new
release on their end.
andy-k added a commit to andy-k/wolges-wasm that referenced this issue Feb 25, 2022
richardneililagan added a commit to richardneililagan/toy-robot-simulator that referenced this issue Mar 6, 2022
`wasm_bindgen` sometimes generates an orphaned unit expression
as part of its macro expansion. This is relatively harmless, but
is flagged by clippy, this codebase's choice for Rust linter.

We have no real control on how `#[wasm_bindgen]` expands,
and no real way to avoid this from happening in the expanded code,
so we opt to disable the `clippy::unused_unit` lint check
on affected files.

Definitely not ideal, but spotting unused units on code we're
writing ourselves are relatively easy to spot anyway.

@see: rustwasm/wasm-bindgen#2774
@arnauorriols
Copy link
Contributor

arnauorriols commented Mar 9, 2022

Is there any ETA of the release? Or any argument why it's not being considered significant? Changing the linting (or update) policies because of a misbehaving 3rd party macro is quite a red flag to us. I'm more concerned about this than the bug itself.

tv42 added a commit to tv42/choosy that referenced this issue Mar 22, 2022
The remaining "unneeded unit expression" is not out fault:
rustwasm/wasm-bindgen#2774
dalcde added a commit to SpectralSequences/sseq that referenced this issue Mar 24, 2022
github-actions bot added a commit to SpectralSequences/sseq that referenced this issue Mar 24, 2022
harshadptl added a commit to FindoraNetwork/platform that referenced this issue Apr 1, 2022
* CHANGELOG update

* dding triple masking code to ledger and query server package

* integrating finutils and all non-src

* additions and fixes in wasm, query server and ledger (#173)

also dependencies and misc changes

* Added functionality to return list of randomizer strings through wasm

* Adding WASM wrappers to triple masking key serialization/deserialization functions

* anon pub key randomizer wasm

* Returning Randomized AXfr pub key as string

* ruc fixes and integration test scripts improvements

* adding wasmcat into this branch

* remove auto wasm build from pull request to main branch

* Integrate zei arkworks backend (#192)

switched to zei develop, added ark patch and fixes for BLSScalar bytes, changed anon keys

* Nullifier hash, wasm oabar and integrate new setup params (#210)

* added a function in wasm for nullifier hash generation
* added to query server a way to check if a nullifier hash exists or not
* added a wasm function to get oabar
* made some changes to support new zei setup parameters

* update positive unit test on txn_builder with anon fees (#208)

* modified axfr_create_verify_unit_positive_tests() by adding fee input

Author: hridambasu
Co-authored-by: Serge-Juarez
Co-authored-by: akhilpeddireddy
Co-authored-by: Harshad Patil

* wasm randomize AXfrKeyPair fn and fix lint

lint errors due to rustwasm/wasm-bindgen#2774

* sync with zei updates

* Fix node reset and start in devnet

* fix compile error caused by yanked anomaly

* Wasm function to deserialize ABAR

* Fix nullifier hash serialization

* Adding serialization, deserialization for AnonKeys object

* Removing fee for non-Fra assets in bar2abar for testing

* Fix AnonKeys serialization

* Fix FeeInputs Vector capacity limit

* Fix added capacity for FeeInputs

* Integrating anon transfer fee and remainder with txn builder and CLI (#231)

Co-authored-by: akhilpeddireddy <akhilpeddireddy@gmail.com>

* cli abar spent status, handle randomizer for axfr remainder

* fix build after zei merkle tree optimization

* Abar to bar integration (#213)

* Added abar_to_bar integration to the platform

1. made changes to ledger to handle the conv ops
2. added script to test abar_to_bar conversion on fresh local net

* Wasm bindingg for abar_to_bar conversion operation

* FeeOp for Abar - Bar conversions

* change axfr public key in integration/demo script

new keys are used after the arkworks switch in zei

* fix compile error caused by yanked anomaly

* Removing Rocksdb patch as the bug in librocksdb is fixed

* Removed invalid short flags for fn commands

* Fix public key and address CLI flags

Co-authored-by: akhilpeddireddy <akhilpeddireddy@gmail.com>
Co-authored-by: charlie <charlie@findora.org>

* Fix FeeInputs multiple insert call

* Fix build error

* Fix new merkle tree depth and abar to bar demo script

* adding wasm support for anon fee and remainder

* fix storage version, lint and wasm build

* fix clippy errors in smt

* add back wasm_bindgen

were removed in v3 when develop got merged in

* Change names of wasm functions

* Apply precompute verifier parameters (#246)

* Apply precompute verifier parameters

* hotfix verifier test code

* Fix add_input bug in add_fee of transaction builder (#245)

* Fix add_input bug in add_fee of transaction builder

* fix fmt

* Anon assets mixing (#244)

* check abar unspent before transfer

* update anon-transfer CLI to support assets

* update anon-transfer-batch CLI to support assets

* add test shell for anon assets mixing

* fix multi_axfr_test shell

* cleanup test tmp_file

* cut down test shell sleep time

* This includes the function descibed in FO-887 (#251)

* This includes the function descibed in FO-887

* dding wasm interface to fee estimation

Co-authored-by: Harshad Patil <harshad0402@gmail.com>

* Anon Fee for ABAR to BAR (#249)

* Updating zei library version

* Regression tests for triple masking (#254)

* Regression tests for
- bar to abar
- abar transfer
- abar to bar

* fix binary path

* Anon fee for abar to bar conversion

* Updating the zei library version

* Upgrade zei version & hotfix unwrap

* randomizer map and remove amount.rs (#256)

* Update zei version for anon_fee

* Triple masking docs (#258)

* Adding docs for Abar conversions

* fix SID pick in bar to abar conversion

* Fix: user param generation after fee calculation in anon transfer

* Fix algo for FRA fee estimation for some corner cases (#262)

* Fix algo for FRA fee estimation for some corner cases

* Fix fmt

* Fix anon transfer transaction build

* Fix build failure & txn serialization

* Fix handle AXfrKeypair pointer in abar_to_bar conversion

* Fix wasm Key null pointer issue

Clonig all the signing and encryption keys to avoid moving of
pointer in rust-wasm code.

Co-authored-by: charlie <charlie@findora.org>
Co-authored-by: Harshad Patil <harshad0402@gmail.com>
Co-authored-by: tommady <tommady@users.noreply.github.com>
Co-authored-by: Hridam Basu <hridam.basu@gmail.com>
Co-authored-by: findora-crypto <weikeng@findora.org>
Co-authored-by: Serge-Juarez <86990655+Serge-Juarez@users.noreply.github.com>
Co-authored-by: Findora-Sun <94740291+findora-sun@users.noreply.github.com>
Co-authored-by: Sun <sun@findora.org>
kettlebell added a commit to ergoplatform/sigma-rust that referenced this issue Apr 7, 2022
kettlebell added a commit to ergoplatform/sigma-rust that referenced this issue Apr 16, 2022
kettlebell added a commit to ergoplatform/sigma-rust that referenced this issue Apr 26, 2022
@mimoo
Copy link

mimoo commented Jun 20, 2022

seeing this in our CI as well

tv42 added a commit to tv42/choosy that referenced this issue Jul 18, 2022
This eliminates the Clippy complaint about redundant unit expression,
see rustwasm/wasm-bindgen#2774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants