{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/21611","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/21611/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/21611/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/21611/events","html_url":"https://github.com/rust-lang/rust/issues/21611","id":55396545,"number":21611,"title":"align_of for small structs does not give the actual alignment of pointers","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/E-easy","name":"E-easy","color":"02e10c"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-high","name":"P-high","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rust-lang/rust/milestones/20","labels_url":"https://api.github.com/repos/rust-lang/rust/milestones/20/labels","id":452034,"number":20,"title":"1.0","description":"This will be the first major release of Rust, where we offer some guaranteed level of support and backwards compatibility.\r\n\r\nThe significant criteria for this release are:\r\n\r\n* Language backwards compatibility - All major features are in, and in their final form. Generally, the only new language features added after this milestone must be backwards compatible, or to fix soundness holes, though we do expect to have some leeway to make small incompatible fixes that have low impact on existing code bases.\r\n\r\n* Library stability - We have a system of measuring and ensuring the stability of API's, and a significant portion of the standard library is declared stable. Stable API's will not change. Large portions of the standard library need to be stable for 1.0, including primitive types, vectors, strings, option, numerics, collections, some I/O and concurrency.\r\n\r\n* User experience - The system is polished and the presentation is complete and professional. New users have a clear path to using and learning the system. This encompasses the web site, documentation, installation, and tooling.\r\n","creator":{"login":"brson","id":147214,"avatar_url":"https://avatars.githubusercontent.com/u/147214?v=3","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"open_issues":33,"closed_issues":329,"state":"open","created_at":"2013-10-10T18:48:33Z","updated_at":"2015-02-05T21:34:10Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-01-25T04:21:36Z","updated_at":"2015-02-06T12:56:03Z","closed_at":null,"body":"```rust\r\n#[derive(Debug, Copy)]\r\nstruct Foo {\r\n    x: u8,\r\n}\r\n\r\nfn main() {\r\n    let f = Foo { x: 1 };\r\n    let vec = vec![f, f, f, f, f];\r\n    \r\n    println!(\"size: {}\", std::mem::size_of::<Foo>());\r\n    println!(\"align: {}\", std::mem::align_of::<Foo>());\r\n    println!(\"alignment offset: {}\", (&vec[2] as *const _ as usize) % std::mem::align_of::<Foo>());\r\n}\r\n```\r\n\r\nIt prints `size: 1` `align: 8` `alignment offset: 2`. I would *expect* that every value of type `T` is aligned to `align_of::<T>()` (i.e. the `%` should always give 0).\r\n\r\nOn x86-64, this applies to anything with alignment < 8, including `#[repr(packed)]` structs.\r\n\r\nI'm not *sure* it's a bug, but it does seem rather confusing.\r\n\r\nAlso, NB. this means `size_of < align_of`.\r\n\r\n(`min_align_of` acts more like I might expect.)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/73232382","html_url":"https://github.com/rust-lang/rust/issues/21611#issuecomment-73232382","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/21611","id":73232382,"user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"created_at":"2015-02-06T12:56:03Z","updated_at":"2015-02-06T12:56:03Z","body":"@tbu- that's the point, the conveniently named \"align_of\" is a dangerous value to use in many situations, while `min_align_of` is conservative and always correct (although may be less efficient than necessary).\r\n\r\nE.g. C++11's alignof acts like `min_align_of`, this prints 1:\r\n\r\n```\r\n#include<cstdio>\r\n\r\nstruct foo { char x; };\r\nint main() {\r\n    printf(\"%lu\\n\", alignof(struct foo));\r\n}\r\n```"}}