Skip to content

Conversation

@DrAsu33
Copy link

@DrAsu33 DrAsu33 commented Nov 24, 2025

Closes #148682

@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the file name needs to be changed.

https://rustc-dev-guide.rust-lang.org/tests/best-practices.html#test-naming

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using the issues directory, please refer to this and choose a more appropriate location.

@@ -0,0 +1,9 @@
// check-pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// check-pass
//@ check-pass

@rust-log-analyzer

This comment has been minimized.

@Kivooeo
Copy link
Member

Kivooeo commented Nov 24, 2025

r? libs

@rustbot rustbot assigned Mark-Simulacrum and unassigned fee1-dead Nov 24, 2025
@Kivooeo Kivooeo added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2025
@DrAsu33
Copy link
Author

DrAsu33 commented Nov 25, 2025

@reddevilmidzy Thanks! Updated as requested.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@reddevilmidzy reddevilmidzy left a comment

Choose a reason for hiding this comment

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

and please squash

View changes since this review

Comment on lines 1 to 2
// @ check-pass
//test Intolter::nth_back does not cause UB for ZSTs with high alignment
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove leading spaces from commands, and add a space before comments.

Suggested change
// @ check-pass
//test Intolter::nth_back does not cause UB for ZSTs with high alignment
//@ check-pass
// test Intolter::nth_back does not cause UB for ZSTs with high alignment

Copy link
Author

Choose a reason for hiding this comment

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

Thanks!It seems that all the CI tests are passed

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using the issues directory, please refer to this and choose a more appropriate location.

@reddevilmidzy
Copy link
Contributor

reddevilmidzy commented Nov 25, 2025

Could you please add close: #148682 to the PR description?(without backtick) GitHub will then automatically close the issue.
and please squash

@Kivooeo Kivooeo changed the title Fix vec iter zst alignment 148682 Fix vec iter zst alignment Nov 25, 2025
@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from ceb3c6f to 069f53f Compare November 26, 2025 00:36
@rustbot
Copy link
Collaborator

rustbot commented Nov 26, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from 069f53f to d94bb76 Compare November 26, 2025 00:39
@DrAsu33 DrAsu33 requested a review from chenyukang November 26, 2025 01:51
@DrAsu33
Copy link
Author

DrAsu33 commented Nov 28, 2025

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 28, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

// Regression test for Undefined Behavior (UB) caused by IntoIter::nth_back (#148682)
// when dealing with high-aligned Zero-Sized Types (ZSTs).
#[test]
#[cfg(miri)]
Copy link
Member

Choose a reason for hiding this comment

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

Why do you only enable this test in Miri?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I thought that the UB could only be detected by miri. I have modified that.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, only Miri will detect UB. But the test should still pass without Miri, and in particular this enures it gets type-checked.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Nov 29, 2025

Also, please run ./x test tidy --bless before committing. No need to wait for CI for simple tidy issues. :)

@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from e608b3a to ef2ceec Compare November 29, 2025 11:38
@rustbot

This comment has been minimized.

@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from ef2ceec to 89b4b30 Compare November 29, 2025 11:44
@DrAsu33
Copy link
Author

DrAsu33 commented Dec 3, 2025

Builds are green and I've addressed all feedback (moved test to library/alloc/tests/vec.rs).

@rustbot ready

@DrAsu33 DrAsu33 requested a review from hkBst December 4, 2025 14:23
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

r=me with extra tests added

View changes since this review

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 8, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 8, 2025
// Regression test for Undefined Behavior (UB) caused by IntoIter::nth_back (#148682)
// when dealing with high-aligned Zero-Sized Types (ZSTs).
#[test]
fn zst_vec_iter_nth_back_regression() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add tests for other collections that I suspect may well have the same bug? At the very least VecDeque, BTreeMap, HashMap, and BinaryHeap all seem likely to be potentially at risk.

@rust-log-analyzer

This comment has been minimized.

This commit consolidates all changes, including the core logic fix for IntoIter::nth_back and the addition of the Miri regression test in `library/alloctests/tests/vec.rs`, to prevent Undefined Behavior (UB) when dealing with highly-aligned Zero-Sized Types.
@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from a246d47 to 34392a9 Compare December 9, 2025 07:57
@DrAsu33
Copy link
Author

DrAsu33 commented Dec 9, 2025

Thanks for the review! @Mark-Simulacrum I've addressed your comments and pushed the changes. Let me know if there's anything else needed.
@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 9, 2025
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 13, 2025

📌 Commit 34392a9 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2025
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Dec 14, 2025
…-148682, r=Mark-Simulacrum

Fix vec iter zst alignment

Closes rust-lang#148682
bors added a commit that referenced this pull request Dec 14, 2025
Rollup of 8 pull requests

Successful merges:

 - #148755 (Constify `DropGuard::dismiss` and trait impls)
 - #148825 (Add SystemTime::{MIN, MAX})
 - #149272 (Fix vec iter zst alignment)
 - #149417 (tidy: Detect outdated workspaces in workspace list)
 - #149437 (Fix trailing newline in JUnit formatter)
 - #149773 (fix va_list test by adding a llvmir signext check)
 - #149894 (Update to mdbook 0.5)
 - #149955 (Fix typo in armv7a-vex-v5 documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Dec 14, 2025
…-148682, r=Mark-Simulacrum

Fix vec iter zst alignment

Closes rust-lang#148682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vec::IntoIter::{nth_back,advance_back_by} creates unaligned reference for ZST with alignment greater than 1