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

unused_unit false positive for macro inputs #4076

Closed
goffrie opened this issue May 10, 2019 · 1 comment · Fixed by #4445
Closed

unused_unit false positive for macro inputs #4076

goffrie opened this issue May 10, 2019 · 1 comment · Fixed by #4445
Assignees
Labels
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 L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion

Comments

@goffrie
Copy link

goffrie commented May 10, 2019

sample test case:

use crossbeam_channel::{unbounded, select};
fn main() {
    let (tx,rx) = unbounded();
    tx.send("hi").unwrap();
    select! {
        recv(rx) -> _x => (),
    }
}
% cargo clippy
    Checking asdf v0.1.0 (/tmp/asdf)
warning: unneeded unit expression
 --> src/main.rs:6:27
  |
6 |         recv(rx) -> _x => (),
  |                           ^^ help: remove the final `()`
  |
  = 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

    Finished dev [unoptimized + debuginfo] target(s) in 0.24s

of course, following the suggestion leads to invalid code.

unused_unit shouldn't fire for unit expressions that came from a macro argument.

@phansch phansch 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 labels May 10, 2019
@phansch phansch assigned phansch and unassigned phansch May 12, 2019
@flip1995 flip1995 added the T-macros Type: Issues with macros and macro expansion label May 13, 2019
@phansch phansch self-assigned this Aug 24, 2019
@phansch
Copy link
Member

phansch commented Aug 24, 2019

Minimal repro:

#![warn(clippy::unused_unit)]

fn main() {
    macro_rules! foo {
        (recv($r:expr) -> $res:pat => $body:expr) => {
            $body
        }
    }

    foo! {
        recv(rx) -> _x => ()
    }
}

phansch added a commit to phansch/rust-clippy that referenced this issue Aug 24, 2019
phansch added a commit to phansch/rust-clippy that referenced this issue Aug 24, 2019
@phansch phansch added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Aug 24, 2019
bors added a commit that referenced this issue Aug 26, 2019
Fix unused_unit false positive

changelog: Fix `unused_unit` false positive

For some reason the `expr` of `stmt.node` didn't contain the expansion information, but the `stmt.span` does.

Fixes #4076
@bors bors closed this as completed in 957dedb Aug 26, 2019
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants