From 085f0a8246b6c39f8a30a5149137b7c61ad48f2d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 26 Jan 2019 20:04:45 -0800 Subject: [PATCH 1/2] Document extern_crate_self --- src/items/extern-crates.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/items/extern-crates.md b/src/items/extern-crates.md index 6c3dcf90c1105..ec52c4b0f046f 100644 --- a/src/items/extern-crates.md +++ b/src/items/extern-crates.md @@ -2,11 +2,12 @@ > **Syntax:**\ > _ExternCrate_ :\ ->    `extern` `crate` [IDENTIFIER] (`as` ( [IDENTIFIER] | `_` ) )? `;` +>    `extern` `crate` ( [IDENTIFIER] | `self` ) (`as` ( [IDENTIFIER] | `_` ) )? `;` An _`extern crate` declaration_ specifies a dependency on an external crate. The external crate is then bound into the declaring scope as the [identifier] -provided in the `extern crate` declaration. +provided in the `extern crate` declaration. The `as` clause can be used to +bind the imported crate to a different name. The external crate is resolved to a specific `soname` at compile time, and a runtime linkage requirement to that `soname` is passed to the linker for @@ -16,6 +17,9 @@ the `crateid` attributes that were declared on the external crate when it was compiled. If no `crateid` is provided, a default `name` attribute is assumed, equal to the [identifier] given in the `extern crate` declaration. +The `self` crate may be imported which creates a binding to the current crate. +In this case the `as` clause must be used to specify the name to bind it to. + Three examples of `extern crate` declarations: ```rust,ignore From 43ae30659ba6ce522e1f5f484397b7e524503de0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 27 Jan 2019 09:02:48 -0800 Subject: [PATCH 2/2] Break up _ExternCrate_ grammar. --- src/items/extern-crates.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/items/extern-crates.md b/src/items/extern-crates.md index ec52c4b0f046f..8648fb47b90e6 100644 --- a/src/items/extern-crates.md +++ b/src/items/extern-crates.md @@ -2,7 +2,13 @@ > **Syntax:**\ > _ExternCrate_ :\ ->    `extern` `crate` ( [IDENTIFIER] | `self` ) (`as` ( [IDENTIFIER] | `_` ) )? `;` +>    `extern` `crate` _CrateRef_ _AsClause_? `;` +> +> _CrateRef_ :\ +>    [IDENTIFIER] | `self` +> +> _AsClause_ :\ +>    `as` ( [IDENTIFIER] | `_` ) An _`extern crate` declaration_ specifies a dependency on an external crate. The external crate is then bound into the declaring scope as the [identifier]