@@ -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 under-constrains the type, it defaults to the
346
+ * If the program context underconstrains the type, it defaults to the
347
347
signed 32-bit integer ` i32 ` .
348
348
349
- * If the program context over-constrains the type, it is considered a
349
+ * If the program context overconstrains 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 under-constrains the type, it defaults to ` f64 ` .
385
+ * If the program context underconstrains the type, it defaults to ` f64 ` .
386
386
387
- * If the program context over-constrains the type, it is considered a
387
+ * If the program context overconstrains 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 thread-safe access.
1295
+ * The types of static values must ascribe to ` Sync ` to allow threadsafe 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,6 +1957,8 @@ 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.
1960
1962
- ` simd ` - on certain tuple structs, derive the arithmetic operators, which
1961
1963
lower to the target's SIMD instructions, if any; the ` simd ` feature gate
1962
1964
is necessary to use this attribute.
@@ -3661,71 +3663,47 @@ sites are:
3661
3663
3662
3664
* ` let ` statements where an explicit type is given.
3663
3665
3664
- For example, ` 128 ` is coerced to have type ` i8 ` in the following:
3665
-
3666
- ``` rust
3667
- let _ : i8 = 128 ;
3668
- ```
3666
+ In ` let _: U = e; ` , ` e ` is coerced to have type ` U ` .
3669
3667
3670
3668
* ` static ` and ` const ` statements (similar to ` let ` statements).
3671
3669
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 ) { }
3670
+ * arguments for function calls.
3681
3671
3682
- fn main () {
3683
- bar ( 128 );
3684
- }
3685
- ```
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 ` ;
3686
3676
3687
- * Instantiations of struct or variant fields
3677
+ * instantiations of struct or variant fields.
3688
3678
3689
- For example, ` 128 ` is coerced to have type ` i8 ` in the following:
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 ` .
3690
3682
3691
- ``` rust
3692
- struct Foo { x : i8 }
3683
+ * function results (either the final line of a block if it is not semicolon
3684
+ terminated or any expression in a ` return ` statement).
3693
3685
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
- ```
3686
+ In `fn foo() -> U { e }`, `e` is coerced to to have type `U`.
3709
3687
3710
3688
If the expression in one of these coercion sites is a coercion-propagating
3711
3689
expression, then the relevant sub-expressions in that expression are also
3712
3690
coercion sites. Propagation recurses from these new coercion sites.
3713
3691
Propagating expressions and their relevant sub-expressions are:
3714
3692
3715
- * Array literals, where the array has type ` [U; n] ` . Each sub-expression in
3693
+ * array literals, where the array has type ` [U; n] ` . Each sub-expression in
3716
3694
the array literal is a coercion site for coercion to type ` U ` .
3717
3695
3718
- * Array literals with repeating syntax, where the array has type ` [U; n] ` . The
3696
+ * array literals with repeating syntax, where the array has type ` [U; n] ` . The
3719
3697
repeated sub-expression is a coercion site for coercion to type ` U ` .
3720
3698
3721
- * Tuples , where a tuple is a coercion site to type ` (U_0, U_1, ..., U_n) ` .
3699
+ * tuples , where a tuple is a coercion site to type ` (U_0, U_1, ..., U_n) ` .
3722
3700
Each sub-expression is a coercion site to the respective type, e.g. the
3723
3701
zeroth sub-expression is a coercion site to type ` U_0 ` .
3724
3702
3725
- * Parenthesised sub-expressions (` (e) ` ): if the expression has type ` U ` , then
3703
+ * parenthesised sub-expressions (` (e) ` ). If the expression has type ` U ` , then
3726
3704
the sub-expression is a coercion site to ` U ` .
3727
3705
3728
- * Blocks: if a block has type ` U ` , then the last expression in the block (if
3706
+ * blocks. If a block has type ` U ` , then the last expression in the block (if
3729
3707
it is not semicolon-terminated) is a coercion site to ` U ` . This includes
3730
3708
blocks which are part of control flow statements, such as ` if ` /` else ` , if
3731
3709
the block has a known type.
@@ -3734,46 +3712,45 @@ the block has a known type.
3734
3712
3735
3713
Coercion is allowed between the following types:
3736
3714
3737
- * ` T ` to ` U ` if ` T ` is a subtype of ` U ` (* reflexive case* )
3715
+ * ` T ` to ` U ` if ` T ` is a subtype of ` U ` (* reflexive case* ).
3738
3716
3739
3717
* ` T_1 ` to ` T_3 ` where ` T_1 ` coerces to ` T_2 ` and ` T_2 ` coerces to ` T_3 `
3740
- (* transitive case* )
3718
+ (* transitive case* ).
3741
3719
3742
3720
Note that this is not fully supported yet
3743
3721
3744
- * ` &mut T ` to ` &T `
3722
+ * ` &mut T ` to ` &T ` .
3745
3723
3746
- * ` *mut T ` to ` *const T `
3724
+ * ` *mut T ` to ` *const T ` .
3747
3725
3748
- * ` &T ` to ` *const T `
3726
+ * ` &T ` to ` *const T ` .
3749
3727
3750
- * ` &mut T ` to ` *mut T `
3728
+ * ` &mut T ` to ` *mut T ` .
3751
3729
3752
3730
* ` &T ` to ` &U ` if ` T ` implements ` Deref<Target = U> ` . For example:
3753
3731
3754
- ``` rust
3755
- use std :: ops :: Deref ;
3756
-
3757
- struct CharContainer {
3758
- value : char
3759
- }
3732
+ ``` rust
3733
+ use std :: ops :: Deref ;
3760
3734
3761
- impl Deref for CharContainer {
3762
- type Target = char ;
3735
+ struct CharContainer {
3736
+ value : char
3737
+ }
3763
3738
3764
- fn deref <'a >(& 'a self ) -> & 'a char {
3765
- & self . value
3766
- }
3767
- }
3739
+ impl Deref for CharContainer {
3740
+ type Target = char ;
3768
3741
3769
- fn foo (arg : & char ) {}
3742
+ fn deref <'a >(& 'a self ) -> & 'a char {
3743
+ & self . value
3744
+ }
3745
+ }
3770
3746
3771
- fn main () {
3772
- let x = & mut CharContainer { value : 'y' };
3773
- foo (x ); // &mut CharContainer is coerced to &char.
3774
- }
3775
- ```
3747
+ fn foo (arg : & char ) {}
3776
3748
3749
+ fn main () {
3750
+ let x = & mut CharContainer { value : 'y' };
3751
+ foo (x ); // &mut CharContainer is coerced to &char.
3752
+ }
3753
+ ```
3777
3754
* ` &mut T ` to ` &mut U ` if ` T ` implements ` DerefMut<Target = U> ` .
3778
3755
3779
3756
* TyCtor(` T ` ) to TyCtor(coerce_inner(` T ` )), where TyCtor(` T ` ) is one of
@@ -3987,7 +3964,7 @@ In general, `--crate-type=bin` or `--crate-type=lib` should be sufficient for
3987
3964
all compilation needs, and the other options are just available if more
3988
3965
fine-grained control is desired over the output format of a Rust crate.
3989
3966
3990
- # Appendix: Rationales and design trade-offs
3967
+ # Appendix: Rationales and design tradeoffs
3991
3968
3992
3969
* TODO* .
3993
3970
@@ -3997,7 +3974,7 @@ Rust is not a particularly original language, with design elements coming from
3997
3974
a wide range of sources. Some of these are listed below (including elements
3998
3975
that have since been removed):
3999
3976
4000
- * SML, OCaml: algebraic data types , pattern matching, type inference,
3977
+ * SML, OCaml: algebraic datatypes , pattern matching, type inference,
4001
3978
semicolon statement separation
4002
3979
* C++: references, RAII, smart pointers, move semantics, monomorphisation,
4003
3980
memory model
0 commit comments