-
Notifications
You must be signed in to change notification settings - Fork 439
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
Import formatting #1143
Comments
Also related is the rustfmt option for this imports_granularity |
Not a technical argument, but speaking from experience, i have observed more Rust codebases in the wild using the merged format. It will also scale better when dozens of structure have to be pulled, and should allow IDEs to collapse the groupings. On a technical note, it's perfectly understandable to want to keep the granular layout. |
Also group_imports could be a nice thing to add. I very much favor |
Ah good to see that there is an option for that (although it is unstable).
My personal opinion would be @metaspace's opinion probably is
The |
i ran a bit of i guess i'll create a patch quickly to add item and fix imports. |
I'd vote for |
We haven't yet decided on a convention, so I think it's a bit early to create a patch. But when we find a consensus, we will gladly accept your patch :) |
In the long run, we will split the kernel crate into subsystem crates, so we will get that later for free. Do we still want to have |
i don't know how code splitting is shaping up, but it is very likely that each subsystem might end up having a dedicated crate, and modules within those. Worst case scenario, if we no longer have enough modules once that happens such that we no longer write import groupings by module, the top-level of the crate would still be considered a module, and individual items from submodules can remain on one line. i doubt we will run into such a situation however. while i'm at it, what LKML thread are you referring to for the comment about using Item? LKML is a vast soup and the attention i can pay to it is minimal |
Yes that could happen. But my answer to Gary was "if the reason for choosing to use
The one linked at the top of the issue: https://lore.kernel.org/rust-for-linux/dd63fcde-ba4c-4a6e-9bde-1af5af37e91b@proton.me/ |
when everyone on the MLs is done picking what they'd like, here's how to implement it: laying things down flat at the level of modules (without removing current groups) would boil down to adding: imports_granularity = "Module/Item/Whatever" to Now, 57 files is a hell of a lot, and i do not think anybody wants to send a single patch for that, nor a series. i guess it would be wiser to just add the option commented out (because it will cause a ton of warnings and not be used by rustfmt on the current minimum working version of the toolchain) and leave that work to the next poor soul who actually runs |
What makes you think that? I think it's going to be fine. Especially since the series is machine-generated it is rather easy to review.
That doesn't seem like an option to me, as Rust kernel code should always be formatted according to rustfmt. |
Yeah, it should be fine. In the worst case, if a patch is too big and can be machine-generated, it could be exceptionally applied directly, for instance. But probably it is not that big. The worst part is probably conflicts when backporting, but they are just imports, so it shouldn't be too bad, and perhaps we could backport the reformatting. But what I would like is that we are really sure about the style we move to -- we should not change this again (if we do).
Yeah, it is likely we would be breaking someone's CI, so it would be best to avoid it if possible. |
Having to deal with the maintainers of all subsystems affected by those 57 files could be a bother, but i have been told that because it's formatting it might not be a problem.
Gotcha.
i seem to understand that this discussion is primarily happening on the LKMLs. i have not seen a dedicated thread on the Zulip. |
Agreed.
It won't be an issue.
The only people that have been discussing this on the LKML (AFAIK) have been Andreas and me. I created this issue to track it somewhere and not lose sight of it. If you want, you can also open a zulip topic about it. |
i would argue it's not my call to make but if this is beneficial to getting input from other people and nobody else wants to do it, i can (assuming i am allowed to create a topic in the General section; i assume anyone can?) |
I recently found that my editor has a “normalize imports” feature. That helps a lot when merging with the nested form. The line by line form is still more efficient to work with though.
…On Mon, Feb 17, 2025 at 12:28, y86-dev ***@***.***(mailto:On Mon, Feb 17, 2025 at 12:28, y86-dev <<a href=)> wrote:
In ***@***.***/) the following question came up: How should we format our imports?
Like this:
use
crate
::
alloc
::
flags
;
use
crate
::
container_of
;
use
crate
::
page
::
PAGE_SIZE
;
use
crate
::
prelude
::
*
;
use
crate
::
str
::
CString
;
use
crate
::
sync
::
Arc
;
use
crate
::
types
::
ForeignOwnable
;
use
crate
::
types
::
Opaque
;
use
core
::
cell
::
UnsafeCell
;
use
core
::
marker
::
PhantomData
;
use
core
::
ptr
::
addr_of
;
use
core
::
ptr
::
addr_of_mut
;
Or merged?:
use
crate
::
{
alloc
::
flags
,
container_of
,
page
::
PAGE_SIZE
,
prelude
::
*
,
str
::
CString
,
sync
::
Arc
,
types
::
{
ForeignOwnable
,
Opaque
}
,
}
;
use
core
::
{
cell
::
UnsafeCell
,
marker
::
PhantomData
,
ptr
::
{
addr_of
,
addr_of_mut
}
,
}
;
The merged form is worse for rebasing, but in my opinion easier to parse at a glance.
—
Reply to this email directly, [view it on GitHub](#1143), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAH4AMXLTLZLUEDXWJRRJBL2QHBXJAVCNFSM6AAAAABXJDOLZKVHI2DSMVQWIX3LMV43ASLTON2WKOZSHA2TONJXGAZDGNI).
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
[y86-dev] y86-dev created an issue [(Rust-for-Linux/linux#1143)](#1143)
In ***@***.***/) the following question came up: How should we format our imports?
Like this:
use
crate
::
alloc
::
flags
;
use
crate
::
container_of
;
use
crate
::
page
::
PAGE_SIZE
;
use
crate
::
prelude
::
*
;
use
crate
::
str
::
CString
;
use
crate
::
sync
::
Arc
;
use
crate
::
types
::
ForeignOwnable
;
use
crate
::
types
::
Opaque
;
use
core
::
cell
::
UnsafeCell
;
use
core
::
marker
::
PhantomData
;
use
core
::
ptr
::
addr_of
;
use
core
::
ptr
::
addr_of_mut
;
Or merged?:
use
crate
::
{
alloc
::
flags
,
container_of
,
page
::
PAGE_SIZE
,
prelude
::
*
,
str
::
CString
,
sync
::
Arc
,
types
::
{
ForeignOwnable
,
Opaque
}
,
}
;
use
core
::
{
cell
::
UnsafeCell
,
marker
::
PhantomData
,
ptr
::
{
addr_of
,
addr_of_mut
}
,
}
;
The merged form is worse for rebasing, but in my opinion easier to parse at a glance.
—
Reply to this email directly, [view it on GitHub](#1143), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAH4AMXLTLZLUEDXWJRRJBL2QHBXJAVCNFSM6AAAAABXJDOLZKVHI2DSMVQWIX3LMV43ASLTON2WKOZSHA2TONJXGAZDGNI).
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
In review the following question came up: How should we format our imports?
Like this:
Or merged?:
The merged form is worse for rebasing, but in my opinion easier to parse at a glance.
The text was updated successfully, but these errors were encountered: