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
Currently alloc, core, and std imports are always reordered lexicographically (when they will be reordered).
However, at least when a reordered group only contains these standard library crates, it feels semantically more natural to use the order core-alloc-std (or std-alloc-core), because they have inclusion relationships (core::* ⊂ alloc::* ⊂ std::*).
For example, if alloc is unavailable then std is always unavailable, and if std is available then core and alloc is always available. alloc-core-std ordering looks somewhat unintuitive because it does not reflect such obvious transitive relations.
I'm not sure exact condition of when these "semantic" order should be chosen over the lexicographic order, but I strongly feel the semantic order is preferred in some situations (for example group_imports = "StdExternalCrate" is set).
Example
rustfmt.toml:
group_imports = "StdExternalCrate"
(and maybe more settings other than StdExternalCrate or group_imports as well...)
Summary
Currently
alloc
,core
, andstd
imports are always reordered lexicographically (when they will be reordered).However, at least when a reordered group only contains these standard library crates, it feels semantically more natural to use the order
core
-alloc
-std
(orstd
-alloc
-core
), because they have inclusion relationships (core::*
⊂alloc::*
⊂std::*
).For example, if
alloc
is unavailable thenstd
is always unavailable, and ifstd
is available thencore
andalloc
is always available.alloc
-core
-std
ordering looks somewhat unintuitive because it does not reflect such obvious transitive relations.I'm not sure exact condition of when these "semantic" order should be chosen over the lexicographic order, but I strongly feel the semantic order is preferred in some situations (for example
group_imports = "StdExternalCrate"
is set).Example
rustfmt.toml
:(and maybe more settings other than
StdExternalCrate
orgroup_imports
as well...)Input (random order):
Expected (semantic: core-alloc-std):
Got (lexicographic: alloc-core-std):
The text was updated successfully, but these errors were encountered: