@@ -343,10 +343,10 @@ The type of an _unsuffixed_ integer literal is determined by type inference:
343343* If an integer type can be _ uniquely_ determined from the surrounding
344344 program context, the unsuffixed integer literal has that type.
345345
346- * If the program context underconstrains the type, it defaults to the
346+ * If the program context under-constrains the type, it defaults to the
347347 signed 32-bit integer ` i32 ` .
348348
349- * If the program context overconstrains the type, it is considered a
349+ * If the program context over-constrains the type, it is considered a
350350 static type error.
351351
352352Examples of integer literals of various forms:
@@ -382,9 +382,9 @@ type inference:
382382 surrounding program context, the unsuffixed floating-point literal
383383 has that type.
384384
385- * If the program context underconstrains the type, it defaults to ` f64 ` .
385+ * If the program context under-constrains the type, it defaults to ` f64 ` .
386386
387- * If the program context overconstrains the type, it is considered a
387+ * If the program context over-constrains the type, it is considered a
388388 static type error.
389389
390390Examples of floating-point literals of various forms:
@@ -1292,7 +1292,7 @@ All access to a static is safe, but there are a number of restrictions on
12921292statics:
12931293
12941294* Statics may not contain any destructors.
1295- * The types of static values must ascribe to ` Sync ` to allow threadsafe access.
1295+ * The types of static values must ascribe to ` Sync ` to allow thread-safe access.
12961296* Statics may not refer to other statics by value, only by reference.
12971297* Constants cannot refer to statics.
12981298
@@ -1694,7 +1694,7 @@ explain, here's a few use cases and what they would entail:
16941694* A crate needs a global available "helper module" to itself, but it doesn't
16951695 want to expose the helper module as a public API. To accomplish this, the
16961696 root of the crate's hierarchy would have a private module which then
1697- internally has a "public api ". Because the entire crate is a descendant of
1697+ internally has a "public API ". Because the entire crate is a descendant of
16981698 the root, then the entire local crate can access this private module through
16991699 the second case.
17001700
@@ -1957,8 +1957,6 @@ macro scope.
19571957 object file that this item's contents will be placed into.
19581958- ` no_mangle ` - on any item, do not apply the standard name mangling. Set the
19591959 symbol for this item to its identifier.
1960- - ` packed ` - on structs or enums, eliminate any padding that would be used to
1961- align fields.
19621960- ` simd ` - on certain tuple structs, derive the arithmetic operators, which
19631961 lower to the target's SIMD instructions, if any; the ` simd ` feature gate
19641962 is necessary to use this attribute.
@@ -3663,47 +3661,71 @@ sites are:
36633661
36643662* ` let ` statements where an explicit type is given.
36653663
3666- In ` let _: U = e; ` , ` e ` is coerced to have type ` U ` .
3664+ For example, ` 128 ` is coerced to have type ` i8 ` in the following:
3665+
3666+ ``` rust
3667+ let _ : i8 = 128 ;
3668+ ```
36673669
36683670* ` static ` and ` const ` statements (similar to ` let ` statements).
36693671
3670- * arguments for function calls.
3672+ * Arguments for function calls
3673+
3674+ The value being coerced is the actual parameter, and it is coerced to
3675+ the type of the formal parameter.
3676+
3677+ For example, ` 128 ` is coerced to have type ` i8 ` in the following:
3678+
3679+ ``` rust
3680+ fn bar (_ : i8 ) { }
36713681
3672- The value being coerced is the
3673- actual parameter and it is coerced to the type of the formal parameter. For
3674- example, let ` foo ` be defined as ` fn foo(x: U) { ... } ` and call it as
3675- ` foo(e); ` . Then ` e ` is coerced to have type ` U ` ;
3682+ fn main () {
3683+ bar ( 128 );
3684+ }
3685+ ```
36763686
3677- * instantiations of struct or variant fields.
3687+ * Instantiations of struct or variant fields
36783688
3679- Assume we have a `struct
3680- Foo { x: U }` and instantiate it as ` Foo { x: e }` . Then ` e` is coerced to
3681- have type ` U ` .
3689+ For example, ` 128 ` is coerced to have type ` i8 ` in the following:
36823690
3683- * function results (either the final line of a block if it is not semicolon
3684- terminated or any expression in a ` return ` statement).
3691+ ``` rust
3692+ struct Foo { x : i8 }
36853693
3686- In `fn foo() -> U { e }`, `e` is coerced to to have type `U`.
3694+ fn main () {
3695+ Foo { x : 128 };
3696+ }
3697+ ```
3698+
3699+ * Function results, either the final line of a block if it is not
3700+ semicolon-terminated or any expression in a ` return ` statement
3701+
3702+ For example, ` 128 ` is coerced to have type ` i8 ` in the following:
3703+
3704+ ``` rust
3705+ fn foo () -> i8 {
3706+ 128
3707+ }
3708+ ```
36873709
36883710If the expression in one of these coercion sites is a coercion-propagating
36893711expression, then the relevant sub-expressions in that expression are also
36903712coercion sites. Propagation recurses from these new coercion sites.
36913713Propagating expressions and their relevant sub-expressions are:
36923714
3693- * array literals, where the array has type ` [U; n] ` . Each sub-expression in
3715+ * Array literals, where the array has type ` [U; n] ` . Each sub-expression in
36943716the array literal is a coercion site for coercion to type ` U ` .
36953717
3696- * array literals with repeating syntax, where the array has type ` [U; n] ` . The
3718+ * Array literals with repeating syntax, where the array has type ` [U; n] ` . The
36973719repeated sub-expression is a coercion site for coercion to type ` U ` .
36983720
3699- * tuples , where a tuple is a coercion site to type ` (U_0, U_1, ..., U_n) ` .
3721+ * Tuples , where a tuple is a coercion site to type ` (U_0, U_1, ..., U_n) ` .
37003722Each sub-expression is a coercion site to the respective type, e.g. the
37013723zeroth sub-expression is a coercion site to type ` U_0 ` .
37023724
3703- * parenthesised sub-expressions (` (e) ` ). If the expression has type ` U ` , then
3725+ * Parenthesised sub-expressions (` (e) ` ): if the expression has type ` U ` , then
37043726the sub-expression is a coercion site to ` U ` .
37053727
3706- * blocks. If a block has type ` U ` , then the last expression in the block (if
3728+ * Blocks: if a block has type ` U ` , then the last expression in the block (if
37073729it is not semicolon-terminated) is a coercion site to ` U ` . This includes
37083730blocks which are part of control flow statements, such as ` if ` /` else ` , if
37093731the block has a known type.
@@ -3712,45 +3734,46 @@ the block has a known type.
37123734
37133735Coercion is allowed between the following types:
37143736
3715- * ` T ` to ` U ` if ` T ` is a subtype of ` U ` (* reflexive case* ).
3737+ * ` T ` to ` U ` if ` T ` is a subtype of ` U ` (* reflexive case* )
37163738
37173739* ` T_1 ` to ` T_3 ` where ` T_1 ` coerces to ` T_2 ` and ` T_2 ` coerces to ` T_3 `
3718- (* transitive case* ).
3740+ (* transitive case* )
37193741
37203742 Note that this is not fully supported yet
37213743
3722- * ` &mut T ` to ` &T ` .
3744+ * ` &mut T ` to ` &T `
37233745
3724- * ` *mut T ` to ` *const T ` .
3746+ * ` *mut T ` to ` *const T `
37253747
3726- * ` &T ` to ` *const T ` .
3748+ * ` &T ` to ` *const T `
37273749
3728- * ` &mut T ` to ` *mut T ` .
3750+ * ` &mut T ` to ` *mut T `
37293751
37303752* ` &T ` to ` &U ` if ` T ` implements ` Deref<Target = U> ` . For example:
37313753
3732- ``` rust
3733- use std :: ops :: Deref ;
3754+ ``` rust
3755+ use std :: ops :: Deref ;
37343756
3735- struct CharContainer {
3736- value : char
3737- }
3757+ struct CharContainer {
3758+ value : char
3759+ }
37383760
3739- impl Deref for CharContainer {
3740- type Target = char ;
3761+ impl Deref for CharContainer {
3762+ type Target = char ;
37413763
3742- fn deref <'a >(& 'a self ) -> & 'a char {
3743- & self . value
3744- }
3745- }
3764+ fn deref <'a >(& 'a self ) -> & 'a char {
3765+ & self . value
3766+ }
3767+ }
37463768
3747- fn foo (arg : & char ) {}
3769+ fn foo (arg : & char ) {}
3770+
3771+ fn main () {
3772+ let x = & mut CharContainer { value : 'y' };
3773+ foo (x ); // &mut CharContainer is coerced to &char.
3774+ }
3775+ ```
37483776
3749- fn main () {
3750- let x = & mut CharContainer { value : 'y' };
3751- foo (x ); // &mut CharContainer is coerced to &char.
3752- }
3753- ```
37543777* ` &mut T ` to ` &mut U ` if ` T ` implements ` DerefMut<Target = U> ` .
37553778
37563779* TyCtor(` T ` ) to TyCtor(coerce_inner(` T ` )), where TyCtor(` T ` ) is one of
@@ -3964,7 +3987,7 @@ In general, `--crate-type=bin` or `--crate-type=lib` should be sufficient for
39643987all compilation needs, and the other options are just available if more
39653988fine-grained control is desired over the output format of a Rust crate.
39663989
3967- # Appendix: Rationales and design tradeoffs
3990+ # Appendix: Rationales and design trade-offs
39683991
39693992* TODO* .
39703993
@@ -3974,7 +3997,7 @@ Rust is not a particularly original language, with design elements coming from
39743997a wide range of sources. Some of these are listed below (including elements
39753998that have since been removed):
39763999
3977- * SML, OCaml: algebraic datatypes , pattern matching, type inference,
4000+ * SML, OCaml: algebraic data types , pattern matching, type inference,
39784001 semicolon statement separation
39794002* C++: references, RAII, smart pointers, move semantics, monomorphisation,
39804003 memory model
0 commit comments