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

Vacuous match body with side-effectful matchee #7094

Closed
ghost opened this issue Apr 16, 2021 · 1 comment · Fixed by #7095
Closed

Vacuous match body with side-effectful matchee #7094

ghost opened this issue Apr 16, 2021 · 1 comment · Fixed by #7095
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-complexity Lint: Belongs in the complexity lint group

Comments

@ghost
Copy link

ghost commented Apr 16, 2021

fn side_effects() {
    println!("hello there!");
}

fn main() {
    match side_effects() {
        _ => (),
    };
}

The clippy error is

warning: this match could be replaced by its body itself
 --> src/main.rs:6:5
  |
6 | /     match side_effects() {
7 | |         _ => (),
8 | |     };
  | |_____^ help: consider using the match body instead: `();`
  |
  = note: `#[warn(clippy::match_single_binding)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding

But if this fix is automatically applied we lose the side effects. Instead I expect this code to be fixed to

    let _ = side_effects();
    // or
    side_effects();

Meta

  • cargo clippy -V: clippy 0.1.51 (2fd73fab 2021-03-23)
  • rustc -Vv:
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1
@ghost ghost added the C-bug Category: Clippy is not doing the correct thing label Apr 16, 2021
@Y-Nak

This comment has been minimized.

@rustbot rustbot added I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-complexity Lint: Belongs in the complexity lint group labels Apr 16, 2021
@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label May 3, 2021
@bors bors closed this as completed in 1fd9975 May 13, 2021
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 good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants