Skip to content
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

Rollup of 5 pull requests #73271

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ba9588e
Add `const_float_bits_conv` for `f64::to_bits` and friends
ecstatic-morse May 22, 2020
040da96
Make floating point classify functions `const fn`
ecstatic-morse May 23, 2020
cbc14a2
Test new floating point bit casts
ecstatic-morse May 22, 2020
407f9a4
Ensure consts get compared at runtime
ecstatic-morse May 23, 2020
9dadeb3
Test `is_nan`
ecstatic-morse May 23, 2020
d1c275b
linker: MSVC supports linking static libraries as a whole archive
petrochenkov May 30, 2020
687767a
Suggest substituting `'static` lifetime in impl/dyn `Trait + 'static`…
estebank May 29, 2020
c91320f
When `'static` is explicit, suggest constraining argument with it
estebank May 30, 2020
abf74b9
Reduce verbosity of suggestion message and mention lifetime in label
estebank May 30, 2020
50c422e
Move overlapping span to a note
estebank May 30, 2020
17951e2
Tweak output for overlapping required/captured spans
estebank May 30, 2020
19bb589
Tweak wording and add error code
estebank May 30, 2020
3cfecde
review comments: wording
estebank Jun 1, 2020
bdfb9b1
Use note for requirement source span
estebank Jun 2, 2020
215de3b
Register new eror code
estebank Jun 2, 2020
187e105
small tweaks
estebank Jun 2, 2020
6145918
Change E0758 to E0759 to avoid conflict with #72912
estebank Jun 3, 2020
fff822f
Migrate to numeric associated consts
tesuji Jun 2, 2020
c29b3fa
On recursive ADT, provide indirection structured suggestion
estebank May 29, 2020
7cde07e
review comments: only suggest one substitution
estebank May 31, 2020
03552ec
fix rebase
estebank Jun 10, 2020
802a9ac
Rollup merge of #72449 - ecstatic-morse:const-float-bitcast, r=RalfJu…
RalfJung Jun 12, 2020
35e5dfe
Rollup merge of #72740 - estebank:recursive-indirection, r=matthewjasper
RalfJung Jun 12, 2020
97ae4f6
Rollup merge of #72785 - petrochenkov:wholemsvc, r=matthewjasper
RalfJung Jun 12, 2020
cb425c8
Rollup merge of #72804 - estebank:opaque-missing-lts-in-fn-2, r=nikom…
RalfJung Jun 12, 2020
eda9d21
Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnay
RalfJung Jun 12, 2020
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
4 changes: 2 additions & 2 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ trait RcBoxPtr<T: ?Sized> {
// The reference count will never be zero when this is called;
// nevertheless, we insert an abort here to hint LLVM at
// an otherwise missed optimization.
if strong == 0 || strong == usize::max_value() {
if strong == 0 || strong == usize::MAX {
abort();
}
self.inner().strong.set(strong + 1);
Expand All @@ -2058,7 +2058,7 @@ trait RcBoxPtr<T: ?Sized> {
// The reference count will never be zero when this is called;
// nevertheless, we insert an abort here to hint LLVM at
// an otherwise missed optimization.
if weak == 0 || weak == usize::max_value() {
if weak == 0 || weak == usize::MAX {
abort();
}
self.inner().weak.set(weak + 1);
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/rc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ fn test_from_vec() {
fn test_downcast() {
use std::any::Any;

let r1: Rc<dyn Any> = Rc::new(i32::max_value());
let r1: Rc<dyn Any> = Rc::new(i32::MAX);
let r2: Rc<dyn Any> = Rc::new("abc");

assert!(r1.clone().downcast::<u32>().is_err());

let r1i32 = r1.downcast::<i32>();
assert!(r1i32.is_ok());
assert_eq!(r1i32.unwrap(), Rc::new(i32::max_value()));
assert_eq!(r1i32.unwrap(), Rc::new(i32::MAX));

assert!(r2.clone().downcast::<i32>().is_err());

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ fn test_from_vec() {
fn test_downcast() {
use std::any::Any;

let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::MAX);
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");

assert!(r1.clone().downcast::<u32>().is_err());

let r1i32 = r1.downcast::<i32>();
assert!(r1i32.is_ok());
assert_eq!(r1i32.unwrap(), Arc::new(i32::max_value()));
assert_eq!(r1i32.unwrap(), Arc::new(i32::MAX));

assert!(r2.clone().downcast::<i32>().is_err());

Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,13 @@ mod slice_index {
data: "hello";
// note: using 0 specifically ensures that the result of overflowing is 0..0,
// so that `get` doesn't simply return None for the wrong reason.
bad: data[0..=usize::max_value()];
bad: data[0..=usize::MAX];
message: "maximum usize";
}

in mod rangetoinclusive {
data: "hello";
bad: data[..=usize::max_value()];
bad: data[..=usize::MAX];
message: "maximum usize";
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn test_reserve() {

#[test]
fn test_zst_capacity() {
assert_eq!(Vec::<()>::new().capacity(), usize::max_value());
assert_eq!(Vec::<()>::new().capacity(), usize::MAX);
}

#[test]
Expand Down Expand Up @@ -563,19 +563,19 @@ fn test_drain_inclusive_range() {

#[test]
fn test_drain_max_vec_size() {
let mut v = Vec::<()>::with_capacity(usize::max_value());
let mut v = Vec::<()>::with_capacity(usize::MAX);
unsafe {
v.set_len(usize::max_value());
v.set_len(usize::MAX);
}
for _ in v.drain(usize::max_value() - 1..) {}
assert_eq!(v.len(), usize::max_value() - 1);
for _ in v.drain(usize::MAX - 1..) {}
assert_eq!(v.len(), usize::MAX - 1);

let mut v = Vec::<()>::with_capacity(usize::max_value());
let mut v = Vec::<()>::with_capacity(usize::MAX);
unsafe {
v.set_len(usize::max_value());
v.set_len(usize::MAX);
}
for _ in v.drain(usize::max_value() - 1..=usize::max_value() - 1) {}
assert_eq!(v.len(), usize::max_value() - 1);
for _ in v.drain(usize::MAX - 1..=usize::MAX - 1) {}
assert_eq!(v.len(), usize::MAX - 1);
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,16 +1163,16 @@ impl<'b> BorrowRef<'b> {
// Incrementing borrow can result in a non-reading value (<= 0) in these cases:
// 1. It was < 0, i.e. there are writing borrows, so we can't allow a read borrow
// due to Rust's reference aliasing rules
// 2. It was isize::max_value() (the max amount of reading borrows) and it overflowed
// into isize::min_value() (the max amount of writing borrows) so we can't allow
// 2. It was isize::MAX (the max amount of reading borrows) and it overflowed
// into isize::MIN (the max amount of writing borrows) so we can't allow
// an additional read borrow because isize can't represent so many read borrows
// (this can only happen if you mem::forget more than a small constant amount of
// `Ref`s, which is not good practice)
None
} else {
// Incrementing borrow can result in a reading value (> 0) in these cases:
// 1. It was = 0, i.e. it wasn't borrowed, and we are taking the first read borrow
// 2. It was > 0 and < isize::max_value(), i.e. there were read borrows, and isize
// 2. It was > 0 and < isize::MAX, i.e. there were read borrows, and isize
// is large enough to represent having one more read borrow
borrow.set(b);
Some(BorrowRef { borrow })
Expand All @@ -1198,7 +1198,7 @@ impl Clone for BorrowRef<'_> {
debug_assert!(is_reading(borrow));
// Prevent the borrow counter from overflowing into
// a writing borrow.
assert!(borrow != isize::max_value());
assert!(borrow != isize::MAX);
self.borrow.set(borrow + 1);
BorrowRef { borrow: self.borrow }
}
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl<'b> BorrowRefMut<'b> {
let borrow = self.borrow.get();
debug_assert!(is_writing(borrow));
// Prevent the borrow counter from underflowing.
assert!(borrow != isize::min_value());
assert!(borrow != isize::MIN);
self.borrow.set(borrow - 1);
BorrowRefMut { borrow: self.borrow }
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ macro_rules! try_from_upper_bounded {
/// is outside of the range of the target type.
#[inline]
fn try_from(u: $source) -> Result<Self, Self::Error> {
if u > (Self::max_value() as $source) {
if u > (Self::MAX as $source) {
Err(TryFromIntError(()))
} else {
Ok(u as Self)
Expand All @@ -239,8 +239,8 @@ macro_rules! try_from_both_bounded {
/// is outside of the range of the target type.
#[inline]
fn try_from(u: $source) -> Result<Self, Self::Error> {
let min = Self::min_value() as $source;
let max = Self::max_value() as $source;
let min = Self::MIN as $source;
let max = Self::MAX as $source;
if u < min || u > max {
Err(TryFromIntError(()))
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
#![feature(constctlz)]
#![feature(const_panic)]
#![feature(const_fn_union)]
#![feature(const_float_bits_conv)]
#![feature(const_float_classify)]
#![feature(const_generics)]
#![feature(const_ptr_offset)]
#![feature(const_ptr_offset_from)]
Expand Down
50 changes: 33 additions & 17 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,18 @@ impl f32 {
/// assert!(!f.is_nan());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_nan(self) -> bool {
pub const fn is_nan(self) -> bool {
self != self
}

// FIXME(#50145): `abs` is publicly unavailable in libcore due to
// concerns about portability, so this implementation is for
// private use internally.
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
fn abs_private(self) -> f32 {
const fn abs_private(self) -> f32 {
f32::from_bits(self.to_bits() & 0x7fff_ffff)
}

Expand All @@ -410,8 +412,9 @@ impl f32 {
/// assert!(neg_inf.is_infinite());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_infinite(self) -> bool {
pub const fn is_infinite(self) -> bool {
self.abs_private() == Self::INFINITY
}

Expand All @@ -430,8 +433,9 @@ impl f32 {
/// assert!(!neg_inf.is_finite());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_finite(self) -> bool {
pub const fn is_finite(self) -> bool {
// There's no need to handle NaN separately: if self is NaN,
// the comparison is not true, exactly as desired.
self.abs_private() < Self::INFINITY
Expand All @@ -457,9 +461,10 @@ impl f32 {
/// ```
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_normal(self) -> bool {
self.classify() == FpCategory::Normal
pub const fn is_normal(self) -> bool {
matches!(self.classify(), FpCategory::Normal)
}

/// Returns the floating point category of the number. If only one property
Expand All @@ -476,7 +481,8 @@ impl f32 {
/// assert_eq!(inf.classify(), FpCategory::Infinite);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn classify(self) -> FpCategory {
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
pub const fn classify(self) -> FpCategory {
const EXP_MASK: u32 = 0x7f800000;
const MAN_MASK: u32 = 0x007fffff;

Expand All @@ -501,8 +507,9 @@ impl f32 {
/// assert!(!g.is_sign_positive());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_sign_positive(self) -> bool {
pub const fn is_sign_positive(self) -> bool {
!self.is_sign_negative()
}

Expand All @@ -517,8 +524,9 @@ impl f32 {
/// assert!(g.is_sign_negative());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_float_classify", issue = "72505")]
#[inline]
pub fn is_sign_negative(self) -> bool {
pub const fn is_sign_negative(self) -> bool {
// IEEE754 says: isSignMinus(x) is true if and only if x has negative sign. isSignMinus
// applies to zeros and NaNs as well.
self.to_bits() & 0x8000_0000 != 0
Expand Down Expand Up @@ -650,8 +658,9 @@ impl f32 {
///
/// ```
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn to_bits(self) -> u32 {
pub const fn to_bits(self) -> u32 {
// SAFETY: `u32` is a plain old datatype so we can always transmute to it
unsafe { mem::transmute(self) }
}
Expand Down Expand Up @@ -693,8 +702,9 @@ impl f32 {
/// assert_eq!(v, 12.5);
/// ```
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn from_bits(v: u32) -> Self {
pub const fn from_bits(v: u32) -> Self {
// SAFETY: `u32` is a plain old datatype so we can always transmute from it
// It turns out the safety issues with sNaN were overblown! Hooray!
unsafe { mem::transmute(v) }
Expand All @@ -710,8 +720,9 @@ impl f32 {
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn to_be_bytes(self) -> [u8; 4] {
pub const fn to_be_bytes(self) -> [u8; 4] {
self.to_bits().to_be_bytes()
}

Expand All @@ -725,8 +736,9 @@ impl f32 {
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn to_le_bytes(self) -> [u8; 4] {
pub const fn to_le_bytes(self) -> [u8; 4] {
self.to_bits().to_le_bytes()
}

Expand All @@ -753,8 +765,9 @@ impl f32 {
/// );
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn to_ne_bytes(self) -> [u8; 4] {
pub const fn to_ne_bytes(self) -> [u8; 4] {
self.to_bits().to_ne_bytes()
}

Expand All @@ -767,8 +780,9 @@ impl f32 {
/// assert_eq!(value, 12.5);
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn from_be_bytes(bytes: [u8; 4]) -> Self {
pub const fn from_be_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_be_bytes(bytes))
}

Expand All @@ -781,8 +795,9 @@ impl f32 {
/// assert_eq!(value, 12.5);
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn from_le_bytes(bytes: [u8; 4]) -> Self {
pub const fn from_le_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_le_bytes(bytes))
}

Expand All @@ -806,8 +821,9 @@ impl f32 {
/// assert_eq!(value, 12.5);
/// ```
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
pub fn from_ne_bytes(bytes: [u8; 4]) -> Self {
pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self {
Self::from_bits(u32::from_ne_bytes(bytes))
}

Expand Down
Loading