Skip to content

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

Closed
@CatsAreFluffy

Description

@CatsAreFluffy

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

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions