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

false positive: unstable const fn #5995

Closed
Nugine opened this issue Sep 1, 2020 · 2 comments · Fixed by #7076
Closed

false positive: unstable const fn #5995

Nugine opened this issue Sep 1, 2020 · 2 comments · Fixed by #7076
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Nugine
Copy link

Nugine commented Sep 1, 2020

I tried this code:

#![deny(clippy::missing_const_for_fn)]

/*
error: this could be a `const fn`
*/

fn is_ascii_digit(byte: u8) -> bool {
    byte.is_ascii_digit()
}

/*
error: `core::num::<impl u8>::is_ascii_digit` is not yet stable as a const fn
*/

// const fn is_ascii_digit(byte: u8) -> bool {
//     byte.is_ascii_digit()
// }

fn main() {
    dbg!(is_ascii_digit(b'1'));
}

Meta

  • cargo clippy -V: clippy 0.0.212 (04488af 2020-08-24)
  • rustc -Vv:
    rustc 1.46.0 (04488afe3 2020-08-24)
    binary: rustc
    commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
    commit-date: 2020-08-24
    host: x86_64-unknown-linux-gnu
    release: 1.46.0
    LLVM version: 10.0
    
@Nugine Nugine added the C-bug Category: Clippy is not doing the correct thing label Sep 1, 2020
@flip1995 flip1995 added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Sep 5, 2020
@rail-rain
Copy link
Contributor

The underlying cause is that rustc_mir::transform::qualify_min_const_fn::is_min_const_fn, which is the lint's core, is not responsible to check whether const fns in stable crates call unstable const fns, rustc_mir::transform::check_consts::validation::Validator is; but Validator panics given a non-const fn. Unless the rework (rust-lang/rust#76618) leaves something useful for the lint, fixing this false positive requires fair amount of rewriting; probably copying some parts of qualify_min_const_fn.

@ecstatic-morse
Copy link
Contributor

It would be fairly easy to add a "speculative" mode to const-checking. I'll look into this once rust-lang/rust#7661 is complete.

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 E-medium Call for participation: Medium difficulty level problem and requires some initial experience. 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