- Feature Name: use_nested_groups
- Start Date: 2017-08-25
- RFC PR: rust-lang/rfcs#2128
- Rust Issue: rust-lang/rust#44494
Summary
Permit{}
groups in imports.
Permit*
in {}
groups in imports.
Motivation
The motivation is ergonomics. Prefixes
Guide-level explanation
Several use
items with common prefixuse
item, in which the prefix{}
.
All kinds of suffixes can be listed*
and "subtrees" with their own curly braces.
A use
item with merged prefixesuse
items with all the prefixes
Reference-level explanation
Syntax:
IMPORT = ATTRS VISIBILITY `use` [`::`] IMPORT_TREE `;`
IMPORT_TREE = `*` |
REL_MOD_PATH `::` `*` |
`{` IMPORT_TREE_LIST `}` |
REL_MOD_PATH `::` `{` IMPORT_TREE_LIST `}` |
REL_MOD_PATH [`as` IDENT]
IMPORT_TREE_LIST = Ø | (IMPORT_TREE `,`)* IMPORT_TREE [`,`]
REL_MOD_PATH = (IDENT `::`)* IDENT
Resolution:
First the import tree is prefixed::
, unless it already starts with ::
, self
or super
.
Then resolution is performed as if the whole import tree were flattened, except that {self}
/{self as name}
are processed specially because a::b::self
is illegal.
Various
Relationships with other proposal
This RFC is an incremental improvement largely independent from other import-related proposals, but it can have effect on some other RFCs.
Some RFCs propose new syntaxes
This RFC removes the these statistics from the equation by reducing verbosity for all imports with common prefix.
For example, the difference in verbosity between A
, B
and C
is minimal and doesn't depend on the number of imports.
Drawbacks
The feature encourages (but not requires) multi-line formatting of a single
With this formatting it becomes harder to grep for use.*MyName
.
Rationale and Alternatives
Status quo is always an alternative.
Unresolved questions
None so far.