55This document is the primary reference for the Rust programming language. It
66provides three kinds of material:
77
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.
119 - Chapters that informally describe the memory model, concurrency model,
1210 runtime services, linkage model and debugging facilities.
1311 - Appendix chapters providing rationale and references to languages that
@@ -23,8 +21,11 @@ separately by extracting documentation attributes from their source code. Many
2321of the features that one might expect to be language features are library
2422features in Rust, so what you're looking for may be there, not here.
2523
24+ You may also be interested in the [ grammar] .
25+
2626[ book ] : book/index.html
2727[ standard ] : std/index.html
28+ [ grammar ] : grammar.html
2829
2930# Notation
3031
@@ -2377,21 +2378,33 @@ considered off, and using the features will result in a compiler error.
23772378
23782379The currently implemented features of the reference compiler are:
23792380
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+
23802385* ` asm ` - The ` asm! ` macro provides a means for inline assembly. This is often
23812386 useful, but the exact syntax for this feature along with its
23822387 semantics are likely to change, so this macro usage must be opted
23832388 into.
23842389
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+
23852398* ` concat_idents ` - Allows use of the ` concat_idents ` macro, which is in many
23862399 ways insufficient for concatenating identifiers, and may be
23872400 removed entirely for something more wholesome.
23882401
2389- * ` default_type_params ` - Allows use of default type parameters. The future of
2390- this feature is uncertain.
2391-
23922402* ` intrinsics ` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
23932403 are inherently unstable and no promise about them is made.
23942404
2405+ * ` int_uint ` - Allows the use of the ` int ` and ` uint ` types, which are deprecated.
2406+ Use ` isize ` and ` usize ` instead.
2407+
23952408* ` lang_items ` - Allows use of the ` #[lang] ` attribute. Like ` intrinsics ` ,
23962409 lang items are inherently unstable and no promise about them
23972410 is made.
@@ -2410,12 +2423,33 @@ The currently implemented features of the reference compiler are:
24102423* ` log_syntax ` - Allows use of the ` log_syntax ` macro attribute, which is a
24112424 nasty hack that will certainly be removed.
24122425
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+
24132434* ` non_ascii_idents ` - The compiler supports the use of non-ascii identifiers,
24142435 but the implementation is a little rough around the
24152436 edges, so this can be seen as an experimental feature
24162437 for now until the specification of identifiers is fully
24172438 fleshed out.
24182439
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+
24192453* ` plugin ` - Usage of [ compiler plugins] [ plugin ] for custom lints or syntax extensions.
24202454 These depend on compiler internals and are subject to change.
24212455
@@ -2431,8 +2465,15 @@ The currently implemented features of the reference compiler are:
24312465* ` simd ` - Allows use of the ` #[simd] ` attribute, which is overly simple and
24322466 not the SIMD interface we want to expose in the long term.
24332467
2468+ * ` simd_ffi ` - Allows use of SIMD vectors in signatures for foreign functions.
2469+ The SIMD interface is subject to change.
2470+
24342471* ` staged_api ` - Allows usage of stability markers and ` #![staged_api] ` in a crate
24352472
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+
24362477* ` struct_inherit ` - Allows using struct inheritance, which is barely
24372478 implemented and will probably be removed. Don't use this.
24382479
@@ -2460,18 +2501,20 @@ The currently implemented features of the reference compiler are:
24602501 which is considered wildly unsafe and will be
24612502 obsoleted by language improvements.
24622503
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+
24632510* ` unmarked_api ` - Allows use of items within a ` #![staged_api] ` crate
24642511 which have not been marked with a stability marker.
24652512 Such items should not be allowed by the compiler to exist,
24662513 so if you need this there probably is a compiler bug.
24672514
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.
24752518
24762519If a feature is promoted to a language feature, then all existing programs will
24772520start to receive compilation warnings about #[ feature] directives which enabled
@@ -2591,9 +2634,8 @@ of any reference that points to it.
25912634
25922635When a [ local variable] ( #memory-slots ) is used as an
25932636[ 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.
25972639
25982640### Literal expressions
25992641
@@ -2701,9 +2743,19 @@ items can bring new names into scopes and declared items are in scope for only
27012743the block itself.
27022744
27032745A 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+ ```
27072759
27082760### Method-call expressions
27092761
@@ -3502,9 +3554,6 @@ elements, respectively, in a parenthesized, comma-separated list.
35023554Because tuple elements don't have a name, they can only be accessed by
35033555pattern-matching.
35043556
3505- The members of a tuple are laid out in memory contiguously, in order specified
3506- by the tuple type.
3507-
35083557An example of a tuple type and its use:
35093558
35103559```
0 commit comments