@@ -343,10 +343,10 @@ The type of an _unsuffixed_ integer literal is determined by type inference:
343
343
* If an integer type can be _ uniquely_ determined from the surrounding
344
344
program context, the unsuffixed integer literal has that type.
345
345
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
347
347
signed 32-bit integer ` i32 ` .
348
348
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
350
350
static type error.
351
351
352
352
Examples of integer literals of various forms:
@@ -382,9 +382,9 @@ type inference:
382
382
surrounding program context, the unsuffixed floating-point literal
383
383
has that type.
384
384
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 ` .
386
386
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
388
388
static type error.
389
389
390
390
Examples 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
1292
1292
statics:
1293
1293
1294
1294
* 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.
1296
1296
* Statics may not refer to other statics by value, only by reference.
1297
1297
* Constants cannot refer to statics.
1298
1298
@@ -1694,7 +1694,7 @@ explain, here's a few use cases and what they would entail:
1694
1694
* A crate needs a global available "helper module" to itself, but it doesn't
1695
1695
want to expose the helper module as a public API. To accomplish this, the
1696
1696
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
1698
1698
the root, then the entire local crate can access this private module through
1699
1699
the second case.
1700
1700
@@ -1957,8 +1957,6 @@ macro scope.
1957
1957
object file that this item's contents will be placed into.
1958
1958
- ` no_mangle ` - on any item, do not apply the standard name mangling. Set the
1959
1959
symbol for this item to its identifier.
1960
- - ` packed ` - on structs or enums, eliminate any padding that would be used to
1961
- align fields.
1962
1960
- ` simd ` - on certain tuple structs, derive the arithmetic operators, which
1963
1961
lower to the target's SIMD instructions, if any; the ` simd ` feature gate
1964
1962
is necessary to use this attribute.
@@ -3663,47 +3661,71 @@ sites are:
3663
3661
3664
3662
* ` let ` statements where an explicit type is given.
3665
3663
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
+ ```
3667
3669
3668
3670
* ` static ` and ` const ` statements (similar to ` let ` statements).
3669
3671
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 ) { }
3671
3681
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
+ ```
3676
3686
3677
- * instantiations of struct or variant fields.
3687
+ * Instantiations of struct or variant fields
3678
3688
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:
3682
3690
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 }
3685
3693
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
+ ```
3687
3709
3688
3710
If the expression in one of these coercion sites is a coercion-propagating
3689
3711
expression, then the relevant sub-expressions in that expression are also
3690
3712
coercion sites. Propagation recurses from these new coercion sites.
3691
3713
Propagating expressions and their relevant sub-expressions are:
3692
3714
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
3694
3716
the array literal is a coercion site for coercion to type ` U ` .
3695
3717
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
3697
3719
repeated sub-expression is a coercion site for coercion to type ` U ` .
3698
3720
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) ` .
3700
3722
Each sub-expression is a coercion site to the respective type, e.g. the
3701
3723
zeroth sub-expression is a coercion site to type ` U_0 ` .
3702
3724
3703
- * parenthesised sub-expressions (` (e) ` ). If the expression has type ` U ` , then
3725
+ * Parenthesised sub-expressions (` (e) ` ): if the expression has type ` U ` , then
3704
3726
the sub-expression is a coercion site to ` U ` .
3705
3727
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
3707
3729
it is not semicolon-terminated) is a coercion site to ` U ` . This includes
3708
3730
blocks which are part of control flow statements, such as ` if ` /` else ` , if
3709
3731
the block has a known type.
@@ -3712,45 +3734,46 @@ the block has a known type.
3712
3734
3713
3735
Coercion is allowed between the following types:
3714
3736
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* )
3716
3738
3717
3739
* ` 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* )
3719
3741
3720
3742
Note that this is not fully supported yet
3721
3743
3722
- * ` &mut T ` to ` &T ` .
3744
+ * ` &mut T ` to ` &T `
3723
3745
3724
- * ` *mut T ` to ` *const T ` .
3746
+ * ` *mut T ` to ` *const T `
3725
3747
3726
- * ` &T ` to ` *const T ` .
3748
+ * ` &T ` to ` *const T `
3727
3749
3728
- * ` &mut T ` to ` *mut T ` .
3750
+ * ` &mut T ` to ` *mut T `
3729
3751
3730
3752
* ` &T ` to ` &U ` if ` T ` implements ` Deref<Target = U> ` . For example:
3731
3753
3732
- ``` rust
3733
- use std :: ops :: Deref ;
3754
+ ``` rust
3755
+ use std :: ops :: Deref ;
3734
3756
3735
- struct CharContainer {
3736
- value : char
3737
- }
3757
+ struct CharContainer {
3758
+ value : char
3759
+ }
3738
3760
3739
- impl Deref for CharContainer {
3740
- type Target = char ;
3761
+ impl Deref for CharContainer {
3762
+ type Target = char ;
3741
3763
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
+ }
3746
3768
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
+ ```
3748
3776
3749
- fn main () {
3750
- let x = & mut CharContainer { value : 'y' };
3751
- foo (x ); // &mut CharContainer is coerced to &char.
3752
- }
3753
- ```
3754
3777
* ` &mut T ` to ` &mut U ` if ` T ` implements ` DerefMut<Target = U> ` .
3755
3778
3756
3779
* 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
3964
3987
all compilation needs, and the other options are just available if more
3965
3988
fine-grained control is desired over the output format of a Rust crate.
3966
3989
3967
- # Appendix: Rationales and design tradeoffs
3990
+ # Appendix: Rationales and design trade-offs
3968
3991
3969
3992
* TODO* .
3970
3993
@@ -3974,7 +3997,7 @@ Rust is not a particularly original language, with design elements coming from
3974
3997
a wide range of sources. Some of these are listed below (including elements
3975
3998
that have since been removed):
3976
3999
3977
- * SML, OCaml: algebraic datatypes , pattern matching, type inference,
4000
+ * SML, OCaml: algebraic data types , pattern matching, type inference,
3978
4001
semicolon statement separation
3979
4002
* C++: references, RAII, smart pointers, move semantics, monomorphisation,
3980
4003
memory model
0 commit comments