{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/47992","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/47992/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/47992/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/47992/events","html_url":"https://github.com/rust-lang/rust/pull/47992","id":294166575,"number":47992,"title":"WIP: Hygiene opt-out for idents in expansion of declarative macros","user":{"login":"alexreg","id":67036,"avatar_url":"https://avatars3.githubusercontent.com/u/67036?v=4","gravatar_id":"","url":"https://api.github.com/users/alexreg","html_url":"https://github.com/alexreg","followers_url":"https://api.github.com/users/alexreg/followers","following_url":"https://api.github.com/users/alexreg/following{/other_user}","gists_url":"https://api.github.com/users/alexreg/gists{/gist_id}","starred_url":"https://api.github.com/users/alexreg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexreg/subscriptions","organizations_url":"https://api.github.com/users/alexreg/orgs","repos_url":"https://api.github.com/users/alexreg/repos","events_url":"https://api.github.com/users/alexreg/events{/privacy}","received_events_url":"https://api.github.com/users/alexreg/received_events","type":"User","site_admin":false},"labels":[{"id":583426710,"url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-review","name":"S-waiting-on-review","color":"d3dddd","default":false},{"id":211668100,"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars0.githubusercontent.com/u/155238?v=4","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"assignees":[{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars0.githubusercontent.com/u/155238?v=4","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},{"login":"petrochenkov","id":5751617,"avatar_url":"https://avatars2.githubusercontent.com/u/5751617?v=4","gravatar_id":"","url":"https://api.github.com/users/petrochenkov","html_url":"https://github.com/petrochenkov","followers_url":"https://api.github.com/users/petrochenkov/followers","following_url":"https://api.github.com/users/petrochenkov/following{/other_user}","gists_url":"https://api.github.com/users/petrochenkov/gists{/gist_id}","starred_url":"https://api.github.com/users/petrochenkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrochenkov/subscriptions","organizations_url":"https://api.github.com/users/petrochenkov/orgs","repos_url":"https://api.github.com/users/petrochenkov/repos","events_url":"https://api.github.com/users/petrochenkov/events{/privacy}","received_events_url":"https://api.github.com/users/petrochenkov/received_events","type":"User","site_admin":false}],"milestone":null,"comments":70,"created_at":"2018-02-04T03:33:12Z","updated_at":"2018-04-18T00:03:55Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/47992","html_url":"https://github.com/rust-lang/rust/pull/47992","diff_url":"https://github.com/rust-lang/rust/pull/47992.diff","patch_url":"https://github.com/rust-lang/rust/pull/47992.patch"},"body":"This PR adds basic support for hygiene opt-out for idents during macro expansion. This has been previously discussed in https://github.com/rust-lang/rust/pull/40847 and https://github.com/rust-lang/rust/issues/39412.\r\n\r\nThe syntax involves prefixing idents with the `#` (i.e. pound/hash) character to indicate that the syntax context of the ident should be that of the call site rather than the definition site.\r\n\r\nThe following now compiles and runs as expected:\r\n\r\n```rust\r\n#![feature(decl_macro)]\r\n\r\nmacro foo($mod_name:ident) {\r\n    pub mod $mod_name {\r\n        pub const #BAR: u32 = 123;\r\n    }\r\n}\r\n\r\nfoo!(foo_mod);\r\n\r\nfn main() {\r\n    println!(\"{}\", foo_mod::BAR);\r\n}\r\n```\r\n\r\nas does:\r\n\r\n```rust\r\n#![feature(decl_macro)]\r\n\r\nmacro foo() {\r\n    pub mod #foo_mod {\r\n        pub const #BAR: u32 = 123;\r\n    }\r\n}\r\n\r\nfoo!();\r\n\r\nfn main() {\r\n    println!(\"{}\", foo_mod::BAR);\r\n}\r\n```\r\n\r\nbut the following does not:\r\n\r\n```rust\r\n#![feature(decl_macro)]\r\n\r\nmacro foo($mod_name:ident) {\r\n    pub mod $mode_name {\r\n        pub const BAR: u32 = 123;\r\n    }\r\n}\r\n\r\nfoo!(foo_mod);\r\n\r\nfn main() {\r\n    println!(\"{}\", foo_mod::BAR);\r\n}\r\n```\r\n\r\nnor does:\r\n\r\n```rust\r\n#![feature(decl_macro)]\r\n\r\nmacro foo() {\r\n    pub mod #foo_mod {\r\n        pub const BAR: u32 = 123;\r\n    }\r\n}\r\n\r\nfoo!();\r\n\r\nfn main() {\r\n    println!(\"{}\", foo_mod::BAR);\r\n}\r\n```\r\n\r\n**Questions:**\r\n* Is the above the behaviour we want?\r\n* Should we implement syntax context \"lifting\" using functionality suggested by RFC? https://github.com/rust-lang/rfcs/pull/2320 – this related to the 2nd question of @petrochenkov [here](https://github.com/rust-lang/rust/issues/39412#issuecomment-361732915)\r\n* Hygiene opt-out doesn't make any sense for `macro_rules` macros, of course, but should we explicitly disallow the `#` syntax in such places? (Currently that is not done.)\r\n\r\nCC @jseyfried"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/382197403","html_url":"https://github.com/rust-lang/rust/pull/47992#issuecomment-382197403","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/47992","id":382197403,"user":{"login":"alexreg","id":67036,"avatar_url":"https://avatars3.githubusercontent.com/u/67036?v=4","gravatar_id":"","url":"https://api.github.com/users/alexreg","html_url":"https://github.com/alexreg","followers_url":"https://api.github.com/users/alexreg/followers","following_url":"https://api.github.com/users/alexreg/following{/other_user}","gists_url":"https://api.github.com/users/alexreg/gists{/gist_id}","starred_url":"https://api.github.com/users/alexreg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexreg/subscriptions","organizations_url":"https://api.github.com/users/alexreg/orgs","repos_url":"https://api.github.com/users/alexreg/repos","events_url":"https://api.github.com/users/alexreg/events{/privacy}","received_events_url":"https://api.github.com/users/alexreg/received_events","type":"User","site_admin":false},"created_at":"2018-04-18T00:03:55Z","updated_at":"2018-04-18T00:03:55Z","author_association":"CONTRIBUTOR","body":"@petrochenkov Oh yeah, it was working with the tests all passing, it just regressed with a recent rebase. It was a change over the last 2 (max 3) weeks that caused it."}}
{"actor":{"display_login":"alexreg"}}