-
Notifications
You must be signed in to change notification settings - Fork 889
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] group_imports
#5083
Comments
merge_imports
imports_granularity
imports_granularity
group_imports
Would it be possible to add a fourth group for the workspace members? They're technically external crates but still different from 3rd party crates. Something like (let me know if this isn't the right place to discuss this) |
No worries @stjepangolemac fine to ask here (and probably worth having pointers to various issues anyway). In short, we're limited by the information that's actually available. More detailed in the issues linked below |
What's preventing the option from stablising as-is? #4693 to me seems to be about the addition of an extra option, but is there any problem with the current options? Any real bugs? |
#4709 seems like a fairly big bug to me. Besides that, did we actually decide that this was the only sane ordering? I'm pretty sure it was waiting on having a few different options for grouping imports before stabilizing, if it is ever going to stabilize. |
I appreciate the interest and willingness of folks to participate in discussions, but should you choose to do so, a gentle reminder to be sure to thoroughly read the thread and linked material. The process for stabilizing an option is both linked, and enumerated with checkboxes, in the issue description. None of those enumerated requirements can be cleared yet, including the fact that yes there's indeed real bugs that are either directly linked or transitively linked from issues/discussions that are directly linked. One can also search open issues to find additional related issues that aren't directly linked. To again echo inline:
|
I’d like for this option to have another value named This is to separate private imports (that are only there for convenience of naming things inside a module’s code) from reexports that affect the public API of a module or crate. |
Seems I forgot to hit the "comment" button the other day, but yes @SimonSapin that type of grouping and variant should be possible with the information available to rustfmt. However, I think it would be best to pull this additional-variant request out so it can be tracked as a separate feature requests, both for work tracking/implementation purposes and because it's not necessary for stabilization of the option nor related to it (we have the ability to add new, unstable variants to already stable options) |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
I don't know that this is so much a bug with use foo::{a, b};
use bar::c;
#[cfg(feature = "d")]
use baz::d;
#[cfg(feature = "e")]
use {baz::{e, f}, qux::g}; This gets funkier when combined with Currently, with use bar::c;
#[cfg(feature = "d")]
use baz::d;
use foo::{a, b};
#[cfg(feature = "e")]
use {baz::{e, f}, qux::g}; Where it becomes pretty difficult to disentangle which |
Unrelated to the above, the other bit I'd love to see from use a;
pub(crate) use b;
pub use c;
use d;
pub use x;
pub(crate) use z; whereas it feels more natural for the sort order to be: pub use c;
pub use x;
pub(crate) use b;
pub(crate) use z;
use a;
use d; (that is, sort by visibility then by item name) |
It makes too many suboptimal choices for now. See rust-lang/rustfmt#5083 (comment) and rust-lang/rustfmt#5083 (comment)
If the above suggestions are to be configurable, I would rather have it in a dictionary format than adding more variants. That is, instead of adding a group_imports = { grouping = "StdExternalCrate", group_by_visibility = true } @jonhoo it may be worth asking the style team at https://github.com/rust-lang/style-team if they would like to take a position on your above two suggestions in case there is interest in making them the style guide default. |
To what extent is it worth blocking on #4709? The only other related issues I see are feature requests, which could be added as an additional configuration later. If there isn't anything that can be done for #4709, it seems like stabilization could potentially move forward as-is. Mini stabilization consideration report:
It seems I would also be curious to hear style team input on #5083 (comment) and #5083 (comment), in case there is a preference to e.g. make the default for all options sort by visibility. Barring any visibility- or attribute-related input, I would propose going forward with the current
The design is simple enough.
The test suite for this option seems reasonably comprehensive. As one data point, I have been using this on various projects for over a year with no noticeable problems.
See the above. I propose stabilizing without a fix for #4709 if it seems like there isn't much to possibly be done here. |
I find #4709 to be a blocker here. As-implemented, I don't think I'd ever want to use this formatting option. (But I should first try this on some real code to see some examples. Maybe imports from local modules are sufficiently rare that it's fine?) It also doesn't behave as documented, as I explained here. |
My other concern is that in practice one often wants to split the "extern" group into multiple subgroups. For example, in rustc I always want to keep the imports from rustc_* crates in their own group. In a rocket-based application I want to separate rust-lang/style-team#131 mentioned "at least three" groups, maybe that was referring to this as well. |
TIL that (I don't know of a case where this import is actually useful, but would still be good to determine how it gets grouped.) |
It's a thing on 2015 edition only, so it's equivalent to |
Oh right, I had entirely forgotten that in the 2015 edition, |
Currently, |
Here's another group_imports issue that is IMO quite severe: #6241. |
sadly it turns out `group_imports = StdExternalCrate` is still in nightly, we can not use the merge import format rule with stable rust. ``` Warning: can't set `normalize_comments = true`, unstable features are only available in nightly channel. Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel. Warning: can't set `normalize_comments = true`, unstable features are only available in nightly channel. Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel. Warning: can't set `normalize_comments = true`, unstable features are only available in nightly channel. Warning: can't set `group_imports = StdExternalCrate`, unstable features are only available in nightly channel. ``` we can add these back when rust-lang/rustfmt#5083 get resolved.
Tracking issue for unstable option: group_imports.
See Processes.md, "Stabilising an Option":
The text was updated successfully, but these errors were encountered: