diff options
| author | bors <bors@rust-lang.org> | 2019-02-07 07:11:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-02-07 07:11:22 +0000 |
| commit | 626e74d5f64cdc820b6c6ac1a5a9a42096cd147a (patch) | |
| tree | 8f6ce3f11950029296f9d247706a3f9b8ae2d214 /src/liballoc | |
| parent | 825f355c7483746f3a17166f34dfabe3b2df1741 (diff) | |
| parent | 000daf948a143557b07442c6c59d8fc473e377c8 (diff) | |
| download | rust-626e74d5f64cdc820b6c6ac1a5a9a42096cd147a.tar.gz rust-626e74d5f64cdc820b6c6ac1a5a9a42096cd147a.zip | |
Auto merge of #58254 - kennytm:rollup, r=kennytm
Rollup of 23 pull requests
Successful merges:
- #58118 (Transition libtest to 2018 edition)
- #58119 (libproc_macro => 2018)
- #58123 (Avoid some bounds checks in binary_heap::{PeekMut,Hole})
- #58124 (libsyntax_pos => 2018)
- #58133 (libsyntax_ext => 2018)
- #58136 (Improve error message and docs for non-UTF-8 bytes in stdio on Windows)
- #58156 (update submodule: rust-installer from 27dec6c to ccdc47b)
- #58192 (Do not ICE in codegen when using a extern_type static)
- #58193 (Move librustc to 2018)
- #58210 (Make an assert debug-only in `find_constraint_paths_between_regions`.)
- #58217 (librustc_tsan => 2018)
- #58218 (librustc_msan => 2018)
- #58219 (librustc_asan => 2018)
- #58220 (libprofiler_builtins => 2018)
- #58223 (librustc_lsan => 2018)
- #58225 (librustc_fs_util => 2018)
- #58228 (librustc_plugin => 2018)
- #58236 (librustc_resolve => 2018)
- #58237 (Fix broken grammar in iter::from_fn() docs)
- #58239 (librustc_apfloat => 2018)
- #58240 (librustc_errors => 2018)
- #58241 (librustc_llvm => 2018)
- #58242 (Document the one TyKind that isn't documented)
Failed merges:
- #58185 (Remove images' url to make it work even without internet connection)
r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/collections/binary_heap.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index f97522140a8..6214e1ce245 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -248,14 +248,18 @@ impl<T: Ord> Drop for PeekMut<'_, T> { impl<T: Ord> Deref for PeekMut<'_, T> { type Target = T; fn deref(&self) -> &T { - &self.heap.data[0] + debug_assert!(!self.heap.is_empty()); + // SAFE: PeekMut is only instantiated for non-empty heaps + unsafe { self.heap.data.get_unchecked(0) } } } #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")] impl<T: Ord> DerefMut for PeekMut<'_, T> { fn deref_mut(&mut self) -> &mut T { - &mut self.heap.data[0] + debug_assert!(!self.heap.is_empty()); + // SAFE: PeekMut is only instantiated for non-empty heaps + unsafe { self.heap.data.get_unchecked_mut(0) } } } @@ -865,7 +869,8 @@ impl<'a, T> Hole<'a, T> { #[inline] unsafe fn new(data: &'a mut [T], pos: usize) -> Self { debug_assert!(pos < data.len()); - let elt = ptr::read(&data[pos]); + // SAFE: pos should be inside the slice + let elt = ptr::read(data.get_unchecked(pos)); Hole { data, elt: ManuallyDrop::new(elt), |
