Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st

}

#[stable(feature = "nonzero", since = "1.28.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think it'll be 1.31 now?

impl From<$Ty> for $Int {
fn from(nonzero: $Ty) -> Self {
nonzero.0 .0
}
}

impl_nonzero_fmt! {
(Debug, Display, Binary, Octal, LowerHex, UpperHex) for $Ty
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/nonzero.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
use std::num::NonZeroU32;
let nz = NonZeroU32::new(5).unwrap();
let num: u32 = nz.into();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps just make this a doctest on the impl, so users can see it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of the types like String/PathBuf in std doesn't have specific docs for their From implementation, and invoking .from/.into is kind of intuition, so I think that's fine without doctest? but if it's really needed, I'd add it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a need. I just found a run-pass test odd for this, as x.py test src/libcore doesn't run those. src/libcore/tests/nonzero.rs might also be a reasonable place for the test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/libcore/tests/nonzero.rs also makes sense to me.

}