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

unnecessary_wraps misses 'return' #6384

Closed
taiki-e opened this issue Nov 26, 2020 · 2 comments · Fixed by #6397
Closed

unnecessary_wraps misses 'return' #6384

taiki-e opened this issue Nov 26, 2020 · 2 comments · Fixed by #6397
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

Comments

@taiki-e
Copy link
Member

taiki-e commented Nov 26, 2020

I tried this code:

fn func(s: &str) -> Option<&'static [&'static str]> {
    Some(match s {
        "a" => &["A"],
        _ => return None,
    })
}

I expected to see this happen: no warning

Instead, this happened:
unnecessary_wraps misses return None and emit warning.

warning: this function's return value is unnecessarily wrapped by `Option`
 --> src/lib.rs:1:1
  |
1 | / fn func(s: &str) -> Option<&'static [&'static str]> {
2 | |     Some(match s {
3 | |         "a" => &["A"],
4 | |         _ => return None,
5 | |     })
6 | | }
  | |_^
  |
  = note: `#[warn(clippy::unnecessary_wraps)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
help: remove `Option` from the return type...
  |
1 | fn func(s: &str) -> &'static [&'static str] {
  |                     ^^^^^^^^^^^^^^^^^^^^^^^
help: ...and change the returning expressions
  |
2 |     match s {
3 |         "a" => &["A"],
4 |         _ => return None,
5 |     }
  |

Meta

  • cargo clippy -V: clippy 0.0.212 (1c389ff 2020-11-24)
  • rustc -Vv:
    rustc 1.50.0-nightly (1c389ffef 2020-11-24)
    binary: rustc
    commit-hash: 1c389ffeff814726dec325f0f2b0c99107df2673
    commit-date: 2020-11-24
    host: x86_64-apple-darwin
    release: 1.50.0-nightly
    

Mentioning @matsujika who implemented this lint in #6070.

@taiki-e taiki-e added the C-bug Category: Clippy is not doing the correct thing label Nov 26, 2020
@giraffate
Copy link
Contributor

@rustbot modify labels: +L-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Nov 26, 2020
@hkmatsumoto
Copy link
Member

hkmatsumoto commented Nov 26, 2020

@taiki-e Thanks for filing the issue, it looks like the match needs an arm for hir::ExprKind::Call.
This wasn't the case. Created PR with an alternative solution.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants