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

'Unsupported constant expr' when matching on tuple-struct constants #6533

Closed
brendanzab opened this issue May 16, 2013 · 4 comments
Closed
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@brendanzab
Copy link
Member

edited because it no longer ICEs.

pub mod glfw {
    pub struct InputState(uint);

    pub static RELEASE  : InputState = InputState(0);
    pub static PRESS    : InputState = InputState(1);
    pub static REPEAT   : InputState = InputState(2);
}

fn action_to_str(state: glfw::InputState) -> ~str {
    use glfw::{RELEASE, PRESS, REPEAT};
    match state {
        RELEASE => { ~"Released" }
        PRESS   => { ~"Pressed"  }
        REPEAT  => { ~"Repeated" }
        _       => { ~"Unknown"  }
    }
}

fn main() {}

Error:

ice.rs:4:40: 4:53 error: unsupported constant expr
ice.rs:4     pub static RELEASE  : InputState = InputState(0);
                                                ^~~~~~~~~~~~~
@msullivan
Copy link
Contributor

This is now a non-ICE failure. Is this something that we intend to support?

../rust-things/bug-6533.rs:5:39: 5:53 error: Unsupported constant expr
../rust-things/bug-6533.rs:5     pub static PRESS    : InputState = InputState(1);

@alexcrichton
Copy link
Member

If the definition were instead InputState { value: uint } then you can create a static, so it seems to be like this should be allowed.

@catamorphism
Copy link
Contributor

Reproduced what @msullivan reported with 2ab4a6f . I agree with @alexcrichton ; doesn't seem like a milestone blocker, though.

@erickt erickt added I-wrong and removed I-ICE labels May 11, 2014
@erickt erickt changed the title ICE: 'Unsupported constant expr' when matching on tuple-struct constants 'Unsupported constant expr' when matching on tuple-struct constants May 11, 2014
@erickt
Copy link
Contributor

erickt commented May 11, 2014

visiting for triage. This code no longer ICEs, but it still can't pattern match on the tuple structs. I updated the body to reflect this.

bors added a commit that referenced this issue Jul 19, 2014
This is accomplished by rewriting static expressions into equivalent patterns.
This way, patterns referencing static variables can both participate
in exhaustiveness analysis as well as be compiled down into the appropriate
branch of the decision trees that match expressions are codegened to.

Fixes #6533.
Fixes #13626.
Fixes #13731.
Fixes #14576.
Fixes #15393.
@bors bors closed this as completed in fba1194 Jul 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants