Skip to content

New deny(const_err) in unreachable code #52966

Closed
@cuviper

Description

@cuviper
use std::{u64, usize};

fn main() {
    if (usize::MAX as u64) < u64::MAX {
        println!("{}", 1 + usize::MAX as u64);
    } else {
        println!("disqualified!");
    }
}

(playground)

This compiles and runs fine on a 32-bit target, but fails on 64-bit 1.29.0-beta.1:

error: attempt to add with overflow
 --> src/main.rs:5:24
  |
5 |         println!("{}", 1 + usize::MAX as u64);
  |                        ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[deny(const_err)] on by default

The same code is fine without even a warning on 64-bit stable 1.27.2. It's also fine on the pre-release 1.28.0 where const-err became deny-by-default (#50653), because the lint isn't triggering at all.

I'm guessing that const-eval is just evaluating more now, thus triggering the lint more often. If this is decided not to be called a regression, it at least warrants a release note for 1.29.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.relnotesMarks issues that should be documented in the release notes of the next release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions