Skip to content

Commit 6495c27

Browse files
committed
rollup merge of #20069: jarod/bitflags
Although using hex literals is not wrong, but I think use binary literals will be better.(especially in examples)
2 parents b187ae5 + a7f1ce3 commit 6495c27

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/libstd/bitflags.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
/// ```{.rust}
2525
/// bitflags! {
2626
/// flags Flags: u32 {
27-
/// const FLAG_A = 0x00000001,
28-
/// const FLAG_B = 0x00000010,
29-
/// const FLAG_C = 0x00000100,
27+
/// const FLAG_A = 0b00000001,
28+
/// const FLAG_B = 0b00000010,
29+
/// const FLAG_C = 0b00000100,
3030
/// const FLAG_ABC = FLAG_A.bits
3131
/// | FLAG_B.bits
3232
/// | FLAG_C.bits,
@@ -50,8 +50,8 @@
5050
///
5151
/// bitflags! {
5252
/// flags Flags: u32 {
53-
/// const FLAG_A = 0x00000001,
54-
/// const FLAG_B = 0x00000010,
53+
/// const FLAG_A = 0b00000001,
54+
/// const FLAG_B = 0b00000010,
5555
/// }
5656
/// }
5757
///
@@ -325,10 +325,10 @@ mod tests {
325325
#[doc = "> "]
326326
#[doc = "> - Richard Feynman"]
327327
flags Flags: u32 {
328-
const FlagA = 0x00000001,
328+
const FlagA = 0b00000001,
329329
#[doc = "<pcwalton> macros are way better at generating code than trans is"]
330-
const FlagB = 0x00000010,
331-
const FlagC = 0x00000100,
330+
const FlagB = 0b00000010,
331+
const FlagC = 0b00000100,
332332
#[doc = "* cmr bed"]
333333
#[doc = "* strcat table"]
334334
#[doc = "<strcat> wait what?"]
@@ -346,33 +346,33 @@ mod tests {
346346

347347
#[test]
348348
fn test_bits(){
349-
assert_eq!(Flags::empty().bits(), 0x00000000);
350-
assert_eq!(FlagA.bits(), 0x00000001);
351-
assert_eq!(FlagABC.bits(), 0x00000111);
349+
assert_eq!(Flags::empty().bits(), 0b00000000);
350+
assert_eq!(FlagA.bits(), 0b00000001);
351+
assert_eq!(FlagABC.bits(), 0b00000111);
352352

353-
assert_eq!(AnotherSetOfFlags::empty().bits(), 0x00);
353+
assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00);
354354
assert_eq!(AnotherFlag.bits(), !0_i8);
355355
}
356356

357357
#[test]
358358
fn test_from_bits() {
359359
assert!(Flags::from_bits(0) == Some(Flags::empty()));
360-
assert!(Flags::from_bits(0x1) == Some(FlagA));
361-
assert!(Flags::from_bits(0x10) == Some(FlagB));
362-
assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB));
363-
assert!(Flags::from_bits(0x1000) == None);
360+
assert!(Flags::from_bits(0b1) == Some(FlagA));
361+
assert!(Flags::from_bits(0b10) == Some(FlagB));
362+
assert!(Flags::from_bits(0b11) == Some(FlagA | FlagB));
363+
assert!(Flags::from_bits(0b1000) == None);
364364

365365
assert!(AnotherSetOfFlags::from_bits(!0_i8) == Some(AnotherFlag));
366366
}
367367

368368
#[test]
369369
fn test_from_bits_truncate() {
370370
assert!(Flags::from_bits_truncate(0) == Flags::empty());
371-
assert!(Flags::from_bits_truncate(0x1) == FlagA);
372-
assert!(Flags::from_bits_truncate(0x10) == FlagB);
373-
assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB));
374-
assert!(Flags::from_bits_truncate(0x1000) == Flags::empty());
375-
assert!(Flags::from_bits_truncate(0x1001) == FlagA);
371+
assert!(Flags::from_bits_truncate(0b1) == FlagA);
372+
assert!(Flags::from_bits_truncate(0b10) == FlagB);
373+
assert!(Flags::from_bits_truncate(0b11) == (FlagA | FlagB));
374+
assert!(Flags::from_bits_truncate(0b1000) == Flags::empty());
375+
assert!(Flags::from_bits_truncate(0b1001) == FlagA);
376376

377377
assert!(AnotherSetOfFlags::from_bits_truncate(0_i8) == AnotherSetOfFlags::empty());
378378
}

0 commit comments

Comments
 (0)