diff options
| author | bors <bors@rust-lang.org> | 2017-01-12 20:44:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-01-12 20:44:02 +0000 |
| commit | e35717814686ea3e3d44a8f5c1c20d1cd50be82a (patch) | |
| tree | 1b4d764f36a18863999d7c2f5b4f3642d63b837f /src/libsyntax/fold.rs | |
| parent | 27b9e6d450590751fca863312a8cf10f289cf1f2 (diff) | |
| parent | 7972c1905beb9d1169475f42231b25d0bc9e83e6 (diff) | |
| download | rust-e35717814686ea3e3d44a8f5c1c20d1cd50be82a.tar.gz rust-e35717814686ea3e3d44a8f5c1c20d1cd50be82a.zip | |
Auto merge of #38814 - Ralith:cfg-fields, r=jseyfried
syntax: enable attributes and cfg on struct fields
This enables conditional compilation of field initializers in a struct literal, simplifying construction of structs whose fields are themselves conditionally present. For example, the intializer for the constant in the following becomes legal, and has the intuitive effect:
```rust
struct Foo {
#[cfg(unix)]
bar: (),
}
const FOO: Foo = Foo {
#[cfg(unix)]
bar: (),
};
```
It's not clear to me whether this calls for the full RFC process, but the implementation was simple enough that I figured I'd begin the conversation with code.
Diffstat (limited to 'src/libsyntax/fold.rs')
| -rw-r--r-- | src/libsyntax/fold.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 7bce00ebcab..10ca9da2112 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -830,6 +830,7 @@ pub fn noop_fold_field<T: Folder>(f: Field, folder: &mut T) -> Field { expr: folder.fold_expr(f.expr), span: folder.new_span(f.span), is_shorthand: f.is_shorthand, + attrs: fold_thin_attrs(f.attrs, folder), } } @@ -1089,6 +1090,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> { ident: folder.fold_ident(f.node.ident), pat: folder.fold_pat(f.node.pat), is_shorthand: f.node.is_shorthand, + attrs: fold_attrs(f.node.attrs.into(), folder).into() }} }); PatKind::Struct(pth, fs, etc) |
