Skip to content

Commit 2c0931e

Browse files
committed
Auto merge of #64281 - Centril:rollup-inyqjf8, r=Centril
Rollup of 4 pull requests Successful merges: - #62205 (Add Iterator comparison methods that take a comparison function) - #64152 (Use backtrace formatting from the backtrace crate) - #64265 (resolve: Mark more erroneous imports as used) - #64267 (rustdoc: fix diagnostic with mixed code block styles) Failed merges: r? @ghost
2 parents 5036237 + 832b47a commit 2c0931e

File tree

13 files changed

+323
-171
lines changed

13 files changed

+323
-171
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ dependencies = [
109109

110110
[[package]]
111111
name = "backtrace"
112-
version = "0.3.35"
112+
version = "0.3.37"
113113
source = "registry+https://github.com/rust-lang/crates.io-index"
114-
checksum = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55"
114+
checksum = "5180c5a20655b14a819b652fd2378fa5f1697b6c9ddad3e695c2f9cedf6df4e2"
115115
dependencies = [
116116
"backtrace-sys",
117117
"cfg-if",

src/libcore/iter/traits/iterator.rs

+103-6
Original file line numberDiff line numberDiff line change
@@ -2557,10 +2557,40 @@ pub trait Iterator {
25572557
/// assert_eq!([1, 2].iter().cmp([1].iter()), Ordering::Greater);
25582558
/// ```
25592559
#[stable(feature = "iter_order", since = "1.5.0")]
2560-
fn cmp<I>(mut self, other: I) -> Ordering where
2560+
fn cmp<I>(self, other: I) -> Ordering
2561+
where
25612562
I: IntoIterator<Item = Self::Item>,
25622563
Self::Item: Ord,
25632564
Self: Sized,
2565+
{
2566+
self.cmp_by(other, |x, y| x.cmp(&y))
2567+
}
2568+
2569+
/// Lexicographically compares the elements of this `Iterator` with those
2570+
/// of another with respect to the specified comparison function.
2571+
///
2572+
/// # Examples
2573+
///
2574+
/// Basic usage:
2575+
///
2576+
/// ```
2577+
/// #![feature(iter_order_by)]
2578+
///
2579+
/// use std::cmp::Ordering;
2580+
///
2581+
/// let xs = [1, 2, 3, 4];
2582+
/// let ys = [1, 4, 9, 16];
2583+
///
2584+
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| x.cmp(&y)), Ordering::Less);
2585+
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| (x * x).cmp(&y)), Ordering::Equal);
2586+
/// assert_eq!(xs.iter().cmp_by(&ys, |&x, &y| (2 * x).cmp(&y)), Ordering::Greater);
2587+
/// ```
2588+
#[unstable(feature = "iter_order_by", issue = "0")]
2589+
fn cmp_by<I, F>(mut self, other: I, mut cmp: F) -> Ordering
2590+
where
2591+
Self: Sized,
2592+
I: IntoIterator,
2593+
F: FnMut(Self::Item, I::Item) -> Ordering,
25642594
{
25652595
let mut other = other.into_iter();
25662596

@@ -2579,7 +2609,7 @@ pub trait Iterator {
25792609
Some(val) => val,
25802610
};
25812611

2582-
match x.cmp(&y) {
2612+
match cmp(x, y) {
25832613
Ordering::Equal => (),
25842614
non_eq => return non_eq,
25852615
}
@@ -2601,10 +2631,49 @@ pub trait Iterator {
26012631
/// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None);
26022632
/// ```
26032633
#[stable(feature = "iter_order", since = "1.5.0")]
2604-
fn partial_cmp<I>(mut self, other: I) -> Option<Ordering> where
2634+
fn partial_cmp<I>(self, other: I) -> Option<Ordering>
2635+
where
26052636
I: IntoIterator,
26062637
Self::Item: PartialOrd<I::Item>,
26072638
Self: Sized,
2639+
{
2640+
self.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
2641+
}
2642+
2643+
/// Lexicographically compares the elements of this `Iterator` with those
2644+
/// of another with respect to the specified comparison function.
2645+
///
2646+
/// # Examples
2647+
///
2648+
/// Basic usage:
2649+
///
2650+
/// ```
2651+
/// #![feature(iter_order_by)]
2652+
///
2653+
/// use std::cmp::Ordering;
2654+
///
2655+
/// let xs = [1.0, 2.0, 3.0, 4.0];
2656+
/// let ys = [1.0, 4.0, 9.0, 16.0];
2657+
///
2658+
/// assert_eq!(
2659+
/// xs.iter().partial_cmp_by(&ys, |&x, &y| x.partial_cmp(&y)),
2660+
/// Some(Ordering::Less)
2661+
/// );
2662+
/// assert_eq!(
2663+
/// xs.iter().partial_cmp_by(&ys, |&x, &y| (x * x).partial_cmp(&y)),
2664+
/// Some(Ordering::Equal)
2665+
/// );
2666+
/// assert_eq!(
2667+
/// xs.iter().partial_cmp_by(&ys, |&x, &y| (2.0 * x).partial_cmp(&y)),
2668+
/// Some(Ordering::Greater)
2669+
/// );
2670+
/// ```
2671+
#[unstable(feature = "iter_order_by", issue = "0")]
2672+
fn partial_cmp_by<I, F>(mut self, other: I, mut partial_cmp: F) -> Option<Ordering>
2673+
where
2674+
Self: Sized,
2675+
I: IntoIterator,
2676+
F: FnMut(Self::Item, I::Item) -> Option<Ordering>,
26082677
{
26092678
let mut other = other.into_iter();
26102679

@@ -2623,7 +2692,7 @@ pub trait Iterator {
26232692
Some(val) => val,
26242693
};
26252694

2626-
match x.partial_cmp(&y) {
2695+
match partial_cmp(x, y) {
26272696
Some(Ordering::Equal) => (),
26282697
non_eq => return non_eq,
26292698
}
@@ -2640,10 +2709,36 @@ pub trait Iterator {
26402709
/// assert_eq!([1].iter().eq([1, 2].iter()), false);
26412710
/// ```
26422711
#[stable(feature = "iter_order", since = "1.5.0")]
2643-
fn eq<I>(mut self, other: I) -> bool where
2712+
fn eq<I>(self, other: I) -> bool
2713+
where
26442714
I: IntoIterator,
26452715
Self::Item: PartialEq<I::Item>,
26462716
Self: Sized,
2717+
{
2718+
self.eq_by(other, |x, y| x == y)
2719+
}
2720+
2721+
/// Determines if the elements of this `Iterator` are equal to those of
2722+
/// another with respect to the specified equality function.
2723+
///
2724+
/// # Examples
2725+
///
2726+
/// Basic usage:
2727+
///
2728+
/// ```
2729+
/// #![feature(iter_order_by)]
2730+
///
2731+
/// let xs = [1, 2, 3, 4];
2732+
/// let ys = [1, 4, 9, 16];
2733+
///
2734+
/// assert!(xs.iter().eq_by(&ys, |&x, &y| x * x == y));
2735+
/// ```
2736+
#[unstable(feature = "iter_order_by", issue = "0")]
2737+
fn eq_by<I, F>(mut self, other: I, mut eq: F) -> bool
2738+
where
2739+
Self: Sized,
2740+
I: IntoIterator,
2741+
F: FnMut(Self::Item, I::Item) -> bool,
26472742
{
26482743
let mut other = other.into_iter();
26492744

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

2661-
if x != y { return false }
2756+
if !eq(x, y) {
2757+
return false;
2758+
}
26622759
}
26632760
}
26642761

src/libcore/tests/iter.rs

+56
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,62 @@ fn test_multi_iter() {
5757
assert!(xs.iter().lt(xs.iter().skip(2)));
5858
}
5959

60+
#[test]
61+
fn test_cmp_by() {
62+
use core::cmp::Ordering;
63+
64+
let f = |x: i32, y: i32| (x * x).cmp(&y);
65+
let xs = || [1, 2, 3, 4].iter().copied();
66+
let ys = || [1, 4, 16].iter().copied();
67+
68+
assert_eq!(xs().cmp_by(ys(), f), Ordering::Less);
69+
assert_eq!(ys().cmp_by(xs(), f), Ordering::Greater);
70+
assert_eq!(xs().cmp_by(xs().map(|x| x * x), f), Ordering::Equal);
71+
assert_eq!(xs().rev().cmp_by(ys().rev(), f), Ordering::Greater);
72+
assert_eq!(xs().cmp_by(ys().rev(), f), Ordering::Less);
73+
assert_eq!(xs().cmp_by(ys().take(2), f), Ordering::Greater);
74+
}
75+
76+
#[test]
77+
fn test_partial_cmp_by() {
78+
use core::cmp::Ordering;
79+
use core::f64;
80+
81+
let f = |x: i32, y: i32| (x * x).partial_cmp(&y);
82+
let xs = || [1, 2, 3, 4].iter().copied();
83+
let ys = || [1, 4, 16].iter().copied();
84+
85+
assert_eq!(xs().partial_cmp_by(ys(), f), Some(Ordering::Less));
86+
assert_eq!(ys().partial_cmp_by(xs(), f), Some(Ordering::Greater));
87+
assert_eq!(xs().partial_cmp_by(xs().map(|x| x * x), f), Some(Ordering::Equal));
88+
assert_eq!(xs().rev().partial_cmp_by(ys().rev(), f), Some(Ordering::Greater));
89+
assert_eq!(xs().partial_cmp_by(xs().rev(), f), Some(Ordering::Less));
90+
assert_eq!(xs().partial_cmp_by(ys().take(2), f), Some(Ordering::Greater));
91+
92+
let f = |x: f64, y: f64| (x * x).partial_cmp(&y);
93+
let xs = || [1.0, 2.0, 3.0, 4.0].iter().copied();
94+
let ys = || [1.0, 4.0, f64::NAN, 16.0].iter().copied();
95+
96+
assert_eq!(xs().partial_cmp_by(ys(), f), None);
97+
assert_eq!(ys().partial_cmp_by(xs(), f), Some(Ordering::Greater));
98+
}
99+
100+
#[test]
101+
fn test_eq_by() {
102+
let f = |x: i32, y: i32| x * x == y;
103+
let xs = || [1, 2, 3, 4].iter().copied();
104+
let ys = || [1, 4, 9, 16].iter().copied();
105+
106+
assert!(xs().eq_by(ys(), f));
107+
assert!(!ys().eq_by(xs(), f));
108+
assert!(!xs().eq_by(xs(), f));
109+
assert!(!ys().eq_by(ys(), f));
110+
111+
assert!(!xs().take(3).eq_by(ys(), f));
112+
assert!(!xs().eq_by(ys().take(3), f));
113+
assert!(xs().take(3).eq_by(ys().take(3), f));
114+
}
115+
60116
#[test]
61117
fn test_counter_from_iter() {
62118
let it = (0..).step_by(5).take(10);

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#![feature(const_fn)]
3434
#![feature(iter_partition_in_place)]
3535
#![feature(iter_is_partitioned)]
36+
#![feature(iter_order_by)]
3637

3738
extern crate test;
3839

src/librustc_resolve/resolve_imports.rs

+8
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
673673
self.throw_unresolved_import_error(errors.clone(), None);
674674
}
675675

676+
for import in &self.r.indeterminate_imports {
677+
// Consider erroneous imports used to avoid duplicate diagnostics.
678+
self.r.used_imports.insert((import.id, TypeNS));
679+
}
676680
// Report unresolved imports only if no hard error was already reported
677681
// to avoid generating multiple errors on the same import.
678682
if !has_errors {
@@ -839,6 +843,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
839843
true, directive.span, directive.crate_lint());
840844
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
841845
directive.vis.set(orig_vis);
846+
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
847+
// Consider erroneous imports used to avoid duplicate diagnostics.
848+
self.r.used_imports.insert((directive.id, TypeNS));
849+
}
842850
let module = match path_res {
843851
PathResult::Module(module) => {
844852
// Consistency checks, analogous to `finalize_macro_resolutions`.

src/librustdoc/html/markdown.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,10 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
931931
is_fenced = true;
932932
previous_offset + fence_idx
933933
}
934-
None => offset,
934+
None => {
935+
is_fenced = false;
936+
offset
937+
}
935938
};
936939
}
937940
}

src/libstd/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unwind = { path = "../libunwind" }
2626
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
2727

2828
[dependencies.backtrace]
29-
version = "0.3.35"
29+
version = "0.3.37"
3030
default-features = false # don't use coresymbolication on OSX
3131
features = [
3232
"rustc-dep-of-std", # enable build support for integrating into libstd

src/libstd/panicking.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
158158

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

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

169169
if panics >= 2 {
170-
Some(backtrace::PrintFormat::Full)
170+
Some(backtrace::PrintFmt::Full)
171171
} else {
172-
backtrace::log_enabled()
172+
backtrace_mod::log_enabled()
173173
}
174174
};
175175

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

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

0 commit comments

Comments
 (0)