Skip to content

Commit

Permalink
Fix patterns of the constants that are const meth
Browse files Browse the repository at this point in the history
See the regression test for the sample code this fixes
  • Loading branch information
nagisa committed Apr 30, 2016
1 parent 8da2bca commit 5f95610
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc_const_eval/eval.rs
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions 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 <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?")
}
}

0 comments on commit 5f95610

Please sign in to comment.