Skip to content
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

Rollup of 7 pull requests #35006

Merged
merged 14 commits into from
Jul 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,21 @@ impl<T> [T] {
///
/// # 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
/// let v = &[1, 2, 3, 4];
/// for win in v.windows(2) {
/// println!("{:?}", win);
/// }
/// If the slice is shorter than `size`:
///
/// ```
/// let slice = ['f', 'o', 'o'];
/// let mut iter = slice.windows(4);
/// assert!(iter.next().is_none());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
7 changes: 4 additions & 3 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,12 @@ impl<T> Vec<T> {
/// ```
///
/// 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 {
/// vec.set_len(0);
/// }
Expand Down
10 changes: 10 additions & 0 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ pub trait BuildHasher {
type Hasher: 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")]
fn build_hasher(&self) -> Self::Hasher;
}
Expand Down
18 changes: 16 additions & 2 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Char(c) => cast_const_int(tcx, Infer(c as u64), ty),
Function(_) => Err(UnimplementedConstVal("casting fn pointers")),
ByteStr(_) => match ty.sty {
ByteStr(b) => match ty.sty {
ty::TyRawPtr(_) => {
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),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl char {
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
/// encoded bytes as a byte slice.
Expand All @@ -415,7 +415,7 @@ impl char {
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
/// encoded form as a slice.
Expand Down
19 changes: 19 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// `Hasher`, but the hashers created by two different `RandomState`
/// 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)]
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
pub struct RandomState {
Expand All @@ -1708,6 +1719,14 @@ pub struct RandomState {

impl RandomState {
/// Constructs a new `RandomState` that is initialized with random keys.
///
/// # Examples
///
/// ```
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// ```
#[inline]
#[allow(deprecated)] // rand
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
Expand Down
19 changes: 4 additions & 15 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
self.span_labels.push((span, label));
}
Expand Down Expand Up @@ -254,7 +240,10 @@ impl MultiSpan {

impl From<Span> for MultiSpan {
fn from(span: Span) -> MultiSpan {
MultiSpan::from_span(span)
MultiSpan {
primary_spans: vec![span],
span_labels: vec![]
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/test/run-pass/const-byte-str-cast.rs
Original file line number Diff line number Diff line change
@@ -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
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -12,4 +12,7 @@

pub fn main() {
let _ = b"x" as &[u8];
let _ = b"y" as &[u8; 1];
let _ = b"z" as *const u8;
let _ = "ä" as *const str;
}