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

manual_unwrap_or hint suggest invalid code, due to macro expansion #6965

Closed
Urcra opened this issue Mar 24, 2021 · 2 comments · Fixed by #7136
Closed

manual_unwrap_or hint suggest invalid code, due to macro expansion #6965

Urcra opened this issue Mar 24, 2021 · 2 comments · Fixed by #7136
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy 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

Comments

@Urcra
Copy link
Contributor

Urcra commented Mar 24, 2021

It seems that clippy expands the macro before applying some hints resulting in invalid code suggested by the hint

I tried this code:

let a_val = match value_t!(matches, "command", f64) {
   Ok(val) => val,
   Err(_) => 0.0,
};

I expected to see this happen:

Suggestion for value_t!(matches, "command", f64).unwrap_or(0.0)

Instead, this happened:

The suggestion seems to expand the macro, causing the code to not compile if applying the hint

help: replace with
    |
417 |     let a_val = (if let Some(v) = $m.value_of($v) {
418 |             match v.parse::<$t>() {
419 |                 Ok(val) => Ok(val),
420 |                 Err(_) => Err(::clap::Error::value_validation_auto(format!(
421 |                     "The argument '{}' isn't a valid value",
422 |                     v
  ...

Meta

  • cargo clippy -V: clippy 0.1.52 (673d0db 2021-03-23)
  • rustc -Vv:
    rustc 1.53.0-nightly (673d0db5e 2021-03-23)
    binary: rustc
    commit-hash: 673d0db5e393e9c64897005b470bfeb6d5aec61b
    commit-date: 2021-03-23
    host: x86_64-unknown-linux-gnu
    release: 1.53.0-nightly
    LLVM version: 12.0.0
    
@Urcra Urcra added the C-bug Category: Clippy is not doing the correct thing label Mar 24, 2021
@giraffate giraffate added 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 labels Mar 24, 2021
@giraffate
Copy link
Contributor

@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Mar 24, 2021
@mgacek8
Copy link
Contributor

mgacek8 commented Apr 26, 2021

@rustbot claim

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 good-first-issue These issues are a good way to get started with Clippy 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants