Merge pull request #1819 from brainlessdeveloper/fix-extern-crate-whitespace

Remove whitespace between words in extern declarations
This commit is contained in:
Seiichi Uchida 2017-07-31 16:21:48 +09:00 committed by GitHub
commit 47456aaa43
3 changed files with 15 additions and 1 deletions

View File

@ -25,6 +25,7 @@ use items::{format_impl, format_trait, rewrite_associated_impl_type, rewrite_ass
rewrite_static, rewrite_type_alias};
use lists::{itemize_list, write_list, DefinitiveListTactic, ListFormatting, SeparatorTactic};
use macros::{rewrite_macro, MacroPosition};
use regex::Regex;
use rewrite::{Rewrite, RewriteContext};
use utils::{self, contains_skip, mk_sp};
@ -331,7 +332,14 @@ impl<'a> FmtVisitor<'a> {
ast::ItemKind::ExternCrate(_) => {
self.format_missing_with_indent(source!(self, item.span).lo);
let new_str = self.snippet(item.span);
self.buffer.push_str(&new_str);
if contains_comment(&new_str) {
self.buffer.push_str(&new_str)
} else {
let no_whitespace =
&new_str.split_whitespace().collect::<Vec<&str>>().join(" ");
self.buffer
.push_str(&Regex::new(r"\s;").unwrap().replace(no_whitespace, ";"));
}
self.last_pos = source!(self, item.span).hi;
}
ast::ItemKind::Struct(ref def, ref generics) => {

View File

@ -1,5 +1,8 @@
// rustfmt-normalize_comments: true
extern crate foo ;
extern crate foo as bar ;
extern "C" {
fn c_func(x: *mut *mut libc::c_void);

View File

@ -1,5 +1,8 @@
// rustfmt-normalize_comments: true
extern crate foo;
extern crate foo as bar;
extern "C" {
fn c_func(x: *mut *mut libc::c_void);