Skip to content

Fix patterns of the constants that are const methods #33284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libcore/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

) }
13 changes: 13 additions & 0 deletions src/libcore/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#![doc(hidden)]

#[cfg(stage0)]
macro_rules! uint_module { ($T:ty, $bits:expr) => (

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -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();

) }
2 changes: 1 addition & 1 deletion src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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?")
}
}