Skip to content

Commit 9316ae5

Browse files
authored
Auto merge of #35006 - Manishearth:rollup, r=Manishearth
Rollup of 7 pull requests - Successful merges: #34965, #34972, #34975, #34976, #34977, #34988, #34989 - Failed merges:
2 parents 2c50f4e + 52c293c commit 9316ae5

File tree

8 files changed

+73
-30
lines changed

8 files changed

+73
-30
lines changed

src/libcollections/slice.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,21 @@ impl<T> [T] {
544544
///
545545
/// # Example
546546
///
547-
/// Print the adjacent pairs of a slice (i.e. `[1,2]`, `[2,3]`,
548-
/// `[3,4]`):
547+
/// ```
548+
/// let slice = ['r', 'u', 's', 't'];
549+
/// let mut iter = slice.windows(2);
550+
/// assert_eq!(iter.next().unwrap(), &['r', 'u']);
551+
/// assert_eq!(iter.next().unwrap(), &['u', 's']);
552+
/// assert_eq!(iter.next().unwrap(), &['s', 't']);
553+
/// assert!(iter.next().is_none());
554+
/// ```
549555
///
550-
/// ```rust
551-
/// let v = &[1, 2, 3, 4];
552-
/// for win in v.windows(2) {
553-
/// println!("{:?}", win);
554-
/// }
556+
/// If the slice is shorter than `size`:
557+
///
558+
/// ```
559+
/// let slice = ['f', 'o', 'o'];
560+
/// let mut iter = slice.windows(4);
561+
/// assert!(iter.next().is_none());
555562
/// ```
556563
#[stable(feature = "rust1", since = "1.0.0")]
557564
#[inline]

src/libcollections/vec.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,12 @@ impl<T> Vec<T> {
593593
/// ```
594594
///
595595
/// In this example, there is a memory leak since the memory locations
596-
/// owned by the vector were not freed prior to the `set_len` call:
596+
/// owned by the inner vectors were not freed prior to the `set_len` call:
597597
///
598598
/// ```
599-
/// let mut vec = vec!['r', 'u', 's', 't'];
600-
///
599+
/// let mut vec = vec![vec![1, 0, 0],
600+
/// vec![0, 1, 0],
601+
/// vec![0, 0, 1]];
601602
/// unsafe {
602603
/// vec.set_len(0);
603604
/// }

src/libcore/hash/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ pub trait BuildHasher {
234234
type Hasher: Hasher;
235235

236236
/// Creates a new hasher.
237+
///
238+
/// # Examples
239+
///
240+
/// ```
241+
/// use std::collections::hash_map::RandomState;
242+
/// use std::hash::BuildHasher;
243+
///
244+
/// let s = RandomState::new();
245+
/// let new_s = s.build_hasher();
246+
/// ```
237247
#[stable(since = "1.7.0", feature = "build_hasher")]
238248
fn build_hasher(&self) -> Self::Hasher;
239249
}

src/librustc_const_eval/eval.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1105,11 +1105,25 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstVal, ty: ty::Ty)
11051105
Float(f) => cast_const_float(tcx, f, ty),
11061106
Char(c) => cast_const_int(tcx, Infer(c as u64), ty),
11071107
Function(_) => Err(UnimplementedConstVal("casting fn pointers")),
1108-
ByteStr(_) => match ty.sty {
1108+
ByteStr(b) => match ty.sty {
11091109
ty::TyRawPtr(_) => {
11101110
Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr"))
11111111
},
1112-
ty::TyRef(..) => Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice")),
1112+
ty::TyRef(_, ty::TypeAndMut { ref ty, mutbl: hir::MutImmutable }) => match ty.sty {
1113+
ty::TyArray(ty, n) if ty == tcx.types.u8 && n == b.len() => Ok(ByteStr(b)),
1114+
ty::TySlice(_) => {
1115+
Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice"))
1116+
},
1117+
_ => Err(CannotCast),
1118+
},
1119+
_ => Err(CannotCast),
1120+
},
1121+
Str(s) => match ty.sty {
1122+
ty::TyRawPtr(_) => Err(ErrKind::UnimplementedConstVal("casting a str to a raw ptr")),
1123+
ty::TyRef(_, ty::TypeAndMut { ref ty, mutbl: hir::MutImmutable }) => match ty.sty {
1124+
ty::TyStr => Ok(Str(s)),
1125+
_ => Err(CannotCast),
1126+
},
11131127
_ => Err(CannotCast),
11141128
},
11151129
_ => Err(CannotCast),

src/librustc_unicode/char.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl char {
392392
C::len_utf16(self)
393393
}
394394

395-
/// Returns an interator over the bytes of this character as UTF-8.
395+
/// Returns an iterator over the bytes of this character as UTF-8.
396396
///
397397
/// The returned iterator also has an `as_slice()` method to view the
398398
/// encoded bytes as a byte slice.
@@ -415,7 +415,7 @@ impl char {
415415
C::encode_utf8(self)
416416
}
417417

418-
/// Returns an interator over the `u16` entries of this character as UTF-16.
418+
/// Returns an iterator over the `u16` entries of this character as UTF-16.
419419
///
420420
/// The returned iterator also has an `as_slice()` method to view the
421421
/// encoded form as a slice.

src/libstd/collections/hash/map.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,17 @@ impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
16991699
/// A particular instance `RandomState` will create the same instances of
17001700
/// `Hasher`, but the hashers created by two different `RandomState`
17011701
/// instances are unlikely to produce the same result for the same values.
1702+
///
1703+
/// # Examples
1704+
///
1705+
/// ```
1706+
/// use std::collections::HashMap;
1707+
/// use std::collections::hash_map::RandomState;
1708+
///
1709+
/// let s = RandomState::new();
1710+
/// let mut map = HashMap::with_hasher(s);
1711+
/// map.insert(1, 2);
1712+
/// ```
17021713
#[derive(Clone)]
17031714
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
17041715
pub struct RandomState {
@@ -1708,6 +1719,14 @@ pub struct RandomState {
17081719

17091720
impl RandomState {
17101721
/// Constructs a new `RandomState` that is initialized with random keys.
1722+
///
1723+
/// # Examples
1724+
///
1725+
/// ```
1726+
/// use std::collections::hash_map::RandomState;
1727+
///
1728+
/// let s = RandomState::new();
1729+
/// ```
17111730
#[inline]
17121731
#[allow(deprecated)] // rand
17131732
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]

src/libsyntax_pos/lib.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,6 @@ impl MultiSpan {
193193
}
194194
}
195195

196-
pub fn from_span(primary_span: Span) -> MultiSpan {
197-
MultiSpan {
198-
primary_spans: vec![primary_span],
199-
span_labels: vec![]
200-
}
201-
}
202-
203-
pub fn from_spans(vec: Vec<Span>) -> MultiSpan {
204-
MultiSpan {
205-
primary_spans: vec,
206-
span_labels: vec![]
207-
}
208-
}
209-
210196
pub fn push_span_label(&mut self, span: Span, label: String) {
211197
self.span_labels.push((span, label));
212198
}
@@ -254,7 +240,10 @@ impl MultiSpan {
254240

255241
impl From<Span> for MultiSpan {
256242
fn from(span: Span) -> MultiSpan {
257-
MultiSpan::from_span(span)
243+
MultiSpan {
244+
primary_spans: vec![span],
245+
span_labels: vec![]
246+
}
258247
}
259248
}
260249

src/test/run-pass/const-byte-str-cast.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -12,4 +12,7 @@
1212

1313
pub fn main() {
1414
let _ = b"x" as &[u8];
15+
let _ = b"y" as &[u8; 1];
16+
let _ = b"z" as *const u8;
17+
let _ = "ä" as *const str;
1518
}

0 commit comments

Comments
 (0)