about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-11-11 00:21:23 +0100
committerGitHub <noreply@github.com>2018-11-11 00:21:23 +0100
commit0f1c1eb48071d4ea02429ae5136444755b299fb7 (patch)
tree28c5944fcca84ec9e8cfedc9bce84ad492ea7518
parent4c50964c5f015f48006b0722545424f80158eea2 (diff)
parentf4c9dd55d6446f6308dc70ab8f88129a87c5daf1 (diff)
downloadrust-0f1c1eb48071d4ea02429ae5136444755b299fb7.tar.gz
rust-0f1c1eb48071d4ea02429ae5136444755b299fb7.zip
Rollup merge of #55828 - oli-obk:promotion_strikes_again, r=eddyb
Add missing `rustc_promotable` attribute to unsigned `min_value` and `max_value`

cc @pnkfelix

fixes #55806
-rw-r--r--src/libcore/num/mod.rs2
-rw-r--r--src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs31
-rw-r--r--src/test/ui/consts/promote_fn_calls.rs13
-rw-r--r--src/test/ui/consts/promote_fn_calls_std.rs30
4 files changed, 76 insertions, 0 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 090147c9fe4..30b7b454684 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -2152,6 +2152,7 @@ Basic usage:
 ", $Feature, "assert_eq!(", stringify!($SelfT), "::min_value(), 0);", $EndFeature, "
 ```"),
             #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_promotable]
             #[inline]
             pub const fn min_value() -> Self { 0 }
         }
@@ -2168,6 +2169,7 @@ Basic usage:
 stringify!($MaxV), ");", $EndFeature, "
 ```"),
             #[stable(feature = "rust1", since = "1.0.0")]
+            #[rustc_promotable]
             #[inline]
             pub const fn max_value() -> Self { !0 }
         }
diff --git a/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs b/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs
new file mode 100644
index 00000000000..f6bbcc60e4e
--- /dev/null
+++ b/src/test/ui/consts/auxiliary/promotable_const_fn_lib.rs
@@ -0,0 +1,31 @@
+// Copyright 2015 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.
+
+// Crate that exports a const fn. Used for testing cross-crate.
+
+#![feature(staged_api, rustc_attrs)]
+#![stable(since="1.0.0", feature = "mep")]
+
+#![crate_type="rlib"]
+
+#[rustc_promotable]
+#[stable(since="1.0.0", feature = "mep")]
+#[inline]
+pub const fn foo() -> usize { 22 }
+
+#[stable(since="1.0.0", feature = "mep")]
+pub struct Foo(usize);
+
+impl Foo {
+    #[stable(since="1.0.0", feature = "mep")]
+    #[inline]
+    #[rustc_promotable]
+    pub const fn foo() -> usize { 22 }
+}
diff --git a/src/test/ui/consts/promote_fn_calls.rs b/src/test/ui/consts/promote_fn_calls.rs
new file mode 100644
index 00000000000..045322de347
--- /dev/null
+++ b/src/test/ui/consts/promote_fn_calls.rs
@@ -0,0 +1,13 @@
+// compile-pass
+// aux-build:promotable_const_fn_lib.rs
+
+#![feature(nll)]
+
+extern crate promotable_const_fn_lib;
+
+use promotable_const_fn_lib::{foo, Foo};
+
+fn main() {
+    let x: &'static usize = &foo();
+    let x: &'static usize = &Foo::foo();
+}
diff --git a/src/test/ui/consts/promote_fn_calls_std.rs b/src/test/ui/consts/promote_fn_calls_std.rs
new file mode 100644
index 00000000000..0350708d673
--- /dev/null
+++ b/src/test/ui/consts/promote_fn_calls_std.rs
@@ -0,0 +1,30 @@
+// compile-pass
+
+#![feature(nll)]
+
+fn main() {
+    let x: &'static u8 = &u8::max_value();
+    let x: &'static u16 = &u16::max_value();
+    let x: &'static u32 = &u32::max_value();
+    let x: &'static u64 = &u64::max_value();
+    let x: &'static u128 = &u128::max_value();
+    let x: &'static usize = &usize::max_value();
+    let x: &'static u8 = &u8::min_value();
+    let x: &'static u16 = &u16::min_value();
+    let x: &'static u32 = &u32::min_value();
+    let x: &'static u64 = &u64::min_value();
+    let x: &'static u128 = &u128::min_value();
+    let x: &'static usize = &usize::min_value();
+    let x: &'static i8 = &i8::max_value();
+    let x: &'static i16 = &i16::max_value();
+    let x: &'static i32 = &i32::max_value();
+    let x: &'static i64 = &i64::max_value();
+    let x: &'static i128 = &i128::max_value();
+    let x: &'static isize = &isize::max_value();
+    let x: &'static i8 = &i8::min_value();
+    let x: &'static i16 = &i16::min_value();
+    let x: &'static i32 = &i32::min_value();
+    let x: &'static i64 = &i64::min_value();
+    let x: &'static i128 = &i128::min_value();
+    let x: &'static isize = &isize::min_value();
+}