Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/test-utils/src/minicore.rs')
-rw-r--r--crates/test-utils/src/minicore.rs38
1 files changed, 30 insertions, 8 deletions
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs
index 8ae3a56227..3018f2c133 100644
--- a/crates/test-utils/src/minicore.rs
+++ b/crates/test-utils/src/minicore.rs
@@ -913,6 +913,7 @@ pub mod fmt {
}
mod rt {
+ use super::*;
extern "C" {
type Opaque;
@@ -930,8 +931,8 @@ pub mod fmt {
unsafe { Argument { formatter: transmute(f), value: transmute(x) } }
}
- pub fn new_display<'b, T: Display>(x: &'b T) -> Argument<'_> {
- Self::new(x, Display::fmt)
+ pub fn new_display<'b, T: crate::fmt::Display>(x: &'b T) -> Argument<'_> {
+ Self::new(x, crate::fmt::Display::fmt)
}
}
@@ -968,7 +969,9 @@ pub mod fmt {
flags: u32,
precision: Count,
width: Count,
- ) -> Self;
+ ) -> Self {
+ Placeholder { position, fill, align, flags, precision, width }
+ }
}
#[lang = "format_unsafe_arg"]
@@ -1007,6 +1010,14 @@ pub mod fmt {
) -> Arguments<'a> {
Arguments { pieces, fmt: Some(fmt), args }
}
+
+ pub const fn as_str(&self) -> Option<&'static str> {
+ match (self.pieces, self.args) {
+ ([], []) => Some(""),
+ ([s], []) => Some(s),
+ _ => None,
+ }
+ }
}
// region:derive
@@ -1156,8 +1167,8 @@ pub mod pin {
pointer: P,
}
impl<P> Pin<P> {
- pub fn new(_pointer: P) -> Pin<P> {
- loop {}
+ pub fn new(pointer: P) -> Pin<P> {
+ Pin { pointer }
}
}
// region:deref
@@ -1382,12 +1393,23 @@ mod panic {
mod panicking {
#[rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
- pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
- panic_fmt(format_args!("{}", *x));
+ pub const fn panic_display<T: crate::fmt::Display>(x: &T) -> ! {
+ panic_fmt(crate::format_args!("{}", *x));
+ }
+
+ // This function is used instead of panic_fmt in const eval.
+ #[lang = "const_panic_fmt"]
+ pub const fn const_panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
+ if let Some(msg) = fmt.as_str() {
+ // The panic_display function is hooked by const eval.
+ panic_display(&msg);
+ } else {
+ loop {}
+ }
}
#[lang = "panic_fmt"] // needed for const-evaluated panics
- pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
+ pub const fn panic_fmt(fmt: crate::fmt::Arguments<'_>) -> ! {
loop {}
}