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 {}
123 // Clone a version of self with any top-level alias removed.
124 fn remove_alias(&self) -> UseSegment {
126 UseSegment::Ident(ref s, _) => UseSegment::Ident(s.clone(), None),
127 UseSegment::Slf(_) => UseSegment::Slf(None),
128 UseSegment::Super(_) => UseSegment::Super(None),
133 fn from_path_segment(path_seg: &ast::PathSegment) -> Option<UseSegment> {
134 let name = path_seg.ident.name.as_str();
135 if name == "{{root}}" {
138 Some(if name == "self" {
139 UseSegment::Slf(None)
140 } else if name == "super" {
141 UseSegment::Super(None)
143 UseSegment::Ident((*name).to_owned(), None)
148 pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
149 let mut result = Vec::with_capacity(use_trees.len());
150 for use_tree in use_trees {
151 if use_tree.has_comment() || use_tree.attrs.is_some() {
152 result.push(use_tree);
156 for flattened in use_tree.flatten() {
157 merge_use_trees_inner(&mut result, flattened);
163 fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
164 for tree in trees.iter_mut() {
165 if tree.share_prefix(&use_tree) {
166 tree.merge(use_tree);
171 trees.push(use_tree);
174 impl fmt::Debug for UseTree {
175 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
176 fmt::Display::fmt(self, f)
180 impl fmt::Debug for UseSegment {
181 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
182 fmt::Display::fmt(self, f)
186 impl fmt::Display for UseSegment {
187 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189 UseSegment::Glob => write!(f, "*"),
190 UseSegment::Ident(ref s, _) => write!(f, "{}", s),
191 UseSegment::Slf(..) => write!(f, "self"),
192 UseSegment::Super(..) => write!(f, "super"),
193 UseSegment::List(ref list) => {
195 for (i, item) in list.iter().enumerate() {
196 let is_last = i == list.len() - 1;
197 write!(f, "{}", item)?;
207 impl fmt::Display for UseTree {
208 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
209 for (i, segment) in self.path.iter().enumerate() {
210 let is_last = i == self.path.len() - 1;
211 write!(f, "{}", segment)?;
221 // Rewrite use tree with `use ` and a trailing `;`.
222 pub fn rewrite_top_level(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
223 let vis = self.visibility
225 .map_or(Cow::from(""), |vis| ::utils::format_visibility(&vis));
226 let use_str = self.rewrite(context, shape.offset_left(vis.len())?)
231 format!("{}use {};", vis, s)
234 if let Some(ref attrs) = self.attrs {
235 let attr_str = attrs.rewrite(context, shape)?;
236 let lo = attrs.last().as_ref()?.span().hi();
237 let hi = self.span.lo();
238 let span = mk_sp(lo, hi);
239 combine_strs_with_missing_comments(context, &attr_str, &use_str, span, shape, false)
245 // FIXME: Use correct span?
246 // The given span is essentially incorrect, since we are reconstructing
247 // use statements. This should not be a problem, though, since we have
248 // already tried to extract comment and observed that there are no comment
249 // around the given use item, and the span will not be used afterward.
250 fn from_path(path: Vec<UseSegment>, span: Span) -> UseTree {
260 pub fn from_ast_with_normalization(
261 context: &RewriteContext,
263 ) -> Option<UseTree> {
265 ast::ItemKind::Use(ref use_tree) => Some(
270 Some(item.vis.clone()),
271 Some(item.span().lo()),
272 if item.attrs.is_empty() {
275 Some(item.attrs.clone())
284 context: &RewriteContext,
286 list_item: Option<ListItem>,
287 visibility: Option<ast::Visibility>,
288 opt_lo: Option<BytePos>,
289 attrs: Option<Vec<ast::Attribute>>,
291 let span = if let Some(lo) = opt_lo {
292 mk_sp(lo, a.span.hi())
296 let mut result = UseTree {
303 for p in &a.prefix.segments {
304 if let Some(use_segment) = UseSegment::from_path_segment(p) {
305 result.path.push(use_segment);
309 UseTreeKind::Glob => {
310 result.path.push(UseSegment::Glob);
312 UseTreeKind::Nested(ref list) => {
313 // Extract comments between nested use items.
314 // This needs to be done before sorting use items.
315 let items: Vec<_> = itemize_list(
316 context.snippet_provider,
317 list.iter().map(|(tree, _)| tree),
320 |tree| tree.span.lo(),
321 |tree| tree.span.hi(),
322 |_| Some("".to_owned()), // We only need comments for now.
323 context.snippet_provider.span_after(a.span, "{"),
327 result.path.push(UseSegment::List(
329 .zip(items.into_iter())
330 .map(|(t, list_item)| {
331 Self::from_ast(context, &t.0, Some(list_item), None, None, None)
336 UseTreeKind::Simple(ref rename) => {
337 let mut name = (*path_to_imported_ident(&a.prefix).name.as_str()).to_owned();
338 let alias = rename.and_then(|ident| {
339 if ident == path_to_imported_ident(&a.prefix) {
342 Some(ident.to_string())
346 let segment = if &name == "self" {
347 UseSegment::Slf(alias)
348 } else if &name == "super" {
349 UseSegment::Super(alias)
351 UseSegment::Ident(name, alias)
354 // `name` is already in result.
356 result.path.push(segment);
362 // Do the adjustments that rustfmt does elsewhere to use paths.
363 pub fn normalize(mut self) -> UseTree {
364 let mut last = self.path.pop().expect("Empty use tree?");
365 // Hack around borrow checker.
366 let mut normalize_sole_list = false;
367 let mut aliased_self = false;
369 // Remove foo::{} or self without attributes.
371 _ if self.attrs.is_some() => (),
372 UseSegment::List(ref list) if list.is_empty() => {
376 UseSegment::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
383 // Normalise foo::self -> foo.
384 if let UseSegment::Slf(None) = last {
385 if !self.path.is_empty() {
390 // Normalise foo::self as bar -> foo as bar.
391 if let UseSegment::Slf(_) = last {
392 match self.path.last() {
394 Some(UseSegment::Ident(_, None)) => {
401 let mut done = false;
403 match self.path.last_mut() {
404 Some(UseSegment::Ident(_, ref mut old_rename)) => {
405 assert!(old_rename.is_none());
406 if let UseSegment::Slf(Some(rename)) = last.clone() {
407 *old_rename = Some(rename);
419 // Normalise foo::{bar} -> foo::bar
420 if let UseSegment::List(ref list) = last {
422 normalize_sole_list = true;
426 if normalize_sole_list {
428 UseSegment::List(list) => {
429 for seg in &list[0].path {
430 self.path.push(seg.clone());
432 return self.normalize();
438 // Recursively normalize elements of a list use (including sorting the list).
439 if let UseSegment::List(list) = last {
440 let mut list = list.into_iter()
441 .map(|ut| ut.normalize())
442 .collect::<Vec<_>>();
444 last = UseSegment::List(list);
447 self.path.push(last);
451 fn has_comment(&self) -> bool {
452 self.list_item.as_ref().map_or(false, ListItem::has_comment)
455 fn same_visibility(&self, other: &UseTree) -> bool {
456 match (&self.visibility, &other.visibility) {
458 Some(codemap::Spanned {
459 node: ast::VisibilityKind::Inherited,
466 Some(codemap::Spanned {
467 node: ast::VisibilityKind::Inherited,
471 | (None, None) => true,
473 Some(codemap::Spanned { node: lnode, .. }),
474 Some(codemap::Spanned { node: rnode, .. }),
480 fn share_prefix(&self, other: &UseTree) -> bool {
481 if self.path.is_empty() || other.path.is_empty() || self.attrs.is_some()
482 || !self.same_visibility(other)
486 self.path[0] == other.path[0]
490 fn flatten(self) -> Vec<UseTree> {
491 if self.path.is_empty() {
494 match self.path.clone().last().unwrap() {
495 UseSegment::List(list) => {
496 let prefix = &self.path[..self.path.len() - 1];
497 let mut result = vec![];
498 for nested_use_tree in list {
499 for mut flattend in &mut nested_use_tree.clone().flatten() {
500 let mut new_path = prefix.to_vec();
501 new_path.append(&mut flattend.path);
502 result.push(UseTree {
506 visibility: self.visibility.clone(),
518 fn merge(&mut self, other: UseTree) {
519 let mut new_path = vec![];
520 for (mut a, b) in self.path
523 .zip(other.path.clone().into_iter())
531 if let Some(merged) = merge_rest(&self.path, &other.path, new_path.len()) {
532 new_path.push(merged);
533 self.span = self.span.to(other.span);
535 self.path = new_path;
539 fn merge_rest(a: &[UseSegment], b: &[UseSegment], len: usize) -> Option<UseSegment> {
540 let a_rest = &a[len..];
541 let b_rest = &b[len..];
542 if a_rest.is_empty() && b_rest.is_empty() {
545 if a_rest.is_empty() {
546 return Some(UseSegment::List(vec![
547 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
548 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
551 if b_rest.is_empty() {
552 return Some(UseSegment::List(vec![
553 UseTree::from_path(vec![UseSegment::Slf(None)], DUMMY_SP),
554 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
557 if let UseSegment::List(mut list) = a_rest[0].clone() {
558 merge_use_trees_inner(&mut list, UseTree::from_path(b_rest.to_vec(), DUMMY_SP));
560 return Some(UseSegment::List(list.clone()));
563 UseTree::from_path(a_rest.to_vec(), DUMMY_SP),
564 UseTree::from_path(b_rest.to_vec(), DUMMY_SP),
567 Some(UseSegment::List(list))
570 impl PartialOrd for UseSegment {
571 fn partial_cmp(&self, other: &UseSegment) -> Option<Ordering> {
572 Some(self.cmp(other))
575 impl PartialOrd for UseTree {
576 fn partial_cmp(&self, other: &UseTree) -> Option<Ordering> {
577 Some(self.cmp(other))
580 impl Ord for UseSegment {
581 fn cmp(&self, other: &UseSegment) -> Ordering {
582 use self::UseSegment::*;
584 fn is_upper_snake_case(s: &str) -> bool {
585 s.chars().all(|c| c.is_uppercase() || c == '_')
588 match (self, other) {
589 (&Slf(ref a), &Slf(ref b)) | (&Super(ref a), &Super(ref b)) => a.cmp(b),
590 (&Glob, &Glob) => Ordering::Equal,
591 (&Ident(ref ia, ref aa), &Ident(ref ib, ref ab)) => {
592 // snake_case < CamelCase < UPPER_SNAKE_CASE
593 if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
594 return Ordering::Greater;
596 if ia.starts_with(char::is_lowercase) && ib.starts_with(char::is_uppercase) {
597 return Ordering::Less;
599 if is_upper_snake_case(ia) && !is_upper_snake_case(ib) {
600 return Ordering::Greater;
602 if !is_upper_snake_case(ia) && is_upper_snake_case(ib) {
603 return Ordering::Less;
605 let ident_ord = ia.cmp(ib);
606 if ident_ord != Ordering::Equal {
609 if aa.is_none() && ab.is_some() {
610 return Ordering::Less;
612 if aa.is_some() && ab.is_none() {
613 return Ordering::Greater;
617 (&List(ref a), &List(ref b)) => {
618 for (a, b) in a.iter().zip(b.iter()) {
620 if ord != Ordering::Equal {
625 a.len().cmp(&b.len())
627 (&Slf(_), _) => Ordering::Less,
628 (_, &Slf(_)) => Ordering::Greater,
629 (&Super(_), _) => Ordering::Less,
630 (_, &Super(_)) => Ordering::Greater,
631 (&Ident(..), _) => Ordering::Less,
632 (_, &Ident(..)) => Ordering::Greater,
633 (&Glob, _) => Ordering::Less,
634 (_, &Glob) => Ordering::Greater,
638 impl Ord for UseTree {
639 fn cmp(&self, other: &UseTree) -> Ordering {
640 for (a, b) in self.path.iter().zip(other.path.iter()) {
642 // The comparison without aliases is a hack to avoid situations like
643 // comparing `a::b` to `a as c` - where the latter should be ordered
644 // first since it is shorter.
645 if ord != Ordering::Equal && a.remove_alias().cmp(&b.remove_alias()) != Ordering::Equal
651 self.path.len().cmp(&other.path.len())
655 fn rewrite_nested_use_tree(
656 context: &RewriteContext,
657 use_tree_list: &[UseTree],
659 ) -> Option<String> {
660 let mut list_items = Vec::with_capacity(use_tree_list.len());
661 let nested_shape = match context.config.imports_indent() {
662 IndentStyle::Block => shape
663 .block_indent(context.config.tab_spaces())
664 .with_max_width(context.config)
666 IndentStyle::Visual => shape.visual_indent(0),
668 for use_tree in use_tree_list {
669 if let Some(mut list_item) = use_tree.list_item.clone() {
670 list_item.item = use_tree.rewrite(context, nested_shape);
671 list_items.push(list_item);
673 list_items.push(ListItem::from_str(use_tree.rewrite(context, nested_shape)?));
676 let has_nested_list = use_tree_list.iter().any(|use_segment| {
680 .map_or(false, |last_segment| match last_segment {
681 UseSegment::List(..) => true,
685 let (tactic, remaining_width) = if has_nested_list {
686 (DefinitiveListTactic::Vertical, 0)
688 let remaining_width = shape.width.checked_sub(2).unwrap_or(0);
689 let tactic = definitive_tactic(
691 context.config.imports_layout(),
695 (tactic, remaining_width)
698 let ends_with_newline = context.config.imports_indent() == IndentStyle::Block
699 && tactic != DefinitiveListTactic::Horizontal;
700 let fmt = ListFormatting {
703 trailing_separator: if ends_with_newline {
704 context.config.trailing_comma()
706 SeparatorTactic::Never
708 separator_place: SeparatorPlace::Back,
711 preserve_newline: true,
712 config: context.config,
715 let list_str = write_list(&list_items, &fmt)?;
717 let result = if (list_str.contains('\n') || list_str.len() > remaining_width)
718 && context.config.imports_indent() == IndentStyle::Block
722 nested_shape.indent.to_string(context.config),
724 shape.indent.to_string(context.config)
727 format!("{{{}}}", list_str)
733 impl Rewrite for UseSegment {
734 fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
736 UseSegment::Ident(ref ident, Some(ref rename)) => format!("{} as {}", ident, rename),
737 UseSegment::Ident(ref ident, None) => ident.clone(),
738 UseSegment::Slf(Some(ref rename)) => format!("self as {}", rename),
739 UseSegment::Slf(None) => "self".to_owned(),
740 UseSegment::Super(Some(ref rename)) => format!("super as {}", rename),
741 UseSegment::Super(None) => "super".to_owned(),
742 UseSegment::Glob => "*".to_owned(),
743 UseSegment::List(ref use_tree_list) => rewrite_nested_use_tree(
747 shape.offset_left(1)?.sub_width(1)?,
753 impl Rewrite for UseTree {
754 // This does NOT format attributes and visibility or add a trailing `;`.
755 fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option<String> {
756 let mut result = String::with_capacity(256);
757 let mut iter = self.path.iter().peekable();
758 while let Some(ref segment) = iter.next() {
759 let segment_str = segment.rewrite(context, shape)?;
760 result.push_str(&segment_str);
761 if iter.peek().is_some() {
762 result.push_str("::");
764 shape = shape.offset_left(2 + segment_str.len())?;
774 use syntax::codemap::DUMMY_SP;
776 // Parse the path part of an import. This parser is not robust and is only
777 // suitable for use in a test harness.
778 fn parse_use_tree(s: &str) -> UseTree {
779 use std::iter::Peekable;
784 input: Peekable<Chars<'a>>,
787 impl<'a> Parser<'a> {
789 self.input.next().unwrap();
791 fn eat(&mut self, c: char) {
792 assert!(self.input.next().unwrap() == c);
795 result: &mut Vec<UseSegment>,
797 alias_buf: &mut Option<String>,
800 let mut alias = None;
801 swap(alias_buf, &mut alias);
803 result.push(UseSegment::Slf(alias));
804 *buf = String::new();
806 } else if buf == "super" {
807 result.push(UseSegment::Super(alias));
808 *buf = String::new();
811 let mut name = String::new();
812 swap(buf, &mut name);
813 result.push(UseSegment::Ident(name, alias));
817 fn parse_in_list(&mut self) -> UseTree {
818 let mut result = vec![];
819 let mut buf = String::new();
820 let mut alias_buf = None;
821 while let Some(&c) = self.input.peek() {
824 assert!(buf.is_empty());
826 result.push(UseSegment::List(self.parse_list()));
830 assert!(buf.is_empty());
832 result.push(UseSegment::Glob);
837 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
840 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
854 alias_buf = Some(String::new());
858 if let Some(ref mut buf) = alias_buf {
866 Self::push_segment(&mut result, &mut buf, &mut alias_buf);
876 fn parse_list(&mut self) -> Vec<UseTree> {
877 let mut result = vec![];
879 match self.input.peek().unwrap() {
880 ',' | ' ' => self.bump(),
884 _ => result.push(self.parse_in_list()),
890 let mut parser = Parser {
891 input: s.chars().peekable(),
893 parser.parse_in_list()
896 macro parse_use_trees($($s:expr),* $(,)*) {
898 $(parse_use_tree($s),)*
903 fn test_use_tree_merge() {
904 macro test_merge([$($input:expr),* $(,)*], [$($output:expr),* $(,)*]) {
906 merge_use_trees(parse_use_trees!($($input,)*)),
907 parse_use_trees!($($output,)*),
911 test_merge!(["a::b::{c, d}", "a::b::{e, f}"], ["a::b::{c, d, e, f}"]);
912 test_merge!(["a::b::c", "a::b"], ["a::b::{self, c}"]);
913 test_merge!(["a::b", "a::b"], ["a::b"]);
914 test_merge!(["a", "a::b", "a::b::c"], ["a::{self, b::{self, c}}"]);
916 ["a::{b::{self, c}, d::e}", "a::d::f"],
917 ["a::{b::{self, c}, d::{e, f}}"]
920 ["a::d::f", "a::{b::{self, c}, d::e}"],
921 ["a::{b::{self, c}, d::{e, f}}"]
924 ["a::{c, d, b}", "a::{d, e, b, a, f}", "a::{f, g, c}"],
925 ["a::{a, b, c, d, e, f, g}"]
930 fn test_use_tree_flatten() {
932 parse_use_tree("a::b::{c, d, e, f}").flatten(),
933 parse_use_trees!("a::b::c", "a::b::d", "a::b::e", "a::b::f",)
937 parse_use_tree("a::b::{c::{d, e, f}, g, h::{i, j, k}}").flatten(),
951 fn test_use_tree_normalize() {
952 assert_eq!(parse_use_tree("a::self").normalize(), parse_use_tree("a"));
954 parse_use_tree("a::self as foo").normalize(),
955 parse_use_tree("a as foo")
957 assert_eq!(parse_use_tree("a::{self}").normalize(), parse_use_tree("a"));
958 assert_eq!(parse_use_tree("a::{b}").normalize(), parse_use_tree("a::b"));
960 parse_use_tree("a::{b, c::self}").normalize(),
961 parse_use_tree("a::{b, c}")
964 parse_use_tree("a::{b as bar, c::self}").normalize(),
965 parse_use_tree("a::{b as bar, c}")
970 fn test_use_tree_ord() {
971 assert!(parse_use_tree("a").normalize() < parse_use_tree("aa").normalize());
972 assert!(parse_use_tree("a").normalize() < parse_use_tree("a::a").normalize());
973 assert!(parse_use_tree("a").normalize() < parse_use_tree("*").normalize());
974 assert!(parse_use_tree("a").normalize() < parse_use_tree("{a, b}").normalize());
975 assert!(parse_use_tree("*").normalize() < parse_use_tree("{a, b}").normalize());
978 parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, dddddddd}").normalize()
979 < parse_use_tree("aaaaaaaaaaaaaaa::{bb, cc, ddddddddd}").normalize()
982 parse_use_tree("serde::de::{Deserialize}").normalize()
983 < parse_use_tree("serde_json").normalize()
985 assert!(parse_use_tree("a::b::c").normalize() < parse_use_tree("a::b::*").normalize());
987 parse_use_tree("foo::{Bar, Baz}").normalize()
988 < parse_use_tree("{Bar, Baz}").normalize()
992 parse_use_tree("foo::{self as bar}").normalize()
993 < parse_use_tree("foo::{qux as bar}").normalize()
996 parse_use_tree("foo::{qux as bar}").normalize()
997 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1000 parse_use_tree("foo::{self as bar, baz}").normalize()
1001 < parse_use_tree("foo::{baz, qux as bar}").normalize()
1004 assert!(parse_use_tree("foo").normalize() < parse_use_tree("Foo").normalize());
1005 assert!(parse_use_tree("foo").normalize() < parse_use_tree("foo::Bar").normalize());
1008 parse_use_tree("std::cmp::{d, c, b, a}").normalize()
1009 < parse_use_tree("std::cmp::{b, e, g, f}").normalize()