Skip to content

Commit

Permalink
Merge #21
Browse files Browse the repository at this point in the history
21: Changes for rust beta 1.62 r=antifuchs a=antifuchs



Co-authored-by: Andreas Fuchs <[email protected]>
  • Loading branch information
bors[bot] and antifuchs authored May 24, 2022
2 parents 84d0607 + 5d4f7ed commit 15a214e
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/compile-fail_1.62/immoral_math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[macro_use]
extern crate nonzero_ext;

use std::num::NonZeroU32;

fn main() {
const _MY_NON_ZERO_U32: NonZeroU32 = nonzero!((42 / 2 - 21) as u32);
}
7 changes: 7 additions & 0 deletions tests/compile-fail_1.62/immoral_math.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> $DIR/immoral_math.rs:7:42
|
7 | const _MY_NON_ZERO_U32: NonZeroU32 = nonzero!((42 / 2 - 21) as u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
39 changes: 39 additions & 0 deletions tests/compile-fail_1.62/issue-17--adverse-conditions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use nonzero_ext::nonzero;
use nonzero_ext::{literals::NonZeroLiteral, NonZeroAble};
use std::num::NonZeroUsize;

struct BadInt(usize);
impl BadInt {
const fn count_ones(&self) -> usize {
1 // oops, even zero counts!
}
}
impl NonZeroAble for BadInt {
type NonZero = NonZeroUsize;

fn into_nonzero(self) -> Option<Self::NonZero> {
NonZeroUsize::new(self.0)
}

unsafe fn into_nonzero_unchecked(self) -> Self::NonZero {
NonZeroUsize::new_unchecked(self.0)
}
}

// And we can't impl:
// impl NonZeroLiteral<BadInt> {} // <- also errors.
trait OtherTrait {
/// # Safety
/// self must not be NonZeroLiteral(BadInt(0))
unsafe fn into_nonzero(self) -> NonZeroUsize;
}

impl OtherTrait for NonZeroLiteral<BadInt> {
unsafe fn into_nonzero(self) -> NonZeroUsize {
unsafe { self.0.into_nonzero_unchecked() }
}
}

fn main() {
nonzero!(BadInt(0));
}
43 changes: 43 additions & 0 deletions tests/compile-fail_1.62/issue-17--adverse-conditions.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error[E0277]: the trait bound `BadInt: literals::sealed::IntegerLiteral` is not satisfied
--> $DIR/issue-17--adverse-conditions.rs:31:21
|
31 | impl OtherTrait for NonZeroLiteral<BadInt> {
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `literals::sealed::IntegerLiteral` is not implemented for `BadInt`
|
= help: the following other types implement trait `literals::sealed::IntegerLiteral`:
i128
i16
i32
i64
i8
isize
u128
u16
and 4 others
note: required by a bound in `NonZeroLiteral`
--> $DIR/literals.rs:15:30
|
15 | pub struct NonZeroLiteral<T: sealed::IntegerLiteral>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `NonZeroLiteral`

error[E0277]: the trait bound `BadInt: literals::sealed::IntegerLiteral` is not satisfied
--> $DIR/issue-17--adverse-conditions.rs:32:28
|
32 | unsafe fn into_nonzero(self) -> NonZeroUsize {
| ^^^^ the trait `literals::sealed::IntegerLiteral` is not implemented for `BadInt`
|
= help: the following other types implement trait `literals::sealed::IntegerLiteral`:
i128
i16
i32
i64
i8
isize
u128
u16
and 4 others
note: required by a bound in `NonZeroLiteral`
--> $DIR/literals.rs:15:30
|
15 | pub struct NonZeroLiteral<T: sealed::IntegerLiteral>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `NonZeroLiteral`
9 changes: 9 additions & 0 deletions tests/compile-fail_1.62/zero_u8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[macro_use]
extern crate nonzero_ext;

use std::num::NonZeroU8;

#[cfg_attr(rustfmt, rustfmt_skip)]
fn main() {
let _a: NonZeroU8 = nonzero!(0u8);
}
7 changes: 7 additions & 0 deletions tests/compile-fail_1.62/zero_u8.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> $DIR/zero_u8.rs:8:25
|
8 | let _a: NonZeroU8 = nonzero!(0u8);
| ^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
9 changes: 9 additions & 0 deletions tests/compile-fail_1.62/zero_usize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[macro_use]
extern crate nonzero_ext;

use std::num::NonZeroUsize;

#[cfg_attr(rustfmt, rustfmt_skip)]
fn main() {
let _a: NonZeroUsize = nonzero!(0usize);
}
7 changes: 7 additions & 0 deletions tests/compile-fail_1.62/zero_usize.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error[E0080]: evaluation of constant value failed
--> $DIR/zero_usize.rs:8:28
|
8 | let _a: NonZeroUsize = nonzero!(0usize);
| ^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/compile-fail_nightly/immoral_math.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ error[E0080]: evaluation of constant value failed
7 | const _MY_NON_ZERO_U32: NonZeroU32 = nonzero!((42 / 2 - 21) as u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/compile-fail_nightly/zero_u8.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ error[E0080]: evaluation of constant value failed
8 | let _a: NonZeroU8 = nonzero!(0u8);
| ^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/compile-fail_nightly/zero_usize.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ error[E0080]: evaluation of constant value failed
8 | let _a: NonZeroUsize = nonzero!(0usize);
| ^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `nonzero` (in Nightly builds, run with -Z macro-backtrace for more info)
11 changes: 9 additions & 2 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn compile_fail_test_prerelease() {
t.compile_fail("tests/compile-fail_nightly/*.rs");
}

#[rustversion::before(1.46)] // nightly+beta has changed the format of the macro backtrace hint.
#[rustversion::before(1.46)]
#[test]
fn compile_fail_test_until_1_45() {
let t = trybuild::TestCases::new();
Expand Down Expand Up @@ -39,9 +39,16 @@ fn compile_fail_test_since_1_54() {
t.compile_fail("tests/compile-fail_1.54/*.rs");
}

#[rustversion::all(since(1.56.0), not(nightly))]
#[rustversion::all(since(1.56.0), before(1.62.0))]
#[test]
fn compile_fail_test_since_1_54() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/compile-fail_1.56/*.rs");
}

#[rustversion::all(since(1.62.0), not(nightly))]
#[test]
fn compile_fail_test_since_1_62() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/compile-fail_1.62/*.rs");
}

0 comments on commit 15a214e

Please sign in to comment.