{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/60352785","id":60352785,"diff_hunk":"@@ -0,0 +1,165 @@\n+- Feature Name: N/A (part of other unstable features)\n+- Start Date: 2016-02-11\n+- RFC PR: (leave this empty)\n+- Rust Issue: (leave this empty)\n+\n+# Summary\n+[summary]: #summary\n+\n+Naming and modularisation for macros.\n+\n+This RFC proposes making macros a first-class citizen in the Rust module system.\n+Both macros by example (`macro_rules` macros) and procedural macros (aka syntax\n+extensions) would use the same naming and modularisation scheme as other items\n+in Rust.\n+\n+For procedural macros, this RFC could be implemented immediately or as part of a\n+larger effort to reform procedural macros. For macros by example, this would be\n+part of a macros 2.0 feature, the rest of which will be described in a separate\n+RFC. This RFC depends on the changes to name resolution described in\n+[RFC 1560](https://github.com/rust-lang/rfcs/pull/1560).\n+\n+# Motivation\n+[motivation]: #motivation\n+\n+Currently, procedural macros are not modularised at all (beyond the crate\n+level). Macros by example have a [custom modularisation\n+scheme](https://github.com/rust-lang/rfcs/blob/master/text/0453-macro-reform.md)\n+which involves modules to some extent, but relies on source ordering and\n+attributes which are not used for other items. Macros cannot be imported or\n+named using the usual syntax. It is confusing that macros use their own system\n+for modularisation. It would be far nicer if they were a more regular feature of\n+Rust in this respect.\n+\n+\n+# Detailed design\n+[design]: #detailed-design\n+\n+## Defining macros\n+\n+This RFC does not propose changes to macro definitions. It is envisaged that\n+definitions of procedural macros will change, see [this blog post](http://ncameron.org/blog/macro-plans-syntax/)\n+for some rough ideas. I'm assuming that procedural macros will be defined in\n+some function-like way and that these functions will be defined in modules in\n+their own crate (to start with).\n+\n+Ordering of macro definitions in the source text will no longer be significant.\n+A macro may be used before it is defined, as long as it can be named. That is,\n+macros follow the same rules regarding ordering as other items. E.g., this will\n+work:\n+\n+```\n+foo!();\n+\n+macro_rules! foo { ... }\n+```\n+\n+Macro expansion order is also not defined by source order. E.g., in `foo!(); bar!();`,\n+`bar` may be expanded before `foo`. Ordering is only guaranteed as far as it is\n+necessary. E.g., if `bar` is only defined by expanding `foo`, then `foo` must be\n+expanded before `bar`.\n+\n+## Function-like macro uses\n+\n+A function-like macro use (c.f., attribute-like macro use) is a macro use which\n+uses `foo!(...)` or `foo! ident (...)` syntax (where `()` may also be `[]` or `{}`).\n+\n+Macros may be named by using a `::`-separated path. Naming follows the same\n+rules as other items in Rust.\n+\n+If a macro `baz` (by example or procedural) is defined in a module `bar` which\n+is nested in `foo`, then it may be used anywhere in the crate using an\n+absolute path: `::foo::bar::baz!(...)`. It can be used via relative paths in the\n+usual way, e.g., inside `foo` as `bar::baz!()`.\n+\n+Macros declared inside a function body can only be used inside that function\n+body.\n+\n+For procedural macros, the path must point to the function defining the macro.\n+\n+The grammar for macros is changed, anywhere we currently parser `name \"!\"`, we\n+now parse `path \"!\"`. I don't think this introduces any issues.\n+\n+Name lookup follows the same name resolution rules as other items. See [RFC\n+1560](https://github.com/rust-lang/rfcs/pull/1560) for details on how name\n+resolution could be adapted to support this.\n+\n+## Attribute-like macro uses\n+\n+Attribute macros may also be named using a `::`-separated path. Other than\n+appearing in an attribute, these also follow the usual Rust naming rules.\n+\n+E.g., `#[::foo::bar::baz(...)]` and `#[bar::baz(...)]` are uses of absolute and\n+relative paths, respectively.\n+\n+\n+## Importing macros\n+\n+Importing macros is done using `use` in the same way as other items. An `!` is\n+not necessary in an import item. Macros are imported into their own namespace\n+and do not shadow or overlap items with the same name in the type or value\n+namespaces.\n+\n+E.g., `use foo::bar::baz;` imports the macro `baz` from the module `::foo::bar`.","path":"text/0000-macro-naming.md","position":107,"original_position":103,"commit_id":"ffbb2f7f3acf08ebd23011d86b6bf70f4a42663a","original_commit_id":"573bd83aaac0896842f136262458c3b3bf671cd7","user":{"login":"nixpulvis","id":715947,"avatar_url":"https://avatars.githubusercontent.com/u/715947?v=3","gravatar_id":"","url":"https://api.github.com/users/nixpulvis","html_url":"https://github.com/nixpulvis","followers_url":"https://api.github.com/users/nixpulvis/followers","following_url":"https://api.github.com/users/nixpulvis/following{/other_user}","gists_url":"https://api.github.com/users/nixpulvis/gists{/gist_id}","starred_url":"https://api.github.com/users/nixpulvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nixpulvis/subscriptions","organizations_url":"https://api.github.com/users/nixpulvis/orgs","repos_url":"https://api.github.com/users/nixpulvis/repos","events_url":"https://api.github.com/users/nixpulvis/events{/privacy}","received_events_url":"https://api.github.com/users/nixpulvis/received_events","type":"User","site_admin":false},"body":"I think this is a critical decision. Should macros look like macros or not in the language. The `!` currently signals this to me, and I would think *should* be universal, or we hide the distinction and remove the `!` everywhere and let macros be more transparent. I'm sure there are a million problems with the latter, but I feel like we should have a clear answer here.","created_at":"2016-04-20T05:43:16Z","updated_at":"2016-04-20T05:43:16Z","html_url":"https://github.com/rust-lang/rfcs/pull/1561#discussion_r60352785","pull_request_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments/60352785"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1561#discussion_r60352785"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561","id":64550041,"html_url":"https://github.com/rust-lang/rfcs/pull/1561","diff_url":"https://github.com/rust-lang/rfcs/pull/1561.diff","patch_url":"https://github.com/rust-lang/rfcs/pull/1561.patch","issue_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1561","number":1561,"state":"open","locked":false,"title":"Macro naming and modularisation","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},"body":"This RFC proposes making macros a first-class citizen in the Rust module system.\r\nBoth macros by example (`macro_rules` macros) and procedural macros (aka syntax\r\nextensions) would use the same naming and modularisation scheme as other items\r\nin Rust.\r\n\r\n[rendered](https://github.com/nrc/rfcs/blob/573bd83aaac0896842f136262458c3b3bf671cd7/text/0000-macro-naming.md)","created_at":"2016-03-29T23:22:36Z","updated_at":"2016-04-20T05:43:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14d5717160da392fa5fedb41bd8fbbf1e6032f44","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,"commits_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/1561/comments","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/ffbb2f7f3acf08ebd23011d86b6bf70f4a42663a","head":{"label":"nrc:macro-naming","ref":"macro-naming","sha":"ffbb2f7f3acf08ebd23011d86b6bf70f4a42663a","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},"repo":{"id":17579664,"name":"rfcs","full_name":"nrc/rfcs","owner":{"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},"private":false,"html_url":"https://github.com/nrc/rfcs","description":"RFCs for changes to Rust","fork":true,"url":"https://api.github.com/repos/nrc/rfcs","forks_url":"https://api.github.com/repos/nrc/rfcs/forks","keys_url":"https://api.github.com/repos/nrc/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nrc/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nrc/rfcs/teams","hooks_url":"https://api.github.com/repos/nrc/rfcs/hooks","issue_events_url":"https://api.github.com/repos/nrc/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/nrc/rfcs/events","assignees_url":"https://api.github.com/repos/nrc/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/nrc/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/nrc/rfcs/tags","blobs_url":"https://api.github.com/repos/nrc/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nrc/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nrc/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/nrc/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nrc/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/nrc/rfcs/languages","stargazers_url":"https://api.github.com/repos/nrc/rfcs/stargazers","contributors_url":"https://api.github.com/repos/nrc/rfcs/contributors","subscribers_url":"https://api.github.com/repos/nrc/rfcs/subscribers","subscription_url":"https://api.github.com/repos/nrc/rfcs/subscription","commits_url":"https://api.github.com/repos/nrc/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/nrc/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/nrc/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/nrc/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/nrc/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/nrc/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nrc/rfcs/merges","archive_url":"https://api.github.com/repos/nrc/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nrc/rfcs/downloads","issues_url":"https://api.github.com/repos/nrc/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/nrc/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/nrc/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/nrc/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nrc/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/nrc/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/nrc/rfcs/deployments","created_at":"2014-03-10T02:38:22Z","updated_at":"2016-02-03T09:16:43Z","pushed_at":"2016-04-19T05:29:18Z","git_url":"git://github.com/nrc/rfcs.git","ssh_url":"git@github.com:nrc/rfcs.git","clone_url":"https://github.com/nrc/rfcs.git","svn_url":"https://github.com/nrc/rfcs","homepage":"","size":2891,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"3d8170295f091c508d064a322cda424c09ee98f2","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17527989,"name":"rfcs","full_name":"rust-lang/rfcs","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/rfcs","description":"RFCs for changes to Rust","fork":false,"url":"https://api.github.com/repos/rust-lang/rfcs","forks_url":"https://api.github.com/repos/rust-lang/rfcs/forks","keys_url":"https://api.github.com/repos/rust-lang/rfcs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rfcs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rfcs/teams","hooks_url":"https://api.github.com/repos/rust-lang/rfcs/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rfcs/events","assignees_url":"https://api.github.com/repos/rust-lang/rfcs/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rfcs/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rfcs/tags","blobs_url":"https://api.github.com/repos/rust-lang/rfcs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rfcs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rfcs/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rfcs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rfcs/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rfcs/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rfcs/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rfcs/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rfcs/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rfcs/subscription","commits_url":"https://api.github.com/repos/rust-lang/rfcs/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rfcs/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rfcs/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/rfcs/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rfcs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rfcs/merges","archive_url":"https://api.github.com/repos/rust-lang/rfcs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rfcs/downloads","issues_url":"https://api.github.com/repos/rust-lang/rfcs/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rfcs/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rfcs/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rfcs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rfcs/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rfcs/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/rfcs/deployments","created_at":"2014-03-07T21:29:00Z","updated_at":"2016-04-19T16:18:42Z","pushed_at":"2016-04-19T07:47:37Z","git_url":"git://github.com/rust-lang/rfcs.git","ssh_url":"git@github.com:rust-lang/rfcs.git","clone_url":"https://github.com/rust-lang/rfcs.git","svn_url":"https://github.com/rust-lang/rfcs","homepage":"","size":5057,"stargazers_count":601,"watchers_count":601,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":296,"mirror_url":null,"open_issues_count":647,"forks":296,"open_issues":647,"watchers":601,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561"},"html":{"href":"https://github.com/rust-lang/rfcs/pull/1561"},"issue":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1561"},"comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/issues/1561/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rfcs/pulls/1561/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rfcs/statuses/ffbb2f7f3acf08ebd23011d86b6bf70f4a42663a"}}}}