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

AtomicUsize::from_mut has incorrect alignment requirements in docs #133342

Closed
CatsAreFluffy opened this issue Nov 22, 2024 · 2 comments · Fixed by #135869
Closed

AtomicUsize::from_mut has incorrect alignment requirements in docs #133342

CatsAreFluffy opened this issue Nov 22, 2024 · 2 comments · Fixed by #135869
Assignees
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@CatsAreFluffy
Copy link

CatsAreFluffy commented Nov 22, 2024

Location

core::sync::atomic::AtomicUsize::from_mut
core::sync::atomic::AtomicIsize::from_mut

Summary

The documentation for AtomicUsize::from_mut claims that it's only available when usize has alignment 8, but in reality it's available when usize has alignment equal to its size (AFAICT), which is different on non-64-bit platforms. For example, this code compiles on 32-bit Linux:

#![feature(atomic_from_mut)]

use std::sync::atomic::AtomicUsize;

pub fn main(){
    let mut x: usize = 0;
    assert_eq!(std::mem::size_of_val(&x), 4);
    let _y: &mut AtomicUsize = AtomicUsize::from_mut(&mut x);
}

Godbolt

@CatsAreFluffy CatsAreFluffy added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Nov 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 22, 2024
@CatsAreFluffy CatsAreFluffy changed the title AtomicUsize::from_mut has incorrect alignment requirements AtomicUsize::from_mut has incorrect alignment requirements in docs Nov 22, 2024
@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 23, 2024
@RodBurman
Copy link

The documentation defines Usize as "The pointer-sized unsigned integer type." and further says "The size of this primitive is how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes."
This it is inherently defined by the target architecture given the architecture supports atomic loads & stores. (as documented). It therefore does seem odd that it would be restricted to 8byte/64bit architectures.

@joboet joboet added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jan 15, 2025
@ARandomDev99
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2025
Make docs for AtomicUsize::from_mut platform-independent

fixes rust-lang#133342
@bors bors closed this as completed in 6b4757b Jan 28, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 28, 2025
Rollup merge of rust-lang#135869 - hkBst:patch-12, r=Noratrieb

Make docs for AtomicUsize::from_mut platform-independent

fixes rust-lang#133342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants