{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/25743","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/25743/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/25743/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/25743/events","html_url":"https://github.com/rust-lang/rust/pull/25743","id":80049069,"number":25743,"title":"Improve diagnostic messages for range patterns.","user":{"login":"michaelsproul","id":4452260,"avatar_url":"https://avatars.githubusercontent.com/u/4452260?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelsproul","html_url":"https://github.com/michaelsproul","followers_url":"https://api.github.com/users/michaelsproul/followers","following_url":"https://api.github.com/users/michaelsproul/following{/other_user}","gists_url":"https://api.github.com/users/michaelsproul/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelsproul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelsproul/subscriptions","organizations_url":"https://api.github.com/users/michaelsproul/orgs","repos_url":"https://api.github.com/users/michaelsproul/repos","events_url":"https://api.github.com/users/michaelsproul/events{/privacy}","received_events_url":"https://api.github.com/users/michaelsproul/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-05-24T04:33:06Z","updated_at":"2015-05-28T06:32:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/25743","html_url":"https://github.com/rust-lang/rust/pull/25743","diff_url":"https://github.com/rust-lang/rust/pull/25743.diff","patch_url":"https://github.com/rust-lang/rust/pull/25743.patch"},"body":"Part of #24407.\r\n\r\nCurrently the diagnostics for range patterns are a bit wrong:\r\n\r\n```rust\r\nfn main() {\r\n    match 5u32 {\r\n        0 ... 10 => (),\r\n        'a' ... 10 => (),\r\n        10 ... 'z' => (),\r\n        \"what\" ... 10 => (),\r\n        \"what\" ... \"well\" => (),\r\n        10 ... \"what\" => ()\r\n    }\r\n}\r\n```\r\n\r\n```\r\nrange.rs:4:9: 4:19 error: mismatched types in range:\r\n expected integral variable,\r\n    found char [E0211]\r\nrange.rs:4         'a' ... 10 => (),\r\n                   ^~~~~~~~~~\r\nrange.rs:4:9: 4:16 error: only char and numeric types are allowed in range [E0029]\r\nrange.rs:4         'a' ... 10 => (),\r\n                   ^~~~~~~\r\nrange.rs:4:9: 4:19 error: mismatched types:\r\n expected `u32`,\r\n    found `char`\r\n(expected u32,\r\n    found char) [E0308]\r\nrange.rs:4         'a' ... 10 => (),\r\n                   ^~~~~~~~~~\r\nrange.rs:5:9: 5:19 error: mismatched types in range:\r\n expected char,\r\n    found integral variable [E0211]\r\nrange.rs:5         10 ... 'z' => (),\r\n                   ^~~~~~~~~~\r\nrange.rs:5:9: 5:15 error: only char and numeric types are allowed in range [E0029]\r\nrange.rs:5         10 ... 'z' => (),\r\n                   ^~~~~~\r\nrange.rs:6:9: 6:22 error: mismatched types in range:\r\n expected integral variable,\r\n    found &-ptr [E0211]\r\nrange.rs:6         \"what\" ... 10 => (),\r\n                   ^~~~~~~~~~~~~\r\nrange.rs:6:9: 6:19 error: only char and numeric types are allowed in range [E0029]\r\nrange.rs:6         \"what\" ... 10 => (),\r\n                   ^~~~~~~~~~\r\nrange.rs:6:9: 6:22 error: mismatched types:\r\n expected `u32`,\r\n    found `&'static str`\r\n(expected u32,\r\n    found &-ptr) [E0308]\r\nrange.rs:6         \"what\" ... 10 => (),\r\n                   ^~~~~~~~~~~~~\r\nrange.rs:7:9: 7:19 error: only char and numeric types are allowed in range [E0029]\r\nrange.rs:7         \"what\" ... \"well\" => (),\r\n                   ^~~~~~~~~~\r\nrange.rs:7:9: 7:26 error: mismatched types:\r\n expected `u32`,\r\n    found `&'static str`\r\n(expected u32,\r\n    found &-ptr) [E0308]\r\nrange.rs:7         \"what\" ... \"well\" => (),\r\n                   ^~~~~~~~~~~~~~~~~\r\nrange.rs:8:9: 8:22 error: mismatched types in range:\r\n expected &-ptr,\r\n    found integral variable [E0211]\r\nrange.rs:8         10 ... \"what\" => ()\r\n                   ^~~~~~~~~~~~~\r\nrange.rs:8:9: 8:15 error: only char and numeric types are allowed in range [E0029]\r\nrange.rs:8         10 ... \"what\" => ()\r\n                   ^~~~~~\r\nerror: aborting due to 12 previous errors\r\n```\r\n\r\nThe problems here are:\r\n\r\n1. The type of the end of the range is used to predict the type of the start (only mildly counter intuitive).\r\n2. E0029 is erroneously generated for `char ... num` and `num ... char`.\r\n2. `u32` is mentioned.\r\n3. Errors which are essentially the same are reported multiple times.\r\n\r\nI've attempted to fix this by checking the requirements in a different order. The output I've achieved for the above example is:\r\n\r\n```\r\n/home/michael/Temp/range.rs:4:17: 4:22 error: mismatched types in range:\r\n expected char,\r\n    found integral variable [E0211]\r\n/home/michael/Temp/range.rs:4         'a' ... 10 => (),\r\n                                              ^~~~~\r\n/home/michael/Temp/range.rs:5:16: 5:22 error: mismatched types in range:\r\n expected integral variable,\r\n    found char [E0211]\r\n/home/michael/Temp/range.rs:5         10 ... 'z' => (),\r\n                                             ^~~~~~\r\n/home/michael/Temp/range.rs:6:9: 6:19 error: only char and numeric types are allowed in range [E0029]\r\n/home/michael/Temp/range.rs:6         \"what\" ... 10 => (),\r\n                                      ^~~~~~~~~~\r\n/home/michael/Temp/range.rs:6:9: 6:19 help: run `rustc --explain E0029` to see a detailed explanation\r\n/home/michael/Temp/range.rs:6:9: 6:19 note: Start type: &'static str\r\nEnd type: _\r\n/home/michael/Temp/range.rs:6         \"what\" ... 10 => (),\r\n                                      ^~~~~~~~~~\r\n/home/michael/Temp/range.rs:7:9: 7:26 error: only char and numeric types are allowed in range [E0029]\r\n/home/michael/Temp/range.rs:7         \"what\" ... \"well\" => (),\r\n                                      ^~~~~~~~~~~~~~~~~\r\n/home/michael/Temp/range.rs:7:9: 7:26 help: run `rustc --explain E0029` to see a detailed explanation\r\n/home/michael/Temp/range.rs:7:9: 7:26 note: Start type: &'static str\r\nEnd type: &'static str\r\n/home/michael/Temp/range.rs:7         \"what\" ... \"well\" => (),\r\n                                      ^~~~~~~~~~~~~~~~~\r\n/home/michael/Temp/range.rs:8:16: 8:25 error: only char and numeric types are allowed in range [E0029]\r\n/home/michael/Temp/range.rs:8         10 ... \"what\" => ()\r\n                                             ^~~~~~~~~\r\n/home/michael/Temp/range.rs:8:16: 8:25 help: run `rustc --explain E0029` to see a detailed explanation\r\n/home/michael/Temp/range.rs:8:16: 8:25 note: Start type: _\r\nEnd type: &'static str\r\n/home/michael/Temp/range.rs:8         10 ... \"what\" => ()\r\n                                             ^~~~~~~~~\r\nerror: aborting due to 5 previous errors\r\n```\r\n\r\nI think this is already tonnes better, but the `Start type/End type` stuff could be neater. I don't think there's really any need to start a `note:` block but I wanted to get some feedback on this. I'd also appreciate advice on how to print the integer types as something other than `_`."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/106194415","html_url":"https://github.com/rust-lang/rust/pull/25743#issuecomment-106194415","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/25743","id":106194415,"user":{"login":"nrc","id":762626,"avatar_url":"https://avatars.githubusercontent.com/u/762626?v=3","gravatar_id":"","url":"https://api.github.com/users/nrc","html_url":"https://github.com/nrc","followers_url":"https://api.github.com/users/nrc/followers","following_url":"https://api.github.com/users/nrc/following{/other_user}","gists_url":"https://api.github.com/users/nrc/gists{/gist_id}","starred_url":"https://api.github.com/users/nrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nrc/subscriptions","organizations_url":"https://api.github.com/users/nrc/orgs","repos_url":"https://api.github.com/users/nrc/repos","events_url":"https://api.github.com/users/nrc/events{/privacy}","received_events_url":"https://api.github.com/users/nrc/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T06:32:00Z","updated_at":"2015-05-28T06:32:00Z","body":"I agree there is no need to start a 'note' block here.\r\n\r\nAs far as I know, you can't get a better representation of the int inference var than `_`, if the compiler can't infer the exact type, it is just a inference variable (well, type checking distinguishes between int vars and other inference vars, but error reporting doesn't).\r\n\r\nThis PR could do with some tests to make sure the errors don't regress.\r\n\r\n(Also, needs a rebase)"}}