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

replace_consts false positive when using integer constant as part of range in match #4969

Closed
5225225 opened this issue Dec 29, 2019 · 1 comment · Fixed by #4977
Closed
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 L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@5225225
Copy link
Contributor

5225225 commented Dec 29, 2019

cargo clippy -V: clippy 0.0.212 (69f99e7 2019-12-14)

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=401f208640cdf49300acf4ef902f01ee

Minimal example:

#![warn(clippy::replace_consts)]

fn main() {
    match 0_u32 {
        0 => "zero",
        // std::u32::MAX is suggested to be replaced with u32::max_value()
        1..=std::u32::MAX => "more",
    };
}

If I try replacing std::u32::MAX with u32::max_value(), I get a syntax error from rust. Wrapping in parenthesis or curly braces doesn't make it valid.

I don't get a warning if it's not part of a range.

@JohnTitor JohnTitor added L-suggestion Lint: Improving, adding or fixing lint suggestions 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 labels Dec 29, 2019
@krishna-veerareddy
Copy link
Contributor

Looks like the fix is to not lint replace_consts within patterns since function calls aren't allowed in them. I will tackle this one.

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 L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants