{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/51713","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/51713/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/51713/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/51713/events","html_url":"https://github.com/rust-lang/rust/issues/51713","id":334900210,"node_id":"MDU6SXNzdWUzMzQ5MDAyMTA=","number":51713,"title":"Add debug asserts to some unsafe functions","user":{"login":"newpavlov","id":329626,"node_id":"MDQ6VXNlcjMyOTYyNg==","avatar_url":"https://avatars0.githubusercontent.com/u/329626?v=4","gravatar_id":"","url":"https://api.github.com/users/newpavlov","html_url":"https://github.com/newpavlov","followers_url":"https://api.github.com/users/newpavlov/followers","following_url":"https://api.github.com/users/newpavlov/following{/other_user}","gists_url":"https://api.github.com/users/newpavlov/gists{/gist_id}","starred_url":"https://api.github.com/users/newpavlov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newpavlov/subscriptions","organizations_url":"https://api.github.com/users/newpavlov/orgs","repos_url":"https://api.github.com/users/newpavlov/repos","events_url":"https://api.github.com/users/newpavlov/events{/privacy}","received_events_url":"https://api.github.com/users/newpavlov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-22T14:31:21Z","updated_at":"2018-06-26T16:38:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"The following functions have restrictions which (ideally) should be respected:\r\n-  `get_unchecked`\r\n- `get_unchecked_mut`\r\n- `slice_unchecked`\r\n- `slice_mut_unchecked`\r\n- `unreachable_unchecked`\r\n- etc. (please comment if you know additional examples)\r\n\r\nIt would be nice to check these restrictions with debug asserts. The main blockers:\r\n- stdlib is distributed with disabled debug assertions, so either implementation will have to use the same hack as in wrapping checks, or we'll have to distribute two versions of stdlib with enabled and disabled debug assertions, and teach `cargo` to switch between them depending on a compilation profile.\r\n- Some code in the stdlib (and probably in some external crates) consciously breaks those restrictions (e.g. `src/liballoc/vec.rs`). Probably it should be rewritten in a more \"correct\" fashion.\r\n\r\nSee internals [thread](https://internals.rust-lang.org/t/7755) for additional discussion."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/400381834","html_url":"https://github.com/rust-lang/rust/issues/51713#issuecomment-400381834","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/51713","id":400381834,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMDM4MTgzNA==","user":{"login":"newpavlov","id":329626,"node_id":"MDQ6VXNlcjMyOTYyNg==","avatar_url":"https://avatars0.githubusercontent.com/u/329626?v=4","gravatar_id":"","url":"https://api.github.com/users/newpavlov","html_url":"https://github.com/newpavlov","followers_url":"https://api.github.com/users/newpavlov/followers","following_url":"https://api.github.com/users/newpavlov/following{/other_user}","gists_url":"https://api.github.com/users/newpavlov/gists{/gist_id}","starred_url":"https://api.github.com/users/newpavlov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newpavlov/subscriptions","organizations_url":"https://api.github.com/users/newpavlov/orgs","repos_url":"https://api.github.com/users/newpavlov/repos","events_url":"https://api.github.com/users/newpavlov/events{/privacy}","received_events_url":"https://api.github.com/users/newpavlov/received_events","type":"User","site_admin":false},"created_at":"2018-06-26T16:38:45Z","updated_at":"2018-06-26T16:38:45Z","author_association":"CONTRIBUTOR","body":"The idea is to explicitly construct slice which will cover valid memory region before indexing it, e.g. `Vec` code can have an unsafe method `get_cap_slice`. Yes, it's more steps, but arguably it's worth it, as many consider `get_unchecked` as an escape hatch for additional performance and use it accordingly without any tools at hand to check if used assumptions are indeed correct."}}
{"actor":{"display_login":"newpavlov"}}