Skip to content

Commit 6cd15a0

Browse files
committed
Auto merge of #41098 - arielb1:rollup, r=arielb1
Rollup of 12 pull requests - Successful merges: #40479, #40561, #40709, #40815, #40909, #40927, #40943, #41015, #41028, #41052, #41054, #41065 - Failed merges:
2 parents 91ae22a + d8b6109 commit 6cd15a0

File tree

27 files changed

+1275
-1087
lines changed

27 files changed

+1275
-1087
lines changed

src/bootstrap/install.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ pub fn install(build: &Build, stage: u32, host: &str) {
4949
install_sh(&build, "docs", "rust-docs", stage, host, &prefix,
5050
&docdir, &libdir, &mandir, &empty_dir);
5151
}
52+
53+
for target in build.config.target.iter() {
54+
install_sh(&build, "std", "rust-std", stage, target, &prefix,
55+
&docdir, &libdir, &mandir, &empty_dir);
56+
}
57+
5258
if build.config.rust_save_analysis {
5359
install_sh(&build, "analysis", "rust-analysis", stage, host, &prefix,
5460
&docdir, &libdir, &mandir, &empty_dir);
5561
}
56-
install_sh(&build, "std", "rust-std", stage, host, &prefix,
57-
&docdir, &libdir, &mandir, &empty_dir);
62+
5863
install_sh(&build, "rustc", "rustc", stage, host, &prefix,
5964
&docdir, &libdir, &mandir, &empty_dir);
6065
t!(fs::remove_dir_all(&empty_dir));

src/doc/unstable-book/src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
- [no_debug](no-debug.md)
124124
- [non_ascii_idents](non-ascii-idents.md)
125125
- [nonzero](nonzero.md)
126+
- [offset_to](offset-to.md)
126127
- [omit_gdb_pretty_printer_section](omit-gdb-pretty-printer-section.md)
127128
- [on_unimplemented](on-unimplemented.md)
128129
- [once_poison](once-poison.md)
@@ -171,6 +172,7 @@
171172
- [slice_concat_ext](slice-concat-ext.md)
172173
- [slice_get_slice](slice-get-slice.md)
173174
- [slice_patterns](slice-patterns.md)
175+
- [slice_rsplit](slice-rsplit.md)
174176
- [sort_internals](sort-internals.md)
175177
- [sort_unstable](sort-unstable.md)
176178
- [specialization](specialization.md)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `offset_to`
2+
3+
The tracking issue for this feature is: [#41079]
4+
5+
[#41079]: https://github.com/rust-lang/rust/issues/41079
6+
7+
------------------------
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `slice_rsplit`
2+
3+
The tracking issue for this feature is: [#41020]
4+
5+
[#41020]: https://github.com/rust-lang/rust/issues/41020
6+
7+
------------------------
8+
9+
The `slice_rsplit` feature enables two methods on slices:
10+
`slice.rsplit(predicate)` and `slice.rsplit_mut(predicate)`.

src/etc/char_private.py

+98-34
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,66 @@ def get_codepoints(f):
7676
for c in range(prev_codepoint + 1, NUM_CODEPOINTS):
7777
yield Codepoint(c, None)
7878

79+
def compress_singletons(singletons):
80+
uppers = [] # (upper, # items in lowers)
81+
lowers = []
82+
83+
for i in singletons:
84+
upper = i >> 8
85+
lower = i & 0xff
86+
if len(uppers) == 0 or uppers[-1][0] != upper:
87+
uppers.append((upper, 1))
88+
else:
89+
upper, count = uppers[-1]
90+
uppers[-1] = upper, count + 1
91+
lowers.append(lower)
92+
93+
return uppers, lowers
94+
95+
def compress_normal(normal):
96+
# lengths 0x00..0x7f are encoded as 00, 01, ..., 7e, 7f
97+
# lengths 0x80..0x7fff are encoded as 80 80, 80 81, ..., ff fe, ff ff
98+
compressed = [] # [truelen, (truelenaux), falselen, (falselenaux)]
99+
100+
prev_start = 0
101+
for start, count in normal:
102+
truelen = start - prev_start
103+
falselen = count
104+
prev_start = start + count
105+
106+
assert truelen < 0x8000 and falselen < 0x8000
107+
entry = []
108+
if truelen > 0x7f:
109+
entry.append(0x80 | (truelen >> 8))
110+
entry.append(truelen & 0xff)
111+
else:
112+
entry.append(truelen & 0x7f)
113+
if falselen > 0x7f:
114+
entry.append(0x80 | (falselen >> 8))
115+
entry.append(falselen & 0xff)
116+
else:
117+
entry.append(falselen & 0x7f)
118+
119+
compressed.append(entry)
120+
121+
return compressed
122+
123+
def print_singletons(uppers, lowers, uppersname, lowersname):
124+
print("const {}: &'static [(u8, u8)] = &[".format(uppersname))
125+
for u, c in uppers:
126+
print(" ({:#04x}, {}),".format(u, c))
127+
print("];")
128+
print("const {}: &'static [u8] = &[".format(lowersname))
129+
for i in range(0, len(lowers), 8):
130+
print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8])))
131+
print("];")
132+
133+
def print_normal(normal, normalname):
134+
print("const {}: &'static [u8] = &[".format(normalname))
135+
for v in normal:
136+
print(" {}".format(" ".join("{:#04x},".format(i) for i in v)))
137+
print("];")
138+
79139
def main():
80140
file = get_file("http://www.unicode.org/Public/UNIDATA/UnicodeData.txt")
81141

@@ -111,6 +171,11 @@ def main():
111171
else:
112172
normal0.append((a, b - a))
113173

174+
singletons0u, singletons0l = compress_singletons(singletons0)
175+
singletons1u, singletons1l = compress_singletons(singletons1)
176+
normal0 = compress_normal(normal0)
177+
normal1 = compress_normal(normal1)
178+
114179
print("""\
115180
// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
116181
// file at the top-level directory of this distribution and at
@@ -125,38 +190,49 @@ def main():
125190
// NOTE: The following code was generated by "src/etc/char_private.py",
126191
// do not edit directly!
127192
128-
use slice::SliceExt;
129-
130-
fn check(x: u16, singletons: &[u16], normal: &[u16]) -> bool {
131-
for &s in singletons {
132-
if x == s {
133-
return false;
134-
} else if x < s {
193+
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8],
194+
normal: &[u8]) -> bool {
195+
let xupper = (x >> 8) as u8;
196+
let mut lowerstart = 0;
197+
for &(upper, lowercount) in singletonuppers {
198+
let lowerend = lowerstart + lowercount as usize;
199+
if xupper == upper {
200+
for &lower in &singletonlowers[lowerstart..lowerend] {
201+
if lower == x as u8 {
202+
return false;
203+
}
204+
}
205+
} else if xupper < upper {
135206
break;
136207
}
208+
lowerstart = lowerend;
137209
}
138-
for w in normal.chunks(2) {
139-
let start = w[0];
140-
let len = w[1];
141-
let difference = (x as i32) - (start as i32);
142-
if 0 <= difference {
143-
if difference < len as i32 {
144-
return false;
145-
}
210+
211+
let mut x = x as i32;
212+
let mut normal = normal.iter().cloned();
213+
let mut current = true;
214+
while let Some(v) = normal.next() {
215+
let len = if v & 0x80 != 0 {
216+
((v & 0x7f) as i32) << 8 | normal.next().unwrap() as i32
146217
} else {
218+
v as i32
219+
};
220+
x -= len;
221+
if x < 0 {
147222
break;
148223
}
224+
current = !current;
149225
}
150-
true
226+
current
151227
}
152228
153229
pub fn is_printable(x: char) -> bool {
154230
let x = x as u32;
155231
let lower = x as u16;
156232
if x < 0x10000 {
157-
check(lower, SINGLETONS0, NORMAL0)
233+
check(lower, SINGLETONS0U, SINGLETONS0L, NORMAL0)
158234
} else if x < 0x20000 {
159-
check(lower, SINGLETONS1, NORMAL1)
235+
check(lower, SINGLETONS1U, SINGLETONS1L, NORMAL1)
160236
} else {\
161237
""")
162238
for a, b in extra:
@@ -169,22 +245,10 @@ def main():
169245
}\
170246
""")
171247
print()
172-
print("const SINGLETONS0: &'static [u16] = &[")
173-
for s in singletons0:
174-
print(" 0x{:x},".format(s))
175-
print("];")
176-
print("const SINGLETONS1: &'static [u16] = &[")
177-
for s in singletons1:
178-
print(" 0x{:x},".format(s))
179-
print("];")
180-
print("const NORMAL0: &'static [u16] = &[")
181-
for a, b in normal0:
182-
print(" 0x{:x}, 0x{:x},".format(a, b))
183-
print("];")
184-
print("const NORMAL1: &'static [u16] = &[")
185-
for a, b in normal1:
186-
print(" 0x{:x}, 0x{:x},".format(a, b))
187-
print("];")
248+
print_singletons(singletons0u, singletons0l, 'SINGLETONS0U', 'SINGLETONS0L')
249+
print_singletons(singletons1u, singletons1l, 'SINGLETONS1U', 'SINGLETONS1L')
250+
print_normal(normal0, 'NORMAL0')
251+
print_normal(normal1, 'NORMAL1')
188252

189253
if __name__ == '__main__':
190254
main()

src/libcollections/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#![feature(shared)]
5353
#![feature(slice_get_slice)]
5454
#![feature(slice_patterns)]
55+
#![feature(slice_rsplit)]
5556
#![cfg_attr(not(test), feature(sort_unstable))]
5657
#![feature(specialization)]
5758
#![feature(staged_api)]
@@ -62,6 +63,7 @@
6263
#![feature(untagged_unions)]
6364
#![cfg_attr(not(test), feature(str_checked_slicing))]
6465
#![cfg_attr(test, feature(rand, test))]
66+
#![feature(offset_to)]
6567

6668
#![no_std]
6769

src/libcollections/slice.rs

+68
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ pub use core::slice::{Iter, IterMut};
115115
pub use core::slice::{SplitMut, ChunksMut, Split};
116116
#[stable(feature = "rust1", since = "1.0.0")]
117117
pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
118+
#[unstable(feature = "slice_rsplit", issue = "41020")]
119+
pub use core::slice::{RSplit, RSplitMut};
118120
#[stable(feature = "rust1", since = "1.0.0")]
119121
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
120122
#[unstable(feature = "slice_get_slice", issue = "35729")]
@@ -779,6 +781,72 @@ impl<T> [T] {
779781
core_slice::SliceExt::split_mut(self, pred)
780782
}
781783

784+
/// Returns an iterator over subslices separated by elements that match
785+
/// `pred`, starting at the end of the slice and working backwards.
786+
/// The matched element is not contained in the subslices.
787+
///
788+
/// # Examples
789+
///
790+
/// ```
791+
/// #![feature(slice_rsplit)]
792+
///
793+
/// let slice = [11, 22, 33, 0, 44, 55];
794+
/// let mut iter = slice.rsplit(|num| *num == 0);
795+
///
796+
/// assert_eq!(iter.next().unwrap(), &[44, 55]);
797+
/// assert_eq!(iter.next().unwrap(), &[11, 22, 33]);
798+
/// assert_eq!(iter.next(), None);
799+
/// ```
800+
///
801+
/// As with `split()`, if the first or last element is matched, an empty
802+
/// slice will be the first (or last) item returned by the iterator.
803+
///
804+
/// ```
805+
/// #![feature(slice_rsplit)]
806+
///
807+
/// let v = &[0, 1, 1, 2, 3, 5, 8];
808+
/// let mut it = v.rsplit(|n| *n % 2 == 0);
809+
/// assert_eq!(it.next().unwrap(), &[]);
810+
/// assert_eq!(it.next().unwrap(), &[3, 5]);
811+
/// assert_eq!(it.next().unwrap(), &[1, 1]);
812+
/// assert_eq!(it.next().unwrap(), &[]);
813+
/// assert_eq!(it.next(), None);
814+
/// ```
815+
#[unstable(feature = "slice_rsplit", issue = "41020")]
816+
#[inline]
817+
pub fn rsplit<F>(&self, pred: F) -> RSplit<T, F>
818+
where F: FnMut(&T) -> bool
819+
{
820+
core_slice::SliceExt::rsplit(self, pred)
821+
}
822+
823+
/// Returns an iterator over mutable subslices separated by elements that
824+
/// match `pred`, starting at the end of the slice and working
825+
/// backwards. The matched element is not contained in the subslices.
826+
///
827+
/// # Examples
828+
///
829+
/// ```
830+
/// #![feature(slice_rsplit)]
831+
///
832+
/// let mut v = [100, 400, 300, 200, 600, 500];
833+
///
834+
/// let mut count = 0;
835+
/// for group in v.rsplit_mut(|num| *num % 3 == 0) {
836+
/// count += 1;
837+
/// group[0] = count;
838+
/// }
839+
/// assert_eq!(v, [3, 400, 300, 2, 600, 1]);
840+
/// ```
841+
///
842+
#[unstable(feature = "slice_rsplit", issue = "41020")]
843+
#[inline]
844+
pub fn rsplit_mut<F>(&mut self, pred: F) -> RSplitMut<T, F>
845+
where F: FnMut(&T) -> bool
846+
{
847+
core_slice::SliceExt::rsplit_mut(self, pred)
848+
}
849+
782850
/// Returns an iterator over subslices separated by elements that match
783851
/// `pred`, limited to returning at most `n` items. The matched element is
784852
/// not contained in the subslices.

0 commit comments

Comments
 (0)