Skip to content

Global paths don't work in match at all #6449

Closed
@huonw

Description

@huonw
fn main() {
    match Some(1i) {
        ::std::option::None => (),
        _ => ()
    }
}

causes

rust: task failed at 'Non-constant path in constant expr', /home/huon/rust/src/librustc/middle/const_eval.rs:245
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7f2d23474c7b]
/usr/local/bin/../lib/librustrt.so(+0x2a7a9)[0x7f2d234857a9]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1a0)[0x7f2d23476c30]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(_ZN3sys13begin_unwind_16_615cb041c655a976_07preE+0x63)[0x7f2d26dd9d93]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x123d22)[0x7f2d26dd9d22]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(_ZN3sys14__extensions__9meth_89249fail_with17_ac9eb45dc42bd6906_07preE+0x6b)[0x7f2d26d1926b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle10const_eval15eval_const_expr15_18e714080831846_07preE+0x1d9)[0x7f2d25260c59]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match11pat_ctor_id17_cae022f360f6f0546_07preE+0x41d)[0x7f2d256fd9bd]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match12missing_ctor15_1c83f67218d27c6_07preE+0x719)[0x7f2d256fec29]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match9is_useful17_171373a22e57e1326_07preE+0x4d0)[0x7f2d256fb260]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match10check_arms17_69fd16459bd67f826_07preE+0x17c)[0x7f2d256f8b3c]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match10check_expr17_cc26556e76f6d92b6_07preE+0x1fa)[0x7f2d256f656a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x7250c5)[0x7f2d256f60c5]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a539f)[0x7f2d2547639f]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a5277)[0x7f2d25476277]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a5089)[0x7f2d25476089]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4aa508)[0x7f2d2547b508]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match8check_fn17_6a2b6ee6eacc23346_07preE+0xb4)[0x7f2d256f7c04]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x726ab9)[0x7f2d256f7ab9]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a333b)[0x7f2d2547433b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a2dc5)[0x7f2d25473dc5]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a25f0)[0x7f2d254735f0]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x4a2435)[0x7f2d25473435]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x2d7881)[0x7f2d252a8881]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6middle11check_match11check_crate17_eabc483fea66f5e46_07preE+0x483)[0x7f2d256f59c3]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa3529b)[0x7f2d25a0629b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0x7155b9)[0x7f2d256e65b9]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_rest17_9368fee59be894ab6_07preE+0x2115)[0x7f2d25a011b5]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver12compile_upto17_3cbff05fabc6d3166_07preE+0x192)[0x7f2d25a06852]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN6driver6driver13compile_input17_d8ffa027e111b5706_07preE+0x107)[0x7f2d25a06cd7]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN12run_compiler17_c7b6fbcba7c0cea46_07preE+0x2bbb)[0x7f2d25a3686b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa7831e)[0x7f2d25a4931e]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa75ccc)[0x7f2d25a46ccc]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa6f6fc)[0x7f2d25a406fc]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa785f8)[0x7f2d25a495f8]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0xecf45)[0x7f2d26da2f45]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x1690d8)[0x7f2d26e1f0d8]
/usr/local/bin/../lib/librustrt.so(_Z18task_start_wrapperP10spawn_args+0x24)[0x7f2d23475624]
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', /home/huon/rust/src/librustc/rustc.rc:355
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x4b)[0x7f2d23474c7b]
/usr/local/bin/../lib/librustrt.so(+0x2a7a9)[0x7f2d234857a9]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1a0)[0x7f2d23476c30]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(_ZN3sys13begin_unwind_16_615cb041c655a976_07preE+0x63)[0x7f2d26dd9d93]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0x123e42)[0x7f2d26dd9e42]
/usr/local/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so(+0xc3d04)[0x7f2d26d79d04]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN7monitor17_db1d451e7194e13d6_07preE+0x2415)[0x7f2d25a39e65]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(+0xa785f8)[0x7f2d25a495f8]
/usr/local/bin/../lib/librustc-c84825241471686d-0.7-pre.so(_ZN4main15_c4de63b748e03d6_07preE+0x69)[0x7f2d25a49259]
rustc(_rust_main+0x2e)[0x400bee]
/usr/local/bin/../lib/librustrt.so(_Z18task_start_wrapperP10spawn_args+0x24)[0x7f2d23475624]
rust: domain main @0xd11430 root task failed

Similarly,

fn main() {
    match Some(1i) {
        ::std::option::Some(1) => (),
        _ => ()
    }
}

is the same, except the actual error message is

rust: task failed at 'Unsupported constant expr', /home/huon/rust/src/librustc/middle/const_eval.rs:245

And

fn main() {
    match Some(1i) {
        ::std::option::Some(_) => (),
        _ => ()
    }
}

doesn't even parse

test.rs:3:29: 3:30 error: unexpected token: `_`
test.rs:3         ::std::option::Some(_) => (),

The versions without the leading :: work fine.

(Among other things, this makes syntax extensions harder/uglier than necessary.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTP-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions