Skip to content

Commit aa6d303

Browse files
committed
Implement RFC 2011
1 parent ab0ef14 commit aa6d303

File tree

10 files changed

+952
-42
lines changed

10 files changed

+952
-42
lines changed

src/libcore/lib.rs

+81
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,84 @@ pub use coresimd::simd;
208208
#[unstable(feature = "stdsimd", issue = "48556")]
209209
#[cfg(not(stage0))]
210210
pub use coresimd::arch;
211+
212+
// FIXME: move to appropriate location
213+
#[doc(hidden)]
214+
#[allow(missing_docs)]
215+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
216+
pub mod assert_helper {
217+
use fmt::{self, Debug, Formatter};
218+
219+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
220+
#[allow(missing_debug_implementations)]
221+
pub enum Captured<T> {
222+
Value(T),
223+
NotCopy,
224+
Unevaluated,
225+
}
226+
227+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
228+
pub struct DebugFallback<T> {
229+
value: Captured<T>,
230+
alt: &'static str,
231+
}
232+
233+
impl<T> DebugFallback<T> {
234+
#[inline]
235+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
236+
pub fn new(value: Captured<T>, alt: &'static str) -> Self {
237+
DebugFallback { value, alt }
238+
}
239+
}
240+
241+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
242+
impl<T> Debug for DebugFallback<T> {
243+
default fn fmt(&self, f: &mut Formatter) -> fmt::Result {
244+
f.write_str(self.alt)
245+
}
246+
}
247+
248+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
249+
impl<T: Debug> Debug for DebugFallback<T> {
250+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
251+
match self.value {
252+
Captured::Value(ref value) => Debug::fmt(value, f),
253+
Captured::NotCopy => f.write_str(self.alt),
254+
Captured::Unevaluated => f.write_str("(unevaluated)"),
255+
}
256+
}
257+
}
258+
259+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
260+
pub trait TryCapture: Sized {
261+
fn try_capture(&self, to: &mut Captured<Self>) -> &Self;
262+
}
263+
264+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
265+
impl<T> TryCapture for T {
266+
#[inline]
267+
default fn try_capture(&self, to: &mut Captured<Self>) -> &Self {
268+
*to = Captured::NotCopy;
269+
self
270+
}
271+
}
272+
273+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
274+
impl<T: Copy> TryCapture for T {
275+
#[inline]
276+
fn try_capture(&self, to: &mut Captured<Self>) -> &Self {
277+
*to = Captured::Value(*self);
278+
self
279+
}
280+
}
281+
282+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
283+
pub struct Unevaluated;
284+
285+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
286+
impl Debug for Unevaluated {
287+
default fn fmt(&self, f: &mut Formatter) -> fmt::Result {
288+
f.write_str("(unevaluated)")
289+
}
290+
}
291+
}

src/libstd/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
#![feature(doc_cfg)]
323323
#![feature(doc_masked)]
324324
#![feature(doc_spotlight)]
325+
#![feature(generic_assert_internals)]
325326
#![cfg_attr(test, feature(update_panic_count))]
326327
#![cfg_attr(windows, feature(used))]
327328
#![cfg_attr(stage0, feature(never_type))]
@@ -536,3 +537,6 @@ pub use stdsimd::arch;
536537
// the rustdoc documentation for primitive types. Using `include!`
537538
// because rustdoc only looks for these modules at the crate level.
538539
include!("primitive_docs.rs");
540+
541+
#[unstable(feature = "generic_assert_internals", issue = "44838")]
542+
pub use core::assert_helper;

src/libsyntax/ast.rs

+16
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,22 @@ pub enum BindingMode {
621621
ByValue(Mutability),
622622
}
623623

624+
impl BindingMode {
625+
pub fn is_by_ref(&self) -> bool {
626+
match *self {
627+
BindingMode::ByRef(..) => true,
628+
_ => false,
629+
}
630+
}
631+
632+
pub fn is_by_value(&self) -> bool {
633+
match *self {
634+
BindingMode::ByValue(..) => true,
635+
_ => false,
636+
}
637+
}
638+
}
639+
624640
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
625641
pub enum RangeEnd {
626642
Included(RangeSyntax),

0 commit comments

Comments
 (0)