-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement RFC 2011 (nicer assert messages) #48973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
aa6d303
9b8e000
8aa55e7
f07097a
259498d
521a510
9aa8cac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,3 +208,84 @@ pub use coresimd::simd; | |
#[unstable(feature = "stdsimd", issue = "48556")] | ||
#[cfg(not(stage0))] | ||
pub use coresimd::arch; | ||
|
||
// FIXME: move to appropriate location | ||
#[doc(hidden)] | ||
#[allow(missing_docs)] | ||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
pub mod assert_helper { | ||
use fmt::{self, Debug, Formatter}; | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
#[allow(missing_debug_implementations)] | ||
pub enum Captured<T> { | ||
Value(T), | ||
NotCopy, | ||
Unevaluated, | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
pub struct DebugFallback<T> { | ||
value: Captured<T>, | ||
alt: &'static str, | ||
} | ||
|
||
impl<T> DebugFallback<T> { | ||
#[inline] | ||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
pub fn new(value: Captured<T>, alt: &'static str) -> Self { | ||
DebugFallback { value, alt } | ||
} | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl<T> Debug for DebugFallback<T> { | ||
default fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.write_str(self.alt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for self.value to be Unevaluated here? If so, I would expect this to print There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, this needs to be match self.value {
Value | NotCopy => alt,
Unevaluated => "(unevaluated)",
} |
||
} | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl<T: Debug> Debug for DebugFallback<T> { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
match self.value { | ||
Captured::Value(ref value) => Debug::fmt(value, f), | ||
Captured::NotCopy => f.write_str(self.alt), | ||
Captured::Unevaluated => f.write_str("(unevaluated)"), | ||
} | ||
} | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
pub trait TryCapture: Sized { | ||
fn try_capture(&self, to: &mut Captured<Self>) -> &Self; | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl<T> TryCapture for T { | ||
#[inline] | ||
default fn try_capture(&self, to: &mut Captured<Self>) -> &Self { | ||
*to = Captured::NotCopy; | ||
self | ||
} | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl<T: Copy> TryCapture for T { | ||
#[inline] | ||
fn try_capture(&self, to: &mut Captured<Self>) -> &Self { | ||
*to = Captured::Value(*self); | ||
self | ||
} | ||
} | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
pub struct Unevaluated; | ||
|
||
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl Debug for Unevaluated { | ||
default fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.write_str("(unevaluated)") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to libcore/asserting.rs (by analogy with runtime support for panicking in libcore/panicking.rs).