{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/24616","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/24616/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/24616/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/24616/events","html_url":"https://github.com/rust-lang/rust/issues/24616","id":69475041,"number":24616,"title":"Constraints on supertraits associated types are ignored","user":{"login":"14427","id":2423611,"avatar_url":"https://avatars.githubusercontent.com/u/2423611?v=3","gravatar_id":"","url":"https://api.github.com/users/14427","html_url":"https://github.com/14427","followers_url":"https://api.github.com/users/14427/followers","following_url":"https://api.github.com/users/14427/following{/other_user}","gists_url":"https://api.github.com/users/14427/gists{/gist_id}","starred_url":"https://api.github.com/users/14427/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/14427/subscriptions","organizations_url":"https://api.github.com/users/14427/orgs","repos_url":"https://api.github.com/users/14427/repos","events_url":"https://api.github.com/users/14427/events{/privacy}","received_events_url":"https://api.github.com/users/14427/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-associated-items","name":"A-associated-items","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-traits","name":"A-traits","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-typesystem","name":"A-typesystem","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-19T23:25:36Z","updated_at":"2015-12-22T05:24:17Z","closed_at":"2015-06-15T13:18:45Z","body":"The following code: \r\n```\r\ntrait Foo {\r\n    type T;\r\n}\r\n\r\ntrait Bar {\r\n    fn bar(&self);\r\n}\r\n\r\ntrait Quux: Foo where Self::T: Bar {\r\n    fn quux(&self) -> Self::T;\r\n}\r\n\r\nstruct Baz<X> {\r\n    x: X,\r\n}\r\n\r\nimpl<X: Quux> Baz<X> {\r\n    fn baz(&self) {\r\n        self.x.quux().bar()\r\n    }\r\n}\r\n```\r\n\r\nfails to compile, with the error message\r\n\r\n`the trait Bar is not implemented for the type <X as Foo>::T [E0277]`\r\n\r\nAs it is impossible for the return type of `quux()` to not return a type that implements `Bar`, I think this is a bug in the compiler."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/166509231","html_url":"https://github.com/rust-lang/rust/issues/24616#issuecomment-166509231","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/24616","id":166509231,"user":{"login":"soltanmm","id":4889063,"avatar_url":"https://avatars.githubusercontent.com/u/4889063?v=3","gravatar_id":"","url":"https://api.github.com/users/soltanmm","html_url":"https://github.com/soltanmm","followers_url":"https://api.github.com/users/soltanmm/followers","following_url":"https://api.github.com/users/soltanmm/following{/other_user}","gists_url":"https://api.github.com/users/soltanmm/gists{/gist_id}","starred_url":"https://api.github.com/users/soltanmm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soltanmm/subscriptions","organizations_url":"https://api.github.com/users/soltanmm/orgs","repos_url":"https://api.github.com/users/soltanmm/repos","events_url":"https://api.github.com/users/soltanmm/events{/privacy}","received_events_url":"https://api.github.com/users/soltanmm/received_events","type":"User","site_admin":false},"created_at":"2015-12-22T05:24:17Z","updated_at":"2015-12-22T05:24:17Z","body":"There's a workaround for the first example:\r\n\r\n```rust\r\ntrait Foo {\r\n    type T;\r\n}\r\n\r\ntrait Bar {\r\n    fn bar(&self);\r\n}\r\n\r\ntrait QuuxMyT {\r\n    type MyT: Bar;\r\n}\r\n\r\ntrait Quux: QuuxMyT + Foo<T=<Self as QuuxMyT>::MyT> {\r\n    fn quux(&self) -> Self::T;\r\n}\r\n\r\nstruct Baz<X> {\r\n    x: X,\r\n}\r\n\r\nimpl<X: Quux> Baz<X> {\r\n    fn baz(&self) {\r\n        self.x.quux().bar()\r\n    }\r\n}\r\n```\r\n\r\nBasically, use the fact that bounds on associated types are always assumed (elaborated? the relevant RFC said 'assume') by moving the bound to a helper trait's associated type, then force the identity relation on that helper trait's associated type and the relevant associated type of the supertrait."}}