]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #39459 - phungleson:fix-short-hand-struct-doc, r=steveklabnik
authorCorey Farwell <coreyf@rwell.org>
Wed, 8 Feb 2017 03:54:26 +0000 (22:54 -0500)
committerGitHub <noreply@github.com>
Wed, 8 Feb 2017 03:54:26 +0000 (22:54 -0500)
Fix short hand struct doc

Don't want to discredit @hngiang effort on this issue.

I just want to lend a hand to fix this issue #38830, it is a very nice feature and is seemingly completed.

Fixes #39096

r? @steveklabnik

1  2 
src/doc/reference.md

diff --combined src/doc/reference.md
index 97ff1c7598f52010c5101b0d3297c96504bc77e1,8139a712bddb25e7c9cdd71adf8621f03df32e41..f9013490418f3da598ef9bfe112411d5b0a2e9d6
@@@ -2114,15 -2114,10 +2114,15 @@@ Sometimes one wants to have different c
  depending on build target, such as targeted operating system, or to enable
  release builds.
  
 -There are two kinds of configuration options, one that is either defined or not
 -(`#[cfg(foo)]`), and the other that contains a string that can be checked
 -against (`#[cfg(bar = "baz")]`). Currently, only compiler-defined configuration
 -options can have the latter form.
 +Configuration options are boolean (on or off) and are named either with a
 +single identifier (e.g. `foo`) or an identifier and a string (e.g. `foo = "bar"`;
 +the quotes are required and spaces around the `=` are unimportant). Note that
 +similarly-named options, such as `foo`, `foo="bar"` and `foo="baz"` may each be set
 +or unset independently.
 +
 +Configuration options are either provided by the compiler or passed in on the
 +command line using `--cfg` (e.g. `rustc main.rs --cfg foo --cfg 'bar="baz"'`).
 +Rust code then checks for their presence using the `#[cfg(...)]` attribute:
  
  ```
  // The function is only included in the build when compiling for OSX
@@@ -2201,10 -2196,7 +2201,10 @@@ You can also set another attribute base
  #[cfg_attr(a, b)]
  ```
  
 -Will be the same as `#[b]` if `a` is set by `cfg`, and nothing otherwise.
 +This is the same as `#[b]` if `a` is set by `cfg`, and nothing otherwise.
 +
 +Lastly, configuration options can be used in expressions by invoking the `cfg!`
 +macro: `cfg!(a)` evaluates to `true` if `a` is set, and `false` otherwise.
  
  ### Lint check attributes
  
@@@ -2765,6 -2757,28 +2765,28 @@@ let base = Point3d {x: 1, y: 2, z: 3}
  Point3d {y: 0, z: 10, .. base};
  ```
  
+ #### Struct field init shorthand
+ When initializing a data structure (struct, enum, union) with named fields,
+ allow writing `fieldname` as a shorthand for `fieldname: fieldname`. This
+ allows a compact syntax for initialization, with less duplication.
+ In the initializer for a `struct` with named fields, a `union` with named
+ fields, or an enum variant with named fields, accept an identifier `field` as a
+ shorthand for `field: field`.
+ Example:
+ ```
+ # #![feature(field_init_shorthand)]
+ # struct Point3d { x: i32, y: i32, z: i32 }
+ # let x = 0;
+ # let y_value = 0;
+ # let z = 0;
+ Point3d { x: x, y: y_value, z: z };
+ Point3d { x, y: y_value, z };
+ ```
  ### Block expressions
  
  A _block expression_ is similar to a module in terms of the declarations that