{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/24092","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/24092/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/24092/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/24092/events","html_url":"https://github.com/rust-lang/rust/issues/24092","id":66452301,"number":24092,"title":"Can't relate two associated types – unsupported cyclic reference between types/traits","user":{"login":"stevenblenkinsop","id":3118803,"avatar_url":"https://avatars.githubusercontent.com/u/3118803?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenblenkinsop","html_url":"https://github.com/stevenblenkinsop","followers_url":"https://api.github.com/users/stevenblenkinsop/followers","following_url":"https://api.github.com/users/stevenblenkinsop/following{/other_user}","gists_url":"https://api.github.com/users/stevenblenkinsop/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenblenkinsop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenblenkinsop/subscriptions","organizations_url":"https://api.github.com/users/stevenblenkinsop/orgs","repos_url":"https://api.github.com/users/stevenblenkinsop/repos","events_url":"https://api.github.com/users/stevenblenkinsop/events{/privacy}","received_events_url":"https://api.github.com/users/stevenblenkinsop/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-typesystem","name":"A-typesystem","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-05T15:57:16Z","updated_at":"2015-04-07T00:21:43Z","closed_at":null,"body":"Trying to compile code with this kind of structure leads to an unsupported cyclic reference error:\r\n\r\n    trait Trait {\r\n        type A;\r\n        type B;\r\n        fn id(self) -> Self { self }\r\n    }\r\n    \r\n    struct S;\r\n    struct SA;\r\n    struct SB;\r\n    struct SAA;\r\n    \r\n    impl Trait for S {\r\n        type A = SA;\r\n        type B = SB;\r\n    }\r\n    \r\n    impl Trait for SA {\r\n        type A = SAA;\r\n        type B = SB;\r\n    }\r\n    \r\n    fn test<T: Trait>() where T::A : Trait<B=T::B> {}\r\n    \r\n    fn main() {}\r\n\r\n```\r\n<anon>:22:42: 22:46 error: unsupported cyclic reference between types/traits detected\r\n<anon>:22 fn test<T: Trait>() where T::A : Trait<B=T::B> {}\r\n                                                   ^~~~\r\nnote: the cycle begins when computing the bounds for type parameter `T`...\r\nnote: ...which then again requires computing the bounds for type parameter `T`, completing the cycle.\r\nerror: aborting due to previous error\r\n```\r\n\r\nThis seems somewhat surprising, since, `T` is merely acting as the scope for `T::A` and `T::B`, which are distinct types. Also, it seems quite reasonable to want to assert a relationship between two associated types. Is there actually something inherently cyclic about this that I'm not seeing, or is it an artefact of how the implementation detects cycles? Also, is this kind of constraint likely to eventually be supported?"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/90295215","html_url":"https://github.com/rust-lang/rust/issues/24092#issuecomment-90295215","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/24092","id":90295215,"user":{"login":"stevenblenkinsop","id":3118803,"avatar_url":"https://avatars.githubusercontent.com/u/3118803?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenblenkinsop","html_url":"https://github.com/stevenblenkinsop","followers_url":"https://api.github.com/users/stevenblenkinsop/followers","following_url":"https://api.github.com/users/stevenblenkinsop/following{/other_user}","gists_url":"https://api.github.com/users/stevenblenkinsop/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenblenkinsop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenblenkinsop/subscriptions","organizations_url":"https://api.github.com/users/stevenblenkinsop/orgs","repos_url":"https://api.github.com/users/stevenblenkinsop/repos","events_url":"https://api.github.com/users/stevenblenkinsop/events{/privacy}","received_events_url":"https://api.github.com/users/stevenblenkinsop/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T00:21:43Z","updated_at":"2015-04-07T00:21:43Z","body":"Turns out the problem the problem goes away when I use the explicit `<T as Trait>::A` notation: http://is.gd/3sJOba\r\n\r\nAside from the overall problem of it being somewhat inconsistent whether you need to use this syntax or not, this is a deeply misleading error. The fact that it shows up might indicate a problem with how the associated type syntax is seen by the compiler. If not, the error should probably be improved regardless."}}