{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/34714403","id":34714403,"diff_hunk":"@@ -335,10 +403,314 @@ This error indicates that an attempt was made to divide by zero (or take the\n remainder of a zero divisor) in a static or constant expression.\n \"##,\n \n+E0022: r##\"\n+Constant functions are not allowed to mutate anything. Thus, binding to an\n+argument with a mutable pattern is not allowed. For example,\n+\n+```\n+const fn foo(mut x: u8) {\n+    // do stuff\n+}\n+```\n+\n+is bad because the function body may not mutate `x`.\n+\n+Remove any mutable bindings from the argument list to fix this error. In case\n+you need to mutate the argument, try lazily initializing a global variable\n+instead of using a const fn, or refactoring the code to a functional style to\n+avoid mutation if possible.\n+\"##,\n+\n+\n+E0038: r####\"\n+\n+Trait objects like `Box<Trait>` can only be constructed when certain\n+requirements are satisfied by the trait in question.\n+\n+Trait objects are a form of dynamic dispatch and use a dynamically sized type\n+for the inner type.  So, for a given trait `Trait`, when `Trait` is treated as a\n+type, as in `Box<Trait>`, the inner type is \"unsized\". In such cases the boxed\n+pointer is a \"fat pointer\" and contains an extra pointer to a method table for\n+dynamic dispatch. This design mandates some restrictions on the types of traits\n+that are allowed to be used in trait objects, which are collectively termed as\n+\"object safety\" rules.\n+\n+Attempting to create a trait object for a non object-safe trait will trigger\n+this error.\n+\n+\n+There are various rules:\n+\n+### The trait cannot require `Self: Sized`\n+\n+When `Trait` is treated as a type, the type does not implement the special\n+`Sized` trait, because the type does not have a known size at compile time and\n+can only be accessed behind a pointer. Thus, if we have a trait like the\n+following:\n+\n+```\n+trait Foo where Self: Sized {\n+\n+}\n+```\n+\n+we cannot create an object of type `Box<Foo>` or `&Foo` since in this case\n+`Self` would not be `Sized`.\n+\n+Generally `Self : Sized` is used to indicate that the trait should not be used\n+as a trait object. If the trait comes from your own crate, consider removing\n+this restriction.\n+\n+### Method references the `Self` type in its arguments or return type\n+\n+This happens when a trait has a method like the following:\n+\n+```\n+trait Trait {\n+    fn foo(&self) -> Self;\n+}\n+impl Trait for String {\n+    fn foo(&self) -> Self {\n+        \"hi\".to_owned()\n+    }\n+}\n+\n+impl Trait for u8 {\n+    fn foo(&self) -> Self {\n+        1\n+    }\n+}\n+```\n+\n+In such a case, the compiler cannot predict the return type of `foo()` in a case\n+like the following:\n+\n+```\n+fn call_foo(x: Box<Trait>) {\n+    let y = x.foo(); // What type is y?\n+    // ...\n+}\n+```\n+\n+If the offending method isn't actually being called on the trait object, you can\n+add a `where Self: Sized` bound on the method:\n+\n+```\n+trait Trait {\n+    fn foo(&self) -> Self where Self: Sized;\n+    // more functions\n+}\n+```\n+\n+Now, `foo()` can no longer be called on the trait object, but you will be\n+allowed to call other trait methods and construct the trait objects. With such a\n+bound, one can still call `foo()` on types implementing that trait that aren't\n+behind trait objects.\n+\n+### Method has generic type parameters\n+\n+As mentioned before, trait objects contain pointers to method tables. So, if we\n+have\n+\n+```\n+trait Trait {\n+    fn foo(&self);\n+}\n+impl Trait for String {\n+    fn foo(&self) {\n+        // implementation 1\n+    }\n+}\n+impl Trait for u8 {\n+    fn foo(&self) {\n+        // implementation 2\n+    }\n+}\n+// ...\n+```\n+\n+at compile time a table of all implementations of `Trait`, containing pointers\n+to the implementation of `foo()` would be generated.\n+\n+This works fine, but when we the method gains generic parameters, we can have a\n+problem.\n+\n+Usually, generic parameters get _monomorphized_. For example, if I have\n+\n+```\n+fn foo<T>(x: T) {\n+    // ...\n+}\n+```\n+\n+the machine code for `foo::<u8>()`, `foo::<bool>()`, `foo::<String>()`, or any\n+other type substitution is different. Hence the compiler generates the\n+implementation on-demand. If you call `foo()` with a `bool` parameter, the\n+compiler will only generate code for `foo::<bool>()`. When we have additional\n+type parameters, the number of monomorphized implementations the compiler\n+generates does not grow drastically, since the compiler will only generate an\n+implementation if the function is called with hard substitutions.\n+\n+However, with trait objects we have to make a table containing _every object\n+that implements the trait_. Now, if it has type parameters, we need to add\n+implementations for every type that implements the trait, bloating the table\n+quickly.","path":"src/librustc/diagnostics.rs","position":293,"original_position":293,"commit_id":"74c5b6f3ad504a53914dddf2b151a9f95e4ca3ff","original_commit_id":"74c5b6f3ad504a53914dddf2b151a9f95e4ca3ff","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'm not sure if its necessary to appeal to combinatorics here. It seems like there's a fundamental problem with linking together different crates. I haven't thought about this too much though... cc @eddyb ","created_at":"2015-07-15T18:48:33Z","updated_at":"2015-07-15T18:48:33Z","html_url":"https://github.com/rust-lang/rust/pull/26963#discussion_r34714403","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/26963","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/34714403"},"html":{"href":"https://github.com/rust-lang/rust/pull/26963#discussion_r34714403"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26963"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/26963","id":39744178,"html_url":"https://github.com/rust-lang/rust/pull/26963","diff_url":"https://github.com/rust-lang/rust/pull/26963.diff","patch_url":"https://github.com/rust-lang/rust/pull/26963.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/26963","number":26963,"state":"open","locked":false,"title":"Bunch of diagnostics fixes and additions","user":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"body":"I'll be adding more commits to this PR as the weekend progresses. Was hoping to make this a mega-PR, but getting some eyes on this early would be nice too.\r\n\r\nr? @steveklabnik\r\n\r\nr? @eddyb on the object safety bits\r\n\r\ncc @michaelsproul\r\n\r\nPart of #24407\r\n","created_at":"2015-07-11T10:48:02Z","updated_at":"2015-07-15T18:48:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2742a1882ba56562906d783af147d91e62723ae5","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/26963/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/26963/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/26963/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/74c5b6f3ad504a53914dddf2b151a9f95e4ca3ff","head":{"label":"Manishearth:improve-diag","ref":"improve-diag","sha":"74c5b6f3ad504a53914dddf2b151a9f95e4ca3ff","user":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"repo":{"id":18477516,"name":"rust","full_name":"Manishearth/rust","owner":{"login":"Manishearth","id":1617736,"avatar_url":"https://avatars.githubusercontent.com/u/1617736?v=3","gravatar_id":"","url":"https://api.github.com/users/Manishearth","html_url":"https://github.com/Manishearth","followers_url":"https://api.github.com/users/Manishearth/followers","following_url":"https://api.github.com/users/Manishearth/following{/other_user}","gists_url":"https://api.github.com/users/Manishearth/gists{/gist_id}","starred_url":"https://api.github.com/users/Manishearth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manishearth/subscriptions","organizations_url":"https://api.github.com/users/Manishearth/orgs","repos_url":"https://api.github.com/users/Manishearth/repos","events_url":"https://api.github.com/users/Manishearth/events{/privacy}","received_events_url":"https://api.github.com/users/Manishearth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Manishearth/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/Manishearth/rust","forks_url":"https://api.github.com/repos/Manishearth/rust/forks","keys_url":"https://api.github.com/repos/Manishearth/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Manishearth/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Manishearth/rust/teams","hooks_url":"https://api.github.com/repos/Manishearth/rust/hooks","issue_events_url":"https://api.github.com/repos/Manishearth/rust/issues/events{/number}","events_url":"https://api.github.com/repos/Manishearth/rust/events","assignees_url":"https://api.github.com/repos/Manishearth/rust/assignees{/user}","branches_url":"https://api.github.com/repos/Manishearth/rust/branches{/branch}","tags_url":"https://api.github.com/repos/Manishearth/rust/tags","blobs_url":"https://api.github.com/repos/Manishearth/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Manishearth/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Manishearth/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/Manishearth/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Manishearth/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/Manishearth/rust/languages","stargazers_url":"https://api.github.com/repos/Manishearth/rust/stargazers","contributors_url":"https://api.github.com/repos/Manishearth/rust/contributors","subscribers_url":"https://api.github.com/repos/Manishearth/rust/subscribers","subscription_url":"https://api.github.com/repos/Manishearth/rust/subscription","commits_url":"https://api.github.com/repos/Manishearth/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/Manishearth/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/Manishearth/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/Manishearth/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/Manishearth/rust/contents/{+path}","compare_url":"https://api.github.com/repos/Manishearth/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Manishearth/rust/merges","archive_url":"https://api.github.com/repos/Manishearth/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Manishearth/rust/downloads","issues_url":"https://api.github.com/repos/Manishearth/rust/issues{/number}","pulls_url":"https://api.github.com/repos/Manishearth/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/Manishearth/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/Manishearth/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Manishearth/rust/labels{/name}","releases_url":"https://api.github.com/repos/Manishearth/rust/releases{/id}","created_at":"2014-04-05T21:54:27Z","updated_at":"2015-02-23T09:02:42Z","pushed_at":"2015-07-14T14:36:11Z","git_url":"git://github.com/Manishearth/rust.git","ssh_url":"git@github.com:Manishearth/rust.git","clone_url":"https://github.com/Manishearth/rust.git","svn_url":"https://github.com/Manishearth/rust","homepage":"http://www.rust-lang.org","size":304741,"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":"1b28ffa5216c845d1cef6b0cb3e5ac7db12025d0","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-15T13:12:25Z","pushed_at":"2015-07-15T18:36:20Z","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":642177,"stargazers_count":12630,"watchers_count":12630,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2434,"mirror_url":null,"open_issues_count":2164,"forks":2434,"open_issues":2164,"watchers":12630,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26963"},"html":{"href":"https://github.com/rust-lang/rust/pull/26963"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/26963"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/26963/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26963/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/26963/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/74c5b6f3ad504a53914dddf2b151a9f95e4ca3ff"}}}}