Skip to content

Commit 2d52e71

Browse files
committed
Remove debug info
1 parent 9e200dc commit 2d52e71

File tree

2 files changed

+9
-183
lines changed

2 files changed

+9
-183
lines changed

src/formatting/imports.rs

Lines changed: 9 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ use crate::formatting::{
2525
/// Returns a name imported by a `use` declaration.
2626
/// E.g., returns `Ordering` for `std::cmp::Ordering` and `self` for `std::cmp::self`.
2727
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-
);
3328
path.segments.last().unwrap().ident
3429
}
3530

@@ -99,7 +94,7 @@ pub(crate) enum UseSegment {
9994
Super(Option<String>),
10095
Crate(Option<String>),
10196
Glob,
102-
Empty, // >>>> [DBO] ADD <<<<<<<
97+
Empty,
10398
List(Vec<UseTree>),
10499
}
105100

@@ -151,33 +146,19 @@ impl UseSegment {
151146
modsep: bool,
152147
) -> Option<UseSegment> {
153148
let name = rewrite_ident(context, path_seg.ident);
154-
debug!(
155-
"** [DBO]: from_path_segment: enter name={:?}, modsep={:?};",
156-
name, modsep
157-
);
158149
if name.is_empty() || name == "{{root}}" {
159-
/* >>>>> [DBO] REPLACE next */
160150
//return None;
161-
debug!("** [DBO]: from_path_segment: replacing {{root}} empty sengment on None;");
162151
if modsep {
163152
return Some(UseSegment::Empty);
164153
} else {
165154
return None;
166155
}
167-
/* <<<<< [DBO] REPLACE next */
168156
}
169157
Some(match name {
170158
"self" => UseSegment::Slf(None),
171159
"super" => UseSegment::Super(None),
172160
"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),
181162
})
182163
}
183164
}
@@ -217,13 +198,8 @@ impl fmt::Display for UseSegment {
217198
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
218199
match *self {
219200
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, _) => {
227203
write!(f, "{}", s)
228204
}
229205
UseSegment::Slf(..) => write!(f, "self"),
@@ -349,8 +325,6 @@ impl UseTree {
349325
opt_lo: Option<BytePos>,
350326
attrs: Option<Vec<ast::Attribute>>,
351327
) -> UseTree {
352-
debug!("** [DBO] from_ast: enter a={:?};", a);
353-
354328
let span = if let Some(lo) = opt_lo {
355329
mk_sp(lo, a.span.hi())
356330
} else {
@@ -376,7 +350,6 @@ impl UseTree {
376350
}
377351
}
378352

379-
/* >>>>>>>> [DBO] ADD */
380353
let segment_from_simple = |path: &ast::Path, rename: &Option<symbol::Ident>| {
381354
let name = rewrite_ident(context, path_to_imported_ident(&path)).to_owned();
382355
let alias = rename.and_then(|ident| {
@@ -389,37 +362,17 @@ impl UseTree {
389362
Some(rewrite_ident(context, ident).to_owned())
390363
}
391364
});
392-
debug!(
393-
"** [DBO] from_ast: segment_from_simple: name={:?}, alias={:?}, rename={:?};",
394-
name, alias, rename
395-
);
396365
match name.as_ref() {
397366
"self" => UseSegment::Slf(alias),
398367
"super" => UseSegment::Super(alias),
399368
"crate" => UseSegment::Crate(alias),
400369
_ => UseSegment::Ident(name, alias),
401370
}
402371
};
403-
/* <<<<<<< [DBO] ADD */
404-
405-
debug!(
406-
"** [DBO] from_ast: before match result.path={:?};",
407-
result.path
408-
);
409372

410373
match a.kind {
411374
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 */
421375
result.path.push(UseSegment::Glob);
422-
debug!("** [DBO] from_ast: Glob result.pathE={:?};", result.path);
423376
}
424377
UseTreeKind::Nested(ref list) => {
425378
// Extract comments between nested use items.
@@ -437,58 +390,9 @@ impl UseTree {
437390
false,
438391
)
439392
.collect();
440-
debug!(
441-
"** [DBO] from_ast: Nested: len={:?}, list={:?}, items={:?}, result={:?};",
442-
list.len(),
443-
list,
444-
items,
445-
result,
446-
);
447393

448394
// find whether a case of a global path and the nested list starts at the root
449395
// 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 **************************/
492396
let mut path = None;
493397
let mut rename = None;
494398
if a.prefix.segments.len() == 1 && list.len() == 1 && result.to_string().is_empty()
@@ -513,17 +417,7 @@ impl UseTree {
513417

514418
if let (Some(path), Some(rename)) = (path, rename) {
515419
result.path.push(segment_from_simple(path, rename));
516-
/******** <<<<<<<< REPLACE PREVIOUS CHANGE **************************/
517420
} 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 *********/
527421
result.path.push(UseSegment::List(
528422
list.iter()
529423
.zip(items.into_iter())
@@ -533,55 +427,18 @@ impl UseTree {
533427
.collect(),
534428
));
535429
};
536-
debug!("** [DBO] from_ast: Nested result.path={:?};", result.path);
537430
}
538431
UseTreeKind::Simple(ref rename, ..) => {
539432
// If the path has leading double colons and is composed of only 2 segments, then we
540433
// bypass the call to path_to_imported_ident which would get only the ident and
541434
// lose the path root, e.g., `that` in `::that`.
542435
// 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 **********/
576436
let segment = segment_from_simple(&a.prefix, rename);
577437
// `name` is already in result.
578438
result.path.pop();
579439
result.path.push(segment);
580-
debug!("** [DBO] from_ast: Simple result.path={:?};", result.path);
581-
/********* >>>>>> [DBO] MOVE into closure simple_to_segment **********/
582440
}
583441
}
584-
debug!("** [DBO] from_ast: resltEE.path={:?};", result.path);
585442
result
586443
}
587444

@@ -822,15 +679,14 @@ impl Ord for UseSegment {
822679
.all(|c| c.is_uppercase() || c == '_' || c.is_numeric())
823680
}
824681

825-
let ret = match (self, other) {
682+
match (self, other) {
826683
(&Slf(ref a), &Slf(ref b))
827684
| (&Super(ref a), &Super(ref b))
828685
| (&Crate(ref a), &Crate(ref b)) => compare_opt_ident_as_versions(&a, &b),
829686
(&Glob, &Glob) => Ordering::Equal,
830687
(&Ident(ref pia, ref aa), &Ident(ref pib, ref ab)) => {
831688
let ia = pia.trim_start_matches("r#");
832689
let ib = pib.trim_start_matches("r#");
833-
debug!("** [DBO] cmp for UseSegment: ia={:?}, ib={:?};", ia, ib);
834690
// snake_case < CamelCase < UPPER_SNAKE_CASE
835691
if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
836692
return Ordering::Greater;
@@ -863,58 +719,30 @@ impl Ord for UseSegment {
863719
(_, &Super(_)) => Ordering::Greater,
864720
(&Crate(_), _) => Ordering::Less,
865721
(_, &Crate(_)) => Ordering::Greater,
866-
/* >>>>>>> [DBO] ADD */
867722
(&Empty, &Empty) => Ordering::Equal,
868723
(&Empty, _) => Ordering::Less,
869724
(_, &Empty) => Ordering::Greater,
870-
/* <<<<<<< [DBO] ADD */
871725
(&Ident(..), _) => Ordering::Less,
872726
(_, &Ident(..)) => Ordering::Greater,
873727
(&Glob, _) => Ordering::Less,
874728
(_, &Glob) => Ordering::Greater,
875-
};
876-
debug!(
877-
"** [DBO] cmp for UseSegment: retEE={:?}, self={:?}, other={:?};",
878-
ret, self, other
879-
);
880-
ret
729+
}
881730
}
882731
}
883732
impl Ord for UseTree {
884733
fn cmp(&self, other: &UseTree) -> Ordering {
885-
debug!(
886-
"** [DBO] cmp for UseTree: enter self={:?}, other={:?};",
887-
self, other
888-
);
889734
for (a, b) in self.path.iter().zip(other.path.iter()) {
890735
// The comparison without aliases is a hack to avoid situations like
891736
// comparing `a::b` to `a as c` - where the latter should be ordered
892737
// first since it is shorter.
893-
//??????!!!!!!!
894738
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-
);
899739
if ord != Ordering::Equal {
900740
return ord;
901741
}
902742
}
903743

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()))
918746
}
919747
}
920748

@@ -1002,7 +830,7 @@ impl Rewrite for UseSegment {
1002830
UseSegment::Crate(Some(ref rename)) => format!("crate as {}", rename),
1003831
UseSegment::Crate(None) => "crate".to_owned(),
1004832
UseSegment::Glob => "*".to_owned(),
1005-
UseSegment::Empty => "".to_owned(), // >>>>>> [DBO] ADD <<<<<<<<
833+
UseSegment::Empty => "".to_owned(),
1006834
UseSegment::List(ref use_tree_list) => rewrite_nested_use_tree(
1007835
context,
1008836
use_tree_list,

src/formatting/reorder.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ fn group_imports(uts: Vec<UseTree>) -> Vec<Vec<UseTree>> {
307307
local_imports.push(ut)
308308
}
309309
// These are probably illegal here
310-
/* >>>>>> [DBO] REPLACE next <<<<<< */
311-
//UseSegment::Glob | UseSegment::List(_) => external_imports.push(ut),
312310
UseSegment::Empty | UseSegment::Glob | UseSegment::List(_) => external_imports.push(ut),
313311
}
314312
}

0 commit comments

Comments
 (0)