Skip to content

Commit 3b3fc2f

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

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

src/imports.rs

Lines changed: 0 additions & 11 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 {

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)