Skip to content

Commit db87e27

Browse files
Rollup merge of #104163 - H4x5:once-repeat-with-debug, r=dtolnay
Don't derive Debug for `OnceWith` & `RepeatWith` Closures don't impl Debug, so the derived impl is kinda useless. The behavior of not debug-printing closures is consistent with the rest of the iterator adapters/sources.
2 parents a377893 + eddb479 commit db87e27

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: library/core/src/iter/sources/once_with.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::fmt;
12
use crate::iter::{FusedIterator, TrustedLen};
23

34
/// Creates an iterator that lazily generates a value exactly once by invoking
@@ -66,12 +67,23 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
6667
///
6768
/// This `struct` is created by the [`once_with()`] function.
6869
/// See its documentation for more.
69-
#[derive(Clone, Debug)]
70+
#[derive(Clone)]
7071
#[stable(feature = "iter_once_with", since = "1.43.0")]
7172
pub struct OnceWith<F> {
7273
gen: Option<F>,
7374
}
7475

76+
#[stable(feature = "iter_once_with_debug", since = "CURRENT_RUSTC_VERSION")]
77+
impl<F> fmt::Debug for OnceWith<F> {
78+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79+
if self.gen.is_some() {
80+
f.write_str("OnceWith(Some(_))")
81+
} else {
82+
f.write_str("OnceWith(None)")
83+
}
84+
}
85+
}
86+
7587
#[stable(feature = "iter_once_with", since = "1.43.0")]
7688
impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
7789
type Item = A;

Diff for: library/core/src/iter/sources/repeat_with.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::fmt;
12
use crate::iter::{FusedIterator, TrustedLen};
23
use crate::ops::Try;
34

@@ -71,12 +72,19 @@ pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
7172
///
7273
/// This `struct` is created by the [`repeat_with()`] function.
7374
/// See its documentation for more.
74-
#[derive(Copy, Clone, Debug)]
75+
#[derive(Copy, Clone)]
7576
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
7677
pub struct RepeatWith<F> {
7778
repeater: F,
7879
}
7980

81+
#[stable(feature = "iterator_repeat_with_debug", since = "CURRENT_RUSTC_VERSION")]
82+
impl<F> fmt::Debug for RepeatWith<F> {
83+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84+
f.debug_struct("RepeatWith").finish_non_exhaustive()
85+
}
86+
}
87+
8088
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
8189
impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
8290
type Item = A;

0 commit comments

Comments
 (0)