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

needless_question_mark follows macros and suggests to replace code inside the macro definition #6921

Closed
matthiaskrgr opened this issue Mar 17, 2021 · 0 comments · Fixed by #6935
Assignees
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

Lint name: needless_question_mark

I tried this code:

macro_rules! try_ {
    ($expr:expr) => {
        || -> _ { Some($expr) }()
    };
}

fn main() {
    let x = Some(3);
    let x = try_!(x?);
}

Suggestion:

warning: question mark operator is useless here
 --> src/main.rs:3:19
  |
3 |         || -> _ { Some($expr) }()
  |                   ^^^^^^^^^^^ help: try: `x`
...
9 |     let x = try_!(x?);
  |             --------- in this macro invocation
  |
  = note: `#[warn(clippy::needless_question_mark)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
  = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

We can't just fill in the macro arguments into the macro definition... 🙃
I guess the easiest way is to just ignore macros?

Meta

clippy 0.1.52 (107896c 2021-03-15)

@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 Mar 17, 2021
@matthiaskrgr matthiaskrgr self-assigned this Mar 18, 2021
bors added a commit that referenced this issue Mar 19, 2021
needless_question_mark: don't lint if Some(..) is inside a macro def and the ? is not.

The suggestion would fail to apply.

Fixes #6921

changelog: needless_question_mark: don't lint if Some(..) is inside a macro def and the ? is not.
@bors bors closed this as completed in b42ec5e Mar 19, 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 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
1 participant