From b4a4ccb4e9cd5097475993a157168fe2912671a7 Mon Sep 17 00:00:00 2001 From: Havvy Date: Wed, 11 Oct 2017 22:31:30 -0700 Subject: [PATCH 1/3] Constant items - Move links to bottom --- src/items/constant-items.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/items/constant-items.md b/src/items/constant-items.md index 182c7e0fb..2a2c37aef 100644 --- a/src/items/constant-items.md +++ b/src/items/constant-items.md @@ -6,8 +6,6 @@ wherever they are used, meaning that they are copied directly into the relevant context when used. References to the same constant are not necessarily guaranteed to refer to the same memory address. -[constant value]: expressions.html#constant-expressions - Constant values must not have destructors, and otherwise permit most forms of data. Constants may refer to the address of other constants, in which case the address will have elided lifetimes where applicable, otherwise – in most cases @@ -15,14 +13,10 @@ address will have elided lifetimes where applicable, otherwise – in most cases elision].) The compiler is, however, still at liberty to translate the constant many times, so the address referred to may not be stable. -[static lifetime elision]: items/static-items.html#static-lifetime-elision - Constants must be explicitly typed. The type may be any type that doesn't implement [`Drop`] and has a `'static` lifetime: any references it contains must have `'static` lifetimes. -[`Drop`]: the-drop-trait.html - ```rust const BIT1: u32 = 1 << 0; const BIT2: u32 = 1 << 1; @@ -40,3 +34,7 @@ const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings { mystring: STRING, }; ``` + +[constant value]: expressions.html#constant-expressions +[static lifetime elision]: items/static-items.html#static-lifetime-elision +[`Drop`]: the-drop-trait.html \ No newline at end of file From 947945d8392025eef97273f094b1ff991251415f Mon Sep 17 00:00:00 2001 From: Havvy Date: Wed, 11 Oct 2017 22:47:21 -0700 Subject: [PATCH 2/3] Paths whitespace/link location cleanup. --- src/paths.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/paths.md b/src/paths.md index 405758694..7346c0321 100644 --- a/src/paths.md +++ b/src/paths.md @@ -5,9 +5,6 @@ a namespace qualifier (`::`). If a path consists of only one component, it may refer to either an [item] or a [variable] in a local control scope. If a path has multiple components, it refers to an item. -[item]: items.html -[variable]: variables.html - Every item has a _canonical path_ within its crate, but the path naming an item is only meaningful within a given crate. There is no global namespace across crates; an item's canonical path merely identifies it within the crate. @@ -19,15 +16,11 @@ x; x::y::z; ``` -Path components are usually [identifiers], but they may -also include angle-bracket-enclosed lists of type arguments. In -[expression] context, the type argument list is given -after a `::` namespace qualifier in order to disambiguate it from a -relational expression involving the less-than symbol (`<`). In type -expression context, the final namespace qualifier is omitted. - -[identifiers]: identifiers.html -[expression]: expressions.html +Path components are usually [identifiers], but they may also include +angle-bracket-enclosed lists of type arguments. In [expression] context, the +type argument list is given after a `::` namespace qualifier in order to +disambiguate it from a relational expression involving the less-than symbol +(`<`). In type expression context, the final namespace qualifier is omitted. Two examples of paths with type arguments: @@ -103,3 +96,8 @@ mod a { } # fn main() {} ``` + +[item]: items.html +[variable]: variables.html +[identifiers]: identifiers.html +[expression]: expressions.html \ No newline at end of file From e675bb9155a7f37bc2a25ac7732f1f9d37e4e710 Mon Sep 17 00:00:00 2001 From: Havvy Date: Thu, 12 Oct 2017 00:12:06 -0700 Subject: [PATCH 3/3] Make canonical paths its own section. --- src/paths.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/paths.md b/src/paths.md index 7346c0321..5b32fa3fa 100644 --- a/src/paths.md +++ b/src/paths.md @@ -5,10 +5,6 @@ a namespace qualifier (`::`). If a path consists of only one component, it may refer to either an [item] or a [variable] in a local control scope. If a path has multiple components, it refers to an item. -Every item has a _canonical path_ within its crate, but the path naming an item -is only meaningful within a given crate. There is no global namespace across -crates; an item's canonical path merely identifies it within the crate. - Two examples of simple paths consisting of only identifier components: ```rust,ignore @@ -97,7 +93,78 @@ mod a { # fn main() {} ``` +## Canonical paths + +Items defined in a module or implementation have a *canonical path* that +corresponds to where within its crate it is defined. All other paths to these +items are aliases. The canonical path is defined as a *path prefix* appended by +the path component the item itself defines. + +[Implementations] and [use declarations] do not have canonical paths, although +the items that implementations define do have them. Items defined in +block expressions do not have canonical paths. Items defined in a module that +does not have a canonical path do not have a canonical path. Associated items +defined in an implementation that refers to an item without a canonical path, +e.g. as the implementing type, the trait being implemented, a type parameter or +bound on a type parameter, do not have canonical paths. + +The path prefix for modules is the canonical path to that module. For bare +implementations, it is the canonical path of the item being implemented +surrounded by angle (`<>`) brackets. For trait implementations, it is the +canonical path of the item being implemented followed by `as` followed by the +canonical path to the trait all surrounded in angle (`<>`) brackets. + +The canonical path is only meaningful within a given crate. There is no global +namespace across crates; an item's canonical path merely identifies it within +the crate. + +```rust +// Comments show the canonical path of the item. + +mod a { // ::a + pub struct Struct; // ::a::Struct + + pub trait Trait { // ::a::Trait + fn f(&self); // a::Trait::f + } + + impl Trait for Struct { + fn f(&self) {} // <::a::Struct as ::a::Trait>::f + } + + impl Struct { + fn g(&self) {} // <::a::Struct>::g + } +} + +mod without { // ::without + fn canonicals() { // ::without::canonicals + struct OtherStruct; // None + + trait OtherTrait { // None + fn g(&self); // None + } + + impl OtherTrait for OtherStruct { + fn g(&self) {} // None + } + + impl OtherTrait for ::a::Struct { + fn g(&self) {} // None + } + + impl ::a::Trait for OtherStruct { + fn f(&self) {} // None + } + } +} + +# fn main() {} +``` [item]: items.html [variable]: variables.html [identifiers]: identifiers.html -[expression]: expressions.html \ No newline at end of file +[expression]: expressions.html +[implementations]: items/implementations.html +[modules]: items/modules.html +[use declarations]: items/use_declarations.html \ No newline at end of file