Skip to content

Commit ec54d65

Browse files
topecongiroytmimi
authored andcommitted
Backport 3999
Do not remove comment from an import with a single item
1 parent 4c78c73 commit ec54d65

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/imports.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl UseTree {
589589

590590
// Normalise foo::{bar} -> foo::bar
591591
if let UseSegmentKind::List(ref list) = last.kind {
592-
if list.len() == 1 && list[0].to_string() != "self" {
592+
if list.len() == 1 && !list[0].has_comment() && list[0].to_string() != "self" {
593593
normalize_sole_list = true;
594594
}
595595
}
@@ -683,9 +683,9 @@ impl UseTree {
683683
let prefix = &self.path[..self.path.len() - 1];
684684
let mut result = vec![];
685685
for nested_use_tree in list {
686-
for flattend in &mut nested_use_tree.clone().flatten(import_granularity) {
686+
for flattened in &mut nested_use_tree.clone().flatten(import_granularity) {
687687
let mut new_path = prefix.to_vec();
688-
new_path.append(&mut flattend.path);
688+
new_path.append(&mut flattened.path);
689689
result.push(UseTree {
690690
path: new_path,
691691
span: self.span,

tests/source/imports/imports.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use self;
2727
use std::io::{self};
2828
use std::io::self;
2929

30+
use a::{/* comment */ item};
31+
use a::{item /* comment */};
32+
3033
mod Foo {
3134
pub use rustc_ast::ast::{
3235
ItemForeignMod,

tests/target/imports/imports.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ use {Bar /* comment */, /* Pre-comment! */ Foo};
3030
use std::io;
3131
use std::io::{self};
3232

33+
use a::{/* comment */ item};
34+
use a::{item /* comment */};
35+
3336
mod Foo {
3437
pub use rustc_ast::ast::{
3538
ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic,

0 commit comments

Comments
 (0)