-
Notifications
You must be signed in to change notification settings - Fork 898
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
[unstable option] imports_granularity
#4991
Comments
When using unstable_features = true
imports_granularity = "Crate" , use triomphe::{
Arc,
// This crate walks along the graph a whole lot and normally doesn't do much refcounting,
// so the offset version is likely a bit better here.
//
// This is unbenched though. Someone might want to check.
OffsetArc,
};
(I wasn't sure whether this deserves its own issue.) |
The dropping of comments with the various options that manipulate imports is a known issue, and one of the hurdles that will have to be overcome before the options, including this one, can be stabilized. It is good to have an inline example here too though, so thank you @Tamschi |
Unfortunately the `imports_granularity` option of rustfmt I used to automate this change is unstable: rust-lang/rustfmt#4991
Unfortunately the `imports_granularity` option of rustfmt I used to automate this change [is unstable](rust-lang/rustfmt#4991).
Hi, is there any progress to make this option stable? |
The absence of updates should be explicitly interpreted as meaning that there are no updates. The process and requirements for stabilizing an option are both linked, and enumerated with checkboxes, in the issue description and will be updated as-and-when there are updates to share I appreciate the interest folks have in being able to use an option on stable. However, this remains a relatively new option with many well known bugs, and as stated above, is not going to be eligible for stabilization any time soon. |
For what its worth, we have been using |
I sent a PR to make rustfmt preserve comments during flattening when they're on the line before a leaf node, or on the same line as a leaf node. e.g. use a::{
// Before a::b
b,
c, // After a::c
}; If import_granularity=Item, then we'll get: // Before a::b
use a::b;
use a::c; // After a::c What I'm less sure about, is what to do when flattening and there's a comment before a non-leaf node. e.g. use a::{
// Before a::b
b::{b1, b2},
c,
}; One easy option is to not flatten non-leaf nodes that have comments, then we'd get: // Before a::b
use a::b::{b1, b2};
use a::c; That would mean we couldn't fully convert granularity to Another option would be to attach the comment to the first leaf contained within. Then we'd get: // Before a::b
use a::b::b1;
use a::b::b2;
use a::c; Although if there was already a comment attached to |
Seems reasonable to me.
Not bad to me, though. Converting from use a::{
// Before a::b
b::{
// Before a::b::b1
b1,
b2
},
c,
}; to // Before a::b
// Before a::b::b1
use a::b::b1;
use a::b::b2;
use a::c; |
Did a reformatting of a fairly large Rust code base (~200k LoC, 767 source files, 60 crates) with Looking for to latest rustfmt here (with the #5030 fix) getting deployed out to Rust Nightly in rustup so it can be used more easily, and (hopefully) soon stabilization of this great option! Thanks to everyone that has contributed to this feature/option! |
I'll also add that I do view folks sharing their experience to be helpful feedback for us, e.g. #4991 (comment) and #4991 (comment) That level of direct feedback absolutely helps feed into that 3rd gate of "well tested, optimally in real world usage", and is appreciated |
Big thanks again to @davidlattimore for addressing the comment issue, and I believe this has us on a good track towards stabilization. I believe there's really only two things left we need to consider before proceeding:
The latter is something anyone could help with and which would be most appreciated. The former is something we need to look at anyway as that's a more general need than any one config option (though anyone interested in helping with that should certainly feel free) |
I've been using both
I've searched the current open issues referencing
|
@calebcartwright If I understand this correctly, what you're requesting is that after stabilisation, it would be possible to:
This behaviour should extend outwards to the publically exported API of the crate, such that adding a new variant is not a breaking change. However, I see that the current config option enums are unreachable from the crate root, so maybe this isn't a concern? Line 15 in 5fa2727
I would be happy to take a first pass at this, I have some bandwidth today |
Would an option like For example, the use foo::{
a, b,
b::{f, g},
c,
d::e,
};
use qux::{h, i}; But that's really bulky. Id be happier with something like this, that wraps at the line length: use foo::{a, b, b::{f, g}, c, d::e,};
use qux::{h, i}; Obviously the difference is pretty dramatic in this example with single-letter modules, but it makes a difference in real-world use too. (also, just another +1 for stabilization in the near future assuming #5269 gets fixed, I've encountered no issues in my past yearish of using this on everything) |
@tgross35, I believe you're looking for the |
Hm, you're right, but it doesn't seem like the 'Crate" imports_granularity setting is quite coherent. I wrote it up on the |
I don't think the default value is correct - it takes up a lot of space. I expect something like imports_granularity = "Crate". At the moment cargo fmt by default can have pages of use statements with one import on each line. That seems an odd default... (totally happy with every other cargo defalut fmt setting, but this one I just seem to have to set) |
Isn't the default value "Preserve" for |
I assume this was said with the best of intent and while I appreciate the positive sentiment, I'd dispute the characterization. However, that's not a topic I'm interested in delving into, not to mention that doing so here would be off topic anyway
I won't say definitively that's the ultimate, exhaustive list of blocking issues, but yes, it's accurate that those remain some of the known bodies of work pending (and blocking) for stabilization of this option. That's been the case for a while, and at least in the case of #5269, is unlikely to change any time soon unless someone else works on them; neither Yacin nor I are likely to be able to allocate any of our rustfmt-bandwidth on those for the foreseeable future. |
Sorry that my remark turned out to be inaccurate, I was just happy to see that PRs are being actively merged & discussed. I hope it didn't appear insensitive. Then, I guess, the main question I have is: do you see any blockers here besides development effort (that can be done by external contributors)? E.g. is there enough capacity to discuss topics, accept/reject proposed solutions, etc (basically everything but submitting PRs)? I'm interested in working on it, but certainly don't want to overburden the rustfmt maintainers. |
I've added a list of open issues regarding |
Hi all. I hope I am not too late with the feedback. I would like to use However, I have a couple of issues with how it works as of nightly-2024-05-13.
use core::mem::{self, MaybeUninit}; ... becomes ... use core::mem::{ // HorizontalVertical is not respected
MaybeUninit,
{self}, // self became wrapped in additional {}
};
use core::fmt;
use core::slice; ... becomes ... use core::{fmt, slice}; // <- Meh?
use library1 as lib1;
use library2 as lib2; ... becomes ... use {library1 as lib1, library2 as lib2}; // <- These don't even share a common prefix. |
Tracking issue for unstable option:
imports_granularity
.Option documentation.
See Processes.md, "Stabilising an Option":
imports_granularity=Item
removes#[cfg()]
attribute from imports #5030imports_granularity = "Module"
causes compile error when path containsself
#4681use
s #3984The text was updated successfully, but these errors were encountered: