Skip to content

Add missing Debug derive to vec::IntoIter #580

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zeenix
Copy link
Contributor

@zeenix zeenix commented Jun 10, 2025

No description provided.

Copy link
Contributor

@sosthene-nitrokey sosthene-nitrokey left a comment

Choose a reason for hiding this comment

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

This would lead to undefined behaviour.

The vec field in the IntoIter struct is not in a valid state after iteration has begun. All elements before next have been "removed" from the Vec through unsafe code even though it's still there. All methods on IntoIter must take care to not read from them.

If you want a Debug implementation, you will need not to go through derive, but instead write a manual implementation. You can take a look at the Clone implementation to see how Debug could be implemented manually.

@sosthene-nitrokey
Copy link
Contributor

sosthene-nitrokey commented Jun 11, 2025

This is where Unsafe fields could come in handy in the future.

@zeenix
Copy link
Contributor Author

zeenix commented Jun 11, 2025

@sosthene-nitrokey Thanks for the review. PTALA. I was first going for a more verbose option (f.debug_struct("IntoIter").field("elements", &s).finish()) but then decided against it. I can change to something like that, if you like.

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.

2 participants