Skip to content

Commit 163f7bc

Browse files
traviscrossehuss
authored andcommitted
Make some editorial improvements
We've merged PR rust-lang#1040, so we can remove the TODO and update the link to point to the specific section. We replace some commas with semicolons where that's the right thing to do grammatically. Where we have "an X is... they are...", we replace that with "an X is... Xs are..." for reasons of avoiding a mismatch between the plurality of the pronoun and its referent. We replace "implementing type" and "defining type" with "type being implemented" and "type being defined", since there is in general a difference (e.g. "the driving force" vs "the force being driven"), and these seem more like the latter than the former. There's a place where we had said, "glob imports are allowed to import conflicting names into the same *namespaces*" (emphasis added). It makes sense what this is trying to say by using the plural there. But it just reads better to use the singular, and if it's true for the singular, it's clearly also true to the plural, so we make that change.
1 parent 127e560 commit 163f7bc

File tree

7 files changed

+52
-48
lines changed

7 files changed

+52
-48
lines changed

src/items/modules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod math {
3434
}
3535
```
3636

37-
Modules are defined in the [type namespace] of the module or block where it is located.
37+
Modules are defined in the [type namespace] of the module or block where they are located.
3838
It is an error to define multiple items with the same name in the same namespace within a module.
3939
See the [scopes chapter] for more details on restrictions and shadowing behavior.
4040

src/items/static-items.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ memory location. Static items have the `static` lifetime, which outlives all
1111
other lifetimes in a Rust program. Static items do not call [`drop`] at the
1212
end of the program.
1313

14-
The static declaration defines the static value in the [value namespace] of the module or block where it is located.
14+
The static declaration defines a static value in the [value namespace] of the module or block where it is located.
1515

1616
The static initializer is a [constant expression] evaluated at compile time.
1717
Static initializers may refer to other statics.

src/items/structs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let p = Point {x: 10, y: 11};
4747
let px: i32 = p.x;
4848
```
4949

50-
A _tuple struct_ is a nominal [tuple type], also defined with the keyword `struct`.
50+
A _tuple struct_ is a nominal [tuple type], and is also defined with the keyword `struct`.
5151
In addition to defining a type, it also defines a constructor of the same name in the [value namespace].
5252
The constructor is a function which can be called to create a new instance of the struct.
5353
For example:

src/items/traits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ interface consists of [associated items], which come in three varieties:
1717
- [types](associated-items.md#associated-types)
1818
- [constants](associated-items.md#associated-constants)
1919

20-
The trait declaration defines the trait in the [type namespace] of the module or block where it is located.
21-
Associated items are defined as members of the trait within their respective namespaces: type namespace for associated types, and value namespace for constants and functions.
20+
The trait declaration defines a trait in the [type namespace] of the module or block where it is located.
21+
Associated items are defined as members of the trait within their respective namespaces. Associated types are defined in the type namespace. Associated constants and associated functions are defined in the value namespace.
2222

2323
All traits define an implicit type parameter `Self` that refers to "the type
2424
that is implementing this interface". Traits may also contain additional type

src/items/type-aliases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
A _type alias_ defines a new name for an existing [type] in the [type namespace] of the module or block where it is located.
1010
Type aliases are declared with the keyword `type`.
11-
Every value has a single, specific type, but may implement several different traits, or be compatible with several different type constraints.
11+
Every value has a single, specific type, but may implement several different traits, and may be compatible with several different type constraints.
1212

1313
For example, the following defines the type `Point` as a synonym for the type
1414
`(u8, u8)`, the type of pairs of unsigned 8 bit integers:

src/items/use-declarations.md

+34-31
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A _use declaration_ creates one or more local name bindings synonymous with
1313
some other [path]. Usually a `use` declaration is used to shorten the path
1414
required to refer to a module item. These declarations may appear in [modules]
1515
and [blocks], usually at the top.
16-
A `use` declaration is also sometimes called an _import_ or if it is public it is a _re-export_.
16+
A `use` declaration is also sometimes called an _import_, or, if it is public, a _re-export_.
1717

1818
[path]: ../paths.md
1919
[modules]: modules.md
@@ -99,7 +99,7 @@ They may create bindings for:
9999

100100
They cannot import [associated items], [generic parameters], [local variables], paths with [`Self`], or [tool attributes]. More restrictions are described below.
101101

102-
`use` will create bindings for all [namespaces] from the imported entities, with the exception of a `self` import (described below) which only imports the type namespace.
102+
`use` will create bindings for all [namespaces] from the imported entities, with the exception that a `self` import will only import from the type namespace (as described below).
103103
For example, the following illustrates creating bindings for the same name in two namespaces:
104104

105105
```rust
@@ -111,12 +111,12 @@ mod stuff {
111111
use stuff::Foo;
112112

113113
fn example() {
114-
let ctor = Foo; // From value namespace
115-
let x: Foo = ctor(123);
114+
let ctor = Foo; // Uses `Foo` from the value namespace.
115+
let x: Foo = ctor(123); // Uses `Foo` From the type namespace.
116116
}
117117
```
118118

119-
> **Edition Differences**: In the 2015 edition, `use` paths are relative from the crate root.
119+
> **Edition differences**: In the 2015 edition, `use` paths are relative to the crate root.
120120
> For example:
121121
>
122122
> ```rust,edition2015
@@ -127,7 +127,8 @@ fn example() {
127127
> mod bar {
128128
> // Resolves `foo` from the crate root.
129129
> use foo::example::iter;
130-
> // :: prefix explicitly resolves `foo` from the crate root.
130+
> // The `::` prefix explicitly resolves `foo`
131+
> // from the crate root.
131132
> use ::foo::baz::foobaz;
132133
> }
133134
>
@@ -154,25 +155,25 @@ mod inner {
154155
155156
## Brace syntax
156157

157-
Braces can be used in the last segment of the path to import multiple entities from the previous segment or the current scope if there are no previous segments.
158+
Braces can be used in the last segment of the path to import multiple entities from the previous segment, or, if there are no previous segments, from the current scope.
158159
Braces can be nested, creating a tree of paths, where each grouping of segments is logically combined with its parent to create a full path.
159160

160161
```rust
161162
// Creates bindings to:
162-
// std::collections::BTreeSet
163-
// std::collections::hash_map
164-
// std::collections::hash_map::HashMap
163+
// - `std::collections::BTreeSet`
164+
// - `std::collections::hash_map`
165+
// - `std::collections::hash_map::HashMap`
165166
use std::collections::{BTreeSet, hash_map::{self, HashMap}};
166167
```
167168

168169
An empty brace does not import anything, though the leading path is validated that it is accessible.
169-
<!-- This is slightly wrong, see https://github.com/rust-lang/rust/issues/61826 -->
170+
<!-- This is slightly wrong, see: https://github.com/rust-lang/rust/issues/61826 -->
170171

171-
> **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.
172+
> **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.
172173
173174
## `self` imports
174175

175-
The keyword `self` may be used in the [brace syntax](#brace-syntax) to create a binding of the parent entity under its own name.
176+
The keyword `self` may be used within [brace syntax](#brace-syntax) to create a binding of the parent entity under its own name.
176177

177178
```rust
178179
mod stuff {
@@ -204,7 +205,7 @@ mod bar {
204205
use bar::foo::{self};
205206
206207
fn main() {
207-
foo(); // Error, `foo` is a module
208+
foo(); //~ ERROR `foo` is a module
208209
}
209210
```
210211

@@ -228,7 +229,8 @@ mod foo {
228229
V2,
229230
}
230231
pub fn bar() {
231-
// Creates local aliases to V1 and V2 of the Example enum.
232+
// Creates local aliases to `V1` and `V2`
233+
// of the `Example` enum.
232234
use Example::*;
233235
let x = V1;
234236
}
@@ -240,9 +242,9 @@ That is, if there is a name already defined by another item in the same namespac
240242
For example:
241243

242244
```rust
243-
// This creates a binding to the `clashing::Foo` tuple struct constructor, but
244-
// does not import its type because that would conflict with the `Foo` struct
245-
// defined here.
245+
// This creates a binding to the `clashing::Foo` tuple struct
246+
// constructor, but does not import its type because that would
247+
// conflict with the `Foo` struct defined here.
246248
//
247249
// Note that the order of definition here is unimportant.
248250
use clashing::*;
@@ -251,11 +253,12 @@ struct Foo {
251253
}
252254

253255
fn do_stuff() {
254-
// Uses the constructor from clashing::Foo
256+
// Uses the constructor from `clashing::Foo`.
255257
let f1 = Foo(123);
256-
// The struct expression uses the type from the Foo struct defined above.
258+
// The struct expression uses the type from
259+
// the `Foo` struct defined above.
257260
let f2 = Foo { field: 1.0 };
258-
// Also imported from the glob import.
261+
// `Bar` is also in scope due to the glob import.
259262
let z = Bar {};
260263
}
261264

@@ -268,7 +271,7 @@ mod clashing {
268271
`*` cannot be used as the first or intermediate segments.
269272
`*` cannot be used to import a module's contents into itself (such as `use self::*;`).
270273

271-
> **Edition Differences**: In the 2015 edition, paths are relative to the crate root, so an import such as `use *;` is valid, and it means to import everything from the crate root.
274+
> **Edition differences**: In the 2015 edition, paths are relative to the crate root, so an import such as `use *;` is valid, and it means to import everything from the crate root.
272275
> This cannot be used in the crate root itself.
273276
274277
## Underscore Imports
@@ -317,10 +320,10 @@ m!(use std as _;);
317320

318321
## Restrictions
319322

320-
The following are restrictions for valid `use` declarations.
323+
The following are restrictions for valid `use` declarations:
321324

322-
* `use crate;` must use `as` to define the name to bind the crate root to.
323-
* `use {self};` is an error, there must be a leading segment when using `self`.
325+
* `use crate;` must use `as` to define the name to which to bind the crate root.
326+
* `use {self};` is an error; there must be a leading segment when using `self`.
324327
* As with any item definition, `use` imports cannot create duplicate bindings of the same name in the same namespace in a module or block.
325328
* `use` paths with `$crate` are not allowed in a [`macro_rules`] expansion.
326329
* `use` paths cannot refer to enum variants through a [type alias]. Example:
@@ -330,17 +333,17 @@ The following are restrictions for valid `use` declarations.
330333
}
331334
type TypeAlias = MyEnum;
332335
333-
use MyEnum::MyVariant; // OK
334-
use TypeAlias::MyVariant; // ERROR
336+
use MyEnum::MyVariant; //~ OK
337+
use TypeAlias::MyVariant; //~ ERROR
335338
```
336339

337340
## Ambiguities
338341

339342
> **Note**: This section is incomplete.
340343
341-
Some situations are an error when there is an ambiguity as to which name a `use` declaration refers to, when there are two name candidates that do not resolve to the same entity.
344+
Some situations are an error when there is an ambiguity as to which name a `use` declaration refers. This happens when there are two name candidates that do not resolve to the same entity.
342345

343-
Glob imports are allowed to import conflicting names in the same namespaces as long as the name is not used or shadowed.
346+
Glob imports are allowed to import conflicting names in the same namespace as long as the name is not used or shadowed.
344347
Example:
345348

346349
```rust
@@ -353,11 +356,11 @@ mod bar {
353356
}
354357

355358
use foo::*;
356-
use bar::*; // Ok, no name conflict.
359+
use bar::*; //~ OK, no name conflict.
357360

358361
fn main() {
359362
// This would be an error, due to the ambiguity.
360-
// let x = Qux;
363+
//let x = Qux;
361364
}
362365
```
363366

src/paths.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Paths
22

33
A *path* is a sequence of one or more path segments separated by `::` tokens.
4-
They are used to refer to [items], values, [types], [macros], and [attributes].
4+
Paths are used to refer to [items], values, [types], [macros], and [attributes].
55

66
Two examples of simple paths consisting of only identifier segments:
77

@@ -224,13 +224,12 @@ impl S {
224224
`Self`, with a capital "S", is used to refer to the current type being implemented or defined. It may be used in the following situations:
225225

226226
* In a [trait] definition, it refers to the type implementing the trait.
227-
* In an [implementation], it refers to the implementing type.
227+
* In an [implementation], it refers to the type being implemented.
228228
When implementing a tuple or unit [struct], it also refers to the constructor in the [value namespace].
229-
* In the definition of a [struct], [enumeration], or [union], it refers to the defining type.
229+
* In the definition of a [struct], [enumeration], or [union], it refers to the type being defined.
230230
The definition is not allowed to be infinitely recursive (there must be an indirection).
231231

232-
The scope of `Self` behaves similarly to a generic parameter, see the [scopes chapter] for more details.
233-
<!-- TODO: update link to #self-scope once https://github.com/rust-lang/reference/pull/1040 is merged. -->
232+
The scope of `Self` behaves similarly to a generic parameter; see the [`Self` scope] section for more details.
234233

235234
`Self` can only be used as the first segment, without a preceding `::`.
236235
The `Self` path cannot include generic arguments (as in `Self::<i32>`).
@@ -257,16 +256,18 @@ impl T for S {
257256
}
258257

259258
// `Self` is in scope within the generics of a trait definition,
260-
// to refer to the defining type.
259+
// to refer to the type being defined.
261260
trait Add<Rhs = Self> {
262261
type Output;
263-
// `Self` can also reference associated items of the implementing types.
262+
// `Self` can also reference associated items of the
263+
// type being implemented.
264264
fn add(self, rhs: Rhs) -> Self::Output;
265265
}
266266

267267
struct NonEmptyList<T> {
268268
head: T,
269-
// A struct can reference itself (as long as it is not infinitely recursive).
269+
// A struct can reference itself (as long as it is not
270+
// infinitely recursive).
270271
tail: Option<Box<Self>>,
271272
}
272273
```
@@ -420,11 +421,12 @@ mod without { // crate::without
420421
[_Type_]: types.md#type-expressions
421422
[_TypeNoBounds_]: types.md#type-expressions
422423
[_TypeParamBounds_]: trait-bounds.md
423-
[literal]: expressions/literal-expr.md
424-
[items]: items.md
425424
[implementations]: items/implementations.md
425+
[items]: items.md
426+
[literal]: expressions/literal-expr.md
426427
[use declarations]: items/use-declarations.md
427428
[IDENTIFIER]: identifiers.md
429+
[`Self` scope]: names/scopes.md#self-scope
428430
[`use`]: items/use-declarations.md
429431
[attributes]: attributes.md
430432
[enumeration]: items/enumerations.md
@@ -435,7 +437,6 @@ mod without { // crate::without
435437
[macros]: macros.md
436438
[mbe]: macros-by-example.md
437439
[patterns]: patterns.md
438-
[scopes chapter]: names/scopes.md
439440
[struct]: items/structs.md
440441
[trait implementations]: items/implementations.md#trait-implementations
441442
[trait]: items/traits.md

0 commit comments

Comments
 (0)