]> git.lizzy.rs Git - rust.git/commitdiff
Use unsafe more idiomatically
authorSteve Klabnik <steve@steveklabnik.com>
Mon, 7 Sep 2015 14:16:57 +0000 (10:16 -0400)
committerSteve Klabnik <steve@steveklabnik.com>
Mon, 7 Sep 2015 14:16:57 +0000 (10:16 -0400)
Generally, including everything that makes an unsafe block safe in the
block is good style. Since the assert! is what makes this safe, it
should go inside the block. I also added a few bits of whitespace.

src/libcore/slice.rs

index cf605f507bca66db2b25854e0cae188f17cea6f5..b5d3129d2683e6cc2fb54405efacd53d5664f048 100644 (file)
@@ -303,8 +303,10 @@ fn get_mut(&mut self, index: usize) -> Option<&mut T> {
     fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
         let len = self.len();
         let ptr = self.as_mut_ptr();
-        assert!(mid <= len);
+
         unsafe {
+            assert!(mid <= len);
+
             (from_raw_parts_mut(ptr, mid),
              from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
         }