Merge pull request #2682 from topecongiro/issue-2670

Do not duplicate attributes on use items
This commit is contained in:
Nick Cameron 2018-05-07 11:21:02 +12:00 committed by GitHub
commit bd7ae5e89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 1 deletions

View File

@ -35,7 +35,7 @@ pub fn path_to_imported_ident(path: &ast::Path) -> ast::Ident {
impl<'a> FmtVisitor<'a> { impl<'a> FmtVisitor<'a> {
pub fn format_import(&mut self, item: &ast::Item, tree: &ast::UseTree) { pub fn format_import(&mut self, item: &ast::Item, tree: &ast::UseTree) {
let span = item.span; let span = item.span();
let shape = self.shape(); let shape = self.shape();
let rw = UseTree::from_ast( let rw = UseTree::from_ast(
&self.get_context(), &self.get_context(),

View File

@ -303,6 +303,13 @@ pub fn visit_item(&mut self, item: &ast::Item) {
let filtered_attrs; let filtered_attrs;
let mut attrs = &item.attrs; let mut attrs = &item.attrs;
match item.node { match item.node {
// For use items, skip rewriting attributes. Just check for a skip attribute.
ast::ItemKind::Use(..) => {
if contains_skip(attrs) {
self.push_skipped_with_span(item.span());
return;
}
}
// Module is inline, in this case we treat it like any other item. // Module is inline, in this case we treat it like any other item.
_ if !is_mod_decl(item) => { _ if !is_mod_decl(item) => {
if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) { if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {

View File

@ -93,3 +93,7 @@ fn test() {
/// This line is not affected. /// This line is not affected.
// This line is deleted. // This line is deleted.
use c; use c;
// #2670
#[macro_use]
use imports_with_attr;

View File

@ -105,3 +105,7 @@ fn test() {
/// This line is not affected. /// This line is not affected.
// This line is deleted. // This line is deleted.
use c; use c;
// #2670
#[macro_use]
use imports_with_attr;