Skip to content

Commit 26ab324

Browse files
committed
Auto merge of #60949 - Centril:rollup-f918e1v, r=Centril
Rollup of 8 pull requests Successful merges: - #60370 (Mark core::alloc::Layout::from_size_align_unchecked const) - #60678 (Stabilize vecdeque_rotate) - #60924 (Explain that ? converts the error type using From) - #60931 (Use iter() for iterating arrays by slice) - #60934 (Declare DefIndex with the newtype_index macro) - #60943 (fix copy-paste typo in docs for ptr::read_volatile) - #60945 (Simplify BufRead::fill_buf doc example using NLL) - #60947 (Fix typos in docs of GlobalAlloc) Failed merges: r? @ghost
2 parents 963184b + 9389c69 commit 26ab324

File tree

31 files changed

+108
-101
lines changed

31 files changed

+108
-101
lines changed

src/liballoc/collections/vec_deque.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,6 @@ impl<T> VecDeque<T> {
19481948
/// # Examples
19491949
///
19501950
/// ```
1951-
/// #![feature(vecdeque_rotate)]
1952-
///
19531951
/// use std::collections::VecDeque;
19541952
///
19551953
/// let mut buf: VecDeque<_> = (0..10).collect();
@@ -1963,7 +1961,7 @@ impl<T> VecDeque<T> {
19631961
/// }
19641962
/// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
19651963
/// ```
1966-
#[unstable(feature = "vecdeque_rotate", issue = "56686")]
1964+
#[stable(feature = "vecdeque_rotate", since = "1.36.0")]
19671965
pub fn rotate_left(&mut self, mid: usize) {
19681966
assert!(mid <= self.len());
19691967
let k = self.len() - mid;
@@ -1993,8 +1991,6 @@ impl<T> VecDeque<T> {
19931991
/// # Examples
19941992
///
19951993
/// ```
1996-
/// #![feature(vecdeque_rotate)]
1997-
///
19981994
/// use std::collections::VecDeque;
19991995
///
20001996
/// let mut buf: VecDeque<_> = (0..10).collect();
@@ -2008,7 +2004,7 @@ impl<T> VecDeque<T> {
20082004
/// }
20092005
/// assert_eq!(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
20102006
/// ```
2011-
#[unstable(feature = "vecdeque_rotate", issue = "56686")]
2007+
#[stable(feature = "vecdeque_rotate", since = "1.36.0")]
20122008
pub fn rotate_right(&mut self, k: usize) {
20132009
assert!(k <= self.len());
20142010
let mid = self.len() - k;

src/liballoc/tests/btree/set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ fn test_union() {
143143
#[test]
144144
// Only tests the simple function definition with respect to intersection
145145
fn test_is_disjoint() {
146-
let one = [1].into_iter().collect::<BTreeSet<_>>();
147-
let two = [2].into_iter().collect::<BTreeSet<_>>();
146+
let one = [1].iter().collect::<BTreeSet<_>>();
147+
let two = [2].iter().collect::<BTreeSet<_>>();
148148
assert!(one.is_disjoint(&two));
149149
}
150150

src/liballoc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(repeat_generic_slice)]
77
#![feature(try_reserve)]
88
#![feature(unboxed_closures)]
9-
#![feature(vecdeque_rotate)]
109
#![deny(rust_2018_idioms)]
1110

1211
use std::hash::{Hash, Hasher};

src/libcore/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Layout {
9999
/// [`Layout::from_size_align`](#method.from_size_align).
100100
#[stable(feature = "alloc_layout", since = "1.28.0")]
101101
#[inline]
102-
pub unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
102+
pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self {
103103
Layout { size_: size, align_: NonZeroUsize::new_unchecked(align) }
104104
}
105105

@@ -480,7 +480,7 @@ pub unsafe trait GlobalAlloc {
480480
/// this allocator,
481481
///
482482
/// * `layout` must be the same layout that was used
483-
/// to allocated that block of memory,
483+
/// to allocate that block of memory,
484484
#[stable(feature = "global_alloc", since = "1.28.0")]
485485
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
486486

@@ -535,7 +535,7 @@ pub unsafe trait GlobalAlloc {
535535
/// * `ptr` must be currently allocated via this allocator,
536536
///
537537
/// * `layout` must be the same layout that was used
538-
/// to allocated that block of memory,
538+
/// to allocate that block of memory,
539539
///
540540
/// * `new_size` must be greater than zero.
541541
///

src/libcore/iter/traits/iterator.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub trait Iterator {
356356
///
357357
/// ```
358358
/// let a = [0, 1, 2, 3, 4, 5];
359-
/// let mut iter = a.into_iter().step_by(2);
359+
/// let mut iter = a.iter().step_by(2);
360360
///
361361
/// assert_eq!(iter.next(), Some(&0));
362362
/// assert_eq!(iter.next(), Some(&2));
@@ -531,7 +531,7 @@ pub trait Iterator {
531531
/// ```
532532
/// let a = [1, 2, 3];
533533
///
534-
/// let mut iter = a.into_iter().map(|x| 2 * x);
534+
/// let mut iter = a.iter().map(|x| 2 * x);
535535
///
536536
/// assert_eq!(iter.next(), Some(2));
537537
/// assert_eq!(iter.next(), Some(4));
@@ -620,7 +620,7 @@ pub trait Iterator {
620620
/// ```
621621
/// let a = [0i32, 1, 2];
622622
///
623-
/// let mut iter = a.into_iter().filter(|x| x.is_positive());
623+
/// let mut iter = a.iter().filter(|x| x.is_positive());
624624
///
625625
/// assert_eq!(iter.next(), Some(&1));
626626
/// assert_eq!(iter.next(), Some(&2));
@@ -634,7 +634,7 @@ pub trait Iterator {
634634
/// ```
635635
/// let a = [0, 1, 2];
636636
///
637-
/// let mut iter = a.into_iter().filter(|x| **x > 1); // need two *s!
637+
/// let mut iter = a.iter().filter(|x| **x > 1); // need two *s!
638638
///
639639
/// assert_eq!(iter.next(), Some(&2));
640640
/// assert_eq!(iter.next(), None);
@@ -646,7 +646,7 @@ pub trait Iterator {
646646
/// ```
647647
/// let a = [0, 1, 2];
648648
///
649-
/// let mut iter = a.into_iter().filter(|&x| *x > 1); // both & and *
649+
/// let mut iter = a.iter().filter(|&x| *x > 1); // both & and *
650650
///
651651
/// assert_eq!(iter.next(), Some(&2));
652652
/// assert_eq!(iter.next(), None);
@@ -657,7 +657,7 @@ pub trait Iterator {
657657
/// ```
658658
/// let a = [0, 1, 2];
659659
///
660-
/// let mut iter = a.into_iter().filter(|&&x| x > 1); // two &s
660+
/// let mut iter = a.iter().filter(|&&x| x > 1); // two &s
661661
///
662662
/// assert_eq!(iter.next(), Some(&2));
663663
/// assert_eq!(iter.next(), None);
@@ -837,7 +837,7 @@ pub trait Iterator {
837837
/// ```
838838
/// let a = [-1i32, 0, 1];
839839
///
840-
/// let mut iter = a.into_iter().skip_while(|x| x.is_negative());
840+
/// let mut iter = a.iter().skip_while(|x| x.is_negative());
841841
///
842842
/// assert_eq!(iter.next(), Some(&0));
843843
/// assert_eq!(iter.next(), Some(&1));
@@ -851,7 +851,7 @@ pub trait Iterator {
851851
/// ```
852852
/// let a = [-1, 0, 1];
853853
///
854-
/// let mut iter = a.into_iter().skip_while(|x| **x < 0); // need two *s!
854+
/// let mut iter = a.iter().skip_while(|x| **x < 0); // need two *s!
855855
///
856856
/// assert_eq!(iter.next(), Some(&0));
857857
/// assert_eq!(iter.next(), Some(&1));
@@ -863,7 +863,7 @@ pub trait Iterator {
863863
/// ```
864864
/// let a = [-1, 0, 1, -2];
865865
///
866-
/// let mut iter = a.into_iter().skip_while(|x| **x < 0);
866+
/// let mut iter = a.iter().skip_while(|x| **x < 0);
867867
///
868868
/// assert_eq!(iter.next(), Some(&0));
869869
/// assert_eq!(iter.next(), Some(&1));
@@ -898,7 +898,7 @@ pub trait Iterator {
898898
/// ```
899899
/// let a = [-1i32, 0, 1];
900900
///
901-
/// let mut iter = a.into_iter().take_while(|x| x.is_negative());
901+
/// let mut iter = a.iter().take_while(|x| x.is_negative());
902902
///
903903
/// assert_eq!(iter.next(), Some(&-1));
904904
/// assert_eq!(iter.next(), None);
@@ -911,7 +911,7 @@ pub trait Iterator {
911911
/// ```
912912
/// let a = [-1, 0, 1];
913913
///
914-
/// let mut iter = a.into_iter().take_while(|x| **x < 0); // need two *s!
914+
/// let mut iter = a.iter().take_while(|x| **x < 0); // need two *s!
915915
///
916916
/// assert_eq!(iter.next(), Some(&-1));
917917
/// assert_eq!(iter.next(), None);
@@ -922,7 +922,7 @@ pub trait Iterator {
922922
/// ```
923923
/// let a = [-1, 0, 1, -2];
924924
///
925-
/// let mut iter = a.into_iter().take_while(|x| **x < 0);
925+
/// let mut iter = a.iter().take_while(|x| **x < 0);
926926
///
927927
/// assert_eq!(iter.next(), Some(&-1));
928928
///
@@ -937,7 +937,7 @@ pub trait Iterator {
937937
///
938938
/// ```
939939
/// let a = [1, 2, 3, 4];
940-
/// let mut iter = a.into_iter();
940+
/// let mut iter = a.iter();
941941
///
942942
/// let result: Vec<i32> = iter.by_ref()
943943
/// .take_while(|n| **n != 3)
@@ -1321,7 +1321,7 @@ pub trait Iterator {
13211321
/// ```
13221322
/// let a = [1, 2, 3];
13231323
///
1324-
/// let iter = a.into_iter();
1324+
/// let iter = a.iter();
13251325
///
13261326
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
13271327
///
@@ -1334,7 +1334,7 @@ pub trait Iterator {
13341334
/// // let's try that again
13351335
/// let a = [1, 2, 3];
13361336
///
1337-
/// let mut iter = a.into_iter();
1337+
/// let mut iter = a.iter();
13381338
///
13391339
/// // instead, we add in a .by_ref()
13401340
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
@@ -1479,7 +1479,7 @@ pub trait Iterator {
14791479
/// let a = [1, 2, 3];
14801480
///
14811481
/// let (even, odd): (Vec<i32>, Vec<i32>) = a
1482-
/// .into_iter()
1482+
/// .iter()
14831483
/// .partition(|&n| n % 2 == 0);
14841484
///
14851485
/// assert_eq!(even, vec![2]);

src/libcore/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
837837
///
838838
/// * `src` must be properly aligned.
839839
///
840-
/// Like [`read`], `read_unaligned` creates a bitwise copy of `T`, regardless of
840+
/// Like [`read`], `read_volatile` creates a bitwise copy of `T`, regardless of
841841
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the returned
842842
/// value and the value at `*src` can [violate memory safety][read-ownership].
843843
/// However, storing non-[`Copy`] types in volatile memory is almost certainly

src/libcore/tests/alloc.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use core::alloc::Layout;
2+
3+
#[test]
4+
fn const_unchecked_layout() {
5+
const SIZE: usize = 0x2000;
6+
const ALIGN: usize = 0x1000;
7+
const LAYOUT: Layout = unsafe { Layout::from_size_align_unchecked(SIZE, ALIGN) };
8+
assert_eq!(LAYOUT.size(), SIZE);
9+
assert_eq!(LAYOUT.align(), ALIGN);
10+
}

src/libcore/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
#![feature(slice_partition_dedup)]
3232
#![feature(copy_within)]
3333
#![feature(int_error_matching)]
34+
#![feature(const_fn)]
3435
#![warn(rust_2018_idioms)]
3536

3637
extern crate test;
3738

39+
mod alloc;
3840
mod any;
3941
mod array;
4042
mod ascii;

src/librustc/hir/def_id.rs

+12-34
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,20 @@ impl fmt::Display for CrateNum {
9696
impl serialize::UseSpecializedEncodable for CrateNum {}
9797
impl serialize::UseSpecializedDecodable for CrateNum {}
9898

99-
/// A DefIndex is an index into the hir-map for a crate, identifying a
100-
/// particular definition. It should really be considered an interned
101-
/// shorthand for a particular DefPath.
102-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
103-
pub struct DefIndex(u32);
104-
105-
/// The crate root is always assigned index 0 by the AST Map code,
106-
/// thanks to `NodeCollector::new`.
107-
pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
99+
newtype_index! {
100+
/// A DefIndex is an index into the hir-map for a crate, identifying a
101+
/// particular definition. It should really be considered an interned
102+
/// shorthand for a particular DefPath.
103+
pub struct DefIndex {
104+
DEBUG_FORMAT = "DefIndex({})",
108105

109-
impl fmt::Debug for DefIndex {
110-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111-
write!(f, "DefIndex({})", self.as_array_index())
106+
/// The crate root is always assigned index 0 by the AST Map code,
107+
/// thanks to `NodeCollector::new`.
108+
const CRATE_DEF_INDEX = 0,
112109
}
113110
}
114111

115112
impl DefIndex {
116-
/// Converts this DefIndex into a zero-based array index.
117-
#[inline]
118-
pub fn as_array_index(&self) -> usize {
119-
self.0 as usize
120-
}
121-
122-
#[inline]
123-
pub fn from_array_index(i: usize) -> DefIndex {
124-
DefIndex(i as u32)
125-
}
126-
127113
// Proc macros from a proc-macro crate have a kind of virtual DefIndex. This
128114
// function maps the index of the macro within the crate (which is also the
129115
// index of the macro in the CrateMetadata::proc_macros array) to the
@@ -132,7 +118,7 @@ impl DefIndex {
132118
// DefIndex for proc macros start from FIRST_FREE_DEF_INDEX,
133119
// because the first FIRST_FREE_DEF_INDEX indexes are reserved
134120
// for internal use.
135-
let def_index = DefIndex::from_array_index(
121+
let def_index = DefIndex::from(
136122
proc_macro_index.checked_add(FIRST_FREE_DEF_INDEX)
137123
.expect("integer overflow adding `proc_macro_index`"));
138124
assert!(def_index != CRATE_DEF_INDEX);
@@ -141,19 +127,11 @@ impl DefIndex {
141127

142128
// This function is the reverse of from_proc_macro_index() above.
143129
pub fn to_proc_macro_index(self: DefIndex) -> usize {
144-
self.as_array_index().checked_sub(FIRST_FREE_DEF_INDEX)
130+
self.index().checked_sub(FIRST_FREE_DEF_INDEX)
145131
.unwrap_or_else(|| {
146132
bug!("using local index {:?} as proc-macro index", self)
147133
})
148134
}
149-
150-
pub fn from_raw_u32(x: u32) -> DefIndex {
151-
DefIndex(x)
152-
}
153-
154-
pub fn as_raw_u32(&self) -> u32 {
155-
self.0
156-
}
157135
}
158136

159137
impl serialize::UseSpecializedEncodable for DefIndex {}
@@ -169,7 +147,7 @@ pub struct DefId {
169147

170148
impl fmt::Debug for DefId {
171149
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
172-
write!(f, "DefId({}:{}", self.krate, self.index.as_array_index())?;
150+
write!(f, "DefId({}:{}", self.krate, self.index.index())?;
173151

174152
ty::tls::with_opt(|opt_tcx| {
175153
if let Some(tcx) = opt_tcx {

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
226226

227227
fn insert_entry(&mut self, id: HirId, entry: Entry<'hir>) {
228228
debug!("hir_map: {:?} => {:?}", id, entry);
229-
let local_map = &mut self.map[id.owner.as_array_index()];
229+
let local_map = &mut self.map[id.owner.index()];
230230
let i = id.local_id.as_u32() as usize;
231231
if local_map.is_none() {
232232
*local_map = Some(IndexVec::with_capacity(i + 1));

0 commit comments

Comments
 (0)