5
5
This document is the primary reference for the Rust programming language. It
6
6
provides three kinds of material:
7
7
8
- - Chapters that formally define the language grammar and, for each
9
- construct, informally describe its semantics and give examples of its
10
- use.
8
+ - Chapters that informally describe each language construct and their use.
11
9
- Chapters that informally describe the memory model, concurrency model,
12
10
runtime services, linkage model and debugging facilities.
13
11
- Appendix chapters providing rationale and references to languages that
@@ -23,8 +21,11 @@ separately by extracting documentation attributes from their source code. Many
23
21
of the features that one might expect to be language features are library
24
22
features in Rust, so what you're looking for may be there, not here.
25
23
24
+ You may also be interested in the [ grammar] .
25
+
26
26
[ book ] : book/index.html
27
27
[ standard ] : std/index.html
28
+ [ grammar ] : grammar.html
28
29
29
30
# Notation
30
31
@@ -2377,21 +2378,33 @@ considered off, and using the features will result in a compiler error.
2377
2378
2378
2379
The currently implemented features of the reference compiler are:
2379
2380
2381
+ * ` advanced_slice_patterns ` - see the [ match expressions] ( #match-expressions )
2382
+ section for discussion; the exact semantics of
2383
+ slice patterns are subject to change.
2384
+
2380
2385
* ` asm ` - The ` asm! ` macro provides a means for inline assembly. This is often
2381
2386
useful, but the exact syntax for this feature along with its
2382
2387
semantics are likely to change, so this macro usage must be opted
2383
2388
into.
2384
2389
2390
+ * ` associated_types ` - Allows type aliases in traits. Experimental.
2391
+
2392
+ * ` box_patterns ` - Allows ` box ` patterns, the exact semantics of which
2393
+ is subject to change.
2394
+
2395
+ * ` box_syntax ` - Allows use of ` box ` expressions, the exact semantics of which
2396
+ is subject to change.
2397
+
2385
2398
* ` concat_idents ` - Allows use of the ` concat_idents ` macro, which is in many
2386
2399
ways insufficient for concatenating identifiers, and may be
2387
2400
removed entirely for something more wholesome.
2388
2401
2389
- * ` default_type_params ` - Allows use of default type parameters. The future of
2390
- this feature is uncertain.
2391
-
2392
2402
* ` intrinsics ` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
2393
2403
are inherently unstable and no promise about them is made.
2394
2404
2405
+ * ` int_uint ` - Allows the use of the ` int ` and ` uint ` types, which are deprecated.
2406
+ Use ` isize ` and ` usize ` instead.
2407
+
2395
2408
* ` lang_items ` - Allows use of the ` #[lang] ` attribute. Like ` intrinsics ` ,
2396
2409
lang items are inherently unstable and no promise about them
2397
2410
is made.
@@ -2410,12 +2423,33 @@ The currently implemented features of the reference compiler are:
2410
2423
* ` log_syntax ` - Allows use of the ` log_syntax ` macro attribute, which is a
2411
2424
nasty hack that will certainly be removed.
2412
2425
2426
+ * ` main ` - Allows use of the ` #[main] ` attribute, which changes the entry point
2427
+ into a Rust program. This capabiilty is subject to change.
2428
+
2429
+ * ` macro_reexport ` - Allows macros to be re-exported from one crate after being imported
2430
+ from another. This feature was originally designed with the sole
2431
+ use case of the Rust standard library in mind, and is subject to
2432
+ change.
2433
+
2413
2434
* ` non_ascii_idents ` - The compiler supports the use of non-ascii identifiers,
2414
2435
but the implementation is a little rough around the
2415
2436
edges, so this can be seen as an experimental feature
2416
2437
for now until the specification of identifiers is fully
2417
2438
fleshed out.
2418
2439
2440
+ * ` no_std ` - Allows the ` #![no_std] ` crate attribute, which disables the implicit
2441
+ ` extern crate std ` . This typically requires use of the unstable APIs
2442
+ behind the libstd "facade", such as libcore and libcollections. It
2443
+ may also cause problems when using syntax extensions, including
2444
+ ` #[derive] ` .
2445
+
2446
+ * ` on_unimplemented ` - Allows the ` #[rustc_on_unimplemented] ` attribute, which allows
2447
+ trait definitions to add specialized notes to error messages
2448
+ when an implementation was expected but not found.
2449
+
2450
+ * ` optin_builtin_traits ` - Allows the definition of default and negative trait
2451
+ implementations. Experimental.
2452
+
2419
2453
* ` plugin ` - Usage of [ compiler plugins] [ plugin ] for custom lints or syntax extensions.
2420
2454
These depend on compiler internals and are subject to change.
2421
2455
@@ -2431,8 +2465,15 @@ The currently implemented features of the reference compiler are:
2431
2465
* ` simd ` - Allows use of the ` #[simd] ` attribute, which is overly simple and
2432
2466
not the SIMD interface we want to expose in the long term.
2433
2467
2468
+ * ` simd_ffi ` - Allows use of SIMD vectors in signatures for foreign functions.
2469
+ The SIMD interface is subject to change.
2470
+
2434
2471
* ` staged_api ` - Allows usage of stability markers and ` #![staged_api] ` in a crate
2435
2472
2473
+ * ` start ` - Allows use of the ` #[start] ` attribute, which changes the entry point
2474
+ into a Rust program. This capabiilty, especially the signature for the
2475
+ annotated function, is subject to change.
2476
+
2436
2477
* ` struct_inherit ` - Allows using struct inheritance, which is barely
2437
2478
implemented and will probably be removed. Don't use this.
2438
2479
@@ -2460,18 +2501,20 @@ The currently implemented features of the reference compiler are:
2460
2501
which is considered wildly unsafe and will be
2461
2502
obsoleted by language improvements.
2462
2503
2504
+ * ` unsafe_no_drop_flag ` - Allows use of the ` #[unsafe_no_drop_flag] ` attribute,
2505
+ which removes hidden flag added to a type that
2506
+ implements the ` Drop ` trait. The design for the
2507
+ ` Drop ` flag is subject to change, and this feature
2508
+ may be removed in the future.
2509
+
2463
2510
* ` unmarked_api ` - Allows use of items within a ` #![staged_api] ` crate
2464
2511
which have not been marked with a stability marker.
2465
2512
Such items should not be allowed by the compiler to exist,
2466
2513
so if you need this there probably is a compiler bug.
2467
2514
2468
- * ` associated_types ` - Allows type aliases in traits. Experimental.
2469
-
2470
- * ` no_std ` - Allows the ` #![no_std] ` crate attribute, which disables the implicit
2471
- ` extern crate std ` . This typically requires use of the unstable APIs
2472
- behind the libstd "facade", such as libcore and libcollections. It
2473
- may also cause problems when using syntax extensions, including
2474
- ` #[derive] ` .
2515
+ * ` visible_private_types ` - Allows public APIs to expose otherwise private
2516
+ types, e.g. as the return type of a public function.
2517
+ This capability may be removed in the future.
2475
2518
2476
2519
If a feature is promoted to a language feature, then all existing programs will
2477
2520
start to receive compilation warnings about #[ feature] directives which enabled
@@ -2591,9 +2634,8 @@ of any reference that points to it.
2591
2634
2592
2635
When a [ local variable] ( #memory-slots ) is used as an
2593
2636
[ rvalue] ( #lvalues,-rvalues-and-temporaries ) the variable will either be moved
2594
- or copied, depending on its type. For types that contain [ owning
2595
- pointers] ( #pointer-types ) or values that implement the special trait ` Drop ` ,
2596
- the variable is moved. All other types are copied.
2637
+ or copied, depending on its type. All values whose type implements ` Copy ` are
2638
+ copied, all others are moved.
2597
2639
2598
2640
### Literal expressions
2599
2641
@@ -2701,9 +2743,19 @@ items can bring new names into scopes and declared items are in scope for only
2701
2743
the block itself.
2702
2744
2703
2745
A block will execute each statement sequentially, and then execute the
2704
- expression (if given). If the final expression is omitted, the type and return
2705
- value of the block are ` () ` , but if it is provided, the type and return value
2706
- of the block are that of the expression itself.
2746
+ expression (if given). If the block ends in a statement, its value is ` () ` :
2747
+
2748
+ ```
2749
+ let x: () = { println!("Hello."); };
2750
+ ```
2751
+
2752
+ If it ends in an expression, its value and type are that of the expression:
2753
+
2754
+ ```
2755
+ let x: i32 = { println!("Hello."); 5 };
2756
+
2757
+ assert_eq!(5, x);
2758
+ ```
2707
2759
2708
2760
### Method-call expressions
2709
2761
@@ -3502,9 +3554,6 @@ elements, respectively, in a parenthesized, comma-separated list.
3502
3554
Because tuple elements don't have a name, they can only be accessed by
3503
3555
pattern-matching.
3504
3556
3505
- The members of a tuple are laid out in memory contiguously, in order specified
3506
- by the tuple type.
3507
-
3508
3557
An example of a tuple type and its use:
3509
3558
3510
3559
```
0 commit comments