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

std: Fix iteration over vectors of 0-size values #13468

Merged
merged 1 commit into from
Apr 13, 2014

Conversation

alexcrichton
Copy link
Member

Previously, all slices derived from a vector whose values were of size 0 had a
null pointer as the 'data' pointer on the slice. This caused first pointer to be
yielded during iteration to always be the null pointer. Due to the null pointer
optimization, this meant that the first return value was None, instead of
Some(&T).

This commit changes slice construction from a Vec instance to use a base pointer
of 1 if the values have zero size. This means that the iterator will never
return null, and the iteration will proceed appropriately.

Closes #13467

Previously, all slices derived from a vector whose values were of size 0 had a
null pointer as the 'data' pointer on the slice. This caused first pointer to be
yielded during iteration to always be the null pointer. Due to the null pointer
optimization, this meant that the first return value was None, instead of
Some(&T).

This commit changes slice construction from a Vec instance to use a base pointer
of 1 if the values have zero size. This means that the iterator will never
return null, and the iteration will proceed appropriately.

Closes rust-lang#13467
@alexcrichton
Copy link
Member Author

Updated as_mut_slice as well (nice catch!), but for now the EMPTY global is private and I have a feeling we can probably deal with that when it comes up (in debugging)

bors added a commit that referenced this pull request Apr 13, 2014
Previously, all slices derived from a vector whose values were of size 0 had a
null pointer as the 'data' pointer on the slice. This caused first pointer to be
yielded during iteration to always be the null pointer. Due to the null pointer
optimization, this meant that the first return value was None, instead of
Some(&T).

This commit changes slice construction from a Vec instance to use a base pointer
of 1 if the values have zero size. This means that the iterator will never
return null, and the iteration will proceed appropriately.

Closes #13467
@bors bors closed this Apr 13, 2014
@bors bors merged commit 7a82d47 into rust-lang:master Apr 13, 2014
@alexcrichton alexcrichton deleted the issue-13467 branch April 13, 2014 17:19
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 3, 2024
…1995

Ignore `--print`/`-Vv` requests in `clippy-driver`

Fixes rust-lang/rust-clippy#12623
Fixes rust-lang/cargo#14385

r? `@flip1995`

changelog: none
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.

Vec<()> does not iterate correctly
3 participants