File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -148,3 +148,17 @@ fn write_u64_min(bh: &mut Bencher) {
148
148
test:: black_box ( format ! ( "{}" , 0u64 ) ) ;
149
149
} ) ;
150
150
}
151
+
152
+ #[ bench]
153
+ fn write_u8_max ( bh : & mut Bencher ) {
154
+ bh. iter ( || {
155
+ test:: black_box ( format ! ( "{}" , u8 :: MAX ) ) ;
156
+ } ) ;
157
+ }
158
+
159
+ #[ bench]
160
+ fn write_u8_min ( bh : & mut Bencher ) {
161
+ bh. iter ( || {
162
+ test:: black_box ( format ! ( "{}" , 0u8 ) ) ;
163
+ } ) ;
164
+ }
Original file line number Diff line number Diff line change
1
+ // Trying to check that formatting u8/u32/u64/etc do not panic.
2
+ //
3
+ // This test does not correctly do so yet.
4
+
5
+ //@ compile-flags: -O
6
+
7
+ #![ crate_type = "lib" ]
8
+
9
+ // expected to need to write some kind of `impl core::fmt::Write` on a struct like this to avoid
10
+ // unrelated panics if `String::write_str` can't make space..
11
+ // struct CanAlwaysBeWrittenTo;
12
+
13
+ use std:: fmt:: Write ;
14
+
15
+ // CHECK-LABEL: @format_int_doesnt_panic
16
+ #[ no_mangle]
17
+ pub fn format_int_doesnt_panic ( s : & mut String ) -> std:: fmt:: Result {
18
+ // CHECK-NOT: panic
19
+ // ... but wait! this will definitely panic if `s.vec.reserve_for_push()` cannot alloc! this
20
+ // shouldn't pass!
21
+ write ! ( s, "{:x}" , 0u8 ) ?;
22
+ write ! ( s, "{:x}" , u8 :: MAX ) ?;
23
+ Ok ( ( ) )
24
+ }
You can’t perform that action at this time.
0 commit comments