Auto merge of #35006 - Manishearth:rollup, r=Manishearth

Rollup of 7 pull requests

- Successful merges: #34965, #34972, #34975, #34976, #34977, #34988, #34989
- Failed merges:
This commit is contained in:
bors 2016-07-24 11:42:06 -07:00 committed by GitHub
commit 9316ae515e
8 changed files with 73 additions and 30 deletions

View file

@ -544,14 +544,21 @@ impl<T> [T] {
/// ///
/// # Example /// # Example
/// ///
/// Print the adjacent pairs of a slice (i.e. `[1,2]`, `[2,3]`, /// ```
/// `[3,4]`): /// let slice = ['r', 'u', 's', 't'];
/// let mut iter = slice.windows(2);
/// assert_eq!(iter.next().unwrap(), &['r', 'u']);
/// assert_eq!(iter.next().unwrap(), &['u', 's']);
/// assert_eq!(iter.next().unwrap(), &['s', 't']);
/// assert!(iter.next().is_none());
/// ```
/// ///
/// ```rust /// If the slice is shorter than `size`:
/// let v = &[1, 2, 3, 4]; ///
/// for win in v.windows(2) { /// ```
/// println!("{:?}", win); /// let slice = ['f', 'o', 'o'];
/// } /// let mut iter = slice.windows(4);
/// assert!(iter.next().is_none());
/// ``` /// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]

View file

@ -593,11 +593,12 @@ impl<T> Vec<T> {
/// ``` /// ```
/// ///
/// In this example, there is a memory leak since the memory locations /// In this example, there is a memory leak since the memory locations
/// owned by the vector were not freed prior to the `set_len` call: /// owned by the inner vectors were not freed prior to the `set_len` call:
/// ///
/// ``` /// ```
/// let mut vec = vec!['r', 'u', 's', 't']; /// let mut vec = vec![vec![1, 0, 0],
/// /// vec![0, 1, 0],
/// vec![0, 0, 1]];
/// unsafe { /// unsafe {
/// vec.set_len(0); /// vec.set_len(0);
/// } /// }

View file

@ -234,6 +234,16 @@ pub trait BuildHasher {
type Hasher: Hasher; type Hasher: Hasher;
/// Creates a new hasher. /// Creates a new hasher.
///
/// # Examples
///
/// ```
/// use std::collections::hash_map::RandomState;
/// use std::hash::BuildHasher;
///
/// let s = RandomState::new();
/// let new_s = s.build_hasher();
/// ```
#[stable(since = "1.7.0", feature = "build_hasher")] #[stable(since = "1.7.0", feature = "build_hasher")]
fn build_hasher(&self) -> Self::Hasher; fn build_hasher(&self) -> Self::Hasher;
} }

View file

@ -1105,11 +1105,25 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstVal, ty: ty::Ty)
Float(f) => cast_const_float(tcx, f, ty), Float(f) => cast_const_float(tcx, f, ty),
Char(c) => cast_const_int(tcx, Infer(c as u64), ty), Char(c) => cast_const_int(tcx, Infer(c as u64), ty),
Function(_) => Err(UnimplementedConstVal("casting fn pointers")), Function(_) => Err(UnimplementedConstVal("casting fn pointers")),
ByteStr(_) => match ty.sty { ByteStr(b) => match ty.sty {
ty::TyRawPtr(_) => { ty::TyRawPtr(_) => {
Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr")) Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr"))
}, },
ty::TyRef(..) => Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice")), ty::TyRef(_, ty::TypeAndMut { ref ty, mutbl: hir::MutImmutable }) => match ty.sty {
ty::TyArray(ty, n) if ty == tcx.types.u8 && n == b.len() => Ok(ByteStr(b)),
ty::TySlice(_) => {
Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice"))
},
_ => Err(CannotCast),
},
_ => Err(CannotCast),
},
Str(s) => match ty.sty {
ty::TyRawPtr(_) => Err(ErrKind::UnimplementedConstVal("casting a str to a raw ptr")),
ty::TyRef(_, ty::TypeAndMut { ref ty, mutbl: hir::MutImmutable }) => match ty.sty {
ty::TyStr => Ok(Str(s)),
_ => Err(CannotCast),
},
_ => Err(CannotCast), _ => Err(CannotCast),
}, },
_ => Err(CannotCast), _ => Err(CannotCast),

View file

@ -392,7 +392,7 @@ impl char {
C::len_utf16(self) C::len_utf16(self)
} }
/// Returns an interator over the bytes of this character as UTF-8. /// Returns an iterator over the bytes of this character as UTF-8.
/// ///
/// The returned iterator also has an `as_slice()` method to view the /// The returned iterator also has an `as_slice()` method to view the
/// encoded bytes as a byte slice. /// encoded bytes as a byte slice.
@ -415,7 +415,7 @@ impl char {
C::encode_utf8(self) C::encode_utf8(self)
} }
/// Returns an interator over the `u16` entries of this character as UTF-16. /// Returns an iterator over the `u16` entries of this character as UTF-16.
/// ///
/// The returned iterator also has an `as_slice()` method to view the /// The returned iterator also has an `as_slice()` method to view the
/// encoded form as a slice. /// encoded form as a slice.

View file

@ -1699,6 +1699,17 @@ impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
/// A particular instance `RandomState` will create the same instances of /// A particular instance `RandomState` will create the same instances of
/// `Hasher`, but the hashers created by two different `RandomState` /// `Hasher`, but the hashers created by two different `RandomState`
/// instances are unlikely to produce the same result for the same values. /// instances are unlikely to produce the same result for the same values.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// let mut map = HashMap::with_hasher(s);
/// map.insert(1, 2);
/// ```
#[derive(Clone)] #[derive(Clone)]
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
pub struct RandomState { pub struct RandomState {
@ -1708,6 +1719,14 @@ pub struct RandomState {
impl RandomState { impl RandomState {
/// Constructs a new `RandomState` that is initialized with random keys. /// Constructs a new `RandomState` that is initialized with random keys.
///
/// # Examples
///
/// ```
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// ```
#[inline] #[inline]
#[allow(deprecated)] // rand #[allow(deprecated)] // rand
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")]

View file

@ -193,20 +193,6 @@ impl MultiSpan {
} }
} }
pub fn from_span(primary_span: Span) -> MultiSpan {
MultiSpan {
primary_spans: vec![primary_span],
span_labels: vec![]
}
}
pub fn from_spans(vec: Vec<Span>) -> MultiSpan {
MultiSpan {
primary_spans: vec,
span_labels: vec![]
}
}
pub fn push_span_label(&mut self, span: Span, label: String) { pub fn push_span_label(&mut self, span: Span, label: String) {
self.span_labels.push((span, label)); self.span_labels.push((span, label));
} }
@ -254,7 +240,10 @@ impl MultiSpan {
impl From<Span> for MultiSpan { impl From<Span> for MultiSpan {
fn from(span: Span) -> MultiSpan { fn from(span: Span) -> MultiSpan {
MultiSpan::from_span(span) MultiSpan {
primary_spans: vec![span],
span_labels: vec![]
}
} }
} }

View file

@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
@ -12,4 +12,7 @@
pub fn main() { pub fn main() {
let _ = b"x" as &[u8]; let _ = b"x" as &[u8];
let _ = b"y" as &[u8; 1];
let _ = b"z" as *const u8;
let _ = "ä" as *const str;
} }