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

Constant evaluation error at wrong location #40604

Closed
phil-opp opened this issue Mar 17, 2017 · 1 comment
Closed

Constant evaluation error at wrong location #40604

phil-opp opened this issue Mar 17, 2017 · 1 comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@phil-opp
Copy link
Contributor

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).

@sanxiyn sanxiyn added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Mar 16, 2018

fixed by #48864

@oli-obk oli-obk closed this as completed Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants