-
Notifications
You must be signed in to change notification settings - Fork 42
document missing import restrictions #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
f96cea0
655bbe3
f18f69d
d02ce01
f69dd3d
91092bf
2b56a0b
9c70941
215f85e
0f2c9c1
d7e8007
2765077
857cd5e
29ca7f8
542679c
c57f5c6
d6f50e9
51e5a8d
106dab1
9e87caf
c2ca8e1
a2fd6c1
8724822
8bc4ab2
001ba74
f237bce
9170045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,7 +327,7 @@ If a :t:`simple path` appears in a :t:`use import` and starts with a | |
| :t:`path segment` expressed as either :t:`keyword` ``crate``, :t:`keyword` | ||
| ``$crate``, :t:`keyword` ``self``, or :t:`keyword` ``super``, then the | ||
| :t:`path` shall be the :t:`simple path prefix` of a :t:`glob import` or a | ||
| :t:`nesting import`, or the :t:`simple path` of a :t:`simple import`. | ||
| :t:`nesting import`, or the :t:`path` of a :t:`simple import`. | ||
|
|
||
| :dp:`fls_cw006jhlboa` | ||
| If a :t:`simple path` appears in a :t:`use import` and starts with a | ||
|
|
@@ -1049,9 +1049,7 @@ An :dt:`import path prefix` is the fully constructed :t:`path` prefix of a | |
| the current :t:`use import`. | ||
|
|
||
| :dp:`fls_2bkcn83smy2y` | ||
| A :t:`simple import` is a :t:`use import` that brings all :t:`entities <entity>` | ||
| it refers to into scope, optionally with a different | ||
| :t:`name` than they are declared with by using a :t:`renaming`. | ||
| A :dt:`simple import` is a :t:`use import` that brings a :t:`simple path` into scope, optionally with a :t:`renaming`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this definition should stay entity/name based. A path is syntax; it does not get brought into scope. A That distinction matters for the new keyword-import restrictions because the meeting discussion resolved the renaming target as the imported entity, not the path or path segment. It also matters for final- Suggested wording for both this paragraph and the glossary entry: A :dt:`simple import` is a :t:`use import` that brings
:t:`entities <entity>` selected by its :t:`simple import path`, or by its
:t:`import path prefix` when its :t:`simple path` ends in :t:`keyword` ``self``
and it appears in a :t:`nesting import`, into :t:`scope`, either under their
declared :t:`[name]s`, under a different :t:`name` by using a :t:`renaming`, or
without a :t:`name` by using a :t:`renaming` with character underscore ``_``.I think the empty-prefix and global-prefix cases should also be explicit. Rust 1.95.0 accepts both :dp:`fls_WAA4WmohGu6T`
An :dt:`import path prefix` is the fully constructed :t:`path` prefix of a
:t:`use import`. An :t:`import path prefix` with no :t:`[path segment]s` and no
:t:`namespace qualifier` resolves to the current :t:`module`. An
:t:`import path prefix` that starts with :t:`namespace qualifier` ``::``
preserves that :t:`namespace qualifier` in the constructed prefix. An
:t:`import path prefix` for a given :t:`simple import` or :t:`glob import` is
constructed as follows:
#. :dp:`fls_IPYvldMqduf4`
Start the :t:`import path prefix` as follows:
* :dp:`fls_MOXId37fcNPY`
If the :t:`use import` is a :t:`simple import`, then start with the
:t:`simple import`'s :t:`simple path` :t:`path prefix`.
* :dp:`fls_2UyFcB6Our1v`
If the :t:`use import` is a :t:`glob import`, then start with the
:t:`glob import`'s :t:`simple path prefix`.
* :dp:`fls_irdKqoYzBM0M`
If the :t:`use import` is a :t:`nesting import`, then start with the
:t:`nesting import`'s :t:`simple path prefix`.
#. :dp:`fls_gAWsqibl4GLq`
Then if the current :t:`use import` is the child of a :t:`nesting import`,
prepend the :t:`nesting import`'s :t:`simple path prefix` to the
:t:`import path prefix`. Repeat this step with the :t:`nesting import` as
the current :t:`use import`.Then I would update :dp:`fls_wRmvtgQkFA6w`
A :t:`simple import` brings :t:`[name]s` into :t:`scope` as follows:
* :dp:`fls_kz2Gij5wHXnl`
If the :t:`simple import` appears in a :t:`nesting import` and the last
:t:`path segment` of its :t:`simple path` is expressed as :t:`keyword`
``self``, then bring the :t:`entity` in :t:`type namespace` that the
:t:`import path prefix` resolves to into :t:`scope`.
* :dp:`fls_ar03D5rxjzy0`
If the :t:`simple path` is :t:`keyword` ``self``, then bring the containing
:t:`module` into :t:`scope`.
* :dp:`fls_ce73bg0BqV1X`
Otherwise bring all :t:`entities <entity>` that the :t:`simple import path`
resolves to that are visible from the location of the
:t:`simple import` into :t:`scope`.This is the semantic counterpart to the path-position rule in the separate I would also update :dp:`fls_iQOgxNihUEr7`
An :t:`entity` imported by a :t:`simple import` subject to a :t:`renaming` with
character underscore ``_`` is added into :t:`scope` without a :t:`name`.The changelog should list |
||
|
|
||
| :dp:`fls_v3a6y2ze44v2` | ||
| A :t:`glob import` is a :t:`use import` that brings all :t:`entities <entity>` | ||
|
|
@@ -1075,7 +1073,7 @@ A :t:`glob import` brings :t:`[name]s` into :t:`scope` as follows: | |
|
|
||
| :dp:`fls_90hQvSh7Bfyg` | ||
| A :dt:`simple import path` is the :t:`path` constructed by appending the last | ||
| :t:`path segment` of a :t:`simple import`'s :t:`simple path` to the | ||
| :t:`path segment` of the :t:`path` of the :t:`simple import` to the | ||
| :t:`import path prefix`. | ||
|
|
||
| :dp:`fls_wRmvtgQkFA6w` | ||
|
|
@@ -1116,7 +1114,7 @@ A :t:`glob import` outside of a :t:`nesting import` without a :t:`simple path | |
| prefix` is rejected, but may still be consumed by :t:`[macro]s`. | ||
|
|
||
| :dp:`fls_RUiFQ17bmRLt` | ||
| A :t:`simple import` with a :t:`simple path` with a single :t:`path segment` of | ||
| A :t:`simple import` with a single :t:`path segment` of | ||
| keyword ``self`` shall be subject to the following: | ||
|
|
||
| * :dp:`fls_hv3xT2CjZuxc` | ||
|
|
@@ -1135,6 +1133,18 @@ same :t:`namespace` but refer to different :t:`entities <entity>` if the | |
| If two :t:`[glob import]s` import the same :t:`entity` under the same :t:`name`, | ||
| the :t:`visibility` of the :t:`name` is the most permissive one. | ||
|
|
||
| :dp:`fls_sUhnfV62HJrb` | ||
| When a :t:`path segment` expressed as :t:`keyword` ``crate`` or :t:`keyword` ``$crate`` is used to import the current :t:`crate`, the :t:`path segment` shall be subject to a :t:`renaming`. | ||
|
|
||
| :dp:`fls_QGdeRTe0H1Uc` | ||
| When :t:`keyword` ``super`` is used to import a parent :t:`module`, the keyword shall be subject to a :t:`renaming`. | ||
|
kirtchev-adacore marked this conversation as resolved.
Outdated
|
||
|
|
||
| :dp:`fls_aam34hsRmKU2` | ||
| A :t:`simple path` consisting of namespace qualifier ``::``, followed by a :t:`path segment` expressed as :t:`keyword` ``self``, shall not be used. | ||
|
tshepang marked this conversation as resolved.
Outdated
|
||
|
|
||
| :dp:`fls_LV94x3HlpBWk` | ||
| A :t:`simple import` shall not refer to :t:`[enum variant]s` through a :t:`type alias`. | ||
|
|
||
| .. rubric:: Examples | ||
|
|
||
| :dp:`fls_5dlnffim6fso` | ||
|
|
@@ -1164,8 +1174,6 @@ The following is a selective import. The imported functions are | |
| use outer_module::inner_module | ||
| {crate_visible_function, visible_function} | ||
|
|
||
| .. rubric:: Legality Rules | ||
|
|
||
|
tshepang marked this conversation as resolved.
|
||
| .. _fls_ydmnb7qnmzzq: | ||
|
|
||
| Shadowing | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target:
src/entities-and-resolution.rst, Paths legality rules nearfls_opn5n5t2mo3m.I think this general path-position rule should also get the Rust 2021 use-path exception for braced/nesting-import final-
selfimports.The ordinary path rule remains that
selfis only used at the beginning of a path. Use declarations have an additionalselfimport behavior inside brace syntax: a finalselfin a nesting import imports the parent entity selected by the fully constructed import prefix. rust-lang/rust#146972 applies this use-path behavior to Rust 2018 and later, which covers the FLS Rust 2021 edition scope.That keeps braced prefixed imports valid, including
use crate::foo::bar::{self};,use crate::foo::bar::{self as name};,use crate::foo::{bar::foobar::quxbaz::self};, anduse crate::foo::{bar::foobar::quxbaz::self as name};. It still rejects direct final-selfpaths such asuse crate::foo::bar::self as name;, initial-selfdirect final paths such asuse self::self as name;, and intermediate-selfpaths such asuse foo::self::bar;anduse a::{b::self::c};.Replace
fls_opn5n5t2mo3mwith:This keeps
self::fooanduse self as name;valid, keepsuse a::b::{self as name};anduse a::{b::self as name};valid for the use-import parent-entity case, and still rejectsuse a::b::self as name;,use self::self as name;,use a::{self::b};, andfoo::self::bar.I checked the following with
rustc +1.95.0 --edition=2021:Since this changes a general path legality paragraph, list
fls_opn5n5t2mo3mas changed in the Rust 1.95 keyword-import changelog entry. The corresponding simple-import semantics should still get thefls_wRmvtgQkFA6wupdate from the simple-import thread so final-selfnesting imports bring the parent entity selected by the import prefix into scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like these suggestions, however
fls_opn5n5t2mo3mshould be split into two:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted the wording for new rule slightly 9e87caf