Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58bb5cf

Browse files
authoredJun 10, 2024
Rollup merge of rust-lang#126191 - ivan-shrimp:nonzero_doc, r=scottmcm
Fix `NonZero` doctest inconsistencies <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> `NonZero`'s doctests contain both `?` and `.unwrap()` with no obvious reason for the difference, so this changes all of them to `?`. Also removes an explicit `std::num::NonZero`.
2 parents e17d6b9 + 0df0a38 commit 58bb5cf

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed
 

‎core/src/num/nonzero.rs

+32-10
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,13 @@ macro_rules! nonzero_integer {
517517
/// ```
518518
/// # use std::num::NonZero;
519519
/// #
520-
#[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(", $leading_zeros_test, ").unwrap();")]
520+
/// # fn main() { test().unwrap(); }
521+
/// # fn test() -> Option<()> {
522+
#[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(", $leading_zeros_test, ")?;")]
521523
///
522524
/// assert_eq!(n.leading_zeros(), 0);
525+
/// # Some(())
526+
/// # }
523527
/// ```
524528
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
525529
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
@@ -545,9 +549,13 @@ macro_rules! nonzero_integer {
545549
/// ```
546550
/// # use std::num::NonZero;
547551
/// #
548-
#[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(0b0101000).unwrap();")]
552+
/// # fn main() { test().unwrap(); }
553+
/// # fn test() -> Option<()> {
554+
#[doc = concat!("let n = NonZero::<", stringify!($Int), ">::new(0b0101000)?;")]
549555
///
550556
/// assert_eq!(n.trailing_zeros(), 3);
557+
/// # Some(())
558+
/// # }
551559
/// ```
552560
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
553561
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
@@ -1101,9 +1109,13 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
11011109
/// ```
11021110
/// # use std::num::NonZero;
11031111
/// #
1104-
#[doc = concat!("assert_eq!(NonZero::new(7", stringify!($Int), ").unwrap().ilog2(), 2);")]
1105-
#[doc = concat!("assert_eq!(NonZero::new(8", stringify!($Int), ").unwrap().ilog2(), 3);")]
1106-
#[doc = concat!("assert_eq!(NonZero::new(9", stringify!($Int), ").unwrap().ilog2(), 3);")]
1112+
/// # fn main() { test().unwrap(); }
1113+
/// # fn test() -> Option<()> {
1114+
#[doc = concat!("assert_eq!(NonZero::new(7", stringify!($Int), ")?.ilog2(), 2);")]
1115+
#[doc = concat!("assert_eq!(NonZero::new(8", stringify!($Int), ")?.ilog2(), 3);")]
1116+
#[doc = concat!("assert_eq!(NonZero::new(9", stringify!($Int), ")?.ilog2(), 3);")]
1117+
/// # Some(())
1118+
/// # }
11071119
/// ```
11081120
#[stable(feature = "int_log", since = "1.67.0")]
11091121
#[rustc_const_stable(feature = "int_log", since = "1.67.0")]
@@ -1126,9 +1138,13 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
11261138
/// ```
11271139
/// # use std::num::NonZero;
11281140
/// #
1129-
#[doc = concat!("assert_eq!(NonZero::new(99", stringify!($Int), ").unwrap().ilog10(), 1);")]
1130-
#[doc = concat!("assert_eq!(NonZero::new(100", stringify!($Int), ").unwrap().ilog10(), 2);")]
1131-
#[doc = concat!("assert_eq!(NonZero::new(101", stringify!($Int), ").unwrap().ilog10(), 2);")]
1141+
/// # fn main() { test().unwrap(); }
1142+
/// # fn test() -> Option<()> {
1143+
#[doc = concat!("assert_eq!(NonZero::new(99", stringify!($Int), ")?.ilog10(), 1);")]
1144+
#[doc = concat!("assert_eq!(NonZero::new(100", stringify!($Int), ")?.ilog10(), 2);")]
1145+
#[doc = concat!("assert_eq!(NonZero::new(101", stringify!($Int), ")?.ilog10(), 2);")]
1146+
/// # Some(())
1147+
/// # }
11321148
/// ```
11331149
#[stable(feature = "int_log", since = "1.67.0")]
11341150
#[rustc_const_stable(feature = "int_log", since = "1.67.0")]
@@ -1187,10 +1203,16 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
11871203
/// Basic usage:
11881204
///
11891205
/// ```
1190-
#[doc = concat!("let eight = std::num::NonZero::new(8", stringify!($Int), ").unwrap();")]
1206+
/// # use std::num::NonZero;
1207+
/// #
1208+
/// # fn main() { test().unwrap(); }
1209+
/// # fn test() -> Option<()> {
1210+
#[doc = concat!("let eight = NonZero::new(8", stringify!($Int), ")?;")]
11911211
/// assert!(eight.is_power_of_two());
1192-
#[doc = concat!("let ten = std::num::NonZero::new(10", stringify!($Int), ").unwrap();")]
1212+
#[doc = concat!("let ten = NonZero::new(10", stringify!($Int), ")?;")]
11931213
/// assert!(!ten.is_power_of_two());
1214+
/// # Some(())
1215+
/// # }
11941216
/// ```
11951217
#[must_use]
11961218
#[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]

0 commit comments

Comments
 (0)
Failed to load comments.