@@ -64,8 +64,6 @@ pub use config::options::CliOptions;
64
64
pub use config:: summary:: Summary ;
65
65
pub use config:: { file_lines, load_config, Config , Verbosity , WriteMode } ;
66
66
67
- pub type FmtResult < T > = std:: result:: Result < T , failure:: Error > ;
68
-
69
67
#[ macro_use]
70
68
mod utils;
71
69
@@ -107,7 +105,7 @@ pub(crate) type FileMap = Vec<FileRecord>;
107
105
108
106
pub ( crate ) type FileRecord = ( FileName , String ) ;
109
107
110
- #[ derive( Fail , Debug , Clone , Copy ) ]
108
+ #[ derive( Fail , Debug ) ]
111
109
pub enum ErrorKind {
112
110
// Line has exceeded character limit (found, maximum)
113
111
#[ fail(
@@ -132,6 +130,14 @@ pub enum ErrorKind {
132
130
// Used a rustfmt:: attribute other than skip
133
131
#[ fail( display = "invalid attribute" ) ]
134
132
BadAttr ,
133
+ #[ fail( display = "io error: {}" , _0) ]
134
+ IoError ( io:: Error ) ,
135
+ }
136
+
137
+ impl From < io:: Error > for ErrorKind {
138
+ fn from ( e : io:: Error ) -> ErrorKind {
139
+ ErrorKind :: IoError ( e)
140
+ }
135
141
}
136
142
137
143
struct FormattingError {
@@ -162,7 +168,9 @@ impl FormattingError {
162
168
}
163
169
fn msg_prefix ( & self ) -> & str {
164
170
match self . kind {
165
- ErrorKind :: LineOverflow ( ..) | ErrorKind :: TrailingWhitespace => "internal error:" ,
171
+ ErrorKind :: LineOverflow ( ..) | ErrorKind :: TrailingWhitespace | ErrorKind :: IoError ( _) => {
172
+ "internal error:"
173
+ }
166
174
ErrorKind :: LicenseCheck | ErrorKind :: BadAttr => "error:" ,
167
175
ErrorKind :: BadIssue ( _) | ErrorKind :: DeprecatedAttr => "warning:" ,
168
176
}
@@ -244,6 +252,7 @@ impl FormatReport {
244
252
| ErrorKind :: BadAttr => {
245
253
errs. has_check_errors = true ;
246
254
}
255
+ _ => { }
247
256
}
248
257
}
249
258
}
@@ -469,7 +478,7 @@ fn should_report_error(
469
478
config : & Config ,
470
479
char_kind : FullCodeCharKind ,
471
480
is_string : bool ,
472
- error_kind : ErrorKind ,
481
+ error_kind : & ErrorKind ,
473
482
) -> bool {
474
483
let allow_error_report = if char_kind. is_comment ( ) || is_string {
475
484
config. error_on_unformatted ( )
@@ -541,7 +550,8 @@ fn format_lines(
541
550
if format_line {
542
551
// Check for (and record) trailing whitespace.
543
552
if let Some ( ..) = last_wspace {
544
- if should_report_error ( config, kind, is_string, ErrorKind :: TrailingWhitespace ) {
553
+ if should_report_error ( config, kind, is_string, & ErrorKind :: TrailingWhitespace )
554
+ {
545
555
trims. push ( ( cur_line, kind, line_buffer. clone ( ) ) ) ;
546
556
}
547
557
line_len -= 1 ;
@@ -551,7 +561,7 @@ fn format_lines(
551
561
let error_kind = ErrorKind :: LineOverflow ( line_len, config. max_width ( ) ) ;
552
562
if line_len > config. max_width ( )
553
563
&& !is_skipped_line ( cur_line, skipped_range)
554
- && should_report_error ( config, kind, is_string, error_kind)
564
+ && should_report_error ( config, kind, is_string, & error_kind)
555
565
{
556
566
errors. push ( FormattingError {
557
567
line : cur_line,
@@ -967,7 +977,7 @@ pub enum Input {
967
977
Text ( String ) ,
968
978
}
969
979
970
- pub fn format_and_emit_report ( input : Input , config : & Config ) -> FmtResult < Summary > {
980
+ pub fn format_and_emit_report ( input : Input , config : & Config ) -> Result < Summary , failure :: Error > {
971
981
if !config. version_meets_requirement ( ) {
972
982
return Err ( format_err ! ( "Version mismatch" ) ) ;
973
983
}
@@ -1000,15 +1010,15 @@ pub fn format_and_emit_report(input: Input, config: &Config) -> FmtResult<Summar
1000
1010
}
1001
1011
}
1002
1012
1003
- pub fn emit_pre_matter ( config : & Config ) -> FmtResult < ( ) > {
1013
+ pub fn emit_pre_matter ( config : & Config ) -> Result < ( ) , ErrorKind > {
1004
1014
if config. write_mode ( ) == WriteMode :: Checkstyle {
1005
1015
let mut out = & mut stdout ( ) ;
1006
1016
checkstyle:: output_header ( & mut out) ?;
1007
1017
}
1008
1018
Ok ( ( ) )
1009
1019
}
1010
1020
1011
- pub fn emit_post_matter ( config : & Config ) -> FmtResult < ( ) > {
1021
+ pub fn emit_post_matter ( config : & Config ) -> Result < ( ) , ErrorKind > {
1012
1022
if config. write_mode ( ) == WriteMode :: Checkstyle {
1013
1023
let mut out = & mut stdout ( ) ;
1014
1024
checkstyle:: output_footer ( & mut out) ?;
0 commit comments