From 5f956103c8a939e69b1da6f9b8f674802520b229 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 30 Apr 2016 03:30:33 +0300 Subject: [PATCH] Fix patterns of the constants that are const meth See the regression test for the sample code this fixes --- src/librustc_const_eval/eval.rs | 2 +- src/test/run-pass/const-meth-pattern.rs | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/const-meth-pattern.rs diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index c2ac3d838c8d0..132caa010d42f 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -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 index 0000000000000..3b27987f190cd --- /dev/null +++ b/src/test/run-pass/const-meth-pattern.rs @@ -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 or the MIT license +// , 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?") + } +}