about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-03-10 05:48:27 +0000
committerbors <bors@rust-lang.org>2020-03-10 05:48:27 +0000
commitdd155df0a69338757ca39a2a606a6accb7b8d342 (patch)
tree1f4a4549551e14c95a31a995a46a57536212e686 /src/libstd
parent3dbade652ed8ebac70f903e01f51cd92c4e4302c (diff)
parent3e9efbd8b409faeaf97943699ce2a15ffb8fc629 (diff)
downloadrust-dd155df0a69338757ca39a2a606a6accb7b8d342.tar.gz
rust-dd155df0a69338757ca39a2a606a6accb7b8d342.zip
Auto merge of #69879 - Centril:rollup-ryea91j, r=Centril
Rollup of 10 pull requests

Successful merges:

 - #69475 (Remove the `no_force` query attribute)
 - #69514 (Remove spotlight)
 - #69677 (rustc_metadata: Give decoder access to whole crate store)
 - #69714 (Make PlaceRef take just one lifetime)
 - #69799 (Allow ZSTs in `AllocRef`)
 - #69817 (test(patterns): add patterns feature tests to borrowck test suite)
 - #69836 (Check if output is immediate value)
 - #69847 (clean up E0393 explanation)
 - #69861 (Add note about localization to std::fmt docs)
 - #69877 (Vec::new is const stable in 1.39 not 1.32)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/alloc.rs47
-rw-r--r--src/libstd/io/mod.rs2
-rw-r--r--src/libstd/lib.rs1
3 files changed, 36 insertions, 14 deletions
diff --git a/src/libstd/alloc.rs b/src/libstd/alloc.rs
index 2da18e06d99..25f3ddcbeba 100644
--- a/src/libstd/alloc.rs
+++ b/src/libstd/alloc.rs
@@ -133,24 +133,41 @@ pub use alloc_crate::alloc::*;
 #[derive(Debug, Default, Copy, Clone)]
 pub struct System;
 
-// The AllocRef impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
+// The AllocRef impl checks the layout size to be non-zero and forwards to the GlobalAlloc impl,
+// which is in `std::sys::*::alloc`.
 #[unstable(feature = "allocator_api", issue = "32838")]
 unsafe impl AllocRef for System {
     #[inline]
-    unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
-        NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr).map(|p| (p, layout.size()))
+    fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
+        if layout.size() == 0 {
+            Ok((layout.dangling(), 0))
+        } else {
+            unsafe {
+                NonNull::new(GlobalAlloc::alloc(self, layout))
+                    .ok_or(AllocErr)
+                    .map(|p| (p, layout.size()))
+            }
+        }
     }
 
     #[inline]
-    unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
-        NonNull::new(GlobalAlloc::alloc_zeroed(self, layout))
-            .ok_or(AllocErr)
-            .map(|p| (p, layout.size()))
+    fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
+        if layout.size() == 0 {
+            Ok((layout.dangling(), 0))
+        } else {
+            unsafe {
+                NonNull::new(GlobalAlloc::alloc_zeroed(self, layout))
+                    .ok_or(AllocErr)
+                    .map(|p| (p, layout.size()))
+            }
+        }
     }
 
     #[inline]
     unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
-        GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
+        if layout.size() != 0 {
+            GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
+        }
     }
 
     #[inline]
@@ -160,9 +177,17 @@ unsafe impl AllocRef for System {
         layout: Layout,
         new_size: usize,
     ) -> Result<(NonNull<u8>, usize), AllocErr> {
-        NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size))
-            .ok_or(AllocErr)
-            .map(|p| (p, new_size))
+        match (layout.size(), new_size) {
+            (0, 0) => Ok((layout.dangling(), 0)),
+            (0, _) => self.alloc(Layout::from_size_align_unchecked(new_size, layout.align())),
+            (_, 0) => {
+                self.dealloc(ptr, layout);
+                Ok((layout.dangling(), 0))
+            }
+            (_, _) => NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size))
+                .ok_or(AllocErr)
+                .map(|p| (p, new_size)),
+        }
     }
 }
 
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 0103e4bd628..420d6ea589a 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -497,7 +497,6 @@ where
 /// [`&str`]: ../../std/primitive.str.html
 /// [slice]: ../../std/primitive.slice.html
 #[stable(feature = "rust1", since = "1.0.0")]
-#[doc(spotlight)]
 pub trait Read {
     /// Pull some bytes from this source into the specified buffer, returning
     /// how many bytes were read.
@@ -1228,7 +1227,6 @@ impl Initializer {
 ///
 /// [`write_all`]: #method.write_all
 #[stable(feature = "rust1", since = "1.0.0")]
-#[doc(spotlight)]
 pub trait Write {
     /// Write a buffer into this writer, returning how many bytes were written.
     ///
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 784868b52e5..231908ddda0 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -255,7 +255,6 @@
 #![feature(doc_cfg)]
 #![feature(doc_keyword)]
 #![feature(doc_masked)]
-#![feature(doc_spotlight)]
 #![feature(dropck_eyepatch)]
 #![feature(duration_constants)]
 #![feature(exact_size_is_empty)]