{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/29476","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/29476/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/29476/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/29476/events","html_url":"https://github.com/rust-lang/rust/issues/29476","id":114298953,"number":29476,"title":"&[T; n] doesn't coerce to &[T] in index operand position","user":{"login":"SDBlumire","id":6872380,"avatar_url":"https://avatars.githubusercontent.com/u/6872380?v=3","gravatar_id":"","url":"https://api.github.com/users/SDBlumire","html_url":"https://github.com/SDBlumire","followers_url":"https://api.github.com/users/SDBlumire/followers","following_url":"https://api.github.com/users/SDBlumire/following{/other_user}","gists_url":"https://api.github.com/users/SDBlumire/gists{/gist_id}","starred_url":"https://api.github.com/users/SDBlumire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SDBlumire/subscriptions","organizations_url":"https://api.github.com/users/SDBlumire/orgs","repos_url":"https://api.github.com/users/SDBlumire/repos","events_url":"https://api.github.com/users/SDBlumire/events{/privacy}","received_events_url":"https://api.github.com/users/SDBlumire/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-lang","name":"A-lang","color":"d7e102"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-10-30T16:02:36Z","updated_at":"2015-12-22T17:19:07Z","closed_at":"2015-11-02T19:44:50Z","body":"```rust\r\nuse std::ops::Index;\r\n\r\nstruct Foo;\r\n\r\nimpl<'a> Index<&'a [usize]> for Foo {\r\n    type Output = Foo;\r\n    fn index(&self, index: &'a [usize]) -> &Foo { panic!() }\r\n}\r\n\r\nfn main() {\r\n    let f = Foo;\r\n    f[&[1, 2, 3]];\r\n}\r\n```\r\n\r\nThe compiler (stable) returns the following error.\r\n\r\n```text\r\n<anon>:12:5: 12:18 error: mismatched types:\r\n expected `&[usize]`,\r\n    found `&[_; 3]`\r\n(expected slice,\r\n    found array of 3 elements) [E0308]\r\n<anon>:12     f[&[1, 2, 3]];\r\n              ^~~~~~~~~~~~~\r\n<anon>:12:5: 12:18 help: see the detailed explanation for E0308\r\nerror: aborting due to previous error\r\n```\r\n\r\nShould the type not be correctly coerced? As only &[usize] is expected, not &[usize; 3]. This can be worked around by using `&[1, 2, 3][...]`, or having the index accept a generic AsRef<[usize]>, however neither of these are ideal."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/166678657","html_url":"https://github.com/rust-lang/rust/issues/29476#issuecomment-166678657","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/29476","id":166678657,"user":{"login":"eddyb","id":77424,"avatar_url":"https://avatars.githubusercontent.com/u/77424?v=3","gravatar_id":"","url":"https://api.github.com/users/eddyb","html_url":"https://github.com/eddyb","followers_url":"https://api.github.com/users/eddyb/followers","following_url":"https://api.github.com/users/eddyb/following{/other_user}","gists_url":"https://api.github.com/users/eddyb/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyb/subscriptions","organizations_url":"https://api.github.com/users/eddyb/orgs","repos_url":"https://api.github.com/users/eddyb/repos","events_url":"https://api.github.com/users/eddyb/events{/privacy}","received_events_url":"https://api.github.com/users/eddyb/received_events","type":"User","site_admin":false},"created_at":"2015-12-22T17:19:07Z","updated_at":"2015-12-22T17:19:07Z","body":"@nikomatsakis I meant we special-case `fixed_length_array[integer]` to avoid marking it as overloaded, *before* looking up an `Index` impl.\r\nIt's the only reason we compute `index_ty` before resolving the impl, instead of type-checking the index expression based on the `Index` impl we found.\r\n\r\n[This is the special-case in the current implementation](https://github.com/rust-lang/rust/blob/42c3ef8f9fd4b0dd1f881c49323bad456163f202/src/librustc_typeck/check/mod.rs#L2271) (sorry for not linking to it earlier).\r\n\r\n"}}