about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe8472 <git@infinite-source.de>2020-08-21 23:53:13 +0200
committerThe8472 <git@infinite-source.de>2020-09-03 20:59:34 +0200
commit9aeea0022225ccc11aae031ebf06dc2b125a29f1 (patch)
tree9bc21ddb0b1792082eb9ab52a311e5ea9d681bc3
parent7badb7a7f8e66f183106ae2eac2062ea6aa63f2f (diff)
downloadrust-9aeea0022225ccc11aae031ebf06dc2b125a29f1.tar.gz
rust-9aeea0022225ccc11aae031ebf06dc2b125a29f1.zip
get things to work under min_specialization by leaning more heavily on #[rustc_unsafe_specialization_marker]
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/alloc/src/vec.rs21
-rw-r--r--library/core/src/iter/traits/marker.rs1
3 files changed, 14 insertions, 9 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 5cbd9d380b0..43b70a51636 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -135,6 +135,7 @@
 #![feature(slice_partition_dedup)]
 #![feature(maybe_uninit_extra, maybe_uninit_slice)]
 #![feature(alloc_layout_extra)]
+#![feature(trusted_random_access)]
 #![feature(try_trait)]
 #![feature(type_alias_impl_trait)]
 #![feature(associated_type_bounds)]
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs
index c0c63a27be5..dcfd3ecb3d3 100644
--- a/library/alloc/src/vec.rs
+++ b/library/alloc/src/vec.rs
@@ -2243,11 +2243,11 @@ fn write_in_place_with_drop<T>(
 #[rustc_unsafe_specialization_marker]
 trait SourceIterMarker: SourceIter<Source: AsIntoIter> {}
 
-impl<T> SourceIterMarker for T where T: SourceIter<Source: AsIntoIter> {}
+impl<T> SourceIterMarker for T where T: SourceIter<Source: AsIntoIter> + InPlaceIterable {}
 
 impl<T, I> SpecFrom<T, I> for Vec<T>
 where
-    I: Iterator<Item = T> + InPlaceIterable + SourceIterMarker,
+    I: Iterator<Item = T> + SourceIterMarker,
 {
     default fn from_iter(mut iterator: I) -> Self {
         // Additional requirements which cannot expressed via trait bounds. We rely on const eval
@@ -2920,6 +2920,17 @@ impl<T> Iterator for IntoIter<T> {
     fn count(self) -> usize {
         self.len()
     }
+
+    unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item
+    where
+        Self: TrustedRandomAccess,
+    {
+        // SAFETY: the caller must uphold the contract for
+        // `Iterator::get_unchecked`.
+        unsafe {
+            if mem::size_of::<T>() == 0 { mem::zeroed() } else { ptr::read(self.ptr.add(i)) }
+        }
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -2967,12 +2978,6 @@ unsafe impl<T> TrustedRandomAccess for IntoIter<T>
 where
     T: Copy,
 {
-    unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item {
-        unsafe {
-            if mem::size_of::<T>() == 0 { mem::zeroed() } else { ptr::read(self.ptr.add(i)) }
-        }
-    }
-
     fn may_have_side_effect() -> bool {
         false
     }
diff --git a/library/core/src/iter/traits/marker.rs b/library/core/src/iter/traits/marker.rs
index 5d31e78dd85..f287196da03 100644
--- a/library/core/src/iter/traits/marker.rs
+++ b/library/core/src/iter/traits/marker.rs
@@ -53,5 +53,4 @@ unsafe impl<I: TrustedLen + ?Sized> TrustedLen for &mut I {}
 ///
 /// [`SourceIter`]: ../../std/iter/trait.SourceIter.html
 #[unstable(issue = "none", feature = "inplace_iteration")]
-#[rustc_specialization_trait]
 pub unsafe trait InPlaceIterable: Iterator {}