{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/35621887","id":35621887,"diff_hunk":"@@ -0,0 +1,98 @@\n+% Meet Safe and Unsafe\n+\n+Programmers in safe \"high-level\" languages face a fundamental dilemma. On one\n+hand, it would be *really* great to just say what you want and not worry about\n+how it's done. On the other hand, that can lead to some *really* poor\n+performance. It may be necessary to drop down to less clear or idiomatic\n+practices to get the performance characteristics you want. Or maybe you just\n+throw up your hands in disgust and decide to shell out to an implementation in\n+a less sugary-wonderful *unsafe* language.\n+\n+Worse, when you want to talk directly to the operating system, you *have* to\n+talk to an unsafe language: *C*. C is ever-present and unavoidable. It's the\n+lingua-franca of the programming world.\n+Even other safe languages generally expose C interfaces for the world at large!\n+Regardless of *why* you're doing it, as soon as your program starts talking to\n+C it stops being safe.\n+\n+With that said, Rust is *totally* a safe programming language.\n+\n+Well, Rust *has* a safe programming language. Let's step back a bit.\n+\n+Rust can be thought of as being composed of two\n+programming languages: *Safe* and *Unsafe*. Safe is For Reals Totally Safe.\n+Unsafe, unsurprisingly, is *not* For Reals Totally Safe. In fact, Unsafe lets\n+you do some really crazy unsafe things.\n+\n+Safe is *the* Rust programming language. If all you do is write Safe Rust,\n+you will never have to worry about type-safety or memory-safety. You will never\n+endure a null or dangling pointer, or any of that Undefined Behaviour nonsense.\n+\n+*That's totally awesome*.\n+\n+The standard library also gives you enough utilities out-of-the-box that you'll\n+be able to write awesome high-performance applications and libraries in pure\n+idiomatic Safe Rust.\n+\n+But maybe you want to talk to another language. Maybe you're writing a\n+low-level abstraction not exposed by the standard library. Maybe you're\n+*writing* the standard library (which is written entirely in Rust). Maybe you\n+need to do something the type-system doesn't understand and just *frob some dang\n+bits*. Maybe you need Unsafe Rust.\n+\n+Unsafe Rust is exactly like Safe Rust with *all* the same rules and semantics.\n+However Unsafe Rust lets you do some *extra* things that are Definitely Not Safe.\n+\n+The only things that are different in Unsafe Rust are that you can:\n+\n+* Dereference raw pointers\n+* Call `unsafe` functions (including C functions, intrinsics, and the raw allocator)\n+* Implement `unsafe` traits\n+* Mutate statics\n+\n+That's it. The reason these operations are relegated to Unsafe is that misusing\n+any of these things will cause the ever dreaded Undefined Behaviour. Invoking\n+Undefined Behaviour gives the compiler full rights to do arbitrarily bad things\n+to your program. You definitely *should not* invoke Undefined Behaviour.\n+\n+Unlike C, Undefined Behaviour is pretty limited in scope in Rust. All the core\n+language cares about is preventing the following things:\n+\n+* Dereferencing null or dangling pointers\n+* Reading [uninitialized memory][]\n+* Breaking the [pointer aliasing rules][]\n+* Producing invalid primitive values:\n+    * dangling/null references\n+    * a `bool` that isn't 0 or 1\n+    * an undefined `enum` discriminant\n+    * a `char` outside the ranges [0x0, 0xD7FF] and [0xE000, 0x10FFFF]\n+    * A non-utf8 `str`\n+* Unwinding into another language\n+* Causing a [data race][race]\n+* Double-dropping a value\n+\n+That's it. That's all the Undefined Behaviour baked into Rust. Of course, unsafe","path":"src/doc/tarpl/meet-safe-and-unsafe.md","position":74,"original_position":74,"commit_id":"05bb1dbc43a620fbbd65ae830bb53ba9768ac185","original_commit_id":"05bb1dbc43a620fbbd65ae830bb53ba9768ac185","user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"body":"I wasn't complaining about the phrase \"double-dropping\"\r\n\r\nI was complaining about the sentence \"That's all the Undefined Behaviour baked into Rust.\"  I think its better to spell it out: These are the *causes of* UB","created_at":"2015-07-28T07:47:11Z","updated_at":"2015-07-28T07:47:11Z","html_url":"https://github.com/rust-lang/rust/pull/27032#discussion_r35621887","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/27032","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/35621887"},"html":{"href":"https://github.com/rust-lang/rust/pull/27032#discussion_r35621887"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/27032"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/27032","id":39887559,"html_url":"https://github.com/rust-lang/rust/pull/27032","diff_url":"https://github.com/rust-lang/rust/pull/27032.diff","patch_url":"https://github.com/rust-lang/rust/pull/27032.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27032","number":27032,"state":"open","locked":false,"title":"The Advanced Rust Programming Language","user":{"login":"Gankro","id":1136864,"avatar_url":"https://avatars.githubusercontent.com/u/1136864?v=3","gravatar_id":"","url":"https://api.github.com/users/Gankro","html_url":"https://github.com/Gankro","followers_url":"https://api.github.com/users/Gankro/followers","following_url":"https://api.github.com/users/Gankro/following{/other_user}","gists_url":"https://api.github.com/users/Gankro/gists{/gist_id}","starred_url":"https://api.github.com/users/Gankro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gankro/subscriptions","organizations_url":"https://api.github.com/users/Gankro/orgs","repos_url":"https://api.github.com/users/Gankro/repos","events_url":"https://api.github.com/users/Gankro/events{/privacy}","received_events_url":"https://api.github.com/users/Gankro/received_events","type":"User","site_admin":false},"body":"I've been baking this out of tree for long enough. This is currently about ~2/5ths the size of TRPL. Time to get it in tree so it can be more widely maintained and scrutinized. I've preserved the whole gruesome history including various rewrites. I can definitely squash these a fair amount if desired. Some random people submitted minor fixes though, so they're mixed in.\r\n\r\nEdit: forgot to link to rendered http://cglab.ca/~abeinges/blah/turpl/_book/\r\n\r\nEdit2:\r\n\r\nTo streamline the review process, I'm going to break this into sections that need official \"domain expert\" approval:\r\n\r\n# Summary\r\n\r\n* [x] Meet Safe and Unsafe: reviewed by @aturon\r\n* [x] Data Layout: reviewed by @arielb1 \r\n* [x] Ownership: reviewed by @aturon ( and sorta @nikomatsakis ) -- significantly updated, may need re-r\r\n* [x] Coversions:  reviewed by @nrc \r\n* [x] Uninitialized Memory: reviewed by @pnkfelix \r\n* [x] Ownership-Oriented Resource Management: NEEDS REVIEW\r\n* [x] Unwinding: reviewed by @alexcrichton \r\n* [x] Concurrency: reviewed by @aturon\r\n* [x] Implementing Vec:  r? @huonw ","created_at":"2015-07-14T07:08:31Z","updated_at":"2015-07-28T07:47:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1c4a4ee7628bf7a155e4fb8fb6b597fec67de46","assignee":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars.githubusercontent.com/u/27786?v=3","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/27032/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/27032/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27032/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/05bb1dbc43a620fbbd65ae830bb53ba9768ac185","head":{"label":"Gankro:tarpl","ref":"tarpl","sha":"05bb1dbc43a620fbbd65ae830bb53ba9768ac185","user":{"login":"Gankro","id":1136864,"avatar_url":"https://avatars.githubusercontent.com/u/1136864?v=3","gravatar_id":"","url":"https://api.github.com/users/Gankro","html_url":"https://github.com/Gankro","followers_url":"https://api.github.com/users/Gankro/followers","following_url":"https://api.github.com/users/Gankro/following{/other_user}","gists_url":"https://api.github.com/users/Gankro/gists{/gist_id}","starred_url":"https://api.github.com/users/Gankro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gankro/subscriptions","organizations_url":"https://api.github.com/users/Gankro/orgs","repos_url":"https://api.github.com/users/Gankro/repos","events_url":"https://api.github.com/users/Gankro/events{/privacy}","received_events_url":"https://api.github.com/users/Gankro/received_events","type":"User","site_admin":false},"repo":{"id":21621250,"name":"rust","full_name":"Gankro/rust","owner":{"login":"Gankro","id":1136864,"avatar_url":"https://avatars.githubusercontent.com/u/1136864?v=3","gravatar_id":"","url":"https://api.github.com/users/Gankro","html_url":"https://github.com/Gankro","followers_url":"https://api.github.com/users/Gankro/followers","following_url":"https://api.github.com/users/Gankro/following{/other_user}","gists_url":"https://api.github.com/users/Gankro/gists{/gist_id}","starred_url":"https://api.github.com/users/Gankro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gankro/subscriptions","organizations_url":"https://api.github.com/users/Gankro/orgs","repos_url":"https://api.github.com/users/Gankro/repos","events_url":"https://api.github.com/users/Gankro/events{/privacy}","received_events_url":"https://api.github.com/users/Gankro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Gankro/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/Gankro/rust","forks_url":"https://api.github.com/repos/Gankro/rust/forks","keys_url":"https://api.github.com/repos/Gankro/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gankro/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gankro/rust/teams","hooks_url":"https://api.github.com/repos/Gankro/rust/hooks","issue_events_url":"https://api.github.com/repos/Gankro/rust/issues/events{/number}","events_url":"https://api.github.com/repos/Gankro/rust/events","assignees_url":"https://api.github.com/repos/Gankro/rust/assignees{/user}","branches_url":"https://api.github.com/repos/Gankro/rust/branches{/branch}","tags_url":"https://api.github.com/repos/Gankro/rust/tags","blobs_url":"https://api.github.com/repos/Gankro/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gankro/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gankro/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gankro/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gankro/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/Gankro/rust/languages","stargazers_url":"https://api.github.com/repos/Gankro/rust/stargazers","contributors_url":"https://api.github.com/repos/Gankro/rust/contributors","subscribers_url":"https://api.github.com/repos/Gankro/rust/subscribers","subscription_url":"https://api.github.com/repos/Gankro/rust/subscription","commits_url":"https://api.github.com/repos/Gankro/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gankro/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gankro/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gankro/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/Gankro/rust/contents/{+path}","compare_url":"https://api.github.com/repos/Gankro/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gankro/rust/merges","archive_url":"https://api.github.com/repos/Gankro/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gankro/rust/downloads","issues_url":"https://api.github.com/repos/Gankro/rust/issues{/number}","pulls_url":"https://api.github.com/repos/Gankro/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/Gankro/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/Gankro/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gankro/rust/labels{/name}","releases_url":"https://api.github.com/repos/Gankro/rust/releases{/id}","created_at":"2014-07-08T16:53:48Z","updated_at":"2015-04-16T01:40:09Z","pushed_at":"2015-07-27T23:01:29Z","git_url":"git://github.com/Gankro/rust.git","ssh_url":"git@github.com:Gankro/rust.git","clone_url":"https://github.com/Gankro/rust.git","svn_url":"https://github.com/Gankro/rust","homepage":"http://www.rust-lang.org","size":308930,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"3e6b03c2d87a1f54bfde2ea82b1f85aa4df04909","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rust","description":"A safe, concurrent, practical language.","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","created_at":"2010-06-16T20:39:03Z","updated_at":"2015-07-28T06:59:04Z","pushed_at":"2015-07-28T07:41:24Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"http://www.rust-lang.org","size":652808,"stargazers_count":12750,"watchers_count":12750,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2461,"mirror_url":null,"open_issues_count":2152,"forks":2461,"open_issues":2152,"watchers":12750,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/27032"},"html":{"href":"https://github.com/rust-lang/rust/pull/27032"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/27032"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/27032/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/27032/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/27032/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/05bb1dbc43a620fbbd65ae830bb53ba9768ac185"}}}}