Skip to content

incorrect hint for expect_fun_call #3839

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

Closed
abbychau opened this issue Mar 4, 2019 · 3 comments
Closed

incorrect hint for expect_fun_call #3839

abbychau opened this issue Mar 4, 2019 · 3 comments
Labels
E-needs-test Call for participation: writing tests

Comments

@abbychau
Copy link

abbychau commented Mar 4, 2019

example:

warning: use of `expect` followed by a function call
  --> src/main.rs:27:45
   |
27 |     dotenv::var(format!("{}_{}", ex_id, i)).expect(&format!("key {}_{} not found", ex_id, i))
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("key {}_{} not found", ex_id))`
   |
   = note: #[warn(clippy::expect_fun_call)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call

should be panic!("key {}_{} not found", ex_id,i), instead of panic!("key {}_{} not found", ex_id)

@ghost
Copy link

ghost commented Mar 4, 2019

I can't reproduce this on the playground.
What version of Clippy are you using?

fn main() {
    let a = 1;
    let b = 2;
    let o = Some(true);
    o.expect(&format!("key {}, {}", a, b));
}
    Checking playground v0.0.1 (/playground)
warning: use of `expect` followed by a function call
 --> src/main.rs:5:7
  |
5 |     o.expect(&format!("key {}, {}", a, b));
  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", a, b))`
  |
  = note: #[warn(clippy::expect_fun_call)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call

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

Playground

@abbychau
Copy link
Author

abbychau commented Mar 5, 2019

❯ cargo clippy --version
clippy 0.0.212 (1b89724b 2019-01-15)

@ghost
Copy link

ghost commented Mar 5, 2019

That's the current stable version. I can reproduce the bug locally with that version.
Looks like this has been fixed by #3690 but I'll add a test case to make sure.

@mcarton mcarton added the E-needs-test Call for participation: writing tests label Mar 5, 2019
bors added a commit that referenced this issue Mar 6, 2019
Ensure `expect_fun_call` bad suggestion is fixed

Closes #3839
@bors bors closed this as completed in #3846 Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: writing tests
Projects
None yet
Development

No branches or pull requests

2 participants