Skip to content

Commit f7fd79a

Browse files
committedDec 13, 2021
Auto merge of #91841 - matthiaskrgr:rollup-zlhsg5a, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #91086 (Implement `TryFrom<&'_ mut [T]>` for `[T; N]`) - #91091 (Stabilize `ControlFlow::{is_break, is_continue}`) - #91749 (BTree: improve public descriptions and comments) - #91819 (rustbot: Add autolabeling for `T-compiler`) - #91824 (Make `(*mut T)::write_bytes` `const`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 22f8bde + 9e662d0 commit f7fd79a

File tree

8 files changed

+110
-59
lines changed

8 files changed

+110
-59
lines changed
 

‎library/alloc/src/collections/btree/set.rs

+56-53
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ enum DifferenceInner<'a, T: 'a> {
155155
self_iter: Iter<'a, T>,
156156
other_set: &'a BTreeSet<T>,
157157
},
158-
Iterate(Iter<'a, T>), // simply produce all values in `self`
158+
Iterate(Iter<'a, T>), // simply produce all elements in `self`
159159
}
160160

161161
#[stable(feature = "collection_debug", since = "1.17.0")]
@@ -207,7 +207,7 @@ enum IntersectionInner<'a, T: 'a> {
207207
small_iter: Iter<'a, T>,
208208
large_set: &'a BTreeSet<T>,
209209
},
210-
Answer(Option<&'a T>), // return a specific value or emptiness
210+
Answer(Option<&'a T>), // return a specific element or emptiness
211211
}
212212

213213
#[stable(feature = "collection_debug", since = "1.17.0")]
@@ -295,8 +295,8 @@ impl<T> BTreeSet<T> {
295295
Range { iter: self.map.range(range) }
296296
}
297297

298-
/// Visits the values representing the difference,
299-
/// i.e., the values that are in `self` but not in `other`,
298+
/// Visits the elements representing the difference,
299+
/// i.e., the elements that are in `self` but not in `other`,
300300
/// in ascending order.
301301
///
302302
/// # Examples
@@ -356,8 +356,8 @@ impl<T> BTreeSet<T> {
356356
}
357357
}
358358

359-
/// Visits the values representing the symmetric difference,
360-
/// i.e., the values that are in `self` or in `other` but not in both,
359+
/// Visits the elements representing the symmetric difference,
360+
/// i.e., the elements that are in `self` or in `other` but not in both,
361361
/// in ascending order.
362362
///
363363
/// # Examples
@@ -384,8 +384,8 @@ impl<T> BTreeSet<T> {
384384
SymmetricDifference(MergeIterInner::new(self.iter(), other.iter()))
385385
}
386386

387-
/// Visits the values representing the intersection,
388-
/// i.e., the values that are both in `self` and `other`,
387+
/// Visits the elements representing the intersection,
388+
/// i.e., the elements that are both in `self` and `other`,
389389
/// in ascending order.
390390
///
391391
/// # Examples
@@ -437,8 +437,8 @@ impl<T> BTreeSet<T> {
437437
}
438438
}
439439

440-
/// Visits the values representing the union,
441-
/// i.e., all the values in `self` or `other`, without duplicates,
440+
/// Visits the elements representing the union,
441+
/// i.e., all the elements in `self` or `other`, without duplicates,
442442
/// in ascending order.
443443
///
444444
/// # Examples
@@ -463,7 +463,7 @@ impl<T> BTreeSet<T> {
463463
Union(MergeIterInner::new(self.iter(), other.iter()))
464464
}
465465

466-
/// Clears the set, removing all values.
466+
/// Clears the set, removing all elements.
467467
///
468468
/// # Examples
469469
///
@@ -480,11 +480,11 @@ impl<T> BTreeSet<T> {
480480
self.map.clear()
481481
}
482482

483-
/// Returns `true` if the set contains a value.
483+
/// Returns `true` if the set contains an element equal to the value.
484484
///
485-
/// The value may be any borrowed form of the set's value type,
485+
/// The value may be any borrowed form of the set's element type,
486486
/// but the ordering on the borrowed form *must* match the
487-
/// ordering on the value type.
487+
/// ordering on the element type.
488488
///
489489
/// # Examples
490490
///
@@ -504,11 +504,12 @@ impl<T> BTreeSet<T> {
504504
self.map.contains_key(value)
505505
}
506506

507-
/// Returns a reference to the value in the set, if any, that is equal to the given value.
507+
/// Returns a reference to the element in the set, if any, that is equal to
508+
/// the value.
508509
///
509-
/// The value may be any borrowed form of the set's value type,
510+
/// The value may be any borrowed form of the set's element type,
510511
/// but the ordering on the borrowed form *must* match the
511-
/// ordering on the value type.
512+
/// ordering on the element type.
512513
///
513514
/// # Examples
514515
///
@@ -555,7 +556,7 @@ impl<T> BTreeSet<T> {
555556
}
556557

557558
/// Returns `true` if the set is a subset of another,
558-
/// i.e., `other` contains at least all the values in `self`.
559+
/// i.e., `other` contains at least all the elements in `self`.
559560
///
560561
/// # Examples
561562
///
@@ -632,7 +633,7 @@ impl<T> BTreeSet<T> {
632633
}
633634

634635
/// Returns `true` if the set is a superset of another,
635-
/// i.e., `self` contains at least all the values in `other`.
636+
/// i.e., `self` contains at least all the elements in `other`.
636637
///
637638
/// # Examples
638639
///
@@ -660,8 +661,8 @@ impl<T> BTreeSet<T> {
660661
other.is_subset(self)
661662
}
662663

663-
/// Returns a reference to the first value in the set, if any.
664-
/// This value is always the minimum of all values in the set.
664+
/// Returns a reference to the first element in the set, if any.
665+
/// This element is always the minimum of all elements in the set.
665666
///
666667
/// # Examples
667668
///
@@ -687,8 +688,8 @@ impl<T> BTreeSet<T> {
687688
self.map.first_key_value().map(|(k, _)| k)
688689
}
689690

690-
/// Returns a reference to the last value in the set, if any.
691-
/// This value is always the maximum of all values in the set.
691+
/// Returns a reference to the last element in the set, if any.
692+
/// This element is always the maximum of all elements in the set.
692693
///
693694
/// # Examples
694695
///
@@ -714,8 +715,8 @@ impl<T> BTreeSet<T> {
714715
self.map.last_key_value().map(|(k, _)| k)
715716
}
716717

717-
/// Removes the first value from the set and returns it, if any.
718-
/// The first value is always the minimum value in the set.
718+
/// Removes the first element from the set and returns it, if any.
719+
/// The first element is always the minimum element in the set.
719720
///
720721
/// # Examples
721722
///
@@ -739,8 +740,8 @@ impl<T> BTreeSet<T> {
739740
self.map.pop_first().map(|kv| kv.0)
740741
}
741742

742-
/// Removes the last value from the set and returns it, if any.
743-
/// The last value is always the maximum value in the set.
743+
/// Removes the last element from the set and returns it, if any.
744+
/// The last element is always the maximum element in the set.
744745
///
745746
/// # Examples
746747
///
@@ -766,10 +767,10 @@ impl<T> BTreeSet<T> {
766767

767768
/// Adds a value to the set.
768769
///
769-
/// If the set did not have this value present, `true` is returned.
770+
/// If the set did not have an equal element present, `true` is returned.
770771
///
771-
/// If the set did have this value present, `false` is returned, and the
772-
/// entry is not updated. See the [module-level documentation] for more.
772+
/// If the set did have an equal element present, `false` is returned, and
773+
/// the entry is not updated. See the [module-level documentation] for more.
773774
///
774775
/// [module-level documentation]: index.html#insert-and-complex-keys
775776
///
@@ -792,8 +793,8 @@ impl<T> BTreeSet<T> {
792793
self.map.insert(value, ()).is_none()
793794
}
794795

795-
/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
796-
/// one. Returns the replaced value.
796+
/// Adds a value to the set, replacing the existing element, if any, that is
797+
/// equal to the value. Returns the replaced element.
797798
///
798799
/// # Examples
799800
///
@@ -815,12 +816,12 @@ impl<T> BTreeSet<T> {
815816
Recover::replace(&mut self.map, value)
816817
}
817818

818-
/// Removes a value from the set. Returns whether the value was
819-
/// present in the set.
819+
/// If the set contains an element equal to the value, removes it from the
820+
/// set and drops it. Returns whether such an element was present.
820821
///
821-
/// The value may be any borrowed form of the set's value type,
822+
/// The value may be any borrowed form of the set's element type,
822823
/// but the ordering on the borrowed form *must* match the
823-
/// ordering on the value type.
824+
/// ordering on the element type.
824825
///
825826
/// # Examples
826827
///
@@ -842,11 +843,12 @@ impl<T> BTreeSet<T> {
842843
self.map.remove(value).is_some()
843844
}
844845

845-
/// Removes and returns the value in the set, if any, that is equal to the given one.
846+
/// Removes and returns the element in the set, if any, that is equal to
847+
/// the value.
846848
///
847-
/// The value may be any borrowed form of the set's value type,
849+
/// The value may be any borrowed form of the set's element type,
848850
/// but the ordering on the borrowed form *must* match the
849-
/// ordering on the value type.
851+
/// ordering on the element type.
850852
///
851853
/// # Examples
852854
///
@@ -926,8 +928,8 @@ impl<T> BTreeSet<T> {
926928
self.map.append(&mut other.map);
927929
}
928930

929-
/// Splits the collection into two at the given value. Returns everything after the given value,
930-
/// including the value.
931+
/// Splits the collection into two at the value. Returns a new collection
932+
/// with all elements greater than or equal to the value.
931933
///
932934
/// # Examples
933935
///
@@ -963,20 +965,20 @@ impl<T> BTreeSet<T> {
963965
BTreeSet { map: self.map.split_off(value) }
964966
}
965967

966-
/// Creates an iterator that visits all values in ascending order and uses a closure
967-
/// to determine if a value should be removed.
968+
/// Creates an iterator that visits all elements in ascending order and
969+
/// uses a closure to determine if an element should be removed.
968970
///
969-
/// If the closure returns `true`, the value is removed from the set and yielded. If
970-
/// the closure returns `false`, or panics, the value remains in the set and will
971-
/// not be yielded.
971+
/// If the closure returns `true`, the element is removed from the set and
972+
/// yielded. If the closure returns `false`, or panics, the element remains
973+
/// in the set and will not be yielded.
972974
///
973-
/// If the iterator is only partially consumed or not consumed at all, each of the
974-
/// remaining values is still subjected to the closure and removed and dropped if it
975-
/// returns `true`.
975+
/// If the iterator is only partially consumed or not consumed at all, each
976+
/// of the remaining elements is still subjected to the closure and removed
977+
/// and dropped if it returns `true`.
976978
///
977-
/// It is unspecified how many more values will be subjected to the closure if a
978-
/// panic occurs in the closure, or if a panic occurs while dropping a value, or if
979-
/// the `DrainFilter` itself is leaked.
979+
/// It is unspecified how many more elements will be subjected to the
980+
/// closure if a panic occurs in the closure, or if a panic occurs while
981+
/// dropping an element, or if the `DrainFilter` itself is leaked.
980982
///
981983
/// # Examples
982984
///
@@ -1001,7 +1003,8 @@ impl<T> BTreeSet<T> {
10011003
DrainFilter { pred, inner: self.map.drain_filter_inner() }
10021004
}
10031005

1004-
/// Gets an iterator that visits the values in the `BTreeSet` in ascending order.
1006+
/// Gets an iterator that visits the elements in the `BTreeSet` in ascending
1007+
/// order.
10051008
///
10061009
/// # Examples
10071010
///

‎library/alloc/src/collections/btree/testing/crash_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// We avoid relying on anything else in the crate, apart from the `Debug` trait.
12
use crate::fmt::Debug;
23
use std::cmp::Ordering;
34
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
@@ -7,8 +8,7 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
78
/// Events are `clone`, `drop` or some anonymous `query`.
89
///
910
/// Crash test dummies are identified and ordered by an id, so they can be used
10-
/// as keys in a BTreeMap. The implementation intentionally uses does not rely
11-
/// on anything defined in the crate, apart from the `Debug` trait.
11+
/// as keys in a BTreeMap.
1212
#[derive(Debug)]
1313
pub struct CrashTestDummy {
1414
pub id: usize,

‎library/core/src/array/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ where
189189
}
190190
}
191191

192+
#[stable(feature = "try_from_mut_slice_to_array", since = "1.59.0")]
193+
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]
194+
where
195+
T: Copy,
196+
{
197+
type Error = TryFromSliceError;
198+
199+
fn try_from(slice: &mut [T]) -> Result<[T; N], TryFromSliceError> {
200+
<Self>::try_from(&*slice)
201+
}
202+
}
203+
192204
#[stable(feature = "try_from", since = "1.34.0")]
193205
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N] {
194206
type Error = TryFromSliceError;

‎library/core/src/ops/control_flow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<B, C> ControlFlow<B, C> {
141141
/// assert!(!ControlFlow::<String, i32>::Continue(3).is_break());
142142
/// ```
143143
#[inline]
144-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
144+
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
145145
pub fn is_break(&self) -> bool {
146146
matches!(*self, ControlFlow::Break(_))
147147
}
@@ -158,7 +158,7 @@ impl<B, C> ControlFlow<B, C> {
158158
/// assert!(ControlFlow::<String, i32>::Continue(3).is_continue());
159159
/// ```
160160
#[inline]
161-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
161+
#[stable(feature = "control_flow_enum_is", since = "1.59.0")]
162162
pub fn is_continue(&self) -> bool {
163163
matches!(*self, ControlFlow::Continue(_))
164164
}

‎library/core/src/ptr/mut_ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,9 @@ impl<T: ?Sized> *mut T {
10691069
///
10701070
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
10711071
#[stable(feature = "pointer_methods", since = "1.26.0")]
1072+
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
10721073
#[inline(always)]
1073-
pub unsafe fn write_bytes(self, val: u8, count: usize)
1074+
pub const unsafe fn write_bytes(self, val: u8, count: usize)
10741075
where
10751076
T: Sized,
10761077
{

‎library/core/tests/array.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,22 @@ fn array_try_from() {
2828
($($N:expr)+) => {
2929
$({
3030
type Array = [u8; $N];
31-
let array: Array = [0; $N];
31+
let mut array: Array = [0; $N];
3232
let slice: &[u8] = &array[..];
3333

3434
let result = <&Array>::try_from(slice);
3535
assert_eq!(&array, result.unwrap());
36+
37+
let result = <Array>::try_from(slice);
38+
assert_eq!(&array, &result.unwrap());
39+
40+
let mut_slice: &mut [u8] = &mut array[..];
41+
let result = <&mut Array>::try_from(mut_slice);
42+
assert_eq!(&[0; $N], result.unwrap());
43+
44+
let mut_slice: &mut [u8] = &mut array[..];
45+
let result = <Array>::try_from(mut_slice);
46+
assert_eq!(&array, &result.unwrap());
3647
})+
3748
}
3849
}

‎library/core/tests/ptr.rs

+15
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ fn test_set_memory() {
250250
assert!(xs == [5u8; 20]);
251251
}
252252

253+
#[test]
254+
#[cfg(not(bootstrap))]
255+
fn test_set_memory_const() {
256+
const XS: [u8; 20] = {
257+
let mut xs = [0u8; 20];
258+
let ptr = xs.as_mut_ptr();
259+
unsafe {
260+
ptr.write_bytes(5u8, xs.len());
261+
}
262+
xs
263+
};
264+
265+
assert!(XS == [5u8; 20]);
266+
}
267+
253268
#[test]
254269
fn test_unsized_nonnull() {
255270
let xs: &[i32] = &[1, 2, 3];

‎triagebot.toml

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ trigger_files = [
114114
"src/tools/rustdoc-themes",
115115
]
116116

117+
[autolabel."T-compiler"]
118+
trigger_files = [
119+
# Source code
120+
"compiler",
121+
122+
# Tests
123+
"src/test/ui",
124+
]
125+
117126
[notify-zulip."I-prioritize"]
118127
zulip_stream = 245100 # #t-compiler/wg-prioritization/alerts
119128
topic = "#{number} {title}"

0 commit comments

Comments
 (0)
Please sign in to comment.