@@ -29,16 +29,10 @@ mod my_ascii {
29
29
fn from ( ascii : Ascii ) -> String {
30
30
// If this module has no bugs, this is safe, because
31
31
// well-formed ASCII text is also well-formed UTF-8.
32
- unsafe {
33
- String :: from_utf8_unchecked ( ascii. 0 )
34
- }
32
+ unsafe { String :: from_utf8_unchecked ( ascii. 0 ) }
35
33
}
36
34
}
37
35
38
- impl From < Ascii > for Vec < u8 > {
39
- fn from ( ascii : Ascii ) -> Vec < u8 > { ascii. 0 }
40
- }
41
-
42
36
// This must be placed inside the `my_ascii` module.
43
37
impl Ascii {
44
38
/// Construct an `Ascii` value from `bytes`, without checking
@@ -59,10 +53,9 @@ mod my_ascii {
59
53
}
60
54
}
61
55
62
-
63
56
#[ test]
64
57
fn good_ascii ( ) {
65
- use self :: my_ascii:: Ascii ;
58
+ use my_ascii:: Ascii ;
66
59
67
60
let bytes: Vec < u8 > = b"ASCII and ye shall receive" . to_vec ( ) ;
68
61
@@ -79,7 +72,7 @@ fn good_ascii() {
79
72
80
73
#[ test]
81
74
fn bad_ascii ( ) {
82
- use self :: my_ascii:: Ascii ;
75
+ use my_ascii:: Ascii ;
83
76
84
77
// Imagine that this vector is the result of some complicated process
85
78
// that we expected to produce ASCII. Something went wrong!
@@ -96,6 +89,5 @@ fn bad_ascii() {
96
89
// `bogus` now holds ill-formed UTF-8. Parsing its first character produces
97
90
// a `char` that is not a valid Unicode code point. That's undefined
98
91
// behavior, so the language doesn't say how this assertion should behave.
99
- // It could pass, fail, crash, do nothing at all, etc.
100
- assert_eq ! ( bogus. chars( ) . next( ) . unwrap( ) as u32 , 0x1fffff_u32 ) ;
92
+ assert_eq ! ( bogus. chars( ) . next( ) . unwrap( ) as u32 , 0x1fffff ) ;
101
93
}
0 commit comments