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

question_mark lint triggers wrongly for if let in closure that does not return a Result #8269

Closed
sdroege opened this issue Jan 12, 2022 · 2 comments
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

@sdroege
Copy link

sdroege commented Jan 12, 2022

Summary

See details below

Lint Name

question_mark

Reproducer

I tried this code:

    src_pad.add_probe(gst::PadProbeType::BUFFER, |_, probe_info| {
        if let Some(gst::PadProbeData::Buffer(ref buffer)) = probe_info.data {
            let map = buffer.map_readable().unwrap();

            let samples = if let Ok(samples) = map.as_slice_of::<i16>() {
                samples
            } else {
                return gst::PadProbeReturn::Ok;
            };
            [...]
        }

        gst::PadProbeReturn::Ok
    });

I saw this happen:

warning: this if-let-else may be rewritten with the `?` operator
  --> examples/src/bin/pad_probes.rs:54:27
   |
54 |               let samples = if let Ok(samples) = map.as_slice_of::<i16>() {
   |  ___________________________^
55 | |                 samples
56 | |             } else {
57 | |                 return gst::PadProbeReturn::Ok;
58 | |             };
   | |_____________^ help: replace it with: `map.as_slice_of::<i16>()?`
   |
   = note: `#[warn(clippy::question_mark)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

I expected to see this happen: Nothing because the closure does not return a Result

Version

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-unknown-linux-gnu
release: 1.58.0
LLVM version: 13.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

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

This is fixed on nightly, would be by #7860 or #8080

@sdroege
Copy link
Author

sdroege commented Jan 12, 2022

Indeed, with nightly this doesn't happen anymore. Thanks!

@sdroege sdroege closed this as completed Jan 12, 2022
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

3 participants