Skip to content

Commit

Permalink
Add some details on item definition order.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jan 17, 2022
1 parent b9823c9 commit 8a00bdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/names/scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8a00bdc

Please sign in to comment.