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};
24 use utils::{is_same_visibility, mk_sp, rewrite_ident};
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) {
38 let span = item.span();
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(
145 context: &RewriteContext,
146 path_seg: &ast::PathSegment,
147 ) -> Option<UseSegment> {
148 let name = rewrite_ident(context, path_seg.ident);
149 if name.is_empty() || name == "{{root}}" {
152 Some(if name == "self" {
153 UseSegment::Slf(None)
154 } else if name == "super" {
155 UseSegment::Super(None)
157 UseSegment::Ident((*name).to_owned(), None)
162 pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
163 let mut result = Vec::with_capacity(use_trees.len());
164 for use_tree in use_trees {
165 if use_tree.has_comment() || use_tree.attrs.is_some() {
166 result.push(use_tree);
170 for flattened in use_tree.flatten() {
171 merge_use_trees_inner(&mut result, flattened);
177 fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
178 for tree in trees.iter_mut() {
179 if tree.share_prefix(&use_tree) {
180 tree.merge(use_tree);
185 trees.push(use_tree);
188 impl fmt::Debug for UseTree {
189 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
190 fmt::Display::fmt(self, f)
194 impl fmt::Debug for UseSegment {
195 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
196 fmt::Display::fmt(self, f)
200 impl fmt::Display for UseSegment {
201 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
203 UseSegment::Glob => write!(f, "*"),
204 UseSegment::Ident(ref s, _) => write!(f, "{}", s),
205 UseSegment::Slf(..) => write!(f, "self"),
206 UseSegment::Super(..) => write!(f, "super"),
207 UseSegment::List(ref list) => {
209 for (i, item) in list.iter().enumerate() {
210 let is_last = i == list.len() - 1;
211 write!(f, "{}", item)?;
221 impl fmt::Display for UseTree {
222 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
223 for (i, segment) in self.path.iter().enumerate() {
224 let is_last = i == self.path.len() - 1;
225 write!(f, "{}", segment)?;
235 // Rewrite use tree with `use ` and a trailing `;`.
236 pub fn rewrite_top_level(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
237 let vis = self.visibility.as_ref().map_or(Cow::from(""), |vis| {
238 ::utils::format_visibility(context, &vis)
241 .rewrite(context, shape.offset_left(vis.len())?)
246 format!("{}use {};", vis, s)
249 if let Some(ref attrs) = self.attrs {
250 let attr_str = attrs.rewrite(context, shape)?;
251 let lo = attrs.last().as_ref()?.span().hi();
252 let hi = self.span.lo();
253 let span = mk_sp(lo, hi);
254 combine_strs_with_missing_comments(context, &attr_str, &use_str, span, shape, false)
260 // FIXME: Use correct span?
261 // The given span is essentially incorrect, since we are reconstructing
262 // use statements. This should not be a problem, though, since we have
263 // already tried to extract comment and observed that there are no comment
264 // around the given use item, and the span will not be used afterward.
265 fn from_path(path: Vec<UseSegment>, span: Span) -> UseTree {
275 pub fn from_ast_with_normalization(
276 context: &RewriteContext,
278 ) -> Option<UseTree> {
280 ast::ItemKind::Use(ref use_tree) => Some(
285 Some(item.vis.clone()),
286 Some(item.span.lo()),
287 if item.attrs.is_empty() {
290 Some(item.attrs.clone())
299 context: &RewriteContext,
301 list_item: Option<ListItem>,
302 visibility: Option<ast::Visibility>,
303 opt_lo: Option<BytePos>,
304 attrs: Option<Vec<ast::Attribute>>,
306 let span = if let Some(lo) = opt_lo {
307 mk_sp(lo, a.span.hi())
311 let mut result = UseTree {
318 for p in &a.prefix.segments {
319 if let Some(use_segment) = UseSegment::from_path_segment(context, p) {
320 result.path.push(use_segment);
324 UseTreeKind::Glob => {
325 result.path.push(UseSegment::Glob);
327 UseTreeKind::Nested(ref list) => {
328 // Extract comments between nested use items.
329 // This needs to be done before sorting use items.
330 let items: Vec<_> = itemize_list(
331 context.snippet_provider,
332 list.iter().map(|(tree, _)| tree),
335 |tree| tree.span.lo(),
336 |tree| tree.span.hi(),
337 |_| Some("".to_owned()), // We only need comments for now.
338 context.snippet_provider.span_after(a.span, "{"),
342 result.path.push(UseSegment::List(
344 .zip(items.into_iter())
345 .map(|(t, list_item)| {
346 Self::from_ast(context, &t.0, Some(list_item), None, None, None)
350 UseTreeKind::Simple(ref rename, ..) => {
351 let name = rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned();
352 let alias = rename.and_then(|ident| {
353 if ident == path_to_imported_ident(&a.prefix) {
356 Some(rewrite_ident(context, ident).to_owned())
360 let segment = if &name == "self" {
361 UseSegment::Slf(alias)
362 } else if &name == "super" {
363 UseSegment::Super(alias)
365 UseSegment::Ident(name, alias)
368 // `name` is already in result.
370 result.path.push(segment);
376 // Do the adjustments that rustfmt does elsewhere to use paths.
377 pub fn normalize(mut self) -> UseTree {
378 let mut last = self.path.pop().expect("Empty use tree?");
379 // Hack around borrow checker.
380 let mut normalize_sole_list = false;
381 let mut aliased_self = false;
383 // Remove foo::{} or self without attributes.
385 _ if self.attrs.is_some() => (),
386 UseSegment::List(ref list) if list.is_empty() => {
390 UseSegment::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
397 // Normalise foo::self -> foo.
398 if let UseSegment::Slf(None) = last {
399 if !self.path.is_empty() {
404 // Normalise foo::self as bar -> foo as bar.
405 if let UseSegment::Slf(_) = last {
406 match self.path.last() {
408 Some(UseSegment::Ident(_, None)) => {
415 let mut done = false;
417 match self.path.last_mut() {
418 Some(UseSegment::Ident(_, ref mut old_rename)) => {
419 assert!(old_rename.is_none());
420 if let UseSegment::Slf(Some(rename)) = last.clone() {
421 *old_rename = Some(rename);
433 // Normalise foo::{bar} -> foo::bar
434 if let UseSegment::List(ref list) = last {
436 normalize_sole_list = true;
440 if normalize_sole_list {
442 UseSegment::List(list) => {
443 for seg in &list[0].path {
444 self.path.push(seg.clone());
446 return self.normalize();
452 // Recursively normalize elements of a list use (including sorting the list).
453 if let UseSegment::List(list) = last {
456 .map(|ut| ut.normalize())
457 .collect::<Vec<_>>();
459 last = UseSegment::List(list);
462 self.path.push(last);
466 fn has_comment(&self) -> bool {
467 self.list_item.as_ref().map_or(false, ListItem::has_comment)
470 fn same_visibility(&self, other: &UseTree) -> bool {
471 match (&self.visibility, &other.visibility) {
473 Some(codemap::Spanned {
474 node: ast::VisibilityKind::Inherited,
481 Some(codemap::Spanned {
482 node: ast::VisibilityKind::Inherited,
486 | (None, None) => true,
487 (Some(ref a), Some(ref b)) => is_same_visibility(a, b),
492 fn share_prefix(&self, other: &UseTree) -> bool {
493 if self.path.is_empty()
494 || other.path.is_empty()
495 || self.attrs.is_some()
496 || !self.same_visibility(other)
500 self.path[0] == other.path[0]
504 fn flatten(self) -> Vec<UseTree> {
505 if self.path.is_empty() {
508 match self.path.clone().last().unwrap() {
509 UseSegment::List(list) => {
510 let prefix = &self.path[..self.path.len() - 1];
511 let mut result = vec![];
512 for nested_use_tree in list {
513 for flattend in &mut nested_use_tree.clone().flatten() {
514 let mut new_path = prefix.to_vec();
515 new_path.append(&mut flattend.path);
516 result.push(UseTree {
520 visibility: self.visibility.clone(),
532 fn merge(&mut self, other: UseTree) {
533 let mut new_path = vec![];
538 .zip(other.path.clone().into_iter())
546 if let Some(merged) = merge_rest(&self.path, &other.path, new_path.len()) {
547 new_path.push(merged);
548 self.span = self.span.to(other.span);
550 self.path = new_path;
554 fn merge_rest(a: &[UseSegment], b: &[UseSegment], len: usize) -> Option<UseSegment> {
555 let a_rest = &a[len..];
556 let b_rest = &b[len..];
557 if a_rest.is_empty() && b_rest.is_empty() {
560 if a_rest.is_empty() {
561 return Some(UseSegment::List(vec![
562 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
563 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
566 if b_rest.is_empty() {
567 return Some(UseSegment::List(vec![
568 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
569 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
572 if let UseSegment::List(mut list) = a_rest[0].clone() {
573 merge_use_trees_inner(&mut list, UseTree::from_path(b_rest.to_vec(), DUMMY_SP));
575 return Some(UseSegment::List(list.clone()));
578 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
579 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
582 Some(UseSegment::List(list))
585 impl PartialOrd for UseSegment {
586 fn partial_cmp(&self, other: &UseSegment) -> Option<Ordering> {
587 Some(self.cmp(other))
590 impl PartialOrd for UseTree {
591 fn partial_cmp(&self, other: &UseTree) -> Option<Ordering> {
592 Some(self.cmp(other))
595 impl Ord for UseSegment {
596 fn cmp(&self, other: &UseSegment) -> Ordering {
597 use self::UseSegment::*;
599 fn is_upper_snake_case(s: &str) -> bool {
601 .all(|c| c.is_uppercase() || c == '_' || c.is_numeric())
604 match (self, other) {
605 (&Slf(ref a), &Slf(ref b)) | (&Super(ref a), &Super(ref b)) => a.cmp(b),
606 (&Glob, &Glob) => Ordering::Equal,
607 (&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
608 // snake_case < CamelCase < UPPER_SNAKE_CASE
609 if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
610 return Ordering::Greater;
612 if ia.starts_with(char::is_lowercase) && ib.starts_with(char::is_uppercase) {
613 return Ordering::Less;
615 if is_upper_snake_case(ia) && !is_upper_snake_case(ib) {
616 return Ordering::Greater;
618 if !is_upper_snake_case(ia) && is_upper_snake_case(ib) {
619 return Ordering::Less;
621 let ident_ord = ia.cmp(ib);
622 if ident_ord != Ordering::Equal {
625 if aa.is_none() && ab.is_some() {
626 return Ordering::Less;
628 if aa.is_some() && ab.is_none() {
629 return Ordering::Greater;
633 (&List(ref a), &List(ref b)) => {
634 for (a, b) in a.iter().zip(b.iter()) {
636 if ord != Ordering::Equal {
641 a.len().cmp(&b.len())
643 (&Slf(_), _) => Ordering::Less,
644 (_, &Slf(_)) => Ordering::Greater,
645 (&Super(_), _) => Ordering::Less,
646 (_, &Super(_)) => Ordering::Greater,
647 (&Ident(..), _) => Ordering::Less,
648 (_, &Ident(..)) => Ordering::Greater,
649 (&Glob, _) => Ordering::Less,
650 (_, &Glob) => Ordering::Greater,
654 impl Ord for UseTree {
655 fn cmp(&self, other: &UseTree) -> Ordering {
656 for (a, b) in self.path.iter().zip(other.path.iter()) {
658 // The comparison without aliases is a hack to avoid situations like
659 // comparing `a::b` to `a as c` - where the latter should be ordered
660 // first since it is shorter.
661 if ord != Ordering::Equal && a.remove_alias().cmp(&b.remove_alias()) != Ordering::Equal
667 self.path.len().cmp(&other.path.len())
671 fn rewrite_nested_use_tree(
672 context: &RewriteContext,
673 use_tree_list: &[UseTree],
675 ) -> Option<String> {
676 let mut list_items = Vec::with_capacity(use_tree_list.len());
677 let nested_shape = match context.config.imports_indent() {
678 IndentStyle::Block => shape
679 .block_indent(context.config.tab_spaces())
680 .with_max_width(context.config)
682 IndentStyle::Visual => shape.visual_indent(0),
684 for use_tree in use_tree_list {
685 if let Some(mut list_item) = use_tree.list_item.clone() {
686 list_item.item = use_tree.rewrite(context, nested_shape);
687 list_items.push(list_item);
689 list_items.push(ListItem::from_str(use_tree.rewrite(context, nested_shape)?));
692 let has_nested_list = use_tree_list.iter().any(|use_segment| {
696 .map_or(false, |last_segment| match last_segment {
697 UseSegment::List(..) => true,
702 let remaining_width = if has_nested_list {
705 shape.width.saturating_sub(2)
708 let tactic = definitive_tactic(
710 context.config.imports_layout(),
715 let ends_with_newline = context.config.imports_indent() == IndentStyle::Block
716 && tactic != DefinitiveListTactic::Horizontal;
717 let fmt = ListFormatting {
720 trailing_separator: if ends_with_newline {
721 context.config.trailing_comma()
723 SeparatorTactic::Never
725 separator_place: SeparatorPlace::Back,
728 preserve_newline: true,
729 nested: has_nested_list,
730 config: context.config,
733 let list_str = write_list(&list_items, &fmt)?;
735 let result = if (list_str.contains('\n') || list_str.len() > remaining_width)
736 && context.config.imports_indent() == IndentStyle::Block
740 nested_shape.indent.to_string(context.config),
742 shape.indent.to_string(context.config)
745 format!("{{{}}}", list_str)
751 impl Rewrite for UseSegment {
752 fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
754 UseSegment::Ident(ref ident, Some(ref rename)) => format!("{} as {}", ident, rename),
755 UseSegment::Ident(ref ident, None) => ident.clone(),
756 UseSegment::Slf(Some(ref rename)) => format!("self as {}", rename),
757 UseSegment::Slf(None) => "self".to_owned(),
758 UseSegment::Super(Some(ref rename)) => format!("super as {}", rename),
759 UseSegment::Super(None) => "super".to_owned(),
760 UseSegment::Glob => "*".to_owned(),
761 UseSegment::List(ref use_tree_list) => rewrite_nested_use_tree(
765 shape.offset_left(1)?.sub_width(1)?,
771 impl Rewrite for UseTree {
772 // This does NOT format attributes and visibility or add a trailing `;`.
773 fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option<String> {
774 let mut result = String::with_capacity(256);
775 let mut iter = self.path.iter().peekable();
776 while let Some(ref segment) = iter.next() {
777 let segment_str = segment.rewrite(context, shape)?;
778 result.push_str(&segment_str);
779 if iter.peek().is_some() {
780 result.push_str("::");
782 shape = shape.offset_left(2 + segment_str.len())?;
792 use syntax::codemap::DUMMY_SP;
794 // Parse the path part of an import. This parser is not robust and is only
795 // suitable for use in a test harness.
796 fn parse_use_tree(s: &str) -> UseTree {
797 use std::iter::Peekable;
802 input: Peekable<Chars<'a>>,
805 impl<'a> Parser<'a> {
807 self.input.next().unwrap();
810 fn eat(&mut self, c: char) {
811 assert!(self.input.next().unwrap() == c);
815 result: &mut Vec<UseSegment>,
817 alias_buf: &mut Option<String>,
820 let mut alias = None;
821 swap(alias_buf, &mut alias);
823 result.push(UseSegment::Slf(alias));
824 *buf = String::new();
826 } else if buf == "super" {
827 result.push(UseSegment::Super(alias));
828 *buf = String::new();
831 let mut name = String::new();
832 swap(buf, &mut name);
833 result.push(UseSegment::Ident(name, alias));
838 fn parse_in_list(&mut self) -> UseTree {
839 let mut result = vec![];
840 let mut buf = String::new();
841 let mut alias_buf = None;
842 while let Some(&c) = self.input.peek() {
845 assert!(buf.is_empty());
847 result.push(UseSegment::List(self.parse_list()));
851 assert!(buf.is_empty());
853 result.push(UseSegment::Glob);
858 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
861 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
875 alias_buf = Some(String::new());
879 if let Some(ref mut buf) = alias_buf {
887 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
897 fn parse_list(&mut self) -> Vec<UseTree> {
898 let mut result = vec![];
900 match self.input.peek().unwrap() {
901 ',' | ' ' => self.bump(),
905 _ => result.push(self.parse_in_list()),
911 let mut parser = Parser {
912 input: s.chars().peekable(),
914 parser.parse_in_list()
917 macro parse_use_trees($($s:expr),* $(,)*) {
919 $(parse_use_tree($s),)*
924 fn test_use_tree_merge() {
925 macro test_merge([$($input:expr),* $(,)*], [$($output:expr),* $(,)*]) {
927 merge_use_trees(parse_use_trees!($($input,)*)),
928 parse_use_trees!($($output,)*),
932 test_merge!(["a::b::{c, d}", "a::b::{e, f}"], ["a::b::{c, d, e, f}"]);
933 test_merge!(["a::b::c", "a::b"], ["a::b::{self, c}"]);
934 test_merge!(["a::b", "a::b"], ["a::b"]);
935 test_merge!(["a", "a::b", "a::b::c"], ["a::{self, b::{self, c}}"]);
937 ["a::{b::{self, c}, d::e}", "a::d::f"],
938 ["a::{b::{self, c}, d::{e, f}}"]
941 ["a::d::f", "a::{b::{self, c}, d::e}"],
942 ["a::{b::{self, c}, d::{e, f}}"]
945 ["a::{c, d, b}", "a::{d, e, b, a, f}", "a::{f, g, c}"],
946 ["a::{a, b, c, d, e, f, g}"]
951 fn test_use_tree_flatten() {
953 parse_use_tree("a::b::{c, d, e, f}").flatten(),
954 parse_use_trees!("a::b::c", "a::b::d", "a::b::e", "a::b::f",)
958 parse_use_tree("a::b::{c::{d, e, f}, g, h::{i, j, k}}").flatten(),
972 fn test_use_tree_normalize() {
973 assert_eq!(parse_use_tree("a::self").normalize(), parse_use_tree("a"));
975 parse_use_tree("a::self as foo").normalize(),
976 parse_use_tree("a as foo")
978 assert_eq!(parse_use_tree("a::{self}").normalize(), parse_use_tree("a"));
979 assert_eq!(parse_use_tree("a::{b}").normalize(), parse_use_tree("a::b"));
981 parse_use_tree("a::{b, c::self}").normalize(),
982 parse_use_tree("a::{b, c}")
985 parse_use_tree("a::{b as bar, c::self}").normalize(),
986 parse_use_tree("a::{b as bar, c}")
991 fn test_use_tree_ord() {
992 assert!(parse_use_tree("a").normalize() < parse_use_tree("aa").normalize());
993 assert!(parse_use_tree("a").normalize() < parse_use_tree("a::a").normalize());
994 assert!(parse_use_tree("a").normalize() < parse_use_tree("*").normalize());
995 assert!(parse_use_tree("a").normalize() < parse_use_tree("{a, b}").normalize());
996 assert!(parse_use_tree("*").normalize() < parse_use_tree("{a, b}").normalize());
999 parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, dddddddd}").normalize()
1000 < parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, ddddddddd}").normalize()
1003 parse_use_tree("serde::de::{Deserialize}").normalize()
1004 < parse_use_tree("serde_json").normalize()
1006 assert!(parse_use_tree("a::b::c").normalize() < parse_use_tree("a::b::*").normalize());
1008 parse_use_tree("foo::{Bar, Baz}").normalize()
1009 < parse_use_tree("{Bar, Baz}").normalize()
1013 parse_use_tree("foo::{self as bar}").normalize()
1014 < parse_use_tree("foo::{qux as bar}").normalize()
1017 parse_use_tree("foo::{qux as bar}").normalize()
1018 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1021 parse_use_tree("foo::{self as bar, baz}").normalize()
1022 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1025 assert!(parse_use_tree("foo").normalize() < parse_use_tree("Foo").normalize());
1026 assert!(parse_use_tree("foo").normalize() < parse_use_tree("foo::Bar").normalize());
1029 parse_use_tree("std::cmp::{d, c, b, a}").normalize()
1030 < parse_use_tree("std::cmp::{b, e, g, f}").normalize()