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

ICE: 'Non-constant path in constant expr' when matching on enum constants #6538

Closed
brendanzab opened this issue May 16, 2013 · 2 comments
Closed

Comments

@brendanzab
Copy link
Member

This could be related to #6533 and #6449

pub enum MouseButton {
    MOUSE_BUTTON_1,
    MOUSE_BUTTON_2,
    MOUSE_BUTTON_3,
    MOUSE_BUTTON_4,
    MOUSE_BUTTON_5,
    MOUSE_BUTTON_6,
    MOUSE_BUTTON_7,
    MOUSE_BUTTON_8,
}

pub static MOUSE_BUTTON_LEFT    : MouseButton = MOUSE_BUTTON_1;
pub static MOUSE_BUTTON_RIGHT   : MouseButton = MOUSE_BUTTON_2;
pub static MOUSE_BUTTON_MIDDLE  : MouseButton = MOUSE_BUTTON_3;

fn mouse_button_to_str(button: MouseButton) -> ~str {
    match button {
        MOUSE_BUTTON_LEFT     => ~"Left",
        MOUSE_BUTTON_RIGHT    => ~"Right",
        MOUSE_BUTTON_MIDDLE   => ~"Middle",
        MOUSE_BUTTON_4        => ~"4",
        MOUSE_BUTTON_5        => ~"5",
        MOUSE_BUTTON_6        => ~"6",
        MOUSE_BUTTON_7        => ~"7",
        MOUSE_BUTTON_8        => ~"8",
    }
}

fn main() {}

Error:

$ RUST_LOG=rustc=1,::rt::backtrace rustc enum-match-ice.rs
rust: task failed at 'Non-constant path in constant expr', /------/rust/src/librustc/middle/const_eval.rs:245
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /------/rust/src/librustc/rustc.rc:355
rust: domain main @0x7ffc9a00ba10 root task failed
@graydon
Copy link
Contributor

graydon commented May 23, 2013

accepted for production-ready milestone

@metajack
Copy link
Contributor

This no longer ICEs. Instead you get a reasonable error message:

$ rustc glfw.rs
glfw.rs:13:48: 13:62 error: Non-constant path in constant expr
glfw.rs:13 pub static MOUSE_BUTTON_RIGHT   : MouseButton = MOUSE_BUTTON_2;
                                                           ^~~~~~~~~~~~~~

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 15, 2021
New lint: vec_init_then_push

fixes: rust-lang#1483

This will trigger on `new`, `default`, and `with_capacity` when the given capacity is less than or equal to the number of push calls. Is there anything else this should trigger on?

changelog: Added lint: `vec_init_then_push`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants