Skip to content

Commit 62d4ff0

Browse files
authored
Merge pull request #517 from ehuss/extern-crate-self
Document extern_crate_self
2 parents 62f9e20 + 43ae306 commit 62d4ff0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/items/extern-crates.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
> **<sup>Syntax:<sup>**\
44
> _ExternCrate_ :\
5-
> &nbsp;&nbsp; `extern` `crate` [IDENTIFIER]&nbsp;(`as` ( [IDENTIFIER] | `_` ) )<sup>?</sup> `;`
5+
> &nbsp;&nbsp; `extern` `crate` _CrateRef_ _AsClause_<sup>?</sup> `;`
6+
>
7+
> _CrateRef_ :\
8+
> &nbsp;&nbsp; [IDENTIFIER] | `self`
9+
>
10+
> _AsClause_ :\
11+
> &nbsp;&nbsp; `as` ( [IDENTIFIER] | `_` )
612
713
An _`extern crate` declaration_ specifies a dependency on an external crate.
814
The external crate is then bound into the declaring scope as the [identifier]
9-
provided in the `extern crate` declaration.
15+
provided in the `extern crate` declaration. The `as` clause can be used to
16+
bind the imported crate to a different name.
1017

1118
The external crate is resolved to a specific `soname` at compile time, and a
1219
runtime linkage requirement to that `soname` is passed to the linker for
@@ -16,6 +23,9 @@ the `crateid` attributes that were declared on the external crate when it was
1623
compiled. If no `crateid` is provided, a default `name` attribute is assumed,
1724
equal to the [identifier] given in the `extern crate` declaration.
1825

26+
The `self` crate may be imported which creates a binding to the current crate.
27+
In this case the `as` clause must be used to specify the name to bind it to.
28+
1929
Three examples of `extern crate` declarations:
2030

2131
```rust,ignore

0 commit comments

Comments
 (0)