+ crate::attr::contains_name(&item.attrs, sym::macro_use)
+}
+
+/// Divides imports into three groups, corresponding to standard, external
+/// and local imports. Sorts each subgroup.
+fn group_imports(uts: Vec<UseTree>) -> Vec<Vec<UseTree>> {
+ let mut std_imports = Vec::new();
+ let mut external_imports = Vec::new();
+ let mut local_imports = Vec::new();
+
+ for ut in uts.into_iter() {
+ if ut.path.is_empty() {
+ external_imports.push(ut);
+ continue;
+ }
+ match &ut.path[0] {
+ UseSegment::Ident(id, _) => match id.as_ref() {
+ "std" | "alloc" | "core" => std_imports.push(ut),
+ _ => external_imports.push(ut),
+ },
+ UseSegment::Slf(_) | UseSegment::Super(_) | UseSegment::Crate(_) => {
+ local_imports.push(ut)
+ }
+ // These are probably illegal here
+ UseSegment::Glob | UseSegment::List(_) => external_imports.push(ut),
+ }
+ }
+
+ vec![std_imports, external_imports, local_imports]