let prefix_c = prev_prefix.qualifiers().count();
let curr_c = curr_path.qualifiers().count() - prefix_c;
let prev_c = prev_path.qualifiers().count() - prefix_c;
- if curr_c <= 1 || prev_c <= 1 {
- // Same prefix but no use tree lists so this has to be of item style.
- break ImportGranularityGuess::Item; // this overwrites CrateOrModule, technically the file doesn't adhere to anything here.
+ if curr_c == 1 && prev_c == 1 {
+ // Same prefix, only differing in the last segment and no use tree lists so this has to be of item style.
+ break ImportGranularityGuess::Item;
+ } else {
+ // Same prefix and no use tree list but differs in more than one segment at the end. This might be module style still.
+ res = ImportGranularityGuess::ModuleOrItem;
}
+ } else {
+ // Same prefix with item tree lists, has to be module style as it
+ // can't be crate style since the trees wouldn't share a prefix then.
+ break ImportGranularityGuess::Module;
}
- // Same prefix with item tree lists, has to be module style as it
- // can't be crate style since the trees wouldn't share a prefix then.
- break ImportGranularityGuess::Module;
}
}
}
Unknown,
Item,
Module,
+ ModuleOrItem,
Crate,
CrateOrModule,
}
ImportGranularityGuess::Unknown => mb,
ImportGranularityGuess::Item => None,
ImportGranularityGuess::Module => Some(MergeBehavior::Module),
+ ImportGranularityGuess::ModuleOrItem => mb.and(Some(MergeBehavior::Module)),
ImportGranularityGuess::Crate => Some(MergeBehavior::Crate),
ImportGranularityGuess::CrateOrModule => mb.or(Some(MergeBehavior::Crate)),
};
",
ImportGranularityGuess::Item,
);
+}
+
+#[test]
+fn guess_module_or_item() {
check_guess(
r"
use foo::bar::Bar;
-use foo::baz;
+use foo::qux;
",
- ImportGranularityGuess::Item,
+ ImportGranularityGuess::ModuleOrItem,
+ );
+ check_guess(
+ r"
+use foo::bar::Bar;
+use foo::bar;
+",
+ ImportGranularityGuess::ModuleOrItem,
);
}