@@ -25,11 +25,6 @@ use crate::formatting::{
25
25
/// Returns a name imported by a `use` declaration.
26
26
/// E.g., returns `Ordering` for `std::cmp::Ordering` and `self` for `std::cmp::self`.
27
27
pub ( crate ) fn path_to_imported_ident ( path : & ast:: Path ) -> symbol:: Ident {
28
- debug ! (
29
- "** [DBO] path_to_imported_ident: enter last segment={:?}, path={:?};" ,
30
- path. segments. last( ) ,
31
- path,
32
- ) ;
33
28
path. segments . last ( ) . unwrap ( ) . ident
34
29
}
35
30
@@ -99,7 +94,7 @@ pub(crate) enum UseSegment {
99
94
Super ( Option < String > ) ,
100
95
Crate ( Option < String > ) ,
101
96
Glob ,
102
- Empty , // >>>> [DBO] ADD <<<<<<<
97
+ Empty ,
103
98
List ( Vec < UseTree > ) ,
104
99
}
105
100
@@ -151,33 +146,19 @@ impl UseSegment {
151
146
modsep : bool ,
152
147
) -> Option < UseSegment > {
153
148
let name = rewrite_ident ( context, path_seg. ident ) ;
154
- debug ! (
155
- "** [DBO]: from_path_segment: enter name={:?}, modsep={:?};" ,
156
- name, modsep
157
- ) ;
158
149
if name. is_empty ( ) || name == "{{root}}" {
159
- /* >>>>> [DBO] REPLACE next */
160
150
//return None;
161
- debug ! ( "** [DBO]: from_path_segment: replacing {{root}} empty sengment on None;" ) ;
162
151
if modsep {
163
152
return Some ( UseSegment :: Empty ) ;
164
153
} else {
165
154
return None ;
166
155
}
167
- /* <<<<< [DBO] REPLACE next */
168
156
}
169
157
Some ( match name {
170
158
"self" => UseSegment :: Slf ( None ) ,
171
159
"super" => UseSegment :: Super ( None ) ,
172
160
"crate" => UseSegment :: Crate ( None ) ,
173
- _ => {
174
- //let mod_sep = if modsep { "::" } else { "" }; // >>>> [DBO] DELETE <<<<
175
- /* >>>>> [DBO] REPLACE next */
176
- //UseSegment::Ident(format!("{}{}", mod_sep, name), None)
177
- // ????????!!!!!!! ADD here and empty segment ???????
178
- UseSegment :: Ident ( name. to_string ( ) , None )
179
- /* <<<<<< [DBO] REPLACE next */
180
- }
161
+ _ => UseSegment :: Ident ( name. to_string ( ) , None ) ,
181
162
} )
182
163
}
183
164
}
@@ -217,13 +198,8 @@ impl fmt::Display for UseSegment {
217
198
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
218
199
match * self {
219
200
UseSegment :: Glob => write ! ( f, "*" ) ,
220
- UseSegment :: Empty => write ! ( f, "" ) , // >>>>> [DBO] ADD <<<<<<
221
- //UseSegment::Ident(ref s, _) => write!(f, "{}", s), >>>>> [DBO] without debug <<<<<
222
- UseSegment :: Ident ( ref s, ref s1) => {
223
- debug ! (
224
- "** [DBO] fmt::Display for UseSegment: Ident s={:?}, s1={:?};" ,
225
- s, s1
226
- ) ;
201
+ UseSegment :: Empty => write ! ( f, "" ) ,
202
+ UseSegment :: Ident ( ref s, _) => {
227
203
write ! ( f, "{}" , s)
228
204
}
229
205
UseSegment :: Slf ( ..) => write ! ( f, "self" ) ,
@@ -349,8 +325,6 @@ impl UseTree {
349
325
opt_lo : Option < BytePos > ,
350
326
attrs : Option < Vec < ast:: Attribute > > ,
351
327
) -> UseTree {
352
- debug ! ( "** [DBO] from_ast: enter a={:?};" , a) ;
353
-
354
328
let span = if let Some ( lo) = opt_lo {
355
329
mk_sp ( lo, a. span . hi ( ) )
356
330
} else {
@@ -376,7 +350,6 @@ impl UseTree {
376
350
}
377
351
}
378
352
379
- /* >>>>>>>> [DBO] ADD */
380
353
let segment_from_simple = |path : & ast:: Path , rename : & Option < symbol:: Ident > | {
381
354
let name = rewrite_ident ( context, path_to_imported_ident ( & path) ) . to_owned ( ) ;
382
355
let alias = rename. and_then ( |ident| {
@@ -389,37 +362,17 @@ impl UseTree {
389
362
Some ( rewrite_ident ( context, ident) . to_owned ( ) )
390
363
}
391
364
} ) ;
392
- debug ! (
393
- "** [DBO] from_ast: segment_from_simple: name={:?}, alias={:?}, rename={:?};" ,
394
- name, alias, rename
395
- ) ;
396
365
match name. as_ref ( ) {
397
366
"self" => UseSegment :: Slf ( alias) ,
398
367
"super" => UseSegment :: Super ( alias) ,
399
368
"crate" => UseSegment :: Crate ( alias) ,
400
369
_ => UseSegment :: Ident ( name, alias) ,
401
370
}
402
371
} ;
403
- /* <<<<<<< [DBO] ADD */
404
-
405
- debug ! (
406
- "** [DBO] from_ast: before match result.path={:?};" ,
407
- result. path
408
- ) ;
409
372
410
373
match a. kind {
411
374
UseTreeKind :: Glob => {
412
- /* >>>>>>>> ????!!!! [DBO] DELETE **********
413
- // in case of a global path and the glob starts at the root, e.g., "::*"
414
- if a.prefix.segments.len() == 1 && leading_modsep {
415
- /* >>>>>> [DBO] REPLACE next <<<<< */
416
- //result.path.push(UseSegment::Ident("".to_owned(), None));
417
- result.path.push(UseSegment::Empty);
418
- debug!("** [DBO] from_ast: Glob result.path1={:?};", result.path);
419
- }
420
- ******** <<<<<<<<<<<< [DBO] DELETE */
421
375
result. path . push ( UseSegment :: Glob ) ;
422
- debug ! ( "** [DBO] from_ast: Glob result.pathE={:?};" , result. path) ;
423
376
}
424
377
UseTreeKind :: Nested ( ref list) => {
425
378
// Extract comments between nested use items.
@@ -437,58 +390,9 @@ impl UseTree {
437
390
false ,
438
391
)
439
392
. collect ( ) ;
440
- debug ! (
441
- "** [DBO] from_ast: Nested: len={:?}, list={:?}, items={:?}, result={:?};" ,
442
- list. len( ) ,
443
- list,
444
- items,
445
- result,
446
- ) ;
447
393
448
394
// find whether a case of a global path and the nested list starts at the root
449
395
// with one item, e.g., "::{foo}", and does not include comments or "as".
450
- /******** >>>>>>> REPLACE PREVIOUS CHANGE **************************
451
- let first_item = if a.prefix.segments.len() == 1
452
- && list.len() == 1
453
- && result.to_string().is_empty()
454
- {
455
- let first = &list[0].0;
456
- match first.kind {
457
- UseTreeKind::Simple(..) => {
458
- // "-1" for the "}"
459
- let snippet = context
460
- .snippet(mk_sp(first.span.lo(), span.hi() - BytePos(1)))
461
- .trim();
462
- // Ensure that indent includes only the name and not
463
- // "as" clause, comments, etc.
464
- if snippet.eq(&format!("{}", first.prefix.segments[0].ident)) {
465
- Some(first)
466
- } else {
467
- None
468
- }
469
- }
470
- _ => None,
471
- }
472
- } else {
473
- None
474
- };
475
-
476
- if let Some(first) = first_item {
477
- // in case of a global path and the nested list starts at the root
478
- // with one item, e.g., "::{foo}"
479
- let tree = Self::from_ast(context, first, None, None, None, None);
480
- //let mod_sep = if leading_modsep { "::" } else { "" }; //>>>> [DBO] DEL <<<<
481
- /* >>>>>> [DBO] REPLACE next <<<<< */
482
- //let seg = UseSegment::Ident(format!("{}{}", mod_sep, tree), None);
483
- let seg = UseSegment::Ident(format!("{}", tree), None);
484
- result.path.pop();
485
- /* >>>>> [DBO] ADD */
486
- if leading_modsep {
487
- result.path.push(UseSegment::Empty);
488
- }
489
- /* <<<<<< [DBO] ADD */
490
- result.path.push(seg);
491
- ***************** REPLACE PREVIOUS CHANGE **************************/
492
396
let mut path = None ;
493
397
let mut rename = None ;
494
398
if a. prefix . segments . len ( ) == 1 && list. len ( ) == 1 && result. to_string ( ) . is_empty ( )
@@ -513,17 +417,7 @@ impl UseTree {
513
417
514
418
if let ( Some ( path) , Some ( rename) ) = ( path, rename) {
515
419
result. path . push ( segment_from_simple ( path, rename) ) ;
516
- /******** <<<<<<<< REPLACE PREVIOUS CHANGE **************************/
517
420
} else {
518
- /******* >>>>>>>> [DBO] DELETE ***********
519
- // in case of a global path and the nested list starts at the root,
520
- // e.g., "::{foo, bar}"
521
- if a.prefix.segments.len() == 1 && leading_modsep {
522
- /* >>>>>> [DBO] REPLACE next <<<<< */
523
- //result.path.push(UseSegment::Ident("".to_owned(), None));
524
- result.path.push(UseSegment::Empty);
525
- }
526
- ********* <<<<<<< [DBO] DELETE *********/
527
421
result. path . push ( UseSegment :: List (
528
422
list. iter ( )
529
423
. zip ( items. into_iter ( ) )
@@ -533,55 +427,18 @@ impl UseTree {
533
427
. collect ( ) ,
534
428
) ) ;
535
429
} ;
536
- debug ! ( "** [DBO] from_ast: Nested result.path={:?};" , result. path) ;
537
430
}
538
431
UseTreeKind :: Simple ( ref rename, ..) => {
539
432
// If the path has leading double colons and is composed of only 2 segments, then we
540
433
// bypass the call to path_to_imported_ident which would get only the ident and
541
434
// lose the path root, e.g., `that` in `::that`.
542
435
// The span of `a.prefix` contains the leading colons.
543
- /******* >>>>>>>> [DBO] REAPLCE ***********
544
- let name = if a.prefix.segments.len() == 2 && leading_modsep {
545
- debug!(
546
- "** [DBO] from_ast: snippet(a.prefix.span)={:?}, a.prefix.segments={:?}",
547
- context.snippet(a.prefix.span), a.prefix.segments
548
- );
549
- context.snippet(a.prefix.span).to_owned()
550
- } else {
551
- rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned()
552
- };
553
- *************** [DBO] REPLACE ***********/
554
- /********* >>>>>> [DBO] MOVE into closure simple_to_segment **********
555
- let name = rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned();
556
- /* <<<<<<<< [DBO] REPLACE *********/
557
- let alias = rename.and_then(|ident| {
558
- if ident.name == sym::underscore_imports {
559
- // for impl-only-use
560
- Some("_".to_owned())
561
- } else if ident == path_to_imported_ident(&a.prefix) {
562
- None
563
- } else {
564
- Some(rewrite_ident(context, ident).to_owned())
565
- }
566
- });
567
-
568
- /* >>>>>> [DBO] REPLACE ********************/
569
- let segment = match name.as_ref() {
570
- "self" => UseSegment::Slf(alias),
571
- "super" => UseSegment::Super(alias),
572
- "crate" => UseSegment::Crate(alias),
573
- _ => UseSegment::Ident(name, alias),
574
- };
575
- ************* [DBO] MOVE into closure simple_to_segment **********/
576
436
let segment = segment_from_simple ( & a. prefix , rename) ;
577
437
// `name` is already in result.
578
438
result. path . pop ( ) ;
579
439
result. path . push ( segment) ;
580
- debug ! ( "** [DBO] from_ast: Simple result.path={:?};" , result. path) ;
581
- /********* >>>>>> [DBO] MOVE into closure simple_to_segment **********/
582
440
}
583
441
}
584
- debug ! ( "** [DBO] from_ast: resltEE.path={:?};" , result. path) ;
585
442
result
586
443
}
587
444
@@ -822,15 +679,14 @@ impl Ord for UseSegment {
822
679
. all ( |c| c. is_uppercase ( ) || c == '_' || c. is_numeric ( ) )
823
680
}
824
681
825
- let ret = match ( self , other) {
682
+ match ( self , other) {
826
683
( & Slf ( ref a) , & Slf ( ref b) )
827
684
| ( & Super ( ref a) , & Super ( ref b) )
828
685
| ( & Crate ( ref a) , & Crate ( ref b) ) => compare_opt_ident_as_versions ( & a, & b) ,
829
686
( & Glob , & Glob ) => Ordering :: Equal ,
830
687
( & Ident ( ref pia, ref aa) , & Ident ( ref pib, ref ab) ) => {
831
688
let ia = pia. trim_start_matches ( "r#" ) ;
832
689
let ib = pib. trim_start_matches ( "r#" ) ;
833
- debug ! ( "** [DBO] cmp for UseSegment: ia={:?}, ib={:?};" , ia, ib) ;
834
690
// snake_case < CamelCase < UPPER_SNAKE_CASE
835
691
if ia. starts_with ( char:: is_uppercase) && ib. starts_with ( char:: is_lowercase) {
836
692
return Ordering :: Greater ;
@@ -863,58 +719,30 @@ impl Ord for UseSegment {
863
719
( _, & Super ( _) ) => Ordering :: Greater ,
864
720
( & Crate ( _) , _) => Ordering :: Less ,
865
721
( _, & Crate ( _) ) => Ordering :: Greater ,
866
- /* >>>>>>> [DBO] ADD */
867
722
( & Empty , & Empty ) => Ordering :: Equal ,
868
723
( & Empty , _) => Ordering :: Less ,
869
724
( _, & Empty ) => Ordering :: Greater ,
870
- /* <<<<<<< [DBO] ADD */
871
725
( & Ident ( ..) , _) => Ordering :: Less ,
872
726
( _, & Ident ( ..) ) => Ordering :: Greater ,
873
727
( & Glob , _) => Ordering :: Less ,
874
728
( _, & Glob ) => Ordering :: Greater ,
875
- } ;
876
- debug ! (
877
- "** [DBO] cmp for UseSegment: retEE={:?}, self={:?}, other={:?};" ,
878
- ret, self , other
879
- ) ;
880
- ret
729
+ }
881
730
}
882
731
}
883
732
impl Ord for UseTree {
884
733
fn cmp ( & self , other : & UseTree ) -> Ordering {
885
- debug ! (
886
- "** [DBO] cmp for UseTree: enter self={:?}, other={:?};" ,
887
- self , other
888
- ) ;
889
734
for ( a, b) in self . path . iter ( ) . zip ( other. path . iter ( ) ) {
890
735
// The comparison without aliases is a hack to avoid situations like
891
736
// comparing `a::b` to `a as c` - where the latter should be ordered
892
737
// first since it is shorter.
893
- //??????!!!!!!!
894
738
let ord = a. remove_alias ( ) . cmp ( & b. remove_alias ( ) ) ;
895
- debug ! (
896
- "** [DBO] cmp for UseTree: next loop ord={:?}, self={:?}, other={:?};" ,
897
- ord, a, b
898
- ) ;
899
739
if ord != Ordering :: Equal {
900
740
return ord;
901
741
}
902
742
}
903
743
904
- /* >>>>>> [DBO] REPLACE next */
905
- //Ord::cmp(&self.path.len(), &other.path.len())
906
- // .then(Ord::cmp(&self.path.last(), &other.path.last()))
907
- //????!!!!!!!
908
- let ret = Ord :: cmp ( & self . path . len ( ) , & other. path . len ( ) )
909
- . then ( Ord :: cmp ( & self . path . last ( ) , & other. path . last ( ) ) ) ;
910
- debug ! (
911
- "** [DBO] cmp for UseTree: end cmp ord={:?}, self.len={:?}, other.len={:?};" ,
912
- ret,
913
- self . path. len( ) ,
914
- other. path. len( ) ,
915
- ) ;
916
- ret
917
- /* <<<<<<< [DBO] REPLACE next */
744
+ Ord :: cmp ( & self . path . len ( ) , & other. path . len ( ) )
745
+ . then ( Ord :: cmp ( & self . path . last ( ) , & other. path . last ( ) ) )
918
746
}
919
747
}
920
748
@@ -1002,7 +830,7 @@ impl Rewrite for UseSegment {
1002
830
UseSegment :: Crate ( Some ( ref rename) ) => format ! ( "crate as {}" , rename) ,
1003
831
UseSegment :: Crate ( None ) => "crate" . to_owned ( ) ,
1004
832
UseSegment :: Glob => "*" . to_owned ( ) ,
1005
- UseSegment :: Empty => "" . to_owned ( ) , // >>>>>> [DBO] ADD <<<<<<<<
833
+ UseSegment :: Empty => "" . to_owned ( ) ,
1006
834
UseSegment :: List ( ref use_tree_list) => rewrite_nested_use_tree (
1007
835
context,
1008
836
use_tree_list,
0 commit comments