about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2015-12-01 17:37:01 +0100
committerOliver 'ker' Schneider <rust19446194516@oli-obk.de>2015-12-06 12:59:53 +0100
commitd23800f3f23eae91fec31172e03fdfc9614c3d1c (patch)
treef3d6326c7d48319ece58bb7567634650abbf73db
parentd75f861518cb3b43acd1ae774fd13605a5dfd2d9 (diff)
downloadrust-d23800f3f23eae91fec31172e03fdfc9614c3d1c.tar.gz
rust-d23800f3f23eae91fec31172e03fdfc9614c3d1c.zip
allow const function calls in consts that are used in patterns
closes #30117
-rw-r--r--src/librustc/middle/const_eval.rs7
-rw-r--r--src/test/run-pass/consts-in-patterns.rs7
2 files changed, 12 insertions, 2 deletions
diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs
index 7b1c38d86d2..a8afefe939b 100644
--- a/src/librustc/middle/const_eval.rs
+++ b/src/librustc/middle/const_eval.rs
@@ -332,6 +332,11 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
             let path = match def.full_def() {
                 def::DefStruct(def_id) => def_to_path(tcx, def_id),
                 def::DefVariant(_, variant_did, _) => def_to_path(tcx, variant_did),
+                def::DefFn(..) => return P(hir::Pat {
+                    id: expr.id,
+                    node: hir::PatLit(P(expr.clone())),
+                    span: span,
+                }),
                 _ => unreachable!()
             };
             let pats = args.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect();
@@ -1462,6 +1467,6 @@ fn get_fn_def<'a>(tcx: &'a ty::ctxt,
             _ => signal!(e, NonConstPath),
         },
         Some(ast_map::NodeTraitItem(..)) => signal!(e, NonConstPath),
-        Some(_) => unimplemented!(),
+        Some(_) => signal!(e, UnimplementedConstVal("calling struct, tuple or variant")),
     }
 }
diff --git a/src/test/run-pass/consts-in-patterns.rs b/src/test/run-pass/consts-in-patterns.rs
index 36e6e160a3b..eec4c940585 100644
--- a/src/test/run-pass/consts-in-patterns.rs
+++ b/src/test/run-pass/consts-in-patterns.rs
@@ -1,4 +1,4 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -8,15 +8,20 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(const_fn)]
 
 const FOO: isize = 10;
 const BAR: isize = 3;
 
+const fn foo() -> isize { 4 }
+const BOO: isize = foo();
+
 pub fn main() {
     let x: isize = 3;
     let y = match x {
         FOO => 1,
         BAR => 2,
+        BOO => 4,
         _ => 3
     };
     assert_eq!(y, 2);