1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std::cmp::Ordering;
14 use syntax::ast::{self, UseTreeKind};
15 use syntax::codemap::{self, BytePos, Span, DUMMY_SP};
17 use codemap::SpanUtils;
18 use comment::combine_strs_with_missing_comments;
19 use config::IndentStyle;
20 use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
21 use rewrite::{Rewrite, RewriteContext};
25 use visitor::FmtVisitor;
30 /// Returns a name imported by a `use` declaration. e.g. returns `Ordering`
31 /// for `std::cmp::Ordering` and `self` for `std::cmp::self`.
32 pub fn path_to_imported_ident(path: &ast::Path) -> ast::Ident {
33 path.segments.last().unwrap().ident
36 impl<'a> FmtVisitor<'a> {
37 pub fn format_import(&mut self, item: &ast::Item, tree: &ast::UseTree) {
39 let shape = self.shape();
40 let rw = UseTree::from_ast(
44 Some(item.vis.clone()),
46 Some(item.attrs.clone()),
47 ).rewrite_top_level(&self.get_context(), shape);
49 Some(ref s) if s.is_empty() => {
50 // Format up to last newline
51 let prev_span = mk_sp(self.last_pos, source!(self, span).lo());
52 let trimmed_snippet = self.snippet(prev_span).trim_right();
53 let span_end = self.last_pos + BytePos(trimmed_snippet.len() as u32);
54 self.format_missing(span_end);
55 // We have an excessive newline from the removed import.
56 if self.buffer.ends_with('\n') {
58 self.line_number -= 1;
60 self.last_pos = source!(self, span).hi();
63 self.format_missing_with_indent(source!(self, span).lo());
65 self.last_pos = source!(self, span).hi();
68 self.format_missing_with_indent(source!(self, span).lo());
69 self.format_missing(source!(self, span).hi());
75 // Ordering of imports
77 // We order imports by translating to our own representation and then sorting.
78 // The Rust AST data structures are really bad for this. Rustfmt applies a bunch
79 // of normalisations to imports and since we want to sort based on the result
80 // of these (and to maintain idempotence) we must apply the same normalisations
81 // to the data structures for sorting.
83 // We sort `self` and `super` before other imports, then identifier imports,
84 // then glob imports, then lists of imports. We do not take aliases into account
85 // when ordering unless the imports are identical except for the alias (rare in
88 // FIXME(#2531) - we should unify the comparison code here with the formatting
89 // code elsewhere since we are essentially string-ifying twice. Furthermore, by
90 // parsing to our own format on comparison, we repeat a lot of work when
93 // FIXME we do a lot of allocation to make our own representation.
94 #[derive(Clone, Eq, PartialEq)]
96 Ident(String, Option<String>),
98 Super(Option<String>),
105 pub path: Vec<UseSegment>,
107 // Comment information within nested use tree.
108 pub list_item: Option<ListItem>,
109 // Additional fields for top level use items.
110 // Should we have another struct for top-level use items rather than reusing this?
111 visibility: Option<ast::Visibility>,
112 attrs: Option<Vec<ast::Attribute>>,
115 impl PartialEq for UseTree {
116 fn eq(&self, other: &UseTree) -> bool {
117 self.path == other.path
120 impl Eq for UseTree {}
122 impl Spanned for UseTree {
123 fn span(&self) -> Span {
124 let lo = if let Some(ref attrs) = self.attrs {
125 attrs.iter().next().map_or(self.span.lo(), |a| a.span.lo())
129 mk_sp(lo, self.span.hi())
134 // Clone a version of self with any top-level alias removed.
135 fn remove_alias(&self) -> UseSegment {
137 UseSegment::Ident(ref s, _) => UseSegment::Ident(s.clone(), None),
138 UseSegment::Slf(_) => UseSegment::Slf(None),
139 UseSegment::Super(_) => UseSegment::Super(None),
144 fn from_path_segment(path_seg: &ast::PathSegment) -> Option<UseSegment> {
145 let name = path_seg.ident.name.as_str();
146 if name == "{{root}}" {
149 Some(if name == "self" {
150 UseSegment::Slf(None)
151 } else if name == "super" {
152 UseSegment::Super(None)
154 UseSegment::Ident((*name).to_owned(), None)
159 pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
160 let mut result = Vec::with_capacity(use_trees.len());
161 for use_tree in use_trees {
162 if use_tree.has_comment() || use_tree.attrs.is_some() {
163 result.push(use_tree);
167 for flattened in use_tree.flatten() {
168 merge_use_trees_inner(&mut result, flattened);
174 fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
175 for tree in trees.iter_mut() {
176 if tree.share_prefix(&use_tree) {
177 tree.merge(use_tree);
182 trees.push(use_tree);
185 impl fmt::Debug for UseTree {
186 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
187 fmt::Display::fmt(self, f)
191 impl fmt::Debug for UseSegment {
192 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
193 fmt::Display::fmt(self, f)
197 impl fmt::Display for UseSegment {
198 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
200 UseSegment::Glob => write!(f, "*"),
201 UseSegment::Ident(ref s, _) => write!(f, "{}", s),
202 UseSegment::Slf(..) => write!(f, "self"),
203 UseSegment::Super(..) => write!(f, "super"),
204 UseSegment::List(ref list) => {
206 for (i, item) in list.iter().enumerate() {
207 let is_last = i == list.len() - 1;
208 write!(f, "{}", item)?;
218 impl fmt::Display for UseTree {
219 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
220 for (i, segment) in self.path.iter().enumerate() {
221 let is_last = i == self.path.len() - 1;
222 write!(f, "{}", segment)?;
232 // Rewrite use tree with `use ` and a trailing `;`.
233 pub fn rewrite_top_level(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
234 let vis = self.visibility
236 .map_or(Cow::from(""), |vis| ::utils::format_visibility(&vis));
237 let use_str = self.rewrite(context, shape.offset_left(vis.len())?)
242 format!("{}use {};", vis, s)
245 if let Some(ref attrs) = self.attrs {
246 let attr_str = attrs.rewrite(context, shape)?;
247 let lo = attrs.last().as_ref()?.span().hi();
248 let hi = self.span.lo();
249 let span = mk_sp(lo, hi);
250 combine_strs_with_missing_comments(context, &attr_str, &use_str, span, shape, false)
256 // FIXME: Use correct span?
257 // The given span is essentially incorrect, since we are reconstructing
258 // use statements. This should not be a problem, though, since we have
259 // already tried to extract comment and observed that there are no comment
260 // around the given use item, and the span will not be used afterward.
261 fn from_path(path: Vec<UseSegment>, span: Span) -> UseTree {
271 pub fn from_ast_with_normalization(
272 context: &RewriteContext,
274 ) -> Option<UseTree> {
276 ast::ItemKind::Use(ref use_tree) => Some(
281 Some(item.vis.clone()),
282 Some(item.span.lo()),
283 if item.attrs.is_empty() {
286 Some(item.attrs.clone())
295 context: &RewriteContext,
297 list_item: Option<ListItem>,
298 visibility: Option<ast::Visibility>,
299 opt_lo: Option<BytePos>,
300 attrs: Option<Vec<ast::Attribute>>,
302 let span = if let Some(lo) = opt_lo {
303 mk_sp(lo, a.span.hi())
307 let mut result = UseTree {
314 for p in &a.prefix.segments {
315 if let Some(use_segment) = UseSegment::from_path_segment(p) {
316 result.path.push(use_segment);
320 UseTreeKind::Glob => {
321 result.path.push(UseSegment::Glob);
323 UseTreeKind::Nested(ref list) => {
324 // Extract comments between nested use items.
325 // This needs to be done before sorting use items.
326 let items: Vec<_> = itemize_list(
327 context.snippet_provider,
328 list.iter().map(|(tree, _)| tree),
331 |tree| tree.span.lo(),
332 |tree| tree.span.hi(),
333 |_| Some("".to_owned()), // We only need comments for now.
334 context.snippet_provider.span_after(a.span, "{"),
338 result.path.push(UseSegment::List(
340 .zip(items.into_iter())
341 .map(|(t, list_item)| {
342 Self::from_ast(context, &t.0, Some(list_item), None, None, None)
347 UseTreeKind::Simple(ref rename) => {
348 let mut name = (*path_to_imported_ident(&a.prefix).name.as_str()).to_owned();
349 let alias = rename.and_then(|ident| {
350 if ident == path_to_imported_ident(&a.prefix) {
353 Some(ident.to_string())
357 let segment = if &name == "self" {
358 UseSegment::Slf(alias)
359 } else if &name == "super" {
360 UseSegment::Super(alias)
362 UseSegment::Ident(name, alias)
365 // `name` is already in result.
367 result.path.push(segment);
373 // Do the adjustments that rustfmt does elsewhere to use paths.
374 pub fn normalize(mut self) -> UseTree {
375 let mut last = self.path.pop().expect("Empty use tree?");
376 // Hack around borrow checker.
377 let mut normalize_sole_list = false;
378 let mut aliased_self = false;
380 // Remove foo::{} or self without attributes.
382 _ if self.attrs.is_some() => (),
383 UseSegment::List(ref list) if list.is_empty() => {
387 UseSegment::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
394 // Normalise foo::self -> foo.
395 if let UseSegment::Slf(None) = last {
396 if !self.path.is_empty() {
401 // Normalise foo::self as bar -> foo as bar.
402 if let UseSegment::Slf(_) = last {
403 match self.path.last() {
405 Some(UseSegment::Ident(_, None)) => {
412 let mut done = false;
414 match self.path.last_mut() {
415 Some(UseSegment::Ident(_, ref mut old_rename)) => {
416 assert!(old_rename.is_none());
417 if let UseSegment::Slf(Some(rename)) = last.clone() {
418 *old_rename = Some(rename);
430 // Normalise foo::{bar} -> foo::bar
431 if let UseSegment::List(ref list) = last {
433 normalize_sole_list = true;
437 if normalize_sole_list {
439 UseSegment::List(list) => {
440 for seg in &list[0].path {
441 self.path.push(seg.clone());
443 return self.normalize();
449 // Recursively normalize elements of a list use (including sorting the list).
450 if let UseSegment::List(list) = last {
451 let mut list = list.into_iter()
452 .map(|ut| ut.normalize())
453 .collect::<Vec<_>>();
455 last = UseSegment::List(list);
458 self.path.push(last);
462 fn has_comment(&self) -> bool {
463 self.list_item.as_ref().map_or(false, ListItem::has_comment)
466 fn same_visibility(&self, other: &UseTree) -> bool {
467 match (&self.visibility, &other.visibility) {
469 Some(codemap::Spanned {
470 node: ast::VisibilityKind::Inherited,
477 Some(codemap::Spanned {
478 node: ast::VisibilityKind::Inherited,
482 | (None, None) => true,
484 Some(codemap::Spanned { node: lnode, .. }),
485 Some(codemap::Spanned { node: rnode, .. }),
491 fn share_prefix(&self, other: &UseTree) -> bool {
492 if self.path.is_empty() || other.path.is_empty() || self.attrs.is_some()
493 || !self.same_visibility(other)
497 self.path[0] == other.path[0]
501 fn flatten(self) -> Vec<UseTree> {
502 if self.path.is_empty() {
505 match self.path.clone().last().unwrap() {
506 UseSegment::List(list) => {
507 let prefix = &self.path[..self.path.len() - 1];
508 let mut result = vec![];
509 for nested_use_tree in list {
510 for mut flattend in &mut nested_use_tree.clone().flatten() {
511 let mut new_path = prefix.to_vec();
512 new_path.append(&mut flattend.path);
513 result.push(UseTree {
517 visibility: self.visibility.clone(),
529 fn merge(&mut self, other: UseTree) {
530 let mut new_path = vec![];
531 for (mut a, b) in self.path
534 .zip(other.path.clone().into_iter())
542 if let Some(merged) = merge_rest(&self.path, &other.path, new_path.len()) {
543 new_path.push(merged);
544 self.span = self.span.to(other.span);
546 self.path = new_path;
550 fn merge_rest(a: &[UseSegment], b: &[UseSegment], len: usize) -> Option<UseSegment> {
551 let a_rest = &a[len..];
552 let b_rest = &b[len..];
553 if a_rest.is_empty() && b_rest.is_empty() {
556 if a_rest.is_empty() {
557 return Some(UseSegment::List(vec![
558 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
559 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
562 if b_rest.is_empty() {
563 return Some(UseSegment::List(vec![
564 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
565 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
568 if let UseSegment::List(mut list) = a_rest[0].clone() {
569 merge_use_trees_inner(&mut list, UseTree::from_path(b_rest.to_vec(), DUMMY_SP));
571 return Some(UseSegment::List(list.clone()));
574 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
575 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
578 Some(UseSegment::List(list))
581 impl PartialOrd for UseSegment {
582 fn partial_cmp(&self, other: &UseSegment) -> Option<Ordering> {
583 Some(self.cmp(other))
586 impl PartialOrd for UseTree {
587 fn partial_cmp(&self, other: &UseTree) -> Option<Ordering> {
588 Some(self.cmp(other))
591 impl Ord for UseSegment {
592 fn cmp(&self, other: &UseSegment) -> Ordering {
593 use self::UseSegment::*;
595 fn is_upper_snake_case(s: &str) -> bool {
596 s.chars().all(|c| c.is_uppercase() || c == '_')
599 match (self, other) {
600 (&Slf(ref a), &Slf(ref b)) | (&Super(ref a), &Super(ref b)) => a.cmp(b),
601 (&Glob, &Glob) => Ordering::Equal,
602 (&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
603 // snake_case < CamelCase < UPPER_SNAKE_CASE
604 if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
605 return Ordering::Greater;
607 if ia.starts_with(char::is_lowercase) && ib.starts_with(char::is_uppercase) {
608 return Ordering::Less;
610 if is_upper_snake_case(ia) && !is_upper_snake_case(ib) {
611 return Ordering::Greater;
613 if !is_upper_snake_case(ia) && is_upper_snake_case(ib) {
614 return Ordering::Less;
616 let ident_ord = ia.cmp(ib);
617 if ident_ord != Ordering::Equal {
620 if aa.is_none() && ab.is_some() {
621 return Ordering::Less;
623 if aa.is_some() && ab.is_none() {
624 return Ordering::Greater;
628 (&List(ref a), &List(ref b)) => {
629 for (a, b) in a.iter().zip(b.iter()) {
631 if ord != Ordering::Equal {
636 a.len().cmp(&b.len())
638 (&Slf(_), _) => Ordering::Less,
639 (_, &Slf(_)) => Ordering::Greater,
640 (&Super(_), _) => Ordering::Less,
641 (_, &Super(_)) => Ordering::Greater,
642 (&Ident(..), _) => Ordering::Less,
643 (_, &Ident(..)) => Ordering::Greater,
644 (&Glob, _) => Ordering::Less,
645 (_, &Glob) => Ordering::Greater,
649 impl Ord for UseTree {
650 fn cmp(&self, other: &UseTree) -> Ordering {
651 for (a, b) in self.path.iter().zip(other.path.iter()) {
653 // The comparison without aliases is a hack to avoid situations like
654 // comparing `a::b` to `a as c` - where the latter should be ordered
655 // first since it is shorter.
656 if ord != Ordering::Equal && a.remove_alias().cmp(&b.remove_alias()) != Ordering::Equal
662 self.path.len().cmp(&other.path.len())
666 fn rewrite_nested_use_tree(
667 context: &RewriteContext,
668 use_tree_list: &[UseTree],
670 ) -> Option<String> {
671 let mut list_items = Vec::with_capacity(use_tree_list.len());
672 let nested_shape = match context.config.imports_indent() {
673 IndentStyle::Block => shape
674 .block_indent(context.config.tab_spaces())
675 .with_max_width(context.config)
677 IndentStyle::Visual => shape.visual_indent(0),
679 for use_tree in use_tree_list {
680 if let Some(mut list_item) = use_tree.list_item.clone() {
681 list_item.item = use_tree.rewrite(context, nested_shape);
682 list_items.push(list_item);
684 list_items.push(ListItem::from_str(use_tree.rewrite(context, nested_shape)?));
687 let has_nested_list = use_tree_list.iter().any(|use_segment| {
691 .map_or(false, |last_segment| match last_segment {
692 UseSegment::List(..) => true,
697 let remaining_width = if has_nested_list {
700 shape.width.checked_sub(2).unwrap_or(0)
703 let tactic = definitive_tactic(
705 context.config.imports_layout(),
710 let ends_with_newline = context.config.imports_indent() == IndentStyle::Block
711 && tactic != DefinitiveListTactic::Horizontal;
712 let fmt = ListFormatting {
715 trailing_separator: if ends_with_newline {
716 context.config.trailing_comma()
718 SeparatorTactic::Never
720 separator_place: SeparatorPlace::Back,
723 preserve_newline: true,
724 config: context.config,
727 let list_str = write_list(&list_items, &fmt)?;
729 let result = if (list_str.contains('\n') || list_str.len() > remaining_width)
730 && context.config.imports_indent() == IndentStyle::Block
734 nested_shape.indent.to_string(context.config),
736 shape.indent.to_string(context.config)
739 format!("{{{}}}", list_str)
745 impl Rewrite for UseSegment {
746 fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
748 UseSegment::Ident(ref ident, Some(ref rename)) => format!("{} as {}", ident, rename),
749 UseSegment::Ident(ref ident, None) => ident.clone(),
750 UseSegment::Slf(Some(ref rename)) => format!("self as {}", rename),
751 UseSegment::Slf(None) => "self".to_owned(),
752 UseSegment::Super(Some(ref rename)) => format!("super as {}", rename),
753 UseSegment::Super(None) => "super".to_owned(),
754 UseSegment::Glob => "*".to_owned(),
755 UseSegment::List(ref use_tree_list) => rewrite_nested_use_tree(
759 shape.offset_left(1)?.sub_width(1)?,
765 impl Rewrite for UseTree {
766 // This does NOT format attributes and visibility or add a trailing `;`.
767 fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option<String> {
768 let mut result = String::with_capacity(256);
769 let mut iter = self.path.iter().peekable();
770 while let Some(ref segment) = iter.next() {
771 let segment_str = segment.rewrite(context, shape)?;
772 result.push_str(&segment_str);
773 if iter.peek().is_some() {
774 result.push_str("::");
776 shape = shape.offset_left(2 + segment_str.len())?;
786 use syntax::codemap::DUMMY_SP;
788 // Parse the path part of an import. This parser is not robust and is only
789 // suitable for use in a test harness.
790 fn parse_use_tree(s: &str) -> UseTree {
791 use std::iter::Peekable;
796 input: Peekable<Chars<'a>>,
799 impl<'a> Parser<'a> {
801 self.input.next().unwrap();
804 fn eat(&mut self, c: char) {
805 assert!(self.input.next().unwrap() == c);
809 result: &mut Vec<UseSegment>,
811 alias_buf: &mut Option<String>,
814 let mut alias = None;
815 swap(alias_buf, &mut alias);
817 result.push(UseSegment::Slf(alias));
818 *buf = String::new();
820 } else if buf == "super" {
821 result.push(UseSegment::Super(alias));
822 *buf = String::new();
825 let mut name = String::new();
826 swap(buf, &mut name);
827 result.push(UseSegment::Ident(name, alias));
832 fn parse_in_list(&mut self) -> UseTree {
833 let mut result = vec![];
834 let mut buf = String::new();
835 let mut alias_buf = None;
836 while let Some(&c) = self.input.peek() {
839 assert!(buf.is_empty());
841 result.push(UseSegment::List(self.parse_list()));
845 assert!(buf.is_empty());
847 result.push(UseSegment::Glob);
852 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
855 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
869 alias_buf = Some(String::new());
873 if let Some(ref mut buf) = alias_buf {
881 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
891 fn parse_list(&mut self) -> Vec<UseTree> {
892 let mut result = vec![];
894 match self.input.peek().unwrap() {
895 ',' | ' ' => self.bump(),
899 _ => result.push(self.parse_in_list()),
905 let mut parser = Parser {
906 input: s.chars().peekable(),
908 parser.parse_in_list()
911 macro parse_use_trees($($s:expr),* $(,)*) {
913 $(parse_use_tree($s),)*
918 fn test_use_tree_merge() {
919 macro test_merge([$($input:expr),* $(,)*], [$($output:expr),* $(,)*]) {
921 merge_use_trees(parse_use_trees!($($input,)*)),
922 parse_use_trees!($($output,)*),
926 test_merge!(["a::b::{c, d}", "a::b::{e, f}"], ["a::b::{c, d, e, f}"]);
927 test_merge!(["a::b::c", "a::b"], ["a::b::{self, c}"]);
928 test_merge!(["a::b", "a::b"], ["a::b"]);
929 test_merge!(["a", "a::b", "a::b::c"], ["a::{self, b::{self, c}}"]);
931 ["a::{b::{self, c}, d::e}", "a::d::f"],
932 ["a::{b::{self, c}, d::{e, f}}"]
935 ["a::d::f", "a::{b::{self, c}, d::e}"],
936 ["a::{b::{self, c}, d::{e, f}}"]
939 ["a::{c, d, b}", "a::{d, e, b, a, f}", "a::{f, g, c}"],
940 ["a::{a, b, c, d, e, f, g}"]
945 fn test_use_tree_flatten() {
947 parse_use_tree("a::b::{c, d, e, f}").flatten(),
948 parse_use_trees!("a::b::c", "a::b::d", "a::b::e", "a::b::f",)
952 parse_use_tree("a::b::{c::{d, e, f}, g, h::{i, j, k}}").flatten(),
966 fn test_use_tree_normalize() {
967 assert_eq!(parse_use_tree("a::self").normalize(), parse_use_tree("a"));
969 parse_use_tree("a::self as foo").normalize(),
970 parse_use_tree("a as foo")
972 assert_eq!(parse_use_tree("a::{self}").normalize(), parse_use_tree("a"));
973 assert_eq!(parse_use_tree("a::{b}").normalize(), parse_use_tree("a::b"));
975 parse_use_tree("a::{b, c::self}").normalize(),
976 parse_use_tree("a::{b, c}")
979 parse_use_tree("a::{b as bar, c::self}").normalize(),
980 parse_use_tree("a::{b as bar, c}")
985 fn test_use_tree_ord() {
986 assert!(parse_use_tree("a").normalize() < parse_use_tree("aa").normalize());
987 assert!(parse_use_tree("a").normalize() < parse_use_tree("a::a").normalize());
988 assert!(parse_use_tree("a").normalize() < parse_use_tree("*").normalize());
989 assert!(parse_use_tree("a").normalize() < parse_use_tree("{a, b}").normalize());
990 assert!(parse_use_tree("*").normalize() < parse_use_tree("{a, b}").normalize());
993 parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, dddddddd}").normalize()
994 < parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, ddddddddd}").normalize()
997 parse_use_tree("serde::de::{Deserialize}").normalize()
998 < parse_use_tree("serde_json").normalize()
1000 assert!(parse_use_tree("a::b::c").normalize() < parse_use_tree("a::b::*").normalize());
1002 parse_use_tree("foo::{Bar, Baz}").normalize()
1003 < parse_use_tree("{Bar, Baz}").normalize()
1007 parse_use_tree("foo::{self as bar}").normalize()
1008 < parse_use_tree("foo::{qux as bar}").normalize()
1011 parse_use_tree("foo::{qux as bar}").normalize()
1012 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1015 parse_use_tree("foo::{self as bar, baz}").normalize()
1016 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1019 assert!(parse_use_tree("foo").normalize() < parse_use_tree("Foo").normalize());
1020 assert!(parse_use_tree("foo").normalize() < parse_use_tree("foo::Bar").normalize());
1023 parse_use_tree("std::cmp::{d, c, b, a}").normalize()
1024 < parse_use_tree("std::cmp::{b, e, g, f}").normalize()