You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/items/use-declarations.md
+26-26
Original file line number
Diff line number
Diff line change
@@ -167,7 +167,7 @@ r[items.use.path.edition2015]
167
167
168
168
## `as` renames
169
169
170
-
r[item.use.as]
170
+
r[items.use.as]
171
171
172
172
The `as` keyword can be used to change the name of an imported entity.
173
173
For example:
@@ -183,9 +183,9 @@ mod inner {
183
183
184
184
## Brace syntax
185
185
186
-
r[item.use.multiple-syntax]
186
+
r[items.use.multiple-syntax]
187
187
188
-
r[item.use.multiple-syntax.intro]
188
+
r[items.use.multiple-syntax.intro]
189
189
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.
190
190
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.
191
191
@@ -197,18 +197,18 @@ Braces can be nested, creating a tree of paths, where each grouping of segments
An empty brace does not import anything, though the leading path is validated that it is accessible.
202
202
<!-- This is slightly wrong, see: https://github.com/rust-lang/rust/issues/61826 -->
203
203
204
-
r[item.use.multiple-syntax.edition2015]
204
+
r[items.use.multiple-syntax.edition2015]
205
205
> **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.
206
206
207
207
## `self` imports
208
208
209
-
r[item.use.self]
209
+
r[items.use.self]
210
210
211
-
r[item.use.self.intro]
211
+
r[items.use.self.intro]
212
212
The keyword `self` may be used within [brace syntax](#brace-syntax) to create a binding of the parent entity under its own name.
213
213
214
214
```rust
@@ -227,7 +227,7 @@ mod example {
227
227
# fnmain() {}
228
228
```
229
229
230
-
r[item.use.self.namespace]
230
+
r[items.use.self.namespace]
231
231
`self` only creates a binding from the [type namespace] of the parent entity.
232
232
For example, in the following, only the `foo` mod is imported:
233
233
@@ -252,9 +252,9 @@ fn main() {
252
252
253
253
## Glob imports
254
254
255
-
r[item.use.glob]
255
+
r[items.use.glob]
256
256
257
-
r[item.use.glob.intro]
257
+
r[items.use.glob.intro]
258
258
The `*` character may be used as the last segment of a `use` path to import all importable entities from the entity of the preceding segment.
259
259
For example:
260
260
@@ -277,7 +277,7 @@ mod foo {
277
277
}
278
278
```
279
279
280
-
r[item.use.glob.shadowing]
280
+
r[items.use.glob.shadowing]
281
281
Items and named imports are allowed to shadow names from glob imports in the same [namespace].
282
282
That is, if there is a name already defined by another item in the same namespace, the glob import will be shadowed.
283
283
For example:
@@ -309,26 +309,26 @@ mod clashing {
309
309
}
310
310
```
311
311
312
-
r[item.use.glob.restriction]
312
+
r[items.use.glob.restriction]
313
313
`*` cannot be used as the first or intermediate segments.
314
314
`*` cannot be used to import a module's contents into itself (such as `use self::*;`).
315
315
316
-
r[item.use.glob.edition2015]
316
+
r[items.use.glob.edition2015]
317
317
> **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.
318
318
> This cannot be used in the crate root itself.
319
319
320
320
## Underscore Imports
321
321
322
-
r[item.use.as-underscore]
322
+
r[items.use.as-underscore]
323
323
324
-
r[item.use.as-underscore.intro]
324
+
r[items.use.as-underscore.intro]
325
325
Items can be imported without binding to a name by using an underscore with
326
326
the form `use path as _`. This is particularly useful to import a trait so
327
327
that its methods may be used without importing the trait's symbol, for example
328
328
if the trait's symbol may conflict with another symbol. Another example is to
329
329
link an external crate without importing its name.
330
330
331
-
r[item.use.as-underscore.glob]
331
+
r[items.use.as-underscore.glob]
332
332
Asterisk glob imports will import items imported with `_` in their unnameable
333
333
form.
334
334
@@ -350,7 +350,7 @@ fn main() {
350
350
}
351
351
```
352
352
353
-
r[item.use.as-underscore.macro]
353
+
r[items.use.as-underscore.macro]
354
354
The unique, unnameable symbols are created after macro expansion so that
355
355
macros may safely emit multiple references to `_` imports. For example, the
356
356
following should not produce an error:
@@ -368,23 +368,23 @@ m!(use std as _;);
368
368
369
369
## Restrictions
370
370
371
-
r[item.use.restriction]
371
+
r[items.use.restriction]
372
372
373
373
The following are restrictions for valid `use` declarations:
374
374
375
-
r[item.use.restriction.crate]
375
+
r[items.use.restriction.crate]
376
376
*`use crate;` must use `as` to define the name to which to bind the crate root.
377
377
378
-
r[item.use.restriction.self]
378
+
r[items.use.restriction.self]
379
379
*`use {self};` is an error; there must be a leading segment when using `self`.
380
380
381
-
r[item.use.restriction.duplicate-name]
381
+
r[items.use.restriction.duplicate-name]
382
382
* As with any item definition, `use` imports cannot create duplicate bindings of the same name in the same namespace in a module or block.
383
383
384
-
r[item.use.restriction.macro-crate]
384
+
r[items.use.restriction.macro-crate]
385
385
*`use` paths with `$crate` are not allowed in a [`macro_rules`] expansion.
386
386
387
-
r[item.use.restriction.variant]
387
+
r[items.use.restriction.variant]
388
388
*`use` paths cannot refer to enum variants through a [type alias]. For example:
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.
407
407
408
-
r[item.use.ambiguity.glob]
408
+
r[items.use.ambiguity.glob]
409
409
Glob imports are allowed to import conflicting names in the same namespace as long as the name is not used.
0 commit comments