]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/trans/_match.rs
librustc: Fix path-qualified and cross-crate constants in match patterns.
[rust.git] / src / librustc / middle / trans / _match.rs
index 45fe40ca1f70fc6e3aca6886dec2b71e870940fe..09f0a4f547a038f3c19a87e014abfc80aa6298ad 100644 (file)
@@ -502,6 +502,16 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
     let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
     do enter_match(bcx, tcx.def_map, m, col, val) |p| {
         match p.node {
+            ast::pat_enum(*) |
+            ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
+                let const_def = tcx.def_map.get(&p.id);
+                let const_def_id = ast_util::def_id_of_def(const_def);
+                if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
+                    Some(~[])
+                } else {
+                    None
+                }
+            }
             ast::pat_enum(_, ref subpats) => {
                 if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
                     match *subpats {
@@ -520,15 +530,6 @@ pub fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
                     None
                 }
             }
-            ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
-                let const_def = tcx.def_map.get(&p.id);
-                let const_def_id = ast_util::def_id_of_def(const_def);
-                if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
-                    Some(~[])
-                } else {
-                    None
-                }
-            }
             ast::pat_lit(l) => {
                 if opt_eq(tcx, &lit(ExprLit(l)), opt) {Some(~[])} else {None}
             }
@@ -806,6 +807,10 @@ fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], +val: Opt) {
                         add_to_set(ccx.tcx, &mut found,
                                    variant_opt(bcx, cur.id));
                     }
+                    Some(ast::def_const(const_did)) => {
+                        add_to_set(ccx.tcx, &mut found,
+                                   lit(ConstLit(const_did)));
+                    }
                     _ => {}
                 }
             }
@@ -1782,6 +1787,9 @@ pub fn bind_irrefutable_pat(bcx: block,
                         }
                     }
                 }
+                Some(ast::def_const(*)) => {
+                    bcx = bind_irrefutable_pat(bcx, pat, val, make_copy, binding_mode);
+                }
                 _ => {
                     // Nothing to do here.
                 }