Skip to content

[unstable option] imports_granularity #4991

@9999years

Description

@9999years

Sub-issues

Sub-issues

0 of 2 Issues completed

Activity

Tamschi

Tamschi commented on Oct 10, 2021

@Tamschi

When using

unstable_features = true
imports_granularity = "Crate"

, cargo +nightly fmt will currently remove comments like this:

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,
};
❯ cargo +nightly fmt --version
rustfmt 1.4.37-nightly (a8f2463c 2021-10-09)

(I wasn't sure whether this deserves its own issue.)

calebcartwright

calebcartwright commented on Oct 10, 2021

@calebcartwright
Member

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

added a commit that references this issue on Oct 23, 2021
added a commit that references this issue on Oct 25, 2021
Xuanwo

Xuanwo commented on Feb 18, 2022

@Xuanwo

Hi, is there any progress to make this option stable?

calebcartwright

calebcartwright commented on Feb 19, 2022

@calebcartwright
Member

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.

Nutomic

Nutomic commented on Feb 21, 2022

@Nutomic

For what its worth, we have been using imports_granularity="Crate" in Lemmy for over a year without any problems. Though we dont put any comments around imports.

65 remaining items

9999years

9999years commented on Apr 10, 2024

@9999years
Author

I've added a list of open issues regarding imports_granularity to the original ticket. Please let me know if there's others to add to the list.

yanchith

yanchith commented on Jun 4, 2024

@yanchith

Hi all. I hope I am not too late with the feedback. I would like to use imports_granularity = "Module", as in theory it is exactly what I'd like to see.

However, I have a couple of issues with how it works as of nightly-2024-05-13.

  1. I think the following diff shows bugs, or at least really unexpected features.
use core::mem::{self, MaybeUninit};

... becomes ...

use core::mem::{  // HorizontalVertical is not respected
    MaybeUninit,
   {self},        // self became wrapped in additional {} 
};
  1. This is technically not a bug, but I'd like to have module imports as separate use statements and only merge non-module items of the last depth level. Maybe this is another imports_granularity? "ModulesWithModuleUsesAsOne".
use core::fmt;
use core::slice;

... becomes ...

use core::{fmt, slice}; // <- Meh?
  1. This one is once again more of a bug in my eyes:
use library1 as lib1;
use library2 as lib2;

... becomes ...

use {library1 as lib1, library2 as lib2}; // <- These don't even share a common prefix.
mnkhouri

mnkhouri commented on Jun 11, 2024

@mnkhouri

@yanchith I filed #6191 so that your point 3. can be discussed, since I also expected the same result you described

Blub

Blub commented on Apr 16, 2025

@Blub

Is there any reason not to stabilize parts of this? Eg. we'd like to use Item as it seems quite straightforward and the most merge-conflict-friendly option of them all. (Anything that re-flows entire blocks of imports is a PITA for git merge & manual reviews)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    unstable optiontracking issue of an unstable option

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Blub@dcormier@faern@Tamschi@gilescope

        Issue actions

          [unstable option] `imports_granularity` · Issue #4991 · rust-lang/rustfmt