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

Debug impls of ExtractIf have inconsistent trait bounds #137654

Open
dtolnay opened this issue Feb 26, 2025 · 4 comments
Open

Debug impls of ExtractIf have inconsistent trait bounds #137654

dtolnay opened this issue Feb 26, 2025 · 4 comments
Labels
C-bug Category: This is a bug. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 26, 2025

std::vec::ExtractIf has:

impl<T, F> Debug for ExtractIf<'_, T, F>
where
    T: Debug,
    F: Debug;

std::collections::linked_list::ExtractIf has:

impl<T, F> Debug for ExtractIf<'_, T, F>
where
    T: Debug;

std::collections::hash_set::ExtractIf has:

impl<T, F> Debug for ExtractIf<'_, T, F>
where
    F: FnMut(&T) -> bool;

std::collections::btree_set::ExtractIf has:

impl<T, F> Debug for ExtractIf<'_, T, F>
where
    T: Debug,
    F: FnMut(&T) -> bool;
Vec LinkedList HashSet BTreeSet
T: Debug ☑️ ☑️ ☑️
F: Debug ☑️
F: FnMut ☑️ ☑️

There should not need to be 4 different permutations for these 4 effectively-identical interfaces. We should be able to decide:

  • Should collection elements be printed or not.
  • Should the predicate be printed or not. Almost certainly not, given that closures do not implement Debug.
  • Should the Debug impl ever need to invoke the predicate. Almost certainly not.
@dtolnay dtolnay added C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2025
@dtolnay
Copy link
Member Author

dtolnay commented Feb 26, 2025

This is time-sensitive for Rust 1.87 if we want to change any of the impls that were just stabilized in nightly.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2025
@Noratrieb Noratrieb added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 26, 2025
@m-ou-se
Copy link
Member

m-ou-se commented Mar 18, 2025

The ExtractIf types for Vec, LinkedList and HashSet have been stabilized in 1.87, which is still in nightly.

The one for BTreeSet is still unstable.

@m-ou-se
Copy link
Member

m-ou-se commented Mar 18, 2025

There should not need to be 4 different permutations for these 4 effectively-identical interfaces. We should be able to decide:

* Should collection elements be printed or not.

* Should the predicate be printed or not. Almost certainly not, given that closures do not implement Debug.

* Should the Debug impl ever need to invoke the predicate. Almost certainly not.

It sounds to me like it should in all cases be T: Debug only, like the one of LinkedList.

@BurntSushi
Copy link
Member

I agree. Just T: Debug only seems like the right call here. Nice catch @dtolnay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants