about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-03-23 11:33:09 -0700
committeriximeow <me@iximeow.net>2024-03-23 11:35:19 -0700
commitcea973f857b63e7c208e822d95c06c4883062449 (patch)
tree3ee78ea8314f4a554ae9d1922252557a163fe0cb /tests
parente7fbf7223f640c5121b21183cd26ecd3ccb6a820 (diff)
downloadrust-cea973f857b63e7c208e822d95c06c4883062449.tar.gz
rust-cea973f857b63e7c208e822d95c06c4883062449.zip
try adding a test that LowerHex and friends don't panic, but it doesn't work
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/fmt_int_no_panic.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/codegen/fmt_int_no_panic.rs b/tests/codegen/fmt_int_no_panic.rs
new file mode 100644
index 00000000000..efd0530bc88
--- /dev/null
+++ b/tests/codegen/fmt_int_no_panic.rs
@@ -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(())
+}