Skip to content

Constant evaluation error at wrong location #40604

Closed
@phil-opp

Description

@phil-opp

When I try to pattern match on a constant created by a const_fn across two crates, I get a constant evaluation error (E0080) that points to a completely random location.

Minimal Example

cargo new foo
cargo new bar

In bar/src/lib.rs:

#![feature(const_fn)]

pub struct Foo(pub u8);

impl Foo {
    pub const fn new(addr: u8) -> Self {
        Foo(addr)
    }
}

In foo/Cargo.toml:

[dependencies]
bar = {path = "../bar"}

In foo/src/lib.rs:

extern crate bar;
use bar::Foo;
const FOO: Foo = Foo::new(0);

pub fn foo() {
    // Lorem ipsum dolor sit amet, consetetur sadipscing elitr
    match Foo::new(0) {
        FOO => {}
    }
}

The Error

When running cargo build in foo, the following error occurs on nightly (0aeb9c1 2017-03-15):

error[E0080]: constant evaluation error
 --> src/lib.rs:6:31
  |
6 |     // Lorem ipsum dolor sit amet, consetetur sadipscing elitr
  |                               ^^^^^^^^^ unimplemented constant expression: tuple struct constructors
  |
note: for pattern here
 --> src/lib.rs:8:9
  |
8 |         FOO => {}
  |         ^^^

error: aborting due to previous error

It doesn't happen when I merge the Foo struct from the bar crate into the foo crate or when I replace the Foo::new(0) call with Foo(0).

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions