Skip to content

Commit d3c2c71

Browse files
committed
Auto merge of rust-lang#33284 - nagisa:mir-fix-constfn-pats, r=alexcrichton
Fix patterns of the constants that are const methods
2 parents 700d3e2 + 04f8ba2 commit d3c2c71

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/libcore/num/int_macros.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![doc(hidden)]
1212

13+
#[cfg(stage0)]
1314
macro_rules! int_module { ($T:ty, $bits:expr) => (
1415

1516
// 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);
2526
pub const MAX: $T = !MIN;
2627

2728
) }
29+
30+
#[cfg(not(stage0))]
31+
macro_rules! int_module { ($T:ident, $bits:expr) => (
32+
33+
#[stable(feature = "rust1", since = "1.0.0")]
34+
#[allow(missing_docs)]
35+
pub const MIN: $T = $T::min_value();
36+
#[stable(feature = "rust1", since = "1.0.0")]
37+
#[allow(missing_docs)]
38+
pub const MAX: $T = $T::max_value();
39+
40+
) }

src/libcore/num/uint_macros.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![doc(hidden)]
1212

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

1516
#[stable(feature = "rust1", since = "1.0.0")]
@@ -20,3 +21,15 @@ pub const MIN: $T = 0 as $T;
2021
pub const MAX: $T = !0 as $T;
2122

2223
) }
24+
25+
#[cfg(not(stage0))]
26+
macro_rules! uint_module { ($T:ident, $bits:expr) => (
27+
28+
#[stable(feature = "rust1", since = "1.0.0")]
29+
#[allow(missing_docs)]
30+
pub const MIN: $T = $T::min_value();
31+
#[stable(feature = "rust1", since = "1.0.0")]
32+
#[allow(missing_docs)]
33+
pub const MAX: $T = $T::max_value();
34+
35+
) }

src/librustc_const_eval/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub fn const_expr_to_pat(tcx: &ty::TyCtxt, expr: &Expr, pat_id: ast::NodeId, spa
281281
let path = match def.full_def() {
282282
Def::Struct(def_id) => def_to_path(tcx, def_id),
283283
Def::Variant(_, variant_did) => def_to_path(tcx, variant_did),
284-
Def::Fn(..) => return Ok(P(hir::Pat {
284+
Def::Fn(..) | Def::Method(..) => return Ok(P(hir::Pat {
285285
id: expr.id,
286286
node: PatKind::Lit(P(expr.clone())),
287287
span: span,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(const_fn)]
11+
12+
struct A;
13+
14+
impl A {
15+
const fn banana() -> bool {
16+
true
17+
}
18+
}
19+
20+
const ABANANA: bool = A::banana();
21+
22+
fn main() {
23+
match true {
24+
ABANANA => {},
25+
_ => panic!("what?")
26+
}
27+
}

0 commit comments

Comments
 (0)