// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. //! Exposes the NonZero lang item which provides optimization hints. use ops::{CoerceUnsized, DispatchFromDyn}; use marker::Freeze; /// A wrapper type for raw pointers and integers that will never be /// NULL or 0 that might allow certain optimizations. #[rustc_layout_scalar_valid_range_start(1)] #[derive(Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[repr(transparent)] pub(crate) struct NonZero(pub(crate) T); // Do not call `T::clone` as theoretically it could turn the field into `0` // invalidating `NonZero`'s invariant. impl Clone for NonZero { fn clone(&self) -> Self { unsafe { NonZero(self.0) } } } impl + Freeze, U: Freeze> CoerceUnsized> for NonZero {} impl + Freeze, U: Freeze> DispatchFromDyn> for NonZero {}