diff options
| author | bors <bors@rust-lang.org> | 2016-05-02 02:33:33 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-02 02:33:33 -0700 |
| commit | d3c2c71988c1b2707c6c2ba19f14dc1ffe6a56fc (patch) | |
| tree | 0e78c2bc545ee877a1c2c96bfa5e547ef5740ada | |
| parent | 700d3e23748c10c4203491856186333dd2952ebf (diff) | |
| parent | 04f8ba2ece3de0892e826db86f491f044e06d24c (diff) | |
| download | rust-d3c2c71988c1b2707c6c2ba19f14dc1ffe6a56fc.tar.gz rust-d3c2c71988c1b2707c6c2ba19f14dc1ffe6a56fc.zip | |
Auto merge of #33284 - nagisa:mir-fix-constfn-pats, r=alexcrichton
Fix patterns of the constants that are const methods
| -rw-r--r-- | src/libcore/num/int_macros.rs | 13 | ||||
| -rw-r--r-- | src/libcore/num/uint_macros.rs | 13 | ||||
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/const-meth-pattern.rs | 27 |
4 files changed, 54 insertions, 1 deletions
diff --git a/src/libcore/num/int_macros.rs b/src/libcore/num/int_macros.rs index 42349257ab7..fb1a3bbe3b4 100644 --- a/src/libcore/num/int_macros.rs +++ b/src/libcore/num/int_macros.rs @@ -10,6 +10,7 @@ #![doc(hidden)] +#[cfg(stage0)] macro_rules! int_module { ($T:ty, $bits:expr) => ( // FIXME(#11621): Should be deprecated once CTFE is implemented in favour of @@ -25,3 +26,15 @@ pub const MIN: $T = (-1 as $T) << ($bits - 1); pub const MAX: $T = !MIN; ) } + +#[cfg(not(stage0))] +macro_rules! int_module { ($T:ident, $bits:expr) => ( + +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(missing_docs)] +pub const MIN: $T = $T::min_value(); +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(missing_docs)] +pub const MAX: $T = $T::max_value(); + +) } diff --git a/src/libcore/num/uint_macros.rs b/src/libcore/num/uint_macros.rs index 6479836cbe1..af6b1b89f96 100644 --- a/src/libcore/num/uint_macros.rs +++ b/src/libcore/num/uint_macros.rs @@ -10,6 +10,7 @@ #![doc(hidden)] +#[cfg(stage0)] macro_rules! uint_module { ($T:ty, $bits:expr) => ( #[stable(feature = "rust1", since = "1.0.0")] @@ -20,3 +21,15 @@ pub const MIN: $T = 0 as $T; pub const MAX: $T = !0 as $T; ) } + +#[cfg(not(stage0))] +macro_rules! uint_module { ($T:ident, $bits:expr) => ( + +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(missing_docs)] +pub const MIN: $T = $T::min_value(); +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(missing_docs)] +pub const MAX: $T = $T::max_value(); + +) } diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index c2ac3d838c8..132caa010d4 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 00000000000..3b27987f190 --- /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 <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?") + } +} |
