{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/31829452","id":31829452,"diff_hunk":"@@ -104,9 +110,6 @@ fn object_safety_violations_for_trait<'tcx>(tcx: &ty::ctxt<'tcx>,\n         .collect();\n \n     // Check the trait itself.\n-    if trait_has_sized_self(tcx, trait_def_id) {","path":"src/librustc/middle/traits/object_safety.rs","position":22,"original_position":22,"commit_id":"3acfe03e5e64923d47d0caa915e4841328a24286","original_commit_id":"3acfe03e5e64923d47d0caa915e4841328a24286","user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"body":"Could this perhaps be left in the same place but check that the violations array doesn't already contain `SizedSelf`?","created_at":"2015-06-05T16:44:38Z","updated_at":"2015-06-05T16:44:38Z","html_url":"https://github.com/rust-lang/rust/pull/26027#discussion_r31829452","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/26027","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/31829452"},"html":{"href":"https://github.com/rust-lang/rust/pull/26027#discussion_r31829452"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26027"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/26027","id":37000372,"html_url":"https://github.com/rust-lang/rust/pull/26027","diff_url":"https://github.com/rust-lang/rust/pull/26027.diff","patch_url":"https://github.com/rust-lang/rust/pull/26027.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/26027","number":26027,"state":"open","locked":false,"title":"Only report Self: Sized violation once.","user":{"login":"nham","id":546409,"avatar_url":"https://avatars.githubusercontent.com/u/546409?v=3","gravatar_id":"","url":"https://api.github.com/users/nham","html_url":"https://github.com/nham","followers_url":"https://api.github.com/users/nham/followers","following_url":"https://api.github.com/users/nham/following{/other_user}","gists_url":"https://api.github.com/users/nham/gists{/gist_id}","starred_url":"https://api.github.com/users/nham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nham/subscriptions","organizations_url":"https://api.github.com/users/nham/orgs","repos_url":"https://api.github.com/users/nham/repos","events_url":"https://api.github.com/users/nham/events{/privacy}","received_events_url":"https://api.github.com/users/nham/received_events","type":"User","site_admin":false},"body":"## Background\r\n\r\nThe cause of #20692 seems to be in [middle::trait::object_safety::object_safety_violations](https://github.com/rust-lang/rust/blob/7ae4a8e9f3150f62964151ef54b3da3cd24ee123/src/librustc/middle/traits/object_safety.rs#L78-L85). The `supertrait_def_ids` call returns an iterator that iterates over trait definition ids. The iteration seems to start at the current trait and then traverse supertraits in order. For example, in the following block of code, it goes `Bar` -> `Foo` -> `Sized`:\r\n\r\n```rust\r\ntrait Foo: Sized { }\r\ntrait Bar: Foo { }\r\n\r\nfn foo<T: Bar>(x: &T) {\r\n    let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Bar` is not object-safe\r\n}\r\n\r\nfn main () {}\r\n```\r\n\r\nHowever for each trait in the hierarchy, `object_safety_violations_in_trait` gets called (in the `.flat_map()` call). Each call (all 3 of them) results in a `Self : Sized` violation since each trait in the hierarchy has `Sized` as a supertrait. That is why the above code compiles with 2 extra notes today:\r\n\r\n```\r\n: rustc 20692.rs\r\n20692.rs:5:13: 5:14 error: cannot convert to a trait object because trait `Bar` is not object-safe [E0038]\r\n20692.rs:5     let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Bar` is not object-safe\r\n                       ^\r\n20692.rs:5:13: 5:14 note: the trait cannot require that `Self : Sized`\r\n20692.rs:5     let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Bar` is not object-safe\r\n                       ^\r\n20692.rs:5:13: 5:14 note: the trait cannot require that `Self : Sized`\r\n20692.rs:5     let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Bar` is not object-safe\r\n                       ^\r\n20692.rs:5:13: 5:14 note: the trait cannot require that `Self : Sized`\r\n20692.rs:5     let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Bar` is not object-safe\r\n                       ^\r\n```\r\n\r\n## The fix\r\n\r\nThe fix I've submitted is to move the `trait_has_sized_self` check out of `object_safety_violations_in_trait` to `object_safety_violations` so it's only called once, and not for each supertrait.\r\n\r\n## How to test?\r\n\r\nI need help here. I don't see how to test it. This doesn't work:\r\n\r\n```rust\r\ntrait Foo: Sized { }\r\ntrait Bar: Foo { }\r\n\r\nfn foo<T: Bar>(x: &T) {\r\n    let _ = x as &Bar; //~ ERROR cannot convert to a trait object because trait `Foo` is not object-safe\r\n                       //~^ NOTE the trait cannot require that `Self : Sized`\r\n}\r\n\r\nfn main() {}\r\n```\r\n\r\nPutting this in compile-fail passes without the fix. It seems that this doesn't try to match the number of notes exactly, so even though compilation results in 3 notes emitted today, it matches the one that is expected in the test and ignores the extra error output.\r\n\r\nAny advice on how to test this fix?\r\n\r\nFixes #20692.","created_at":"2015-06-05T04:34:28Z","updated_at":"2015-06-05T16:44:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9a17f01bcb2cbc918651b47efa72e1fbebc6144","assignee":{"login":"Aatch","id":342416,"avatar_url":"https://avatars.githubusercontent.com/u/342416?v=3","gravatar_id":"","url":"https://api.github.com/users/Aatch","html_url":"https://github.com/Aatch","followers_url":"https://api.github.com/users/Aatch/followers","following_url":"https://api.github.com/users/Aatch/following{/other_user}","gists_url":"https://api.github.com/users/Aatch/gists{/gist_id}","starred_url":"https://api.github.com/users/Aatch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aatch/subscriptions","organizations_url":"https://api.github.com/users/Aatch/orgs","repos_url":"https://api.github.com/users/Aatch/repos","events_url":"https://api.github.com/users/Aatch/events{/privacy}","received_events_url":"https://api.github.com/users/Aatch/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/26027/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/26027/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/26027/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/3acfe03e5e64923d47d0caa915e4841328a24286","head":{"label":"nham:fix_E0038_dup","ref":"fix_E0038_dup","sha":"3acfe03e5e64923d47d0caa915e4841328a24286","user":{"login":"nham","id":546409,"avatar_url":"https://avatars.githubusercontent.com/u/546409?v=3","gravatar_id":"","url":"https://api.github.com/users/nham","html_url":"https://github.com/nham","followers_url":"https://api.github.com/users/nham/followers","following_url":"https://api.github.com/users/nham/following{/other_user}","gists_url":"https://api.github.com/users/nham/gists{/gist_id}","starred_url":"https://api.github.com/users/nham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nham/subscriptions","organizations_url":"https://api.github.com/users/nham/orgs","repos_url":"https://api.github.com/users/nham/repos","events_url":"https://api.github.com/users/nham/events{/privacy}","received_events_url":"https://api.github.com/users/nham/received_events","type":"User","site_admin":false},"repo":{"id":16223890,"name":"rust","full_name":"nham/rust","owner":{"login":"nham","id":546409,"avatar_url":"https://avatars.githubusercontent.com/u/546409?v=3","gravatar_id":"","url":"https://api.github.com/users/nham","html_url":"https://github.com/nham","followers_url":"https://api.github.com/users/nham/followers","following_url":"https://api.github.com/users/nham/following{/other_user}","gists_url":"https://api.github.com/users/nham/gists{/gist_id}","starred_url":"https://api.github.com/users/nham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nham/subscriptions","organizations_url":"https://api.github.com/users/nham/orgs","repos_url":"https://api.github.com/users/nham/repos","events_url":"https://api.github.com/users/nham/events{/privacy}","received_events_url":"https://api.github.com/users/nham/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nham/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/nham/rust","forks_url":"https://api.github.com/repos/nham/rust/forks","keys_url":"https://api.github.com/repos/nham/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nham/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nham/rust/teams","hooks_url":"https://api.github.com/repos/nham/rust/hooks","issue_events_url":"https://api.github.com/repos/nham/rust/issues/events{/number}","events_url":"https://api.github.com/repos/nham/rust/events","assignees_url":"https://api.github.com/repos/nham/rust/assignees{/user}","branches_url":"https://api.github.com/repos/nham/rust/branches{/branch}","tags_url":"https://api.github.com/repos/nham/rust/tags","blobs_url":"https://api.github.com/repos/nham/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nham/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nham/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/nham/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nham/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/nham/rust/languages","stargazers_url":"https://api.github.com/repos/nham/rust/stargazers","contributors_url":"https://api.github.com/repos/nham/rust/contributors","subscribers_url":"https://api.github.com/repos/nham/rust/subscribers","subscription_url":"https://api.github.com/repos/nham/rust/subscription","commits_url":"https://api.github.com/repos/nham/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/nham/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/nham/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/nham/rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/nham/rust/contents/{+path}","compare_url":"https://api.github.com/repos/nham/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nham/rust/merges","archive_url":"https://api.github.com/repos/nham/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nham/rust/downloads","issues_url":"https://api.github.com/repos/nham/rust/issues{/number}","pulls_url":"https://api.github.com/repos/nham/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/nham/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/nham/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nham/rust/labels{/name}","releases_url":"https://api.github.com/repos/nham/rust/releases{/id}","created_at":"2014-01-25T03:24:48Z","updated_at":"2014-07-08T19:13:04Z","pushed_at":"2015-06-05T04:06:48Z","git_url":"git://github.com/nham/rust.git","ssh_url":"git@github.com:nham/rust.git","clone_url":"https://github.com/nham/rust.git","svn_url":"https://github.com/nham/rust","homepage":"http://www.rust-lang.org","size":294135,"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":"e0ca6b1a314f949827fda499ee29dcbf6ef18acd","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-06-05T16:38:34Z","pushed_at":"2015-06-05T15:27:37Z","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":672410,"stargazers_count":12020,"watchers_count":12020,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2310,"mirror_url":null,"open_issues_count":2086,"forks":2310,"open_issues":2086,"watchers":12020,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26027"},"html":{"href":"https://github.com/rust-lang/rust/pull/26027"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/26027"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/26027/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/26027/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/26027/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/3acfe03e5e64923d47d0caa915e4841328a24286"}}}}