]> git.lizzy.rs Git - rust.git/commitdiff
Fix patterns of the constants that are const meth
authorSimonas Kazlauskas <git@kazlauskas.me>
Sat, 30 Apr 2016 00:30:33 +0000 (03:30 +0300)
committerSimonas Kazlauskas <git@kazlauskas.me>
Sat, 30 Apr 2016 00:40:09 +0000 (03:40 +0300)
See the regression test for the sample code this fixes

src/librustc_const_eval/eval.rs
src/test/run-pass/const-meth-pattern.rs [new file with mode: 0644]

index c2ac3d838c8d071074982ad2997dcb84e083eeea..132caa010d42f526d3b8fc94d74aafe75f13693c 100644 (file)
@@ -281,7 +281,7 @@ pub fn const_expr_to_pat(tcx: &ty::TyCtxt, expr: &Expr, pat_id: ast::NodeId, spa
             let path = match def.full_def() {
                 Def::Struct(def_id) => def_to_path(tcx, def_id),
                 Def::Variant(_, variant_did) => def_to_path(tcx, variant_did),
-                Def::Fn(..) => return Ok(P(hir::Pat {
+                Def::Fn(..) | Def::Method(..) => return Ok(P(hir::Pat {
                     id: expr.id,
                     node: PatKind::Lit(P(expr.clone())),
                     span: span,
diff --git a/src/test/run-pass/const-meth-pattern.rs b/src/test/run-pass/const-meth-pattern.rs
new file mode 100644 (file)
index 0000000..3b27987
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![feature(const_fn)]
+
+struct A;
+
+impl A {
+    const fn banana() -> bool {
+        true
+    }
+}
+
+const ABANANA: bool = A::banana();
+
+fn main() {
+    match true {
+        ABANANA => {},
+        _ => panic!("what?")
+    }
+}