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

unit_arg breaks code #10016

Open
matthiaskrgr opened this issue Dec 1, 2022 · 1 comment
Open

unit_arg breaks code #10016

matthiaskrgr opened this issue Dec 1, 2022 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

unit_arg

Reproducer

I tried this code:

#![allow(dead_code)]
#![allow(unused_assignments)]
#![allow(unused_variables)]
#![allow(unreachable_code)]

trait UnitDefault {
    fn default() -> Self;
}

impl UnitDefault for () {
    fn default() -> () {
        panic!()
    }
}

fn match_arm() {
    let _x = match Ok(UnitDefault::default()) {
        Ok(v) => v,
        Err(()) => return,
    };
}

fn match_arm_rev() {
    let _x = match Ok(UnitDefault::default()) {
        Err(()) => return,
        Ok(v) => v,
    };
}

fn main() {}

I saw this happen:

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> src/main.rs:18:9
   |
7  |     fn default() -> Self;
   |     --------------------- `UnitDefault::default` defined here
...
18 |         UnitDefault::default();
   |         ^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> src/main.rs:28:9
   |
7  |     fn default() -> Self;
   |     --------------------- `UnitDefault::default` defined here
...
28 |         UnitDefault::default();
   |         ^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0790`.
Original diagnostics will follow.

warning: passing a unit value to a function
  --> src/main.rs:17:20
   |
17 |     let _x = match Ok(UnitDefault::default()) {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
   = note: requested on the command line with `-W clippy::unit-arg`
help: move the expression in front of the call and replace it with the unit literal `()`
   |
17 ~     let _x = match {
18 +         UnitDefault::default();
19 +         Ok(())
20 ~     } {
   |

warning: passing a unit value to a function
  --> src/main.rs:24:20
   |
24 |     let _x = match Ok(UnitDefault::default()) {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
   |
24 ~     let _x = match {
25 +         UnitDefault::default();
26 +         Ok(())
27 ~     } {
   |

Version

rustc 1.67.0-nightly (c97b539e4 2022-11-30)
binary: rustc
commit-hash: c97b539e408ea353f4fde2f9251d598291fec421
commit-date: 2022-11-30
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 1, 2022
@teor2345
Copy link
Contributor

We get a similar error when trying to fix https://github.com/ZcashFoundation/zebra/blob/d501d07898be9e5a77fc89908822b3890e9d687d/zebra-rpc/src/server/tests/vectors.rs#L57

I've included one example of each error, it is repeated multiple times in the file:

warning: failed to automatically apply fixes suggested by rustc to crate `zebra_rpc`                                                                                                                       
                                                                                                                                                                                                           
after fixes were automatically applied the compiler reported errors within these files:                                                                                                                    
                                                                                                                                                                                                           
  * zebra-rpc/src/server/tests/vectors.rs                                                                                                                                                                  
                                                                                                                                                                                                           
This likely indicates a bug in either rustc or cargo itself,                                                                                                                                               
and we would appreciate a bug report! You're likely to see                                                                                                                                                 
a number of compiler warnings after this message which cargo                                                                                                                                               
attempted to fix but failed. If you could open an issue at                                                                                                                                                 
https://github.com/rust-lang/rust-clippy/issues                                                                                                                                                            
quoting the full output of this command we'd be very appreciative!                                                                                                                                         
Note that you may be able to make some more progress in the near-term                                                                                                                                      
fixing code with the `--broken-code` flag                                                                                                                                                                  
                                                                                                                                                                                                           
The following errors were reported:                                                                                                                                                                        
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type                                                                                                    
  --> zebra-rpc/src/server/tests/vectors.rs:58:13                                                                                                                                                          
   |                                                                                                                                                                                                       
58 |             Default::default();                                                                                                                                                                       
   |             ^^^^^^^^^^^^^^^^ cannot call associated function of trait                                                                                                                                 
   |                                                                                                                                                                                                       
help: use a fully-qualified path to a specific available implementation (1046 found)                                                                                                                       
   |                                                                                                                                                                                                       
58 |             <std::sync::LazyLock<T> as Default>::default();                                                                                                                                           
   |             ++++++++++++++++++++++++++        +                                         
...
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0790`.
Original diagnostics will follow.

warning: passing a unit value to a function
  --> zebra-rpc/src/server/tests/vectors.rs:57:79
   |
57 |           let (rpc_server_task_handle, rpc_tx_queue_task_handle, _rpc_server) = RpcServer::spawn(
   |  _______________________________________________________________________________^
58 | |             config,
59 | |             Default::default(),
60 | |             "RPC server test",
...  |
67 | |             Mainnet,
68 | |         );
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
   = note: `#[warn(clippy::unit_arg)]` on by default
help: move the expression in front of the call and replace it with the unit literal `()`
   |
57 ~         let (rpc_server_task_handle, rpc_tx_queue_task_handle, _rpc_server) = {
58 +             Default::default();
59 +             RpcServer::spawn(
60 +                 config,
61 +                 (),
62 +                 "RPC server test",
63 +                 Buffer::new(mempool.clone(), 1),
64 +                 Buffer::new(state.clone(), 1),
65 +                 Buffer::new(chain_verifier.clone(), 1),
66 +                 MockSyncStatus::default(),
67 +                 MockAddressBookPeers::default(),
68 +                 NoChainTip,
69 +                 Mainnet,
70 +             )
71 ~         };
   |
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

2 participants