From 8a00bdc2768a091aed2062701cf866f19b657f4d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 30 Jun 2021 17:40:51 -0700 Subject: [PATCH] Add some details on item definition order. --- src/items.md | 5 +++++ src/names/scopes.md | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/items.md b/src/items.md index 9bc07a62c..3d7f53242 100644 --- a/src/items.md +++ b/src/items.md @@ -56,6 +56,9 @@ There are several kinds of items: Items may be declared in the [root of the crate], a [module][modules], or a [statement]. Additionally, a subset of items, called [associated items], may be declared in [traits] and [implementations]. +Items may be defined in any order, with the exception of [`macro_rules`] which has its own scoping behavior. +[Name resolution] of item names allows items to be defined before or after where the item is referred to in the module or block. + See [item scopes] for information on the scoping rules of items. [_ConstantItem_]: items/constant-items.md @@ -77,6 +80,7 @@ See [item scopes] for information on the scoping rules of items. [_Visibility_]: visibility-and-privacy.md [`extern crate` declarations]: items/extern-crates.md [`extern` blocks]: items/external-blocks.md +[`macro_rules`]: macros-by-example.md [`use` declarations]: items/use-declarations.md [associated items]: items/associated-items.md [constant items]: items/constant-items.md @@ -85,6 +89,7 @@ See [item scopes] for information on the scoping rules of items. [implementations]: items/implementations.md [item scopes]: names/scopes.md#item-scopes [modules]: items/modules.md +[name resolution]: names/name-resolution.md [paths]: paths.md [root of the crate]: crates-and-source-files.md [statement]: statements.md diff --git a/src/names/scopes.md b/src/names/scopes.md index 617c1aa4e..035676a6a 100644 --- a/src/names/scopes.md +++ b/src/names/scopes.md @@ -23,6 +23,8 @@ A [path] may be used to refer to an item in another module. [Associated items] are not scoped and can only be referred to by using a [path] leading from the type they are associated with. [Methods] can also be referred to via [call expressions]. +Similar to items within a module or block, it is an error to introduce an item within a trait or implementation that is a duplicate of another item in the trait or impl in the same namespace. + ## Pattern binding scopes The scope of a local variable [pattern] binding depends on where it is used: