From 9e41c4b682f625ae7860255c2d17790f5d9f324a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 22 Feb 2020 13:28:53 -0800 Subject: [PATCH 1/4] Relax str::get_unchecked precondition to permit empty slicing Prior to this commit, `str` documented that `get_unchecked` had the precondition that "`begin` must come before `end`". This would appear to prohibit empty slices (i.e. begin == end). In practice, get_unchecked is called often with empty slices. Let's relax the precondition so as to allow them. --- src/libcore/str/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 668b3ff3a367f..9c0db5d98725d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2486,7 +2486,7 @@ impl str { /// Callers of this function are responsible that these preconditions are /// satisfied: /// - /// * The starting index must come before the ending index; + /// * The starting index must not exceed the ending index; /// * Indexes must be within bounds of the original slice; /// * Indexes must lie on UTF-8 sequence boundaries. /// @@ -2518,7 +2518,7 @@ impl str { /// Callers of this function are responsible that these preconditions are /// satisfied: /// - /// * The starting index must come before the ending index; + /// * The starting index must not exceed the ending index; /// * Indexes must be within bounds of the original slice; /// * Indexes must lie on UTF-8 sequence boundaries. /// @@ -2563,7 +2563,7 @@ impl str { /// Callers of this function are responsible that three preconditions are /// satisfied: /// - /// * `begin` must come before `end`. + /// * `begin` must not exceed `end`. /// * `begin` and `end` must be byte positions within the string slice. /// * `begin` and `end` must lie on UTF-8 sequence boundaries. /// @@ -2612,7 +2612,7 @@ impl str { /// Callers of this function are responsible that three preconditions are /// satisfied: /// - /// * `begin` must come before `end`. + /// * `begin` must not exceed `end`. /// * `begin` and `end` must be byte positions within the string slice. /// * `begin` and `end` must lie on UTF-8 sequence boundaries. #[stable(feature = "str_slice_mut", since = "1.5.0")] From 2cf339aeda77f29a8ad609f88b67591e0a668b89 Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Sat, 22 Feb 2020 23:19:05 +0100 Subject: [PATCH 2/4] Fix doc example for `MaybeUninit::get_mut()` Suggested by @ametisf in https://github.com/rust-lang/rust/pull/65948#issuecomment-589988183 Co-Authored-By: Frantisek Fladung --- src/libcore/mem/maybe_uninit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 5fb3c651b6b38..58aaac21ad751 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -669,7 +669,7 @@ impl MaybeUninit { /// // Now we can use `buf` as a normal slice: /// buf.sort_unstable(); /// assert!( - /// buf.chunks(2).all(|chunk| chunk[0] <= chunk[1]), + /// buf.windows(2).all(|pair| pair[0] <= pair[1]), /// "buffer is sorted", /// ); /// ``` From ad47bf50f6ff9d7a73e54bed6ab518c01ae2fdc5 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sat, 22 Feb 2020 22:25:47 -0500 Subject: [PATCH 3/4] Add rustdoc aliases to `ptr::copy` and `ptr::copy_nonoverlapping` --- src/libcore/intrinsics.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 2cee23a5c752c..43f8cfc0c473f 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1515,6 +1515,7 @@ fn overlaps(src: *const T, dst: *const T, count: usize) -> bool { /// ``` /// /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append +#[doc(alias = "memcpy")] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { @@ -1579,6 +1580,7 @@ pub unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { /// dst /// } /// ``` +#[doc(alias = "memmove")] #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub unsafe fn copy(src: *const T, dst: *mut T, count: usize) { From 78e4bd1c758b59593c02e2785e8024dbec6069f4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 23 Feb 2020 12:02:32 +0100 Subject: [PATCH 4/4] Clean up E0367 explanation --- src/librustc_error_codes/error_codes/E0367.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0367.md b/src/librustc_error_codes/error_codes/E0367.md index 7d661b2f03388..cfebeada27214 100644 --- a/src/librustc_error_codes/error_codes/E0367.md +++ b/src/librustc_error_codes/error_codes/E0367.md @@ -1,8 +1,9 @@ An attempt was made to implement `Drop` on a specialization of a generic type. -An example is shown below: + +Erroneous code example: ```compile_fail,E0367 -trait Foo{} +trait Foo {} struct MyStruct { t: T