Skip to content

Commit

Permalink
Fixes from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jul 25, 2024
1 parent 9fbd6f0 commit 94cce75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/items/enumerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ enum Enum {
```

Variant constructors are similar to [struct] definitions, and can be referenced by a path from the enumeration name, including in [use declarations].
The constructors are defined in both the [type namespace] and [value namespace] within the enumeration.
Each variant defines its type in the [type namespace], though that type cannot be used as a type specifier.
Each variant also defines 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].
A unit-like variant can be instantiated with a [path 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
Expand All @@ -98,7 +99,9 @@ enum Examples {

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.
```

Expand Down
12 changes: 7 additions & 5 deletions src/items/use-declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A _use declaration_ creates one or more local name bindings synonymous with
some other [path]. Usually a `use` declaration is used to shorten the path
required to refer to a module item. These declarations may appear in [modules]
and [blocks], usually at the top.
A `use` declaration is also sometimes called an "import".
A `use` declaration is also sometimes called an _import_ or if it is public it is a _re-export_.

[path]: ../paths.md
[modules]: modules.md
Expand Down Expand Up @@ -165,7 +165,8 @@ Braces can be nested, creating a tree of paths, where each grouping of segments
use std::collections::{BTreeSet, hash_map::{self, HashMap}};
```

An empty brace does not import anything. `a::b::{}` is treated as `a::b::{self as _}` and `use {};` has no effect.
An empty brace does not import anything, though the leading path is validated that it is accessible.
<!-- This is slightly wrong, see /~https://github.com/rust-lang/rust/issues/61826 -->

> **Edition Differences**: In the 2015 edition, paths are relative to the crate root, so an import such as `use {foo, bar};` will import the names `foo` and `bar` from the crate root, whereas starting in 2018 those names are relative to the current scope.
Expand Down Expand Up @@ -207,8 +208,9 @@ fn main() {
}
```

> **Note**: `self` as the first segment of a `use` path has a different meaning from `self` inside braces.
> See [`self`] in the paths chapter for more information no the meaning of a leading `self`.
> **Note**: `self` may also be used as the first segment of a path.
> The usage of `self` as the first segment and inside a `use` brace is logically the same; it means the current module of the parent segment, or the current module if there is no parent segment.
> See [`self`] in the paths chapter for more information on the meaning of a leading `self`.
## Glob imports

Expand All @@ -234,7 +236,7 @@ mod foo {
```

Items and named imports are allowed to shadow names from glob imports in the same [namespace].
That is, if there is a name already defined by another item in the same namespace, the glob import will skip it.
That is, if there is a name already defined by another item in the same namespace, the glob import will be shadowed.
For example:

```rust
Expand Down
2 changes: 1 addition & 1 deletion src/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl S {

* In a [trait] definition, it refers to the type implementing the trait.
* In an [implementation], it refers to the implementing type.
When implementing a tuple or unit [struct], [enumeration], or [union], it also refers to the constructor in the [value namespace].
When implementing a tuple or unit [struct], it also refers to the constructor in the [value namespace].
* In the definition of a [struct], [enumeration], or [union], it refers to the defining type.
The definition is not allowed to be infinitely recursive (there must be an indirection).

Expand Down

0 comments on commit 94cce75

Please sign in to comment.