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
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 28, 2025
Comment on lines 1 to 10
//@ check-pass
// test Intolter::nth_back does not cause UB for ZSTs with high alignment

#[repr(align(8))]
struct Thing;

fn main() {
let v = vec![Thing, Thing];
let _ = v.into_iter().nth_back(1);
}
Copy link
Member

@hkBst hkBst Nov 28, 2025

Choose a reason for hiding this comment

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

The issue shows a reproduction using Miri, so I'm wondering how this test is supposed to reproduce that. IIUC this does the equivalent of "cargo check", no, while what is needed is a miri check.

@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch 2 times, most recently from 580eef1 to 1a055d7 Compare November 29, 2025 06:22
@@ -0,0 +1,10 @@
//@ run-pass
Copy link
Member

Choose a reason for hiding this comment

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

This still will not be a test we run under miri, I believe.

We do run the standard library's tests under miri, however.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 29, 2025
@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from fd0b327 to 8ef3419 Compare November 29, 2025 07:14
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2025

The Miri subtree was changed

cc @rust-lang/miri

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Some comments for the Miri test. :)
I did not look at the libs part.

FWIW, we do run the standard library test suite in Miri. So maybe it would make more sense to add this there? We already have some tests in the standard library test suite that are primarily meant for Miri.

View changes since this review

Copy link
Member

Choose a reason for hiding this comment

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

Please use lower-case filenames.

Comment on lines 1 to 2
//@ compile-flags: -Zmiri-symbolic-alignment-check
//@ run-pass
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//@ compile-flags: -Zmiri-symbolic-alignment-check
//@ run-pass
//@compile-flags: -Zmiri-symbolic-alignment-check

Please follow the conventions of surrounding files.

Comment on lines 25 to 26

// The main assertion is that the program runs to completion without Miri reporting UB.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The main assertion is that the program runs to completion without Miri reporting UB.

This doesn't need to be explicitly stated.

//@ compile-flags: -Zmiri-symbolic-alignment-check
//@ run-pass

use std::ptr;
Copy link
Member

Choose a reason for hiding this comment

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

What are you importing std::ptr for?

@DrAsu33 DrAsu33 force-pushed the fix-vec-iter-zst-alignment-148682 branch from d7b95bc to 2096afe Compare November 29, 2025 07:43
@DrAsu33
Copy link
Author

DrAsu33 commented Nov 29, 2025

Hello @RalfJung .Thanks for the guidance!But I'm still wondering about where I should place test file. Could you please confirm the exact directory path you'd like me to place the new test file (zst_nth_back.rs)?

@RalfJung
Copy link
Member

RalfJung commented Nov 29, 2025

library/alloctests/tests/vec.rs seems like the right place. It's not going to be a new file, just a new test function.

@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.

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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