Skip to content

Commit 71a983f

Browse files
authored
Fix master (#4057)
1 parent 75a375f commit 71a983f

File tree

13 files changed

+59
-50
lines changed

13 files changed

+59
-50
lines changed

rustfmt-core/rustfmt-bin/src/bin/main.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ fn format(opt: Opt) -> Result<i32> {
475475
return format_string(buf, opt);
476476
}
477477

478+
if let Some(file) = opt.files.iter().find(|f| !f.exists()) {
479+
return Err(format_err!(
480+
"Error: file `{}` does not exist",
481+
file.display()
482+
));
483+
}
484+
if let Some(dir) = opt.files.iter().find(|f| f.is_dir()) {
485+
return Err(format_err!("Error: `{}` is a directory", dir.display()));
486+
}
487+
478488
let (config, config_path) = load_config(None, Some(&opt))?;
479489

480490
if config.verbose() == Verbosity::Verbose {
@@ -489,30 +499,22 @@ fn format(opt: Opt) -> Result<i32> {
489499
for pair in FileConfigPairIter::new(&opt, config_path.is_some()) {
490500
let file = pair.file;
491501

492-
if !file.exists() {
493-
eprintln!("Error: file `{}` does not exist", file.display());
494-
session.add_operational_error();
495-
} else if file.is_dir() {
496-
eprintln!("Error: `{}` is a directory", file.display());
497-
session.add_operational_error();
498-
} else {
499-
if let FileConfig::Local(local_config, config_path) = pair.config {
500-
if let Some(path) = config_path {
501-
if local_config.verbose() == Verbosity::Verbose {
502-
println!(
503-
"Using rustfmt config file {} for {}",
504-
path.display(),
505-
file.display()
506-
);
507-
}
502+
if let FileConfig::Local(local_config, config_path) = pair.config {
503+
if let Some(path) = config_path {
504+
if local_config.verbose() == Verbosity::Verbose {
505+
println!(
506+
"Using rustfmt config file {} for {}",
507+
path.display(),
508+
file.display()
509+
);
508510
}
509-
510-
session.override_config(local_config, |sess| {
511-
format_and_emit_report(sess, Input::File(file.to_path_buf()))
512-
});
513-
} else {
514-
format_and_emit_report(&mut session, Input::File(file.to_path_buf()));
515511
}
512+
513+
session.override_config(local_config, |sess| {
514+
format_and_emit_report(sess, Input::File(file.to_path_buf()))
515+
});
516+
} else {
517+
format_and_emit_report(&mut session, Input::File(file.to_path_buf()));
516518
}
517519
}
518520

rustfmt-core/rustfmt-lib/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Format attributes and meta items.
22
3-
use rustc_span::{BytePos, DUMMY_SP, Span, symbol::sym};
3+
use rustc_span::{symbol::sym, BytePos, Span, DUMMY_SP};
44
use syntax::ast;
55

66
use self::doc_comment::DocCommentFormatter;

rustfmt-core/rustfmt-lib/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22
use std::cmp::Ordering;
33
use std::fmt;
44

5-
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol::sym};
5+
use rustc_span::{source_map, symbol::sym, BytePos, Span, DUMMY_SP};
66
use syntax::ast::{self, UseTreeKind};
77

88
use crate::comment::combine_strs_with_missing_comments;

rustfmt-core/rustfmt-lib/src/items.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::borrow::Cow;
44
use std::cmp::{max, min, Ordering};
55

66
use regex::Regex;
7-
use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol};
7+
use rustc_span::{source_map, symbol, BytePos, Span, DUMMY_SP};
88
use syntax::visit;
99
use syntax::{ast, ptr};
1010

@@ -287,8 +287,8 @@ impl<'a> FnSig<'a> {
287287
defaultness,
288288
unsafety: fn_sig.header.unsafety,
289289
visibility: vis.clone(),
290-
}
291-
}
290+
},
291+
},
292292
_ => unreachable!(),
293293
}
294294
}
@@ -744,7 +744,13 @@ pub(crate) fn format_impl(
744744
item: &ast::Item,
745745
offset: Indent,
746746
) -> Option<String> {
747-
if let ast::ItemKind::Impl { ref generics, ref self_ty, ref items, ..} = item.kind {
747+
if let ast::ItemKind::Impl {
748+
ref generics,
749+
ref self_ty,
750+
ref items,
751+
..
752+
} = item.kind
753+
{
748754
let mut result = String::with_capacity(128);
749755
let ref_and_type = format_impl_ref_and_type(context, item, offset)?;
750756
let sep = offset.to_string_with_newline(context.config);
@@ -1760,9 +1766,7 @@ impl<'a> StaticParts<'a> {
17601766
pub(crate) fn from_item(item: &'a ast::Item) -> Self {
17611767
let (prefix, ty, mutability, expr) = match item.kind {
17621768
ast::ItemKind::Static(ref ty, mutability, ref expr) => ("static", ty, mutability, expr),
1763-
ast::ItemKind::Const(ref ty, ref expr) => {
1764-
("const", ty, ast::Mutability::Not, expr)
1765-
}
1769+
ast::ItemKind::Const(ref ty, ref expr) => ("const", ty, ast::Mutability::Not, expr),
17661770
_ => unreachable!(),
17671771
};
17681772
StaticParts {

rustfmt-core/rustfmt-lib/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
1414

1515
use rustc_ast_pretty::pprust;
1616
use rustc_parse::{new_parser_from_tts, parser::Parser};
17-
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, symbol::kw};
17+
use rustc_span::{symbol::kw, BytePos, Span, Symbol, DUMMY_SP};
1818
use syntax::token::{BinOpToken, DelimToken, Token, TokenKind};
1919
use syntax::tokenstream::{Cursor, TokenStream, TokenTree};
2020
use syntax::{ast, ptr};

rustfmt-core/rustfmt-lib/src/patterns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl Rewrite for Pat {
199199
shape,
200200
SeparatorPlace::Front,
201201
)
202-
},
202+
}
203203
(_, _) => unimplemented!(),
204-
}
204+
},
205205
PatKind::Ref(ref pat, mutability) => {
206206
let prefix = format!("&{}", format_mutability(mutability));
207207
rewrite_unary_prefix(context, &prefix, &**pat, shape)

rustfmt-core/rustfmt-lib/src/reorder.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use std::cmp::{Ord, Ordering};
1010

11-
use rustc_span::{Span, symbol::sym};
11+
use rustc_span::{symbol::sym, Span};
1212
use syntax::{ast, attr};
1313

1414
use crate::config::Config;
@@ -31,10 +31,8 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
3131
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
3232
// `extern crate foo as bar;`
3333
// ^^^ Comparing this.
34-
let a_orig_name =
35-
a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
36-
let b_orig_name =
37-
b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
34+
let a_orig_name = a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
35+
let b_orig_name = b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
3836
let result = a_orig_name.cmp(&b_orig_name);
3937
if result != Ordering::Equal {
4038
return result;

rustfmt-core/rustfmt-lib/src/skip.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ impl SkipContext {
3333
syntax::ast::AttrKind::Normal(ref attr_item) => {
3434
if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) {
3535
get_skip_names(&mut self.macros, attr)
36-
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes) {
36+
} else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes)
37+
{
3738
get_skip_names(&mut self.attributes, attr)
3839
}
3940
}

rustfmt-core/rustfmt-lib/src/syntux/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
44

55
use rustc_errors::{Diagnostic, PResult};
66
use rustc_parse::{new_sub_parser_from_file, parser::Parser as RawParser};
7-
use rustc_span::{DUMMY_SP, Span, symbol::kw};
7+
use rustc_span::{symbol::kw, Span, DUMMY_SP};
88
use syntax::ast;
99
use syntax::token::{DelimToken, TokenKind};
1010

rustfmt-core/rustfmt-lib/src/syntux/session.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use rustc_data_structures::sync::{Lrc, Send};
66
use rustc_errors::emitter::{Emitter, EmitterWriter};
77
use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel};
88
use rustc_session::parse::ParseSess as RawParseSess;
9-
use rustc_span::{BytePos, source_map::{FilePathMapping, SourceMap}, Span};
9+
use rustc_span::{
10+
source_map::{FilePathMapping, SourceMap},
11+
BytePos, Span,
12+
};
1013
use syntax::ast;
1114

1215
use crate::config::file_lines::LineRange;
@@ -274,8 +277,8 @@ mod tests {
274277
use crate::config::IgnoreList;
275278
use crate::is_nightly_channel;
276279
use crate::utils::mk_sp;
280+
use rustc_span::{FileName as SourceMapFileName, MultiSpan, DUMMY_SP};
277281
use std::path::PathBuf;
278-
use rustc_span::{DUMMY_SP, MultiSpan, FileName as SourceMapFileName};
279282

280283
struct TestEmitter {
281284
num_emitted_errors: Rc<RefCell<u32>>,

rustfmt-core/rustfmt-lib/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter::ExactSizeIterator;
22
use std::ops::Deref;
33

4-
use rustc_span::{BytePos, Span, symbol::kw};
4+
use rustc_span::{symbol::kw, BytePos, Span};
55
use syntax::ast::{self, FunctionRetTy, Mutability};
66

77
use crate::config::lists::*;

rustfmt-core/rustfmt-lib/src/utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use rustc_ast_pretty::pprust;
4-
use rustc_span::{BytePos, ExpnId, Span, sym, Symbol, SyntaxContext};
4+
use rustc_span::{sym, BytePos, ExpnId, Span, Symbol, SyntaxContext};
55
use rustc_target::spec::abi;
66
use syntax::ast::{
77
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
@@ -255,7 +255,8 @@ fn is_skip(meta_item: &MetaItem) -> bool {
255255
match meta_item.kind {
256256
MetaItemKind::Word => {
257257
let path_str = pprust::path_to_string(&meta_item.path);
258-
path_str == &*skip_annotation().as_str() || path_str == &*depr_skip_annotation().as_str()
258+
path_str == &*skip_annotation().as_str()
259+
|| path_str == &*depr_skip_annotation().as_str()
259260
}
260261
MetaItemKind::List(ref l) => {
261262
meta_item.check_name(sym::cfg_attr) && l.len() == 2 && is_skip_nested(&l[1])

rustfmt-core/rustfmt-lib/src/visitor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cell::{Cell, RefCell};
22
use std::rc::Rc;
33

44
use rustc_span::{BytePos, Pos, Span};
5-
use syntax::{ast, visit, token::DelimToken};
5+
use syntax::{ast, token::DelimToken, visit};
66

77
use crate::attr::*;
88
use crate::comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
@@ -14,7 +14,7 @@ use crate::items::{
1414
rewrite_opaque_impl_type, rewrite_opaque_type, rewrite_type_alias, FnBraceStyle, FnSig,
1515
StaticParts, StructParts,
1616
};
17-
use crate::macros::{rewrite_macro, rewrite_macro_def, MacroPosition, macro_style};
17+
use crate::macros::{macro_style, rewrite_macro, rewrite_macro_def, MacroPosition};
1818
use crate::rewrite::{Rewrite, RewriteContext};
1919
use crate::shape::{Indent, Shape};
2020
use crate::skip::{is_skip_attr, SkipContext};
@@ -448,7 +448,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
448448
if should_visit_node_again {
449449
match item.kind {
450450
ast::ItemKind::Use(ref tree) => self.format_import(item, tree),
451-
ast::ItemKind::Impl {..} => {
451+
ast::ItemKind::Impl { .. } => {
452452
let block_indent = self.block_indent;
453453
let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent));
454454
self.push_rewrite(item.span, rw);
@@ -664,7 +664,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
664664
self.block_indent,
665665
),
666666
None => rewrite_associated(),
667-
}
667+
},
668668
};
669669
self.push_rewrite(ii.span, rewrite);
670670
}

0 commit comments

Comments
 (0)