{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/32382","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/32382/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/32382/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/32382/events","html_url":"https://github.com/rust-lang/rust/issues/32382","id":142215368,"number":32382,"title":"Lifetime bound error when using the indexing operator with an associated type containing a lifetime","user":{"login":"koute","id":246574,"avatar_url":"https://avatars.githubusercontent.com/u/246574?v=3","gravatar_id":"","url":"https://api.github.com/users/koute","html_url":"https://github.com/koute","followers_url":"https://api.github.com/users/koute/followers","following_url":"https://api.github.com/users/koute/following{/other_user}","gists_url":"https://api.github.com/users/koute/gists{/gist_id}","starred_url":"https://api.github.com/users/koute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koute/subscriptions","organizations_url":"https://api.github.com/users/koute/orgs","repos_url":"https://api.github.com/users/koute/repos","events_url":"https://api.github.com/users/koute/events{/privacy}","received_events_url":"https://api.github.com/users/koute/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-nominated","name":"I-nominated","color":"e10c02"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/regression-from-stable-to-stable","name":"regression-from-stable-to-stable","color":"FF309F"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2"}],"state":"open","locked":false,"assignee":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2016-03-20T22:30:46Z","updated_at":"2016-06-23T20:50:54Z","closed_at":null,"body":"Please consider the following code:\r\n\r\n```rust\r\nuse std::marker::PhantomData;\r\nuse std::ops::Index;\r\n\r\npub trait Context: Clone {\r\n    type Container: ?Sized;\r\n    fn foobar_1( container: &Self::Container ) -> &str;\r\n    fn foobar_2( container: &Self::Container ) -> &str;\r\n    fn foobar_3( container: &Self::Container ) -> &str;\r\n}\r\n\r\n#[derive(Clone)]\r\nstruct Foobar<'a> {\r\n    phantom: PhantomData<&'a ()>\r\n}\r\n\r\nimpl<'a> Context for Foobar<'a> {\r\n    type Container = [&'a str];\r\n\r\n    fn foobar_1<'r>( container: &'r [&'a str] ) -> &'r str {\r\n        // This compiles fine.\r\n        container[0]\r\n    }\r\n\r\n    fn foobar_2<'r>( container: &'r Self::Container ) -> &'r str {\r\n        // This also compiles fine.\r\n        container.index( 0 )\r\n    }\r\n\r\n    fn foobar_3<'r>( container: &'r Self::Container ) -> &'r str {\r\n        // error: `*container[..]` does not live long enough\r\n        container[0]\r\n    }\r\n}\r\n\r\nfn main() {}\r\n```\r\n\r\nwhich fails with the following error:\r\n\r\n```\r\ntest.rs:31:9: 31:21 error: `*container[..]` does not live long enough\r\ntest.rs:31         container[0]\r\n                   ^~~~~~~~~~~~\r\ntest.rs:29:66: 32:6 note: reference must be valid for the lifetime 'r as defined on the block at 29:65...\r\ntest.rs:29     fn foobar_3<'r>( container: &'r Self::Container ) -> &'r str {\r\ntest.rs:30         // error: `*container[..]` does not live long enough\r\ntest.rs:31         container[0]\r\ntest.rs:32     }\r\ntest.rs:29:66: 32:6 note: ...but borrowed value is only valid for the lifetime 'a as defined on the block at 29:65\r\ntest.rs:29     fn foobar_3<'r>( container: &'r Self::Container ) -> &'r str {\r\ntest.rs:30         // error: `*container[..]` does not live long enough\r\ntest.rs:31         container[0]\r\ntest.rs:32     }\r\nerror: aborting due to previous error\r\n```\r\n\r\nSo if I use `.index()` and use an associated type it compiles fine. If I use `[]` and replace the associated type with the underlying type it also compiles fine. Logic would have it that if I use `[]` and I'll leave the associated type as-is it should also compile fine, but alas, I get an error, which doesn't really make any sense.\r\n\r\nRust version: rustc 1.9.0-nightly (b12b4e4e3 2016-03-17)\r\n\r\nThis is a regression; this code used to compile on at least 1.4, 1.5 and 1.6; it broke at 1.7."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/228179688","html_url":"https://github.com/rust-lang/rust/issues/32382#issuecomment-228179688","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/32382","id":228179688,"user":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"created_at":"2016-06-23T20:50:54Z","updated_at":"2016-06-23T20:50:54Z","body":"I will look at this."}}
{"actor":{"display_login":"pnkfelix"}}