{"action":"created","issue":{"url":"https://api.github.com/repos/nrc/rustfmt/issues/340","labels_url":"https://api.github.com/repos/nrc/rustfmt/issues/340/labels{/name}","comments_url":"https://api.github.com/repos/nrc/rustfmt/issues/340/comments","events_url":"https://api.github.com/repos/nrc/rustfmt/issues/340/events","html_url":"https://github.com/nrc/rustfmt/issues/340","id":107435134,"number":340,"title":"match with only one non-empty arm should be `if let`","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},"labels":[{"url":"https://api.github.com/repos/nrc/rustfmt/labels/fun!","name":"fun!","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-21T02:46:46Z","updated_at":"2015-09-27T19:02:19Z","closed_at":null,"body":"e.g.,\r\n\r\n```\r\nmatch hint {\r\n    Some(h) => acc.push(h),\r\n    None => { }\r\n}\r\n```\r\n\r\nto\r\n\r\n```\r\nif let Some(h) = hint {\r\n    acc.push(h)\r\n}\r\n```\r\n\r\nThis definitely needs to be an option! And will need some funky tests, I bet there are edge cases where we can't do this."},"comment":{"url":"https://api.github.com/repos/nrc/rustfmt/issues/comments/143587787","html_url":"https://github.com/nrc/rustfmt/issues/340#issuecomment-143587787","issue_url":"https://api.github.com/repos/nrc/rustfmt/issues/340","id":143587787,"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-09-27T19:02:19Z","updated_at":"2015-09-27T19:02:19Z","body":"@TimNN wow, that's thorough, good stuff. Comments:\r\n\r\n> An empty arm is an arm which is either the unit expressions () or an empty block {}\r\n\r\nYou should check what happens with `()` match arms, in particular when they're used in expression position - you might need an `else` in that case or it isn't an exhaustive match. Not sure of the exact behaviour.\r\n\r\nI would probably start without `WildcardOnly` - if someone wants it later, then add it, otherwise keep it simple.\r\n\r\n> Rewrite empty matches to let _ = $match_expr\r\n\r\nWhy not just $match_expr; ? We could also just warn. Fine to leave this till later in any case\r\n\r\nI hope that this can be a context-free transformation, i.e., we should not consider whether we are in expression position. If the author doesn't want the change, they can disable the option of use #[rustfmt_skip].\r\n\r\nI think I still prefer the `if let` in the long line situation - it's still two lines shorter and the meaning is clearer. Note though that I would indent the second line of the conditional to align with the start of `Maybe...`, rather than have one tab space indent. (Not sure what rustfmt does in this case).\r\n"}}