mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
try adding a test that LowerHex and friends don't panic, but it doesn't work
This commit is contained in:
parent
e7fbf7223f
commit
cea973f857
@ -148,3 +148,17 @@ fn write_u64_min(bh: &mut Bencher) {
|
||||
test::black_box(format!("{}", 0u64));
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn write_u8_max(bh: &mut Bencher) {
|
||||
bh.iter(|| {
|
||||
test::black_box(format!("{}", u8::MAX));
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn write_u8_min(bh: &mut Bencher) {
|
||||
bh.iter(|| {
|
||||
test::black_box(format!("{}", 0u8));
|
||||
});
|
||||
}
|
||||
|
24
tests/codegen/fmt_int_no_panic.rs
Normal file
24
tests/codegen/fmt_int_no_panic.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Trying to check that formatting u8/u32/u64/etc do not panic.
|
||||
//
|
||||
// This test does not correctly do so yet.
|
||||
|
||||
//@ compile-flags: -O
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// expected to need to write some kind of `impl core::fmt::Write` on a struct like this to avoid
|
||||
// unrelated panics if `String::write_str` can't make space..
|
||||
// struct CanAlwaysBeWrittenTo;
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
// CHECK-LABEL: @format_int_doesnt_panic
|
||||
#[no_mangle]
|
||||
pub fn format_int_doesnt_panic(s: &mut String) -> std::fmt::Result {
|
||||
// CHECK-NOT: panic
|
||||
// ... but wait! this will definitely panic if `s.vec.reserve_for_push()` cannot alloc! this
|
||||
// shouldn't pass!
|
||||
write!(s, "{:x}", 0u8)?;
|
||||
write!(s, "{:x}", u8::MAX)?;
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user