{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/66530717","id":66530717,"diff_hunk":"@@ -0,0 +1,223 @@\n+- Feature Name: missing_derefs\n+- Start Date: 2016-06-09\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+[summary]: #summary\n+\n+Add `&move` pointers, the `DerefMove` trait, and the unsafe\n+`DerefPure` traits. Allow using `DerefPure` derefs in lvalues.\n+\n+# Motivation\n+[motivation]: #motivation\n+\n+Rust's `Box` has a few features that are not implementable by library\n+traits: it is possible to match on `Box` with box patterns, and to\n+move out of it.\n+\n+User-defined types also want to make use of these features.\n+\n+Also, it is not possible to use pattern matching on structures that\n+contain smart pointers. We would want this to be possible.\n+\n+# Detailed design\n+[design]: #detailed-design\n+\n+## DerefPure\n+\n+Add a `DerefPure` trait:\n+```Rust\n+pub unsafe trait DerefPure : Deref {}\n+```\n+\n+Implmenenting the `DerefPure` trait tells the compiler that dereferences\n+of the type it is implemented for behave like dereferences of normal\n+pointers - as long as the receiver is borrowed, the compiler can merge,\n+move and remove calls to the `Deref` methods, and the returned pointer\n+will stay the same.\n+\n+Also, the methods must not panic and (if `DerefMove` is implemented) may\n+be called on a partially-initialized value.\n+\n+If a type implements `DerefPure`, then user-defined dereferences of it\n+are implemented with a `deref` lvalue projection as if they were a built-in\n+pointer.\n+\n+Types implementing `DerefPure` can be used in `box` patterns. This works\n+like all the other reference patterns. For example, if `Vec` implements\n+`DerefPure` and `BasicBlockData.statements` is a `Vec`:\n+\n+```Rust\n+match self.basic_blocks[*start] {\n+    BasicBlockData {\n+        statements: box [],\n+        terminator: ref mut terminator @ Some(Terminator {\n+\t    kind: TerminatorKind::Goto { .. }, ..\n+\t}), ..\n+    } => { /* .. */ }\n+    _ => return\n+};\n+```\n+\n+## &move\n+\n+Add a new mutability `move`. `&move` references are references that own their\n+contents, but not the memory they refer to.\n+\n+When parsing a `move` closure, `&move |..` is parsed as `& (move |..` -\n+as creating a `move` closure and taking an immutable reference to it, rather\n+than creating a non-moving closure and taking an `&move` reference to it. Of\n+course, you can force the other choice by explicit parentheses - `&move (|..`.\n+\n+Unlike some other proposals, the [RFC1214] rules remain the same - a\n+`&'a move T` reference requires that `T: 'a`. We may want to relax these\n+rules.\n+\n+`&move` references are tracked by the move checker just like ordinary\n+values. They are linear - when they are dropped, their unmoved contents\n+are dropped. It is possible to initialize/reinitialize them just like normal\n+variables.\n+\n+Outside of the move checker, `&move` references always have valid contents.\n+If you want to create a temporary uninitialized `&move` reference, you can\n+use `mem::forget`:\n+\n+```Rust\n+unsafe fn move_val_init_from_closure<T, F: FnOnce() -> T>(p: *mut T, f: F)\n+{\n+    let ptr = &move *p;\n+    mem::forget(*ptr);\n+    *ptr = f(); // if `f` panics, `*ptr` is not dropped.\n+}\n+```\n+\n+An `&move x.y` borrow, unlike the other borrows, actually moves out of\n+`x.y`. This applies to all borrows, including implicit reborrows. I think\n+this would make implicit reborrows useless, but it is the consequence of\n+the rules.\n+\n+Of course, it is possible to borrow `&move` references as either `&` or\n+`&mut`, and not possible to borrow `&` or `&mut` references as `&move`.\n+\n+## DerefMove\n+\n+This allows moving out of user-defined types.\n+\n+Add a `DerefMove` trait:\n+```Rust\n+pub trait DerefMove: DerefMut + DerefPure {","path":"text/0000-missing-derefs.md","position":109,"original_position":109,"commit_id":"cc6b0be138e96fedaaf0c398950ee33be964b7ec","original_commit_id":"cc6b0be138e96fedaaf0c398950ee33be964b7ec","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"body":"What do you mean by that?","created_at":"2016-06-09T22:07:48Z","updated_at":"2016-06-09T22:07:48Z","html_url":"https://github.com/rust-lang/rfcs/pull/1646#discussion_r66530717","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/66530717"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1646#discussion_r66530717"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646","id":73192046,"html_url":"https://github.com/rust-lang/rfcs/pull/1646","diff_url":"https://github.com/rust-lang/rfcs/pull/1646.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/1646.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1646","number":1646,"state":"open","locked":false,"title":"&move, DerefMove, DerefPure and box patterns","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"body":"I think I managed to get these features together into something I like.\r\n\r\n[Rendered](https://github.com/arielb1/rfcs/blob/missing-derefs/text/0000-missing-derefs.md).","created_at":"2016-06-09T10:41:06Z","updated_at":"2016-06-09T22:07:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"682fc25c621d7a661794ee35c6de5167ee50d68c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1646/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/cc6b0be138e96fedaaf0c398950ee33be964b7ec","head":{"label":"arielb1:missing-derefs","ref":"missing-derefs","sha":"cc6b0be138e96fedaaf0c398950ee33be964b7ec","user":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"repo":{"id":21432441,"name":"rfcs","full_name":"arielb1/rfcs","owner":{"login":"arielb1","id":1830974,"avatar_url":"https://avatars.githubusercontent.com/u/1830974?v=3","gravatar_id":"","url":"https://api.github.com/users/arielb1","html_url":"https://github.com/arielb1","followers_url":"https://api.github.com/users/arielb1/followers","following_url":"https://api.github.com/users/arielb1/following{/other_user}","gists_url":"https://api.github.com/users/arielb1/gists{/gist_id}","starred_url":"https://api.github.com/users/arielb1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arielb1/subscriptions","organizations_url":"https://api.github.com/users/arielb1/orgs","repos_url":"https://api.github.com/users/arielb1/repos","events_url":"https://api.github.com/users/arielb1/events{/privacy}","received_events_url":"https://api.github.com/users/arielb1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arielb1/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/arielb1/rfcs","forks_url":"https://api.github.com/repos/arielb1/rfcs/forks","keys_url":"https://api.github.com/repos/arielb1/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arielb1/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arielb1/rfcs/teams","hooks_url":"https://api.github.com/repos/arielb1/rfcs/hooks","issue_events_url":"https://api.github.com/repos/arielb1/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/arielb1/rfcs/events","assignees_url":"https://api.github.com/repos/arielb1/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/arielb1/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/arielb1/rfcs/tags","blobs_url":"https://api.github.com/repos/arielb1/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arielb1/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arielb1/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/arielb1/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arielb1/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/arielb1/rfcs/languages","stargazers_url":"https://api.github.com/repos/arielb1/rfcs/stargazers","contributors_url":"https://api.github.com/repos/arielb1/rfcs/contributors","subscribers_url":"https://api.github.com/repos/arielb1/rfcs/subscribers","subscription_url":"https://api.github.com/repos/arielb1/rfcs/subscription","commits_url":"https://api.github.com/repos/arielb1/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/arielb1/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/arielb1/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/arielb1/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/arielb1/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/arielb1/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arielb1/rfcs/merges","archive_url":"https://api.github.com/repos/arielb1/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arielb1/rfcs/downloads","issues_url":"https://api.github.com/repos/arielb1/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/arielb1/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/arielb1/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/arielb1/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arielb1/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/arielb1/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/arielb1/rfcs/deployments","created_at":"2014-07-02T17:01:55Z","updated_at":"2016-04-27T13:27:31Z","pushed_at":"2016-06-09T14:18:42Z","git_url":"git://github.com/arielb1/rfcs.git","ssh_url":"git@github.com:arielb1/rfcs.git","clone_url":"https://github.com/arielb1/rfcs.git","svn_url":"https://github.com/arielb1/rfcs","homepage":"","size":2880,"stargazers_count":0,"watchers_count":0,"language":null,"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":"8fb87426c63b29e32072ac48684901fa54f6e3a8","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":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","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/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rfcs/deployments","created_at":"2014-03-07T21:29:00Z","updated_at":"2016-06-07T04:16:26Z","pushed_at":"2016-06-09T16:08:55Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"","size":5560,"stargazers_count":653,"watchers_count":653,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":322,"mirror_url":null,"open_issues_count":681,"forks":322,"open_issues":681,"watchers":653,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1646"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1646"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1646/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1646/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/cc6b0be138e96fedaaf0c398950ee33be964b7ec"}}}}
{"actor":{"display_login":"arielb1"}}