diff --git a/src/attributes.md b/src/attributes.md index 08b6c0692..a56e276f6 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -174,7 +174,7 @@ active. All other attributes are inert. ## Tool attributes The compiler may allow attributes for external tools where each tool resides -in its own namespace in the [tool prelude]. The first segment of the attribute +in its own module in the [tool prelude]. The first segment of the attribute path is the name of the tool, with one or more additional segments whose interpretation is up to the tool. diff --git a/src/items/constant-items.md b/src/items/constant-items.md index 9d48762ef..9fb218519 100644 --- a/src/items/constant-items.md +++ b/src/items/constant-items.md @@ -11,6 +11,8 @@ context when used. This includes usage of constants from external crates, and non-[`Copy`] types. References to the same constant are not necessarily guaranteed to refer to the same memory address. +The constant declaration defines the constant value in the [value namespace] of the module or block where it is located. + Constants must be explicitly typed. The type must have a `'static` lifetime: any references in the initializer must have `'static` lifetimes. @@ -115,3 +117,4 @@ fn unused_generic_function() { [_Type_]: ../types.md#type-expressions [_Expression_]: ../expressions.md [`Copy`]: ../special-types-and-traits.md#copy +[value namespace]: ../names/namespaces.md diff --git a/src/items/enumerations.md b/src/items/enumerations.md index 0d42bfd05..5f008461a 100644 --- a/src/items/enumerations.md +++ b/src/items/enumerations.md @@ -30,6 +30,7 @@ nominal [enumerated type] as well as a set of *constructors*, that can be used to create or pattern-match values of the corresponding enumerated type. Enumerations are declared with the keyword `enum`. +The `enum` declaration defines the enumeration type in the [type namespace] of the module or block where it is located. An example of an `enum` item and its use: @@ -80,6 +81,30 @@ enum Enum { } ``` +Variant constructors are similar to [struct] definitions, and can be referenced by a path from the enumeration name, including in [use declarations]. +Each variant defines its type in the [type namespace], though that type cannot be used as a type specifier. +Tuple-like and unit-like variants also define a constructor in the [value namespace]. + +A struct-like variant can be instantiated with a [struct expression]. +A tuple-like variant can be instantiated with a [call expression] or a [struct expression]. +A unit-like variant can be instantiated with a [path expression] or a [struct expression]. +For example: + +```rust +enum Examples { + UnitLike, + TupleLike(i32), + StructLike { value: i32 }, +} + +use Examples::*; // Creates aliases to all variants. +let x = UnitLike; // Path expression of the const item. +let x = UnitLike {}; // Struct expression. +let y = TupleLike(123); // Call expression. +let y = TupleLike { 0: 123 }; // Struct expression using integer field names. +let z = StructLike { value: 123 }; // Struct expression. +``` + ## Discriminants @@ -299,20 +324,27 @@ enum E { } ``` -[IDENTIFIER]: ../identifiers.md -[_GenericParams_]: generics.md -[_WhereClause_]: generics.md#where-clauses [_Expression_]: ../expressions.md -[_TupleFields_]: structs.md +[_GenericParams_]: generics.md [_StructFields_]: structs.md +[_TupleFields_]: structs.md [_Visibility_]: ../visibility-and-privacy.md -[enumerated type]: ../types/enum.md +[_WhereClause_]: generics.md#where-clauses +[`C` representation]: ../type-layout.md#the-c-representation [`mem::discriminant`]: ../../std/mem/fn.discriminant.html -[never type]: ../types/never.md -[unit-only]: #unit-only-enum -[numeric cast]: ../expressions/operator-expr.md#semantics +[call expression]: ../expressions/call-expr.md [constant expression]: ../const_eval.md#constant-expressions [default representation]: ../type-layout.md#the-default-representation -[primitive representation]: ../type-layout.md#primitive-representations -[`C` representation]: ../type-layout.md#the-c-representation +[enumerated type]: ../types/enum.md [Field-less enums]: #field-less-enum +[IDENTIFIER]: ../identifiers.md +[never type]: ../types/never.md +[numeric cast]: ../expressions/operator-expr.md#semantics +[path expression]: ../expressions/path-expr.md +[primitive representation]: ../type-layout.md#primitive-representations +[struct expression]: ../expressions/struct-expr.md +[struct]: structs.md +[type namespace]: ../names/namespaces.md +[unit-only]: #unit-only-enum +[use declarations]: use-declarations.md +[value namespace]: ../names/namespaces.md diff --git a/src/items/extern-crates.md b/src/items/extern-crates.md index 9dd6a5eb9..523e9720d 100644 --- a/src/items/extern-crates.md +++ b/src/items/extern-crates.md @@ -11,11 +11,9 @@ >    `as` ( [IDENTIFIER] | `_` ) An _`extern crate` declaration_ specifies a dependency on an external crate. -The external crate is then bound into the declaring scope as the [identifier] -provided in the `extern crate` declaration. Additionally, if the `extern -crate` appears in the crate root, then the crate name is also added to the -[extern prelude], making it automatically in scope in all modules. The `as` -clause can be used to bind the imported crate to a different name. +The external crate is then bound into the declaring scope as the given [identifier] in the [type namespace]. +Additionally, if the `extern crate` appears in the crate root, then the crate name is also added to the [extern prelude], making it automatically in scope in all modules. +The `as` clause can be used to bind the imported crate to a different name. The external crate is resolved to a specific `soname` at compile time, and a runtime linkage requirement to that `soname` is passed to the linker for @@ -74,6 +72,7 @@ crate to access only its macros. [extern prelude]: ../names/preludes.md#extern-prelude [`macro_use` prelude]: ../names/preludes.md#macro_use-prelude [`crate_name` attributes]: ../crates-and-source-files.md#the-crate_name-attribute +[type namespace]: ../names/namespaces.md