{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/1602","repository_url":"https://api.github.com/repos/rust-lang/rfcs","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1602/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1602/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1602/events","html_url":"https://github.com/rust-lang/rfcs/issues/1602","id":152110865,"node_id":"MDU6SXNzdWUxNTIxMTA4NjU=","number":1602,"title":"C++-style initializer list","user":{"login":"bombless","id":1296393,"node_id":"MDQ6VXNlcjEyOTYzOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/1296393?v=4","gravatar_id":"","url":"https://api.github.com/users/bombless","html_url":"https://github.com/bombless","followers_url":"https://api.github.com/users/bombless/followers","following_url":"https://api.github.com/users/bombless/following{/other_user}","gists_url":"https://api.github.com/users/bombless/gists{/gist_id}","starred_url":"https://api.github.com/users/bombless/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bombless/subscriptions","organizations_url":"https://api.github.com/users/bombless/orgs","repos_url":"https://api.github.com/users/bombless/repos","events_url":"https://api.github.com/users/bombless/events{/privacy}","received_events_url":"https://api.github.com/users/bombless/received_events","type":"User","site_admin":false},"labels":[{"id":211667886,"node_id":"MDU6TGFiZWwyMTE2Njc4ODY=","url":"https://api.github.com/repos/rust-lang/rfcs/labels/T-lang","name":"T-lang","color":"bfd4f2","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":30,"created_at":"2016-05-01T05:17:30Z","updated_at":"2018-10-07T21:36:28Z","closed_at":"2018-10-07T21:36:28Z","author_association":"NONE","body":"In C++ you can use an initializer to initialize a map, which looks like a map literal and feels nice.\n\n``` C++\n#include <map>\nint main() {\n    auto m = std::map<int, int> { { 1, 2 }, { 3, 4 } };\n}\n\n```\n\n[playground](https://gcc.godbolt.org/#compilers:!%28%28compiler:g6,options:'',source:'%23include+%3Cmap%3E%0Aint+main%28%29+%7B%0A++++auto+m+%3D+std::map%3Cint,+int%3E+%7B+%7B+1,+2+%7D,+%7B+3,+4+%7D+%7D%3B%0A%7D%0A'%29%29,filterAsm:%28commentOnly:!t,directives:!t,labels:!t%29,version:3)\n\nSo I suggest we can do something like this:\n\n``` Rust\nlet m = <HashMap<i32, i32>> { // wrapping type name with <> to indicate type like in UFCS\n  ( 1, 2 ),\n  ( 3, 4 ),\n};\n```\n\nwhich do similar thing as above C++ code.\n\nWe already have initializer list built-in so we don't need to tackle about the initializer side.\n\nLet me explain how above Rust code work:\nIt is desugared to:\n\n``` Rust\nlet m: HashMap<i32, i32> = vec![(1, 2), (3, 4)].into_iter().collect(); // I hope we can drain array here\n```\n\n[playground](https://play.rust-lang.org/?gist=9c795112e0a4313988eee67e3b6048f4&version=stable&backtrace=0&run=1)\nThe trick is that `impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>` is done already.\n\nTo sum up, points are:\n- start with a type here so we know it's about a type, not for the propose of mentioning some associated item and not to start struct literals and such\n- wrap a list in braces and separate with comma\n- each item in the list is plain expression, so the syntax is very flexible\n\nNow you might argue that if the desugared form is already okay why should we accept this fancy sugar.\nI say this sugaring form is much more human-parsable and can make life easier.\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments/427689128","html_url":"https://github.com/rust-lang/rfcs/issues/1602#issuecomment-427689128","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1602","id":427689128,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzY4OTEyOA==","user":{"login":"Centril","id":855702,"node_id":"MDQ6VXNlcjg1NTcwMg==","avatar_url":"https://avatars2.githubusercontent.com/u/855702?v=4","gravatar_id":"","url":"https://api.github.com/users/Centril","html_url":"https://github.com/Centril","followers_url":"https://api.github.com/users/Centril/followers","following_url":"https://api.github.com/users/Centril/following{/other_user}","gists_url":"https://api.github.com/users/Centril/gists{/gist_id}","starred_url":"https://api.github.com/users/Centril/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Centril/subscriptions","organizations_url":"https://api.github.com/users/Centril/orgs","repos_url":"https://api.github.com/users/Centril/repos","events_url":"https://api.github.com/users/Centril/events{/privacy}","received_events_url":"https://api.github.com/users/Centril/received_events","type":"User","site_admin":false},"created_at":"2018-10-07T21:36:28Z","updated_at":"2018-10-07T21:36:28Z","author_association":"CONTRIBUTOR","body":"Closing in favor of https://github.com/rust-lang/rfcs/issues/542."}}
{"actor":{"display_login":"Centril"}}