Skip to content

Actually move out of Box in moving-out-of-Box test#2204

Merged
ehuss merged 1 commit intorust-lang:masterfrom
dianne:fix-box-deref-example
Mar 13, 2026
Merged

Actually move out of Box in moving-out-of-Box test#2204
ehuss merged 1 commit intorust-lang:masterfrom
dianne:fix-box-deref-example

Conversation

@dianne
Copy link
Contributor

@dianne dianne commented Mar 11, 2026

I looked at #2075 again after it merged and noticed a test I wrote there is wrong; oops! let _ = $place; doesn't actually perform a move; a place-to-value coercion is needed.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 11, 2026
assert_eq!(*y, 11);
let z = Box::new(NoCopy);
let _: NoCopy = *z;
let _z: NoCopy = *z;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drop::<NoCopy>(*z) or { *z } would also get the job done here. Maybe the drop would be the most explicit? Using a pattern binding is a bit more subtle; I expect it may not be obvious if you're not deeply in the weeds already that _z differs from _.

Comment on lines +188 to +189
let z = Box::new(NoCopy);
let _: NoCopy = *z;
let _z: NoCopy = *z;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think to maintain consistency with the rest of the example above, it's fine to just assign to a local.

Since we have kind of run out of letters, and to avoid any confusion around _ prefixes, how about just using different variable names here? Such as a and b or whatever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a, b, etc. sounds fine to me; I've done that (after slightly misinterpreting and first renaming _z to a ^^). I broke the pattern intentionally since that assignment is part of the example for Box (I figured each reference/pointer would get one letter), but I agree about avoiding _ prefixes. In any case, I don't have a strong preference.

@dianne dianne force-pushed the fix-box-deref-example branch 2 times, most recently from cf23bba to 93bd844 Compare March 11, 2026 23:41
@dianne dianne force-pushed the fix-box-deref-example branch from 93bd844 to 95aaeee Compare March 11, 2026 23:42
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

@ehuss ehuss added this pull request to the merge queue Mar 13, 2026
Merged via the queue into rust-lang:master with commit 76016c6 Mar 13, 2026
6 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 13, 2026
@dianne dianne deleted the fix-box-deref-example branch March 13, 2026 18:39
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.

3 participants