Skip to content

Commit bd7ae5e

Browse files
authored
Merge pull request #2682 from topecongiro/issue-2670
Do not duplicate attributes on use items
2 parents 4bbd5c4 + e59ceaf commit bd7ae5e

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn path_to_imported_ident(path: &ast::Path) -> ast::Ident {
3535

3636
impl<'a> FmtVisitor<'a> {
3737
pub fn format_import(&mut self, item: &ast::Item, tree: &ast::UseTree) {
38-
let span = item.span;
38+
let span = item.span();
3939
let shape = self.shape();
4040
let rw = UseTree::from_ast(
4141
&self.get_context(),

src/visitor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
303303
let filtered_attrs;
304304
let mut attrs = &item.attrs;
305305
match item.node {
306+
// For use items, skip rewriting attributes. Just check for a skip attribute.
307+
ast::ItemKind::Use(..) => {
308+
if contains_skip(attrs) {
309+
self.push_skipped_with_span(item.span());
310+
return;
311+
}
312+
}
306313
// Module is inline, in this case we treat it like any other item.
307314
_ if !is_mod_decl(item) => {
308315
if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {

tests/source/imports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ use a::{b::{c::{xxx, yyy, zzz}}};
9393
/// This line is not affected.
9494
// This line is deleted.
9595
use c;
96+
97+
// #2670
98+
#[macro_use]
99+
use imports_with_attr;

tests/target/imports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ use a::b::c::{xxx, yyy, zzz};
105105
/// This line is not affected.
106106
// This line is deleted.
107107
use c;
108+
109+
// #2670
110+
#[macro_use]
111+
use imports_with_attr;

0 commit comments

Comments
 (0)