{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/1297","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1297/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1297/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1297/events","html_url":"https://github.com/rust-lang/rfcs/issues/1297","id":108433893,"number":1297,"title":"Perhaps warn on a backwards Range","user":{"login":"Jragonmiris","id":3078382,"avatar_url":"https://avatars.githubusercontent.com/u/3078382?v=3","gravatar_id":"","url":"https://api.github.com/users/Jragonmiris","html_url":"https://github.com/Jragonmiris","followers_url":"https://api.github.com/users/Jragonmiris/followers","following_url":"https://api.github.com/users/Jragonmiris/following{/other_user}","gists_url":"https://api.github.com/users/Jragonmiris/gists{/gist_id}","starred_url":"https://api.github.com/users/Jragonmiris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jragonmiris/subscriptions","organizations_url":"https://api.github.com/users/Jragonmiris/orgs","repos_url":"https://api.github.com/users/Jragonmiris/repos","events_url":"https://api.github.com/users/Jragonmiris/events{/privacy}","received_events_url":"https://api.github.com/users/Jragonmiris/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-26T02:07:03Z","updated_at":"2015-09-26T02:07:03Z","closed_at":null,"body":"Recently I did the following:\r\n\r\n    for i in (idx..0) { \r\n        //stuff\r\n    }\r\n\r\nThere the type of `idx` was `usize`.\r\n\r\nThis, of course, does not exactly do what is intended (count backwards from idx to 0), and I couldn't find the bug for a while. The iterator does absolutely nothing at all, it doesn't even panic. I think it may be useful to have a warning emitted when this can be detected. I think the following two cases should be surefire:\r\n\r\n1. Two indices `(a..b)` where `b` and `a`'s values are known at compile time, and `b < a`.\r\n2. A terminal index, `min` in `(a..min)` where `min` is the minimum value for the type, e.g. if `a` is `i32` then `(a..std::i32::MIN)` would tickle it. If `a` is a usize then `(a..0)` would tickle it. This is because a range-exclusive Range like `..` can only produce an empty iterator if the last index is min, so it's almost certainly an attempt at a backwards iterator.\r\n\r\nThere may be other provable cases, but these are the immediately obvious ones."}}