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

Fix IntoIterator derived bounds (#208) #284

Merged
merged 12 commits into from
Aug 11, 2023

Conversation

MegaBluejay
Copy link
Contributor

@MegaBluejay MegaBluejay commented Aug 8, 2023

Resolves #208

Synopsis

For generic structs, some derived IntoIterator bounds are based on the struct's type parameters, rather than the field used in the implementation.

Solution

Require only the type of the field used to be IntoIterator

Checklist

  • Documentation is updated (if required)
  • Tests are added/updated (if required)
  • CHANGELOG entry is added (if required)

Note

I don't think this is a breaking change, since no program where the newly added bounds aren't satisfied would have compiled.

@MegaBluejay MegaBluejay marked this pull request as ready for review August 8, 2023 13:47
@MegaBluejay MegaBluejay changed the title Fix IntoIterator derived bounds Fix IntoIterator derived bounds (#208) Aug 8, 2023
tests/into_iterator.rs Show resolved Hide resolved
tests/into_iterator.rs Show resolved Hide resolved
impl/src/into_iterator.rs Show resolved Hide resolved
Copy link
Collaborator

@tyranron tyranron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are still failing.

iter: I,
vals: &[T],
) {
assert_eq!(iter.into_iter().collect::<Vec<_>>(), vals);
Copy link
Collaborator

@tyranron tyranron Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MegaBluejay such unification is not good for tests, as doesn't allow us to understand well which assertion in the test case is failing exactly:

---- generic stdout ----
thread 'generic' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- generic_bounds stdout ----
thread 'generic_bounds' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5

---- generic_refs stdout ----
thread 'generic_refs' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5

---- generic_owned stdout ----
thread 'generic_owned' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5

---- named_single stdout ----
thread 'named_single' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5

---- tuple_single stdout ----
thread 'tuple_single' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3]`,
 right: `[]`', tests/into_iterator.rs:18:5

#[track_caller] may be helpful here to some degree, but not when multiple assertions are united in the same helper function.

@tyranron tyranron added this to the 1.0.0 milestone Aug 11, 2023
@tyranron tyranron merged commit 334df59 into JelteF:master Aug 11, 2023
16 checks passed
@tyranron tyranron linked an issue Aug 11, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntoIterator for generic type includes unnecessary trait bounds IntoIterator deriving fails on typed struct
3 participants