Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #64281

Merged
merged 8 commits into from
Sep 8, 2019
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ dependencies = [

[[package]]
name = "backtrace"
version = "0.3.35"
version = "0.3.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55"
checksum = "5180c5a20655b14a819b652fd2378fa5f1697b6c9ddad3e695c2f9cedf6df4e2"
dependencies = [
"backtrace-sys",
"cfg-if",
Expand Down
109 changes: 103 additions & 6 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2557,10 +2557,40 @@ pub trait Iterator {
/// assert_eq!([1, 2].iter().cmp([1].iter()), Ordering::Greater);
/// ```
#[stable(feature = "iter_order", since = "1.5.0")]
fn cmp<I>(mut self, other: I) -> Ordering where
fn cmp<I>(self, other: I) -> Ordering
where
I: IntoIterator<Item = Self::Item>,
Self::Item: Ord,
Self: Sized,
{
self.cmp_by(other, |x, y| x.cmp(&y))
}

/// Lexicographically compares the elements of this `Iterator` with those
/// of another with respect to the specified comparison function.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(iter_order_by)]
///
/// use std::cmp::Ordering;
///
/// let xs = [1, 2, 3, 4];
/// let ys = [1, 4, 9, 16];
///
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| x.cmp(&y)), Ordering::Less);
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| (x * x).cmp(&y)), Ordering::Equal);
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| (2 * x).cmp(&y)), Ordering::Greater);
/// ```
#[unstable(feature = "iter_order_by", issue = "0")]
fn cmp_by<I, F>(mut self, other: I, mut cmp: F) -> Ordering
where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, I::Item) -> Ordering,
{
let mut other = other.into_iter();

Expand All @@ -2579,7 +2609,7 @@ pub trait Iterator {
Some(val) => val,
};

match x.cmp(&y) {
match cmp(x, y) {
Ordering::Equal => (),
non_eq => return non_eq,
}
Expand All @@ -2601,10 +2631,49 @@ pub trait Iterator {
/// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None);
/// ```
#[stable(feature = "iter_order", since = "1.5.0")]
fn partial_cmp<I>(mut self, other: I) -> Option<Ordering> where
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where
I: IntoIterator,
Self::Item: PartialOrd<I::Item>,
Self: Sized,
{
self.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
}

/// Lexicographically compares the elements of this `Iterator` with those
/// of another with respect to the specified comparison function.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(iter_order_by)]
///
/// use std::cmp::Ordering;
///
/// let xs = [1.0, 2.0, 3.0, 4.0];
/// let ys = [1.0, 4.0, 9.0, 16.0];
///
/// assert_eq!(
/// xs.iter().partial_cmp_by(&ys, |&x, &y| x.partial_cmp(&y)),
/// Some(Ordering::Less)
/// );
/// assert_eq!(
/// xs.iter().partial_cmp_by(&ys, |&x, &y| (x * x).partial_cmp(&y)),
/// Some(Ordering::Equal)
/// );
/// assert_eq!(
/// xs.iter().partial_cmp_by(&ys, |&x, &y| (2.0 * x).partial_cmp(&y)),
/// Some(Ordering::Greater)
/// );
/// ```
#[unstable(feature = "iter_order_by", issue = "0")]
fn partial_cmp_by<I, F>(mut self, other: I, mut partial_cmp: F) -> Option<Ordering>
where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, I::Item) -> Option<Ordering>,
{
let mut other = other.into_iter();

Expand All @@ -2623,7 +2692,7 @@ pub trait Iterator {
Some(val) => val,
};

match x.partial_cmp(&y) {
match partial_cmp(x, y) {
Some(Ordering::Equal) => (),
non_eq => return non_eq,
}
Expand All @@ -2640,10 +2709,36 @@ pub trait Iterator {
/// assert_eq!([1].iter().eq([1, 2].iter()), false);
/// ```
#[stable(feature = "iter_order", since = "1.5.0")]
fn eq<I>(mut self, other: I) -> bool where
fn eq<I>(self, other: I) -> bool
where
I: IntoIterator,
Self::Item: PartialEq<I::Item>,
Self: Sized,
{
self.eq_by(other, |x, y| x == y)
}

/// Determines if the elements of this `Iterator` are equal to those of
/// another with respect to the specified equality function.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(iter_order_by)]
///
/// let xs = [1, 2, 3, 4];
/// let ys = [1, 4, 9, 16];
///
/// assert!(xs.iter().eq_by(&ys, |&x, &y| x * x == y));
/// ```
#[unstable(feature = "iter_order_by", issue = "0")]
fn eq_by<I, F>(mut self, other: I, mut eq: F) -> bool
where
Self: Sized,
I: IntoIterator,
F: FnMut(Self::Item, I::Item) -> bool,
{
let mut other = other.into_iter();

Expand All @@ -2658,7 +2753,9 @@ pub trait Iterator {
Some(val) => val,
};

if x != y { return false }
if !eq(x, y) {
return false;
}
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,62 @@ fn test_multi_iter() {
assert!(xs.iter().lt(xs.iter().skip(2)));
}

#[test]
fn test_cmp_by() {
use core::cmp::Ordering;

let f = |x: i32, y: i32| (x * x).cmp(&y);
let xs = || [1, 2, 3, 4].iter().copied();
let ys = || [1, 4, 16].iter().copied();

assert_eq!(xs().cmp_by(ys(), f), Ordering::Less);
assert_eq!(ys().cmp_by(xs(), f), Ordering::Greater);
assert_eq!(xs().cmp_by(xs().map(|x| x * x), f), Ordering::Equal);
assert_eq!(xs().rev().cmp_by(ys().rev(), f), Ordering::Greater);
assert_eq!(xs().cmp_by(ys().rev(), f), Ordering::Less);
assert_eq!(xs().cmp_by(ys().take(2), f), Ordering::Greater);
}

#[test]
fn test_partial_cmp_by() {
use core::cmp::Ordering;
use core::f64;

let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
let xs = || [1, 2, 3, 4].iter().copied();
let ys = || [1, 4, 16].iter().copied();

assert_eq!(xs().partial_cmp_by(ys(), f), Some(Ordering::Less));
assert_eq!(ys().partial_cmp_by(xs(), f), Some(Ordering::Greater));
assert_eq!(xs().partial_cmp_by(xs().map(|x| x * x), f), Some(Ordering::Equal));
assert_eq!(xs().rev().partial_cmp_by(ys().rev(), f), Some(Ordering::Greater));
assert_eq!(xs().partial_cmp_by(xs().rev(), f), Some(Ordering::Less));
assert_eq!(xs().partial_cmp_by(ys().take(2), f), Some(Ordering::Greater));

let f = |x: f64, y: f64| (x * x).partial_cmp(&y);
let xs = || [1.0, 2.0, 3.0, 4.0].iter().copied();
let ys = || [1.0, 4.0, f64::NAN, 16.0].iter().copied();

assert_eq!(xs().partial_cmp_by(ys(), f), None);
assert_eq!(ys().partial_cmp_by(xs(), f), Some(Ordering::Greater));
}

#[test]
fn test_eq_by() {
let f = |x: i32, y: i32| x * x == y;
let xs = || [1, 2, 3, 4].iter().copied();
let ys = || [1, 4, 9, 16].iter().copied();

assert!(xs().eq_by(ys(), f));
assert!(!ys().eq_by(xs(), f));
assert!(!xs().eq_by(xs(), f));
assert!(!ys().eq_by(ys(), f));

assert!(!xs().take(3).eq_by(ys(), f));
assert!(!xs().eq_by(ys().take(3), f));
assert!(xs().take(3).eq_by(ys().take(3), f));
}

#[test]
fn test_counter_from_iter() {
let it = (0..).step_by(5).take(10);
Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#![feature(const_fn)]
#![feature(iter_partition_in_place)]
#![feature(iter_is_partitioned)]
#![feature(iter_order_by)]

extern crate test;

Expand Down
8 changes: 8 additions & 0 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
self.throw_unresolved_import_error(errors.clone(), None);
}

for import in &self.r.indeterminate_imports {
// Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((import.id, TypeNS));
}
// Report unresolved imports only if no hard error was already reported
// to avoid generating multiple errors on the same import.
if !has_errors {
Expand Down Expand Up @@ -839,6 +843,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
true, directive.span, directive.crate_lint());
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
directive.vis.set(orig_vis);
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
// Consider erroneous imports used to avoid duplicate diagnostics.
self.r.used_imports.insert((directive.id, TypeNS));
}
let module = match path_res {
PathResult::Module(module) => {
// Consistency checks, analogous to `finalize_macro_resolutions`.
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,10 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
is_fenced = true;
previous_offset + fence_idx
}
None => offset,
None => {
is_fenced = false;
offset
}
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ unwind = { path = "../libunwind" }
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }

[dependencies.backtrace]
version = "0.3.35"
version = "0.3.37"
default-features = false # don't use coresymbolication on OSX
features = [
"rustc-dep-of-std", # enable build support for integrating into libstd
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {

fn default_hook(info: &PanicInfo<'_>) {
#[cfg(feature = "backtrace")]
use crate::sys_common::backtrace;
use crate::sys_common::{backtrace as backtrace_mod};

// If this is a double panic, make sure that we print a backtrace
// for this panic. Otherwise only print it if logging is enabled.
Expand All @@ -167,9 +167,9 @@ fn default_hook(info: &PanicInfo<'_>) {
let panics = update_panic_count(0);

if panics >= 2 {
Some(backtrace::PrintFormat::Full)
Some(backtrace::PrintFmt::Full)
} else {
backtrace::log_enabled()
backtrace_mod::log_enabled()
}
};

Expand Down Expand Up @@ -197,7 +197,7 @@ fn default_hook(info: &PanicInfo<'_>) {
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);

if let Some(format) = log_backtrace {
let _ = backtrace::print(err, format);
let _ = backtrace_mod::print(err, format);
} else if FIRST_PANIC.compare_and_swap(true, false, Ordering::SeqCst) {
let _ = writeln!(err, "note: run with `RUST_BACKTRACE=1` \
environment variable to display a backtrace.");
Expand Down
Loading