Skip to content

Diagnostic: "constant evaluation error" without further details #41893

Closed
@SimonSapin

Description

@SimonSapin
#![feature(nonzero, const_fn)]

extern crate core;

mod a {
    use core::nonzero::NonZero;

    #[derive(Eq, PartialEq)]
    pub struct Foo {
        bar: NonZero<u64>,  // Private
    }

    pub const FOO: Foo = Foo {
        bar: unsafe { NonZero::new(2) },
    };
}

fn main() {
    assert!(a::FOO == a::FOO);
    assert!(match a::FOO {
        a::FOO => true,
        _ => false,
    });
}

rustc 1.19.0-nightly (d3abc80 2017-05-09)

error[E0080]: constant evaluation error
   |
note: for pattern here
  --> a.rs:21:9
   |
21 |         a::FOO => true,
   |         ^^^^^^

error: aborting due to previous error

The error message doesn’t say what’s wrong with this pattern. Based on code in src/librustc/middle/const_val.rs it looks like more info should be printed, with ConstEvalErr::description.

CC @eddyb

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions