GitHub PullRequestReviewCommentEvent at 2014-08-04 05:40:08
Repository: rust
Actor: kballard
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/15741194","id":15741194,"diff_hunk":"@@ -0,0 +1,59 @@\n+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT\n+// file at the top-level directory of this distribution and at\n+// http://rust-lang.org/COPYRIGHT.\n+//\n+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or\n+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license\n+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your\n+// option. This file may not be copied, modified, or distributed\n+// except according to those terms.\n+\n+use std::gc::{Gc, GC};\n+\n+use ast;\n+use attr;\n+use codemap::Span;\n+use ext::base::ExtCtxt;\n+use ext::build::AstBuilder;\n+\n+pub fn expand(cx: &mut ExtCtxt, sp: Span, mi: Gc<ast::MetaItem>, it: Gc<ast::Item>)\n+          -> Gc<ast::Item> {\n+    let (cfg, attr) = match mi.node {\n+        ast::MetaList(_, ref mis) if mis.len() == 2 => (mis[0], mis[1]),\n+        _ => {\n+            cx.span_err(sp, \"expected `#[cfg_attr(<cfg pattern>, <attr>)]`\");\n+            return it;\n+        }\n+    };\n+\n+    let mut out = (*it).clone();\n+    if cfg_matches(cx, cfg) {\n+        out.attrs.push(cx.attribute(attr.span, attr));\n+    }\n+\n+    box(GC) out\n+}\n+\n+fn cfg_matches(cx: &mut ExtCtxt, cfg: Gc<ast::MetaItem>) -> bool {\n+    match cfg.node {\n+        ast::MetaList(ref pred, ref mis) if pred.get() == \"any\" =>\n+            mis.iter().any(|mi| cfg_matches(cx, *mi)),\n+        ast::MetaList(ref pred, ref mis) if pred.get() == \"all\" =>\n+            mis.iter().all(|mi| cfg_matches(cx, *mi)),","path":"src/libsyntax/ext/cfg_attr.rs","position":42,"original_position":42,"commit_id":"26322100172cf92812846b7959659bd2fd7ea553","original_commit_id":"26322100172cf92812846b7959659bd2fd7ea553","user":{"login":"kballard","id":714,"avatar_url":"https://avatars.githubusercontent.com/u/714?v=1","gravatar_id":"6451ee8093c9cedc94f6c813b4dde2c5","url":"https://api.github.com/users/kballard","html_url":"https://github.com/kballard","followers_url":"https://api.github.com/users/kballard/followers","following_url":"https://api.github.com/users/kballard/following{/other_user}","gists_url":"https://api.github.com/users/kballard/gists{/gist_id}","starred_url":"https://api.github.com/users/kballard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kballard/subscriptions","organizations_url":"https://api.github.com/users/kballard/orgs","repos_url":"https://api.github.com/users/kballard/repos","events_url":"https://api.github.com/users/kballard/events{/privacy}","received_events_url":"https://api.github.com/users/kballard/received_events","type":"User","site_admin":false},"body":"These match arms need braces. They're on a second line, and [our style](http://aturon.github.io/style/braces.html#match-arms-get-braces,-except-for-single-line-expressions.-[rfc]) says only use match arms for single-line expressions.","created_at":"2014-08-04T05:40:08Z","updated_at":"2014-08-04T05:40:08Z","html_url":"https://github.com/rust-lang/rust/pull/16230#discussion_r15741194","pull_request_url":"https://api.github.com/repos/rust-lang/rust/pulls/16230","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/15741194"},"html":{"href":"https://github.com/rust-lang/rust/pull/16230#discussion_r15741194"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/16230"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/16230","id":19261579,"html_url":"https://github.com/rust-lang/rust/pull/16230","diff_url":"https://github.com/rust-lang/rust/pull/16230.diff","patch_url":"https://github.com/rust-lang/rust/pull/16230.patch","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/16230","number":16230,"state":"open","title":"Add a cfg_attr syntax extension","user":{"login":"sfackler","id":1455697,"avatar_url":"https://avatars.githubusercontent.com/u/1455697?v=1","gravatar_id":"084245accd7db8465b8a221ae08e2127","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"body":"This extends cfg-gating to attributes.\r\n\r\n```rust\r\n#[cfg_attr(<cfg pattern>, <attr>)]\r\n```\r\nwill expand to\r\n```rust\r\n#[<attr>]\r\n```\r\nif the `<cfg pattern>` matches the current cfg environment, and nothing\r\nif it does not. The grammar for the cfg pattern has a simple\r\nrecursive structure:\r\n\r\n * `value` and `key = \"value\"` are cfg patterns,\r\n * `not(<cfg pattern>)` is a cfg pattern and matches if `<cfg pattern>`\r\n    does not.\r\n * `all(<cfg pattern>, ...)` is a cfg pattern and matches if all of the\r\n    `<cfg pattern>`s do.\r\n * `any(<cfg pattern>, ...)` is a cfg pattern and matches if any of the\r\n    `<cfg pattern>`s do.\r\n\r\nExamples:\r\n\r\n```rust\r\n// only derive Show for assert_eq! in tests\r\n#[cfg_attr(test, deriving(Show))]\r\nstruct Foo { ... }\r\n\r\n// only derive Show for assert_eq! in tests and debug builds\r\n#[cfg_attr(any(test, not(ndebug)), deriving(Show))]\r\nstruct Foo { ... }\r\n\r\n// ignore a test in certain cases\r\n#[test]\r\n#[cfg_attr(all(not(target_os = \"linux\"), target_endian = \"big\"), ignore)]\r\nfn test_broken_thing() { ... }\r\n\r\n// Avoid duplication when fixing staging issues in rustc\r\n#[cfg_attr(not(stage0), lang=\"iter\")]\r\npub trait Iterator<T> { ... }\r\n```\r\n\r\nI also deprecated the `#[ignore(cfg(...))]` syntax in favor of `#[cfg_attr(..., ignore)]`.\r\n\r\nI think this cfg pattern syntax is a good system to move `#[cfg(...)]` to as well, but that should probably go through an RFC first.","created_at":"2014-08-04T00:59:24Z","updated_at":"2014-08-04T05:40:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8d6868259308a586367a75466ab18d5dd2be94f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/rust/pulls/16230/commits","review_comments_url":"https://api.github.com/repos/rust-lang/rust/pulls/16230/comments","review_comment_url":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/16230/comments","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/26322100172cf92812846b7959659bd2fd7ea553","head":{"label":"sfackler:cfg-attr","ref":"cfg-attr","sha":"26322100172cf92812846b7959659bd2fd7ea553","user":{"login":"sfackler","id":1455697,"avatar_url":"https://avatars.githubusercontent.com/u/1455697?v=1","gravatar_id":"084245accd7db8465b8a221ae08e2127","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"repo":{"id":10324482,"name":"rust","full_name":"sfackler/rust","owner":{"login":"sfackler","id":1455697,"avatar_url":"https://avatars.githubusercontent.com/u/1455697?v=1","gravatar_id":"084245accd7db8465b8a221ae08e2127","url":"https://api.github.com/users/sfackler","html_url":"https://github.com/sfackler","followers_url":"https://api.github.com/users/sfackler/followers","following_url":"https://api.github.com/users/sfackler/following{/other_user}","gists_url":"https://api.github.com/users/sfackler/gists{/gist_id}","starred_url":"https://api.github.com/users/sfackler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfackler/subscriptions","organizations_url":"https://api.github.com/users/sfackler/orgs","repos_url":"https://api.github.com/users/sfackler/repos","events_url":"https://api.github.com/users/sfackler/events{/privacy}","received_events_url":"https://api.github.com/users/sfackler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sfackler/rust","description":"a safe, concurrent, practical language","fork":true,"url":"https://api.github.com/repos/sfackler/rust","forks_url":"https://api.github.com/repos/sfackler/rust/forks","keys_url":"https://api.github.com/repos/sfackler/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sfackler/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sfackler/rust/teams","hooks_url":"https://api.github.com/repos/sfackler/rust/hooks","issue_events_url":"https://api.github.com/repos/sfackler/rust/issues/events{/number}","events_url":"https://api.github.com/repos/sfackler/rust/events","assignees_url":"https://api.github.com/repos/sfackler/rust/assignees{/user}","branches_url":"https://api.github.com/repos/sfackler/rust/branches{/branch}","tags_url":"https://api.github.com/repos/sfackler/rust/tags","blobs_url":"https://api.github.com/repos/sfackler/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sfackler/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sfackler/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/sfackler/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sfackler/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/sfackler/rust/languages","stargazers_url":"https://api.github.com/repos/sfackler/rust/stargazers","contributors_url":"https://api.github.com/repos/sfackler/rust/contributors","subscribers_url":"https://api.github.com/repos/sfackler/rust/subscribers","subscription_url":"https://api.github.com/repos/sfackler/rust/subscription","commits_url":"https://api.github.com/repos/sfackler/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/sfackler/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/sfackler/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/sfackler/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/sfackler/rust/contents/{+path}","compare_url":"https://api.github.com/repos/sfackler/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sfackler/rust/merges","archive_url":"https://api.github.com/repos/sfackler/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sfackler/rust/downloads","issues_url":"https://api.github.com/repos/sfackler/rust/issues{/number}","pulls_url":"https://api.github.com/repos/sfackler/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/sfackler/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/sfackler/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sfackler/rust/labels{/name}","releases_url":"https://api.github.com/repos/sfackler/rust/releases{/id}","created_at":"2013-05-27T23:45:53Z","updated_at":"2014-06-19T06:28:07Z","pushed_at":"2014-08-04T00:59:48Z","git_url":"git://github.com/sfackler/rust.git","ssh_url":"git@github.com:sfackler/rust.git","clone_url":"https://github.com/sfackler/rust.git","svn_url":"https://github.com/sfackler/rust","homepage":"http://www.rust-lang.org","size":148062,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"d34e011b8e4b7df4433aaf32ea42e36a577a6386","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=1","gravatar_id":"a4268b59e433144466a0f67cbcfd8cdc","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":724712,"name":"rust","full_name":"rust-lang/rust","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=1","gravatar_id":"a4268b59e433144466a0f67cbcfd8cdc","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/rust","description":"a safe, concurrent, practical language","fork":false,"url":"https://api.github.com/repos/rust-lang/rust","forks_url":"https://api.github.com/repos/rust-lang/rust/forks","keys_url":"https://api.github.com/repos/rust-lang/rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/rust/teams","hooks_url":"https://api.github.com/repos/rust-lang/rust/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/rust/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/rust/events","assignees_url":"https://api.github.com/repos/rust-lang/rust/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/rust/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/rust/tags","blobs_url":"https://api.github.com/repos/rust-lang/rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/rust/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/rust/languages","stargazers_url":"https://api.github.com/repos/rust-lang/rust/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/rust/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/rust/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/rust/subscription","commits_url":"https://api.github.com/repos/rust-lang/rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/rust/issues/comments/{number}","contents_url":"https://api.github.com/repos/rust-lang/rust/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/rust/merges","archive_url":"https://api.github.com/repos/rust-lang/rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/rust/downloads","issues_url":"https://api.github.com/repos/rust-lang/rust/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/rust/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/rust/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/rust/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/rust/releases{/id}","created_at":"2010-06-16T20:39:03Z","updated_at":"2014-08-04T03:22:10Z","pushed_at":"2014-08-04T05:16:36Z","git_url":"git://github.com/rust-lang/rust.git","ssh_url":"git@github.com:rust-lang/rust.git","clone_url":"https://github.com/rust-lang/rust.git","svn_url":"https://github.com/rust-lang/rust","homepage":"http://www.rust-lang.org","size":421395,"stargazers_count":5955,"watchers_count":5955,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1205,"mirror_url":null,"open_issues_count":1784,"forks":1205,"open_issues":1784,"watchers":5955,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/16230"},"html":{"href":"https://github.com/rust-lang/rust/pull/16230"},"issue":{"href":"https://api.github.com/repos/rust-lang/rust/issues/16230"},"comments":{"href":"https://api.github.com/repos/rust-lang/rust/issues/16230/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/16230/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/rust/pulls/16230/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/rust/statuses/26322100172cf92812846b7959659bd2fd7ea553"}}}}