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

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

Closed
huonw opened this issue May 13, 2013 · 10 comments
Closed

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

huonw opened this issue May 13, 2013 · 10 comments
Labels
A-parser Area: The parsing of Rust source code to an AST P-medium Medium priority

Comments

@huonw
Copy link
Member

huonw commented May 13, 2013

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

@brendanzab
Copy link
Member

use ::core::option::Some; doesn't work either. I don't know if this is related.

@jdm
Copy link
Contributor

jdm commented May 13, 2013

Nominating for feature complete.

@brendanzab
Copy link
Member

This could be related: #6533

@brendanzab
Copy link
Member

Interestingly I get the same error here, without any paths:

pub enum MouseButton {
    MOUSE_BUTTON_1 = 1,
    MOUSE_BUTTON_2 = 2,
    MOUSE_BUTTON_3 = 3,
    MOUSE_BUTTON_4 = 4,
    MOUSE_BUTTON_5 = 5,
    MOUSE_BUTTON_6 = 6,
    MOUSE_BUTTON_7 = 7,
    MOUSE_BUTTON_8 = 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 @0x7f8b7080ba10 root task failed

@jdm
Copy link
Contributor

jdm commented May 16, 2013

@bjz, I would file that as a new issue.

@graydon
Copy link
Contributor

graydon commented May 16, 2013

accepted for production-ready milestone

@pnkfelix
Copy link
Member

pnkfelix commented Jul 2, 2013

linking to #6143 for unified tracking of resolve

@catamorphism
Copy link
Contributor

Bug triage. Milestone looks right.

@wilkie
Copy link

wilkie commented Jan 5, 2014

Recently, referring to https://gist.github.com/wilkie/157110f8387ecfce021e I get an error not already mentioned here:

bug.rs:10:7: 10:9 error: unexpected token: `::`
bug.rs:10       ::foo::X => {},

Using a use statement to avoid having to begin with a '::' does work as a workaround, but it is still not obvious that one cannot explicitly scope something within a match.

@pnkfelix
Copy link
Member

Just a bug, not a 1.0 blocker.

P-high, not 1.0.

@pnkfelix pnkfelix modified the milestone: 1.0 Mar 20, 2014
durka added a commit to durka/rust that referenced this issue Mar 10, 2016
This replaces some `if`s with `match`es. This was originally not possible
because using a global path in a match statement caused a "non-constant
path in constant expr" ICE. The issue is long since closed, though you still
hit it (as an error now, not an ICE) if you try to generate match patterns
using pat_lit(expr_path). But it works when constructing the patterns more
carefully.
durka added a commit to durka/rust that referenced this issue Mar 10, 2016
This replaces some `if`s with `match`es. This was originally not possible
because using a global path in a match statement caused a "non-constant
path in constant expr" ICE. The issue is long since closed, though you still
hit it (as an error now, not an ICE) if you try to generate match patterns
using pat_lit(expr_path). But it works when constructing the patterns more
carefully.
durka added a commit to durka/rust that referenced this issue Mar 13, 2016
This replaces some `if`s with `match`es. This was originally not possible
because using a global path in a match statement caused a "non-constant
path in constant expr" ICE. The issue is long since closed, though you still
hit it (as an error now, not an ICE) if you try to generate match patterns
using pat_lit(expr_path). But it works when constructing the patterns more
carefully.
durka added a commit to durka/rust that referenced this issue Mar 14, 2016
This replaces some `if`s with `match`es. This was originally not possible
because using a global path in a match statement caused a "non-constant
path in constant expr" ICE. The issue is long since closed, though you still
hit it (as an error now, not an ICE) if you try to generate match patterns
using pat_lit(expr_path). But it works when constructing the patterns more
carefully.
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 20, 2020
needless_borrow: print the type in the lint message

changelog: needless_borrow: print type in lint message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

8 participants