Skip to content

Commit 1f57e48

Browse files
committedNov 23, 2018
Auto merge of rust-lang#56186 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests Successful merges: - rust-lang#55767 (Disable some pretty-printers when gdb is rust-enabled) - rust-lang#55838 (Fix #[cfg] for step impl on ranges) - rust-lang#55869 (Add std::iter::unfold) - rust-lang#55945 (Ensure that the argument to `static_assert` is a `bool`) - rust-lang#56022 (When popping in CTFE, perform validation before jumping to next statement to have a better span for the error) - rust-lang#56048 (Add rustc_codegen_ssa to sysroot) - rust-lang#56091 (Fix json output in the self-profiler) - rust-lang#56097 (Fix invalid bitcast taking bool out of a union represented as a scalar) - rust-lang#56116 (ci: Download clang/lldb from tarballs) - rust-lang#56120 (Add unstable Literal::subspan().) - rust-lang#56154 (Pass additional linker flags when targeting Fuchsia) - rust-lang#56162 (std::str Adapt documentation to reality) - rust-lang#56163 ([master] Backport 1.30.1 release notes) - rust-lang#56168 (Fix the tracking issue for hash_raw_entry) Failed merges: r? @ghost

File tree

27 files changed

+606
-96
lines changed

27 files changed

+606
-96
lines changed
 

‎Cargo.lock

+18-1
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,7 @@ dependencies = [
20732073
name = "rustc-main"
20742074
version = "0.0.0"
20752075
dependencies = [
2076+
"rustc_codegen_ssa 0.0.0",
20762077
"rustc_driver 0.0.0",
20772078
"rustc_target 0.0.0",
20782079
]
@@ -2169,18 +2170,34 @@ dependencies = [
21692170
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
21702171
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
21712172
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
2172-
"rustc_codegen_ssa 0.0.0",
21732173
"rustc_llvm 0.0.0",
21742174
]
21752175

21762176
[[package]]
21772177
name = "rustc_codegen_ssa"
21782178
version = "0.0.0"
21792179
dependencies = [
2180+
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
21802181
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
2182+
"jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
2183+
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
2184+
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
21812185
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
21822186
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
2187+
"rustc 0.0.0",
21832188
"rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
2189+
"rustc_allocator 0.0.0",
2190+
"rustc_apfloat 0.0.0",
2191+
"rustc_codegen_utils 0.0.0",
2192+
"rustc_data_structures 0.0.0",
2193+
"rustc_errors 0.0.0",
2194+
"rustc_fs_util 0.0.0",
2195+
"rustc_incremental 0.0.0",
2196+
"rustc_mir 0.0.0",
2197+
"rustc_target 0.0.0",
2198+
"serialize 0.0.0",
2199+
"syntax 0.0.0",
2200+
"syntax_pos 0.0.0",
21842201
]
21852202

21862203
[[package]]

‎RELEASES.md

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ Cargo
7474
[cargo-rename-reference]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
7575
[const-reference]: https://doc.rust-lang.org/reference/items/functions.html#const-functions
7676

77+
Version 1.30.1 (2018-11-08)
78+
===========================
79+
80+
- [Fixed overflow ICE in rustdoc][54199]
81+
- [Cap Cargo progress bar width at 60 in MSYS terminals][cargo/6122]
82+
83+
[54199]: https://github.com/rust-lang/rust/pull/54199
84+
[cargo/6122]: https://github.com/rust-lang/cargo/pull/6122
7785

7886
Version 1.30.0 (2018-10-25)
7987
==========================

‎src/ci/init_repo.sh

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function fetch_submodule {
5555
}
5656

5757
included="src/llvm src/llvm-emscripten src/doc/book src/doc/rust-by-example"
58+
included="$included src/tools/lld src/tools/clang src/tools/lldb"
5859
modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
5960
modules=($modules)
6061
use_git=""

‎src/etc/gdb_rust_pretty_printing.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
if sys.version_info[0] >= 3:
1919
xrange = range
2020

21+
rust_enabled = 'set language rust' in gdb.execute('complete set language ru', to_string = True)
22+
2123
#===============================================================================
2224
# GDB Pretty Printing Module for Rust
2325
#===============================================================================
@@ -99,27 +101,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
99101
val = GdbValue(gdb_val)
100102
type_kind = val.type.get_type_kind()
101103

102-
if type_kind == rustpp.TYPE_KIND_EMPTY:
103-
return RustEmptyPrinter(val)
104-
105-
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
106-
return RustStructPrinter(val,
107-
omit_first_field = False,
108-
omit_type_name = False,
109-
is_tuple_like = False)
110-
111-
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
112-
return RustStructPrinter(val,
113-
omit_first_field = True,
114-
omit_type_name = False,
115-
is_tuple_like = False)
116-
117104
if type_kind == rustpp.TYPE_KIND_SLICE:
118105
return RustSlicePrinter(val)
119106

120-
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
121-
return RustStringSlicePrinter(val)
122-
123107
if type_kind == rustpp.TYPE_KIND_STD_VEC:
124108
return RustStdVecPrinter(val)
125109

@@ -138,6 +122,29 @@ def rust_pretty_printer_lookup_function(gdb_val):
138122
if type_kind == rustpp.TYPE_KIND_OS_STRING:
139123
return RustOsStringPrinter(val)
140124

125+
# Checks after this point should only be for "compiler" types --
126+
# things that gdb's Rust language support knows about.
127+
if rust_enabled:
128+
return None
129+
130+
if type_kind == rustpp.TYPE_KIND_EMPTY:
131+
return RustEmptyPrinter(val)
132+
133+
if type_kind == rustpp.TYPE_KIND_REGULAR_STRUCT:
134+
return RustStructPrinter(val,
135+
omit_first_field = False,
136+
omit_type_name = False,
137+
is_tuple_like = False)
138+
139+
if type_kind == rustpp.TYPE_KIND_STRUCT_VARIANT:
140+
return RustStructPrinter(val,
141+
omit_first_field = True,
142+
omit_type_name = False,
143+
is_tuple_like = False)
144+
145+
if type_kind == rustpp.TYPE_KIND_STR_SLICE:
146+
return RustStringSlicePrinter(val)
147+
141148
if type_kind == rustpp.TYPE_KIND_TUPLE:
142149
return RustStructPrinter(val,
143150
omit_first_field = False,

‎src/libcore/iter/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@
112112
//!
113113
//! // next() is the only required method
114114
//! fn next(&mut self) -> Option<usize> {
115-
//! // increment our count. This is why we started at zero.
115+
//! // Increment our count. This is why we started at zero.
116116
//! self.count += 1;
117117
//!
118-
//! // check to see if we've finished counting or not.
118+
//! // Check to see if we've finished counting or not.
119119
//! if self.count < 6 {
120120
//! Some(self.count)
121121
//! } else {
@@ -339,6 +339,8 @@ pub use self::sources::{RepeatWith, repeat_with};
339339
pub use self::sources::{Empty, empty};
340340
#[stable(feature = "iter_once", since = "1.2.0")]
341341
pub use self::sources::{Once, once};
342+
#[unstable(feature = "iter_unfold", issue = "55977")]
343+
pub use self::sources::{Unfold, unfold, Successors, successors};
342344

343345
#[stable(feature = "rust1", since = "1.0.0")]
344346
pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend};

‎src/libcore/iter/range.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ macro_rules! step_impl_no_between {
166166
}
167167

168168
step_impl_unsigned!(usize u8 u16);
169-
#[cfg(not(target_pointer_witdth = "16"))]
169+
#[cfg(not(target_pointer_width = "16"))]
170170
step_impl_unsigned!(u32);
171-
#[cfg(target_pointer_witdth = "16")]
171+
#[cfg(target_pointer_width = "16")]
172172
step_impl_no_between!(u32);
173173
step_impl_signed!([isize: usize] [i8: u8] [i16: u16]);
174-
#[cfg(not(target_pointer_witdth = "16"))]
174+
#[cfg(not(target_pointer_width = "16"))]
175175
step_impl_signed!([i32: u32]);
176-
#[cfg(target_pointer_witdth = "16")]
176+
#[cfg(target_pointer_width = "16")]
177177
step_impl_no_between!(i32);
178178
#[cfg(target_pointer_width = "64")]
179179
step_impl_unsigned!(u64);

‎src/libcore/iter/sources.rs

+161
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,164 @@ impl<T> FusedIterator for Once<T> {}
386386
pub fn once<T>(value: T) -> Once<T> {
387387
Once { inner: Some(value).into_iter() }
388388
}
389+
390+
/// Creates a new iterator where each iteration calls the provided closure
391+
/// `F: FnMut(&mut St) -> Option<T>`.
392+
///
393+
/// This allows creating a custom iterator with any behavior
394+
/// without using the more verbose syntax of creating a dedicated type
395+
/// and implementing the `Iterator` trait for it.
396+
///
397+
/// In addition to its captures and environment,
398+
/// the closure is given a mutable reference to some state
399+
/// that is preserved across iterations.
400+
/// That state starts as the given `initial_state` value.
401+
///
402+
/// Note that the `Unfold` iterator doesn’t make assumptions about the behavior of the closure,
403+
/// and therefore conservatively does not implement [`FusedIterator`],
404+
/// or override [`Iterator::size_hint`] from its default `(0, None)`.
405+
///
406+
/// [`FusedIterator`]: trait.FusedIterator.html
407+
/// [`Iterator::size_hint`]: trait.Iterator.html#method.size_hint
408+
///
409+
/// # Examples
410+
///
411+
/// Let’s re-implement the counter iterator from [module-level documentation]:
412+
///
413+
/// [module-level documentation]: index.html
414+
///
415+
/// ```
416+
/// #![feature(iter_unfold)]
417+
/// let counter = std::iter::unfold(0, |count| {
418+
/// // Increment our count. This is why we started at zero.
419+
/// *count += 1;
420+
///
421+
/// // Check to see if we've finished counting or not.
422+
/// if *count < 6 {
423+
/// Some(*count)
424+
/// } else {
425+
/// None
426+
/// }
427+
/// });
428+
/// assert_eq!(counter.collect::<Vec<_>>(), &[1, 2, 3, 4, 5]);
429+
/// ```
430+
#[inline]
431+
#[unstable(feature = "iter_unfold", issue = "55977")]
432+
pub fn unfold<St, T, F>(initial_state: St, f: F) -> Unfold<St, F>
433+
where F: FnMut(&mut St) -> Option<T>
434+
{
435+
Unfold {
436+
state: initial_state,
437+
f,
438+
}
439+
}
440+
441+
/// An iterator where each iteration calls the provided closure `F: FnMut(&mut St) -> Option<T>`.
442+
///
443+
/// This `struct` is created by the [`unfold`] function.
444+
/// See its documentation for more.
445+
///
446+
/// [`unfold`]: fn.unfold.html
447+
#[derive(Clone)]
448+
#[unstable(feature = "iter_unfold", issue = "55977")]
449+
pub struct Unfold<St, F> {
450+
state: St,
451+
f: F,
452+
}
453+
454+
#[unstable(feature = "iter_unfold", issue = "55977")]
455+
impl<St, T, F> Iterator for Unfold<St, F>
456+
where F: FnMut(&mut St) -> Option<T>
457+
{
458+
type Item = T;
459+
460+
#[inline]
461+
fn next(&mut self) -> Option<Self::Item> {
462+
(self.f)(&mut self.state)
463+
}
464+
}
465+
466+
#[unstable(feature = "iter_unfold", issue = "55977")]
467+
impl<St: fmt::Debug, F> fmt::Debug for Unfold<St, F> {
468+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
469+
f.debug_struct("Unfold")
470+
.field("state", &self.state)
471+
.finish()
472+
}
473+
}
474+
475+
/// Creates a new iterator where each successive item is computed based on the preceding one.
476+
///
477+
/// The iterator starts with the given first item (if any)
478+
/// and calls the given `FnMut(&T) -> Option<T>` closure to compute each item’s successor.
479+
///
480+
/// ```
481+
/// #![feature(iter_unfold)]
482+
/// use std::iter::successors;
483+
///
484+
/// let powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
485+
/// assert_eq!(powers_of_10.collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]);
486+
/// ```
487+
#[unstable(feature = "iter_unfold", issue = "55977")]
488+
pub fn successors<T, F>(first: Option<T>, succ: F) -> Successors<T, F>
489+
where F: FnMut(&T) -> Option<T>
490+
{
491+
// If this function returned `impl Iterator<Item=T>`
492+
// it could be based on `unfold` and not need a dedicated type.
493+
// However having a named `Successors<T, F>` type allows it to be `Clone` when `T` and `F` are.
494+
Successors {
495+
next: first,
496+
succ,
497+
}
498+
}
499+
500+
/// An new iterator where each successive item is computed based on the preceding one.
501+
///
502+
/// This `struct` is created by the [`successors`] function.
503+
/// See its documentation for more.
504+
///
505+
/// [`successors`]: fn.successors.html
506+
#[derive(Clone)]
507+
#[unstable(feature = "iter_unfold", issue = "55977")]
508+
pub struct Successors<T, F> {
509+
next: Option<T>,
510+
succ: F,
511+
}
512+
513+
#[unstable(feature = "iter_unfold", issue = "55977")]
514+
impl<T, F> Iterator for Successors<T, F>
515+
where F: FnMut(&T) -> Option<T>
516+
{
517+
type Item = T;
518+
519+
#[inline]
520+
fn next(&mut self) -> Option<Self::Item> {
521+
self.next.take().map(|item| {
522+
self.next = (self.succ)(&item);
523+
item
524+
})
525+
}
526+
527+
#[inline]
528+
fn size_hint(&self) -> (usize, Option<usize>) {
529+
if self.next.is_some() {
530+
(1, None)
531+
} else {
532+
(0, Some(0))
533+
}
534+
}
535+
}
536+
537+
#[unstable(feature = "iter_unfold", issue = "55977")]
538+
impl<T, F> FusedIterator for Successors<T, F>
539+
where F: FnMut(&T) -> Option<T>
540+
{}
541+
542+
#[unstable(feature = "iter_unfold", issue = "55977")]
543+
impl<T: fmt::Debug, F> fmt::Debug for Successors<T, F> {
544+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545+
f.debug_struct("Successors")
546+
.field("next", &self.next)
547+
.finish()
548+
}
549+
}

‎src/libcore/str/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1424,10 +1424,8 @@ fn contains_nonascii(x: usize) -> bool {
14241424
(x & NONASCII_MASK) != 0
14251425
}
14261426

1427-
/// Walks through `iter` checking that it's a valid UTF-8 sequence,
1428-
/// returning `true` in that case, or, if it is invalid, `false` with
1429-
/// `iter` reset such that it is pointing at the first byte in the
1430-
/// invalid sequence.
1427+
/// Walks through `v` checking that it's a valid UTF-8 sequence,
1428+
/// returning `Ok(())` in that case, or, if it is invalid, `Err(err)`.
14311429
#[inline]
14321430
fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
14331431
let mut index = 0;

‎src/libcore/tests/iter.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,17 @@ fn test_repeat_with_take_collect() {
17591759
assert_eq!(v, vec![1, 2, 4, 8, 16]);
17601760
}
17611761

1762+
#[test]
1763+
fn test_successors() {
1764+
let mut powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
1765+
assert_eq!(powers_of_10.by_ref().collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]);
1766+
assert_eq!(powers_of_10.next(), None);
1767+
1768+
let mut empty = successors(None::<u32>, |_| unimplemented!());
1769+
assert_eq!(empty.next(), None);
1770+
assert_eq!(empty.next(), None);
1771+
}
1772+
17621773
#[test]
17631774
fn test_fuse() {
17641775
let mut it = 0..3;

‎src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(flt2dec)]
2020
#![feature(fmt_internals)]
2121
#![feature(hashmap_internals)]
22+
#![feature(iter_unfold)]
2223
#![feature(pattern)]
2324
#![feature(range_is_empty)]
2425
#![feature(raw)]

0 commit comments

Comments
 (0)
Please sign in to comment.