Skip to content

Commit

Permalink
Don’t create NonZero(0) in test/ui/print_type_sizes/nullable.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 22, 2017
1 parent f732911 commit ff7f220
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/test/ui/print_type_sizes/nullable.rs
Expand Up @@ -42,7 +42,7 @@ impl Default for EmbeddedDiscr {
}

#[derive(Default)]
pub struct IndirectNonZero<T: Zeroable> {
pub struct IndirectNonZero<T: Zeroable + One> {
pre: u8,
nested: NestedNonZero<T>,
post: u16,
Expand All @@ -54,14 +54,22 @@ pub struct NestedNonZero<T: Zeroable> {
post: u16,
}

impl<T: Zeroable+Default> Default for NestedNonZero<T> {
impl<T: Zeroable+One> Default for NestedNonZero<T> {
fn default() -> Self {
unsafe {
NestedNonZero { pre: 0, val: NonZero::new_unchecked(Default::default()), post: 0 }
NestedNonZero { pre: 0, val: NonZero::new_unchecked(T::one()), post: 0 }
}
}
}

pub trait One {
fn one() -> Self;
}

impl One for u32 {
fn one() -> Self { 1 }
}

pub fn main() {
let _x: MyOption<NonZero<u32>> = Default::default();
let _y: EmbeddedDiscr = Default::default();
Expand Down

0 comments on commit ff7f220

Please sign in to comment.