-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21: Changes for rust beta 1.62 r=antifuchs a=antifuchs Co-authored-by: Andreas Fuchs <[email protected]>
- Loading branch information
Showing
12 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
tests/compile-fail_1.62/issue-17--adverse-conditions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters