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

funkiness related to static constants in match patterns #13731

Closed
pnkfelix opened this issue Apr 24, 2014 · 2 comments
Closed

funkiness related to static constants in match patterns #13731

pnkfelix opened this issue Apr 24, 2014 · 2 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@pnkfelix
Copy link
Member

Some code:

#![crate_type="lib"]

pub mod variant0 {
    pub enum A { A(()) }
    pub static B: A = A(());

    pub fn main() {
    }
}

#[cfg(variant1)]
pub mod variant1 {
    pub enum A { A(()) }
    pub static B: A = A(()); // <-- error here ...

    // /tmp/s.rs:6:23: 6:28 error: unsupported constant expr
    // /tmp/s.rs:6     pub static B: A = A(());
    //                                  ^~~~~

    pub fn main() {
        match A(()) {
            B => (), // ... introduced by use of `B` here
            _ => (), }
    }
}

#[cfg(variant2)]
pub mod variant2 {
    pub enum C { D=3, E=4 }
    pub static F : C = D;

    pub fn main() {
        match D { F => (), _ => (), }
    }
}

pub mod variant3 {
    pub enum C { D=3, E=4 }
    pub static F : int = 3;

    pub fn main() {
        match D as int { F => (), _ => (), }
    }
}

Some funkiness:

% rustc /tmp/s.rs
% rustc --cfg variant1 /tmp/s.rs
/tmp/s.rs:14:23: 14:28 error: unsupported constant expr
/tmp/s.rs:14     pub static B: A = A(()); // <-- error here ...
                                   ^~~~~
% rustc --cfg variant2 /tmp/s.rs
error: internal compiler error: only scalars and strings supported in compare_values
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at '~Any', /Users/fklock/Dev/Mozilla/rust.git/src/libsyntax/diagnostic.rs:155

%  

The oddity in variant1, as noted in the comments, is that the use of B in a match pattern is causing the compiler to complain about its definition as a static item.

The oddity in variant2 is that we hit an ICE. :)

@jfager
Copy link
Contributor

jfager commented Apr 24, 2014

See also funkiness in #11940

@lifthrasiir
Copy link
Contributor

Duplicate of #13626.

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.

4 participants