Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ impl UseTree {
if self.path.is_empty() || self.contains_comment() {
return vec![self];
}
let (mut doc_comments, attributes): (ast::AttrVec, ast::AttrVec) = self
.attrs
.iter()
.cloned()
.flat_map(|attrs| attrs.into_iter())
.partition(|attr| attr.is_doc_comment());
match &self.path.clone().last().unwrap().kind {
UseSegmentKind::List(list) => {
if list.len() == 1 && list[0].path.len() == 1 {
Expand All @@ -720,7 +726,12 @@ impl UseTree {
visibility: self.visibility.clone(),
// only retain attributes for `ImportGranularity::Item`
attrs: match import_granularity {
ImportGranularity::Item => self.attrs.clone(),
ImportGranularity::Item => Some(
doc_comments
.drain(..)
.chain(attributes.iter().cloned())
.collect(),
),
_ => None,
},
});
Expand Down
10 changes: 10 additions & 0 deletions tests/source/issue-6927/rustdoc_comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// rustfmt-imports_granularity: Item

/// rustdoc comment
use a::{a, b, c};

// standard comment
use b::{a, b, c};

#[doc = "also rustdoc comment"]
use c::{a, b, c};
18 changes: 18 additions & 0 deletions tests/target/issue-6927/rustdoc_comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// rustfmt-imports_granularity: Item

/// rustdoc comment
use a::a;
use a::b;
use a::c;

// standard comment
use b::a;
use b::b;
use b::c;

#[doc = "also rustdoc comment"]
use c::a;
#[doc = "also rustdoc comment"]
use c::b;
#[doc = "also rustdoc comment"]
use c::c;
Loading