@@ -36,34 +36,47 @@ impl MultiImport {
3636}
3737
3838#[ derive( Debug , Default ) ]
39- pub struct PathedMultiImports ( IndexMap < Vec < String > , MultiImport > ) ;
39+ pub struct PathedMultiImports ( IndexMap < ( bool , Vec < String > ) , MultiImport > ) ;
4040
4141impl PathedMultiImports {
4242 pub fn new ( ) -> Self {
4343 Self :: default ( )
4444 }
4545
46- pub fn get_mut ( & mut self , path : Vec < String > ) -> & mut MultiImport {
47- self . 0 . entry ( path) . or_insert ( MultiImport :: new ( ) )
46+ pub fn get_mut ( & mut self , is_absolute : bool , path : Vec < String > ) -> & mut MultiImport {
47+ self . 0
48+ . entry ( ( is_absolute, path) )
49+ . or_insert ( MultiImport :: new ( ) )
4850 }
4951
5052 pub fn into_items ( self ) -> Vec < Box < Item > > {
51- fn build_items ( ( mut path, imports) : ( Vec < String > , MultiImport ) ) -> Box < Item > {
52- let mut leaves = imports. leaves ;
53- let attrs = imports. attrs . unwrap_or_else ( mk) ;
54-
55- if leaves. len ( ) == 1 {
56- path. push ( leaves. pop ( ) . unwrap ( ) ) ;
57-
58- let path = mk ( ) . abs_path ( path) ;
59- attrs. use_simple_item ( path, None as Option < Ident > )
60- } else {
61- let path = mk ( ) . abs_path ( path) ;
62- attrs. use_multiple_item ( path, leaves. into_iter ( ) )
63- }
64- }
65-
66- self . 0 . into_iter ( ) . map ( build_items) . collect ( )
53+ self . 0
54+ . into_iter ( )
55+ . map ( |( ( is_absolute, mut path) , imports) | {
56+ let mut leaves = imports. leaves ;
57+ let attrs = imports. attrs . unwrap_or_else ( mk) ;
58+
59+ if leaves. len ( ) == 1 {
60+ path. push ( leaves. pop ( ) . unwrap ( ) ) ;
61+
62+ let path = if is_absolute {
63+ mk ( ) . abs_path ( path)
64+ } else {
65+ mk ( ) . path ( path)
66+ } ;
67+
68+ attrs. use_simple_item ( path, None as Option < Ident > )
69+ } else {
70+ let path = if is_absolute {
71+ mk ( ) . abs_path ( path)
72+ } else {
73+ mk ( ) . path ( path)
74+ } ;
75+
76+ attrs. use_multiple_item ( path, leaves. into_iter ( ) )
77+ }
78+ } )
79+ . collect ( )
6780 }
6881}
6982
@@ -89,12 +102,20 @@ impl ItemStore {
89102 self . foreign_items . push ( item) ;
90103 }
91104
92- pub fn add_use ( & mut self , path : Vec < String > , ident : & str ) {
93- self . uses . get_mut ( path) . insert ( ident)
105+ pub fn add_use ( & mut self , is_absolute : bool , path : Vec < String > , ident : & str ) {
106+ self . uses . get_mut ( is_absolute , path) . insert ( ident)
94107 }
95108
96- pub fn add_use_with_attr ( & mut self , path : Vec < String > , ident : & str , attrs : Builder ) {
97- self . uses . get_mut ( path) . insert_with_attr ( ident, attrs)
109+ pub fn add_use_with_attr (
110+ & mut self ,
111+ is_absolute : bool ,
112+ path : Vec < String > ,
113+ ident : & str ,
114+ attrs : Builder ,
115+ ) {
116+ self . uses
117+ . get_mut ( is_absolute, path)
118+ . insert_with_attr ( ident, attrs)
98119 }
99120
100121 pub fn drain ( & mut self ) -> ( Vec < Box < Item > > , Vec < ForeignItem > , PathedMultiImports ) {
0 commit comments