{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/29850","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/29850/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/29850/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/29850/events","html_url":"https://github.com/rust-lang/rust/pull/29850","id":117026933,"number":29850,"title":"Implements RFC 16, attributes on statements and expressions.","user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"pnkfelix","id":173127,"avatar_url":"https://avatars.githubusercontent.com/u/173127?v=3","gravatar_id":"","url":"https://api.github.com/users/pnkfelix","html_url":"https://github.com/pnkfelix","followers_url":"https://api.github.com/users/pnkfelix/followers","following_url":"https://api.github.com/users/pnkfelix/following{/other_user}","gists_url":"https://api.github.com/users/pnkfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/pnkfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnkfelix/subscriptions","organizations_url":"https://api.github.com/users/pnkfelix/orgs","repos_url":"https://api.github.com/users/pnkfelix/repos","events_url":"https://api.github.com/users/pnkfelix/events{/privacy}","received_events_url":"https://api.github.com/users/pnkfelix/received_events","type":"User","site_admin":false},"milestone":null,"comments":11,"created_at":"2015-11-15T23:33:57Z","updated_at":"2015-11-24T18:19:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/29850","html_url":"https://github.com/rust-lang/rust/pull/29850","diff_url":"https://github.com/rust-lang/rust/pull/29850.diff","patch_url":"https://github.com/rust-lang/rust/pull/29850.patch"},"body":"See https://github.com/rust-lang/rfcs/pull/16 and https://github.com/rust-lang/rust/issues/15701\r\n\r\n- Added syntax support for attributes on expressions and all syntax nodes in statement position.\r\n- Extended `#[cfg]` folder to allow removal of statements, and\r\nof expressions in optional positions like expression lists and trailing\r\nblock expressions.\r\n- Extended lint checker to recognize lint levels on expressions and\r\nlocals.\r\n- As per RFC, attributes are not yet accepted on `if` expressions.\r\n\r\nExamples:\r\n  ```rust\r\n#[cfg(unset)]\r\nlet x = y;\r\n#[cfg(unset)]\r\n{\r\n        ...\r\n}\r\nassert_eq!((1, #[cfg(unset)] 2, 3), (1, 3));\r\n\r\n#[allow(non_snake_case_name)]\r\nlet FOO = 0;\r\n```\r\n\r\nImplementation wise, there are a few rough corners and open questions:\r\n- The parser work ended up a bit ugly.\r\n- The pretty printer change was based mostly on guessing.\r\n- Similar to the `if` case, there are some places in the grammar where a new `Expr` node starts,\r\n  but where it seemed weird to accept attributes and hence the parser doesn't. This includes:\r\n  - const expressions in patterns\r\n  - in the middle of an postfix operator chain (that is, after `.`, before indexing, before calls)\r\n  - on range expressions, since `#[attr] x .. y` parses as  `(#[attr] x) .. y`, which is inconsistent with\r\n    `#[attr] .. y` which would parse as `#[attr] (.. y)`\r\n- Attributes are added as additional `Option<Box<Vec<Attribute>>>` fields in expressions and locals.\r\n- Memory impact has not been measured yet.\r\n- A cfg-away trailing expression in a block does not currently promote the previous `StmtExpr` in a block to a new trailing expr. That is to say, this won't work:\r\n```rust\r\nlet x = {\r\n    #[cfg(foo)]\r\n    Foo { data: x }\r\n    #[cfg(not(foo))]\r\n    Foo { data: y }\r\n};\r\n```\r\n- One-element tuples can have their inner expression removed to become Unit, but just Parenthesis can't. Eg, `(#[cfg(unset)] x,) == ()` but `(#[cfg(unset)] x) == error`. This seemed reasonable to me since tuples and unit are type constructors, but could probably be argued either way.\r\n- Attributes on macro nodes are currently unconditionally dropped during macro expansion, which seemed fine since macro disappear at that point?\r\n- Attributes on `ast::ExprParens` will be prepend-ed to the inner expression in the hir folder.\r\n- The work on pretty printer tests for this did trigger, but not fix errors regarding macros:\r\n  - expression `foo![]` prints as `foo!()` \r\n  - expression `foo!{}` prints as `foo!()` \r\n  - statement `foo![];` prints as `foo!();` \r\n  - statement `foo!{};` prints as `foo!();` \r\n  - statement `foo!{}` triggers a `None` unwrap ICE.\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/159361443","html_url":"https://github.com/rust-lang/rust/pull/29850#issuecomment-159361443","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/29850","id":159361443,"user":{"login":"Kimundi","id":2903206,"avatar_url":"https://avatars.githubusercontent.com/u/2903206?v=3","gravatar_id":"","url":"https://api.github.com/users/Kimundi","html_url":"https://github.com/Kimundi","followers_url":"https://api.github.com/users/Kimundi/followers","following_url":"https://api.github.com/users/Kimundi/following{/other_user}","gists_url":"https://api.github.com/users/Kimundi/gists{/gist_id}","starred_url":"https://api.github.com/users/Kimundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kimundi/subscriptions","organizations_url":"https://api.github.com/users/Kimundi/orgs","repos_url":"https://api.github.com/users/Kimundi/repos","events_url":"https://api.github.com/users/Kimundi/events{/privacy}","received_events_url":"https://api.github.com/users/Kimundi/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T18:19:47Z","updated_at":"2015-11-24T18:19:47Z","body":"Okay, I added the feature gate and rebased on upstream changes.\r\n\r\n@durka I tested the macro case, and `$e:expr` rather than `#[attr:meta] $e:expr` gets picked. Not sure how/if to handle that differently though..."}}