Skip to content

Commit 831c2bd

Browse files
committed
fix: #6558 don't try to repair invalid self-imports.
Attempts break idempotence.
1 parent 1443bba commit 831c2bd

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

src/imports.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -557,20 +557,9 @@ impl UseTree {
557557
self.path = vec![];
558558
return self;
559559
}
560-
UseSegmentKind::Slf(None) if self.path.is_empty() && self.visibility.is_some() => {
561-
self.path = vec![];
562-
return self;
563-
}
564560
_ => (),
565561
}
566562

567-
// Normalise foo::self -> foo.
568-
if let UseSegmentKind::Slf(None) = last.kind {
569-
if !self.path.is_empty() {
570-
return self;
571-
}
572-
}
573-
574563
// Normalise foo::self as bar -> foo as bar.
575564
if let UseSegmentKind::Slf(_) = last.kind {
576565
if let Some(UseSegment {
@@ -1482,7 +1471,11 @@ mod test {
14821471

14831472
#[test]
14841473
fn test_use_tree_normalize() {
1485-
assert_eq!(parse_use_tree("a::self").normalize(), parse_use_tree("a"));
1474+
assert_eq!(
1475+
parse_use_tree("a::self").normalize(),
1476+
// No longer normalized #6558
1477+
parse_use_tree("a::self")
1478+
);
14861479
assert_eq!(
14871480
parse_use_tree("a::self as foo").normalize(),
14881481
parse_use_tree("a as foo")
@@ -1494,11 +1487,13 @@ mod test {
14941487
assert_eq!(parse_use_tree("a::{b}").normalize(), parse_use_tree("a::b"));
14951488
assert_eq!(
14961489
parse_use_tree("a::{b, c::self}").normalize(),
1497-
parse_use_tree("a::{b, c}")
1490+
// No longer normalized #6558
1491+
parse_use_tree("a::{b, c::self}")
14981492
);
14991493
assert_eq!(
15001494
parse_use_tree("a::{b as bar, c::self}").normalize(),
1501-
parse_use_tree("a::{b as bar, c}")
1495+
// No longer normalized #6558
1496+
parse_use_tree("a::{b as bar, c::self}")
15021497
);
15031498
}
15041499

tests/source/imports/imports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ pub use rustc_ast::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, Expr
2323

2424
use rustc_ast::some::{};
2525

26+
// compilation error that will (and should) be ignored by rustfmt #6558
2627
use self;
2728
use std::io::{self};
29+
// compilation error that will (and should) be ignored by rustfmt #6558
2830
use std::io::self;
2931

3032
mod Foo {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::lexer;
22
use crate::lexer::tokens::TokenData;
33
use crate::lexer::{tokens::TokenData};
4+
// compilation error that will (and should) be ignored by rustfmt #6558
45
use crate::lexer::self;
56
use crate::lexer::{self};
67
use crate::lexer::{self, tokens::TokenData};

tests/source/issue_6558.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Removing `self` breaks idempotence, leaving it causes a compilation error
2+
// which the user should be made aware of #6558
3+
use self;
4+
use self::self;
5+
use self::self::self;

tests/target/imports/imports.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ use rustc_ast::{self};
2727
use Foo::{Bar, Baz};
2828
use {Bar /* comment */, /* Pre-comment! */ Foo};
2929

30-
use std::io;
30+
// compilation error that will (and should) be ignored by rustfmt #6558
31+
use self;
3132
use std::io::{self};
33+
// compilation error that will (and should) be ignored by rustfmt #6558
34+
use std::io::self;
3235

3336
mod Foo {
3437
pub use rustc_ast::ast::{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::lexer;
2-
use crate::lexer;
32
use crate::lexer::tokens::TokenData;
43
use crate::lexer::tokens::TokenData;
4+
// compilation error that will (and should) be ignored by rustfmt #6558
5+
use crate::lexer::self;
56
use crate::lexer::{self};
67
use crate::lexer::{self, tokens::TokenData};

tests/target/issue_6558.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Removing `self` breaks idempotence, leaving it causes a compilation error
2+
// which the user should be made aware of #6558
3+
use self;
4+
use self::self;
5+
use self::self::self;

0 commit comments

Comments
 (0)