Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0df0a38

Browse files
committed
fixNonZero doctest inconsistencies
1 parente6c378f commit0df0a38

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

‎core/src/num/nonzero.rs‎

Lines changed: 32 additions & 10 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp