Skip to content

Commit

Permalink
Use generic NonZero.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Apr 21, 2024
1 parent 4fee811 commit 386e822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(custom_mir)]

use std::intrinsics::mir::*;
use std::num::NonZeroI32;
use std::num::NonZero;

// We define our own option type so that we can control the variant indices.
#[allow(unused)]
Expand All @@ -13,7 +13,7 @@ enum Option<T> {
use Option::*;

#[custom_mir(dialect = "runtime", phase = "optimized")]
fn set_discriminant(ptr: &mut Option<NonZeroI32>) {
fn set_discriminant(ptr: &mut Option<NonZero<i32>>) {
mir! {
{
// We set the discriminant to `Some`, which is a NOP since this is the niched variant.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::num::*;
use std::num::NonZero;

#[repr(C)]
struct S1(NonZeroI32);
struct S1(NonZero<i32>);

#[repr(C)]
struct S2(i32);
Expand All @@ -11,6 +11,6 @@ fn callee(_s: S2) {}
fn main() {
let fnptr: fn(S2) = callee;
let fnptr: fn(S1) = unsafe { std::mem::transmute(fnptr) };
fnptr(S1(NonZeroI32::new(1).unwrap()));
fnptr(S1(NonZero::new(1).unwrap()));
//~^ ERROR: calling a function with argument of type S2 passing data of type S1
}

0 comments on commit 386e822

Please sign in to comment.