Skip to content

Commit 8a00bdc

Browse files
committed
Add some details on item definition order.
1 parent b9823c9 commit 8a00bdc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/items.md

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ There are several kinds of items:
5656
Items may be declared in the [root of the crate], a [module][modules], or a [statement].
5757
Additionally, a subset of items, called [associated items], may be declared in [traits] and [implementations].
5858

59+
Items may be defined in any order, with the exception of [`macro_rules`] which has its own scoping behavior.
60+
[Name resolution] of item names allows items to be defined before or after where the item is referred to in the module or block.
61+
5962
See [item scopes] for information on the scoping rules of items.
6063

6164
[_ConstantItem_]: items/constant-items.md
@@ -77,6 +80,7 @@ See [item scopes] for information on the scoping rules of items.
7780
[_Visibility_]: visibility-and-privacy.md
7881
[`extern crate` declarations]: items/extern-crates.md
7982
[`extern` blocks]: items/external-blocks.md
83+
[`macro_rules`]: macros-by-example.md
8084
[`use` declarations]: items/use-declarations.md
8185
[associated items]: items/associated-items.md
8286
[constant items]: items/constant-items.md
@@ -85,6 +89,7 @@ See [item scopes] for information on the scoping rules of items.
8589
[implementations]: items/implementations.md
8690
[item scopes]: names/scopes.md#item-scopes
8791
[modules]: items/modules.md
92+
[name resolution]: names/name-resolution.md
8893
[paths]: paths.md
8994
[root of the crate]: crates-and-source-files.md
9095
[statement]: statements.md

src/names/scopes.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ A [path] may be used to refer to an item in another module.
2323
[Associated items] are not scoped and can only be referred to by using a [path] leading from the type they are associated with.
2424
[Methods] can also be referred to via [call expressions].
2525

26+
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.
27+
2628
## Pattern binding scopes
2729

2830
The scope of a local variable [pattern] binding depends on where it is used:

0 commit comments

Comments
 (0)