Skip to content

Commit

Permalink
Implement RFC 2011
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Mar 24, 2018
1 parent ab0ef14 commit aa6d303
Show file tree
Hide file tree
Showing 10 changed files with 952 additions and 42 deletions.
81 changes: 81 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

#[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)")
}
}
}
4 changes: 4 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
#![feature(doc_cfg)]
#![feature(doc_masked)]
#![feature(doc_spotlight)]
#![feature(generic_assert_internals)]
#![cfg_attr(test, feature(update_panic_count))]
#![cfg_attr(windows, feature(used))]
#![cfg_attr(stage0, feature(never_type))]
Expand Down Expand Up @@ -536,3 +537,6 @@ pub use stdsimd::arch;
// the rustdoc documentation for primitive types. Using `include!`
// because rustdoc only looks for these modules at the crate level.
include!("primitive_docs.rs");

#[unstable(feature = "generic_assert_internals", issue = "44838")]
pub use core::assert_helper;
16 changes: 16 additions & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,22 @@ pub enum BindingMode {
ByValue(Mutability),
}

impl BindingMode {
pub fn is_by_ref(&self) -> bool {
match *self {
BindingMode::ByRef(..) => true,
_ => false,
}
}

pub fn is_by_value(&self) -> bool {
match *self {
BindingMode::ByValue(..) => true,
_ => false,
}
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum RangeEnd {
Included(RangeSyntax),
Expand Down
Loading

0 comments on commit aa6d303

Please sign in to comment.