{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/27192427","id":27192427,"diff_hunk":"@@ -82,20 +82,61 @@ use marker::Sized;\n // Any trait\n ///////////////////////////////////////////////////////////////////////////////\n \n+/// A marker trait indicates a type that can be reflected over. This\n+/// trait is implemented for all types. Its purpose is to ensure that\n+/// when you write a generic function that will employ reflection,\n+/// that must be reflected (no pun intended) in the generic bounds of\n+/// that function. Here is an example:\n+///\n+/// ```\n+/// # use std::any::{Any, Reflect};\n+/// fn foo<T:Reflect>(x: &T) {\n+///     let any: &Any = x;\n+///     if any.is::<u32>() { println!(\"u32\"); }\n+/// }\n+/// ```\n+///\n+/// Note that the declaration `T:Reflect` is required (it would also\n+/// be possible, and perhaps clearer, to write `T:Any`, because\n+/// `T:Any` implies `T:Reflect`). `foo` would not type check if `T`\n+/// were unbounded. The bound serves to alert `foo`'s caller to the\n+/// fact that `foo` may behave differently depending on whether\n+/// `T=u32` or not. In particular, thanks to the `Reflect` bound,\n+/// callers know that a function declared like `fn bar<T>(...)` will\n+/// always act in precisely the same way no matter what type `T` is\n+/// supplied, beacuse there are no bounds declared on `T`. (The\n+/// ability for a caller to reason about what a function may do based\n+/// solely on what generic bounds are declared is often called the\n+/// [\"parametricity property\"][1].)\n+///\n+/// [1]: http://en.wikipedia.org/wiki/Parametricity\n+#[rustc_reflect_like]\n+#[stable(feature = \"rust1\", since = \"1.0.0\")]\n+pub trait Reflect: 'static {\n+}\n+\n+#[cfg(stage0)]\n+impl<T: 'static> Reflect for T { }","path":"src/libcore/any.rs","position":56,"original_position":56,"commit_id":"8846f0dbee296ce32d19c15e4c30531dee0e2161","original_commit_id":"10382d617a6a00c413346a2c8a496c7e7104a086","user":{"login":"FlaPer87","id":13816,"avatar_url":"https://avatars.githubusercontent.com/u/13816?v=3","gravatar_id":"","url":"https://api.github.com/users/FlaPer87","html_url":"https://github.com/FlaPer87","followers_url":"https://api.github.com/users/FlaPer87/followers","following_url":"https://api.github.com/users/FlaPer87/following{/other_user}","gists_url":"https://api.github.com/users/FlaPer87/gists{/gist_id}","starred_url":"https://api.github.com/users/FlaPer87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FlaPer87/subscriptions","organizations_url":"https://api.github.com/users/FlaPer87/orgs","repos_url":"https://api.github.com/users/FlaPer87/repos","events_url":"https://api.github.com/users/FlaPer87/events{/privacy}","received_events_url":"https://api.github.com/users/FlaPer87/received_events","type":"User","site_admin":false},"body":"oh mmh, I thought we already had a snapshot for defaulted traits.","created_at":"2015-03-26T07:24:45Z","updated_at":"2015-03-26T07:24:45Z","html_url":"https://github.com/rust-lang/rust/pull/23712#discussion_r27192427","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/23712","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/27192427"},"html":{"href":"https://github.com/rust-lang/rust/pull/23712#discussion_r27192427"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23712"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/23712","id":31961109,"html_url":"https://github.com/rust-lang/rust/pull/23712","diff_url":"https://github.com/rust-lang/rust/pull/23712.diff","patch_url":"https://github.com/rust-lang/rust/pull/23712.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/23712","number":23712,"state":"open","locked":false,"title":"Reflect trait","user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"body":"This PR introduces a `Reflect` marker trait which is a supertrait of `Any`. The idea is that `Reflect` is defined for all concrete types, but is not defined for type parameters unless there is a `T:Reflect` bound. This is intended to preserve the parametricity property. This allows the `Any` interface to be stabilized without committing us to unbounded reflection that is not easily detectable by the caller.\r\n\r\nThe implementation of `Reflect` relies on an experimental variant of OIBIT. This variant behaves differently for objects, since it requires that all types exposed as part of the object's *interface* are `Reflect`, but isn't concerned about other types that may be closed over. In other words, you don't have to write `Foo+Reflect` in order for `Foo: Reflect` to hold (where `Foo` is a trait).\r\n\r\nGiven that `Any` is slated to stabilization and hence that we are committed to some form of reflection, the goal of this PR is to leave our options open with respect to parametricity. I see the options for full stabilization as follows (I think an RFC would be an appropriate way to confirm whichever of these three routes we take):\r\n\r\n1. We make `Reflect` a lang-item. \r\n2. We stabilize some version of the OIBIT variation I implemented as a general mechanism that may be appropriate for other use cases.\r\n3. We give up on preserving parametricity here and just have `impl<T> Reflect for T` instead. In that case, `Reflect` is a harmless but not especially useful trait going forward.\r\n\r\ncc @aturon \r\ncc @alexcrichton \r\ncc @glaebhoerl (this is more-or-less your proposal, as I understood it)\r\ncc @reem (this is more-or-less what we discussed on IRC at some point)\r\ncc @FlaPer87 (vaguely pertains to OIBIT)\r\n","created_at":"2015-03-25T20:12:39Z","updated_at":"2015-03-26T07:24:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11168d0d13ac06e238f19f0de14223f96722f242","assignee":{"login":"FlaPer87","id":13816,"avatar_url":"https://avatars.githubusercontent.com/u/13816?v=3","gravatar_id":"","url":"https://api.github.com/users/FlaPer87","html_url":"https://github.com/FlaPer87","followers_url":"https://api.github.com/users/FlaPer87/followers","following_url":"https://api.github.com/users/FlaPer87/following{/other_user}","gists_url":"https://api.github.com/users/FlaPer87/gists{/gist_id}","starred_url":"https://api.github.com/users/FlaPer87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FlaPer87/subscriptions","organizations_url":"https://api.github.com/users/FlaPer87/orgs","repos_url":"https://api.github.com/users/FlaPer87/repos","events_url":"https://api.github.com/users/FlaPer87/events{/privacy}","received_events_url":"https://api.github.com/users/FlaPer87/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/23712/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/23712/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/23712/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/8846f0dbee296ce32d19c15e4c30531dee0e2161","head":{"label":"nikomatsakis:reflect-trait","ref":"reflect-trait","sha":"8846f0dbee296ce32d19c15e4c30531dee0e2161","user":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"repo":{"id":1672543,"name":"rust","full_name":"nikomatsakis/rust","owner":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nikomatsakis/rust","description":"A work-in-progress programming language; not yet suitable for users","fork":true,"url":"https://api.github.com/repos/nikomatsakis/rust","forks_url":"https://api.github.com/repos/nikomatsakis/rust/forks","keys_url":"https://api.github.com/repos/nikomatsakis/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nikomatsakis/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nikomatsakis/rust/teams","hooks_url":"https://api.github.com/repos/nikomatsakis/rust/hooks","issue_events_url":"https://api.github.com/repos/nikomatsakis/rust/issues/events{/number}","events_url":"https://api.github.com/repos/nikomatsakis/rust/events","assignees_url":"https://api.github.com/repos/nikomatsakis/rust/assignees{/user}","branches_url":"https://api.github.com/repos/nikomatsakis/rust/branches{/branch}","tags_url":"https://api.github.com/repos/nikomatsakis/rust/tags","blobs_url":"https://api.github.com/repos/nikomatsakis/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nikomatsakis/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nikomatsakis/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/nikomatsakis/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nikomatsakis/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/nikomatsakis/rust/languages","stargazers_url":"https://api.github.com/repos/nikomatsakis/rust/stargazers","contributors_url":"https://api.github.com/repos/nikomatsakis/rust/contributors","subscribers_url":"https://api.github.com/repos/nikomatsakis/rust/subscribers","subscription_url":"https://api.github.com/repos/nikomatsakis/rust/subscription","commits_url":"https://api.github.com/repos/nikomatsakis/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/nikomatsakis/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/nikomatsakis/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/nikomatsakis/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/nikomatsakis/rust/contents/{+path}","compare_url":"https://api.github.com/repos/nikomatsakis/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nikomatsakis/rust/merges","archive_url":"https://api.github.com/repos/nikomatsakis/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nikomatsakis/rust/downloads","issues_url":"https://api.github.com/repos/nikomatsakis/rust/issues{/number}","pulls_url":"https://api.github.com/repos/nikomatsakis/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/nikomatsakis/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/nikomatsakis/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nikomatsakis/rust/labels{/name}","releases_url":"https://api.github.com/repos/nikomatsakis/rust/releases{/id}","created_at":"2011-04-27T20:20:29Z","updated_at":"2014-07-10T00:11:47Z","pushed_at":"2015-03-25T23:58:38Z","git_url":"git://github.com/nikomatsakis/rust.git","ssh_url":"git@github.com:nikomatsakis/rust.git","clone_url":"https://github.com/nikomatsakis/rust.git","svn_url":"https://github.com/nikomatsakis/rust","homepage":"","size":272086,"stargazers_count":4,"watchers_count":4,"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":4,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"a923278c6278c63468d74772c58dbf788e88f58c","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-03-26T05:07:38Z","pushed_at":"2015-03-26T06:31:55Z","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":520960,"stargazers_count":9840,"watchers_count":9840,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1911,"mirror_url":null,"open_issues_count":2063,"forks":1911,"open_issues":2063,"watchers":9840,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23712"},"html":{"href":"https://github.com/rust-lang/rust/pull/23712"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/23712"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/23712/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/23712/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/23712/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/8846f0dbee296ce32d19c15e4c30531dee0e2161"}}}}