@@ -27,9 +27,6 @@ pub use hir::PrefixKind;
2727/// How imports should be grouped into use statements.
2828#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
2929pub enum ImportGranularity {
30- /// Do not change the granularity of any imports and preserve the original structure written
31- /// by the developer.
32- Preserve ,
3330 /// Merge imports from the same crate into a single use statement.
3431 Crate ,
3532 /// Merge imports from the same module into a single use statement.
@@ -174,17 +171,26 @@ fn insert_use_with_alias_option(
174171 ImportGranularity :: Crate => Some ( MergeBehavior :: Crate ) ,
175172 ImportGranularity :: Module => Some ( MergeBehavior :: Module ) ,
176173 ImportGranularity :: One => Some ( MergeBehavior :: One ) ,
177- ImportGranularity :: Item | ImportGranularity :: Preserve => None ,
174+ ImportGranularity :: Item => None ,
178175 } ;
179176 if !cfg. enforce_granularity {
180177 let file_granularity = guess_granularity_from_scope ( scope) ;
181178 mb = match file_granularity {
182179 ImportGranularityGuess :: Unknown => mb,
183180 ImportGranularityGuess :: Item => None ,
184181 ImportGranularityGuess :: Module => Some ( MergeBehavior :: Module ) ,
185- ImportGranularityGuess :: ModuleOrItem => mb. and ( Some ( MergeBehavior :: Module ) ) ,
182+ // We use the user's setting to infer if this is module or item.
183+ ImportGranularityGuess :: ModuleOrItem => match mb {
184+ Some ( MergeBehavior :: Module ) | None => mb,
185+ // There isn't really a way to decide between module or item here, so we just pick one.
186+ // FIXME: Maybe it is possible to infer based on semantic analysis?
187+ Some ( MergeBehavior :: One | MergeBehavior :: Crate ) => Some ( MergeBehavior :: Module ) ,
188+ } ,
186189 ImportGranularityGuess :: Crate => Some ( MergeBehavior :: Crate ) ,
187- ImportGranularityGuess :: CrateOrModule => mb. or ( Some ( MergeBehavior :: Crate ) ) ,
190+ ImportGranularityGuess :: CrateOrModule => match mb {
191+ Some ( MergeBehavior :: Crate | MergeBehavior :: Module ) => mb,
192+ Some ( MergeBehavior :: One ) | None => Some ( MergeBehavior :: Crate ) ,
193+ } ,
188194 ImportGranularityGuess :: One => Some ( MergeBehavior :: One ) ,
189195 } ;
190196 }
0 commit comments