@@ -10,6 +10,7 @@ pub enum CliError {
10
10
CommandFailed ( String ) ,
11
11
IoError ( io:: Error ) ,
12
12
ProjectRootNotFound ,
13
+ RustfmtNotInstalled ,
13
14
WalkDirError ( walkdir:: Error ) ,
14
15
}
15
16
@@ -36,6 +37,8 @@ pub fn run(check: bool, verbose: bool) {
36
37
37
38
let project_root = project_root ( ) ?;
38
39
40
+ rustfmt_test ( context) ?;
41
+
39
42
success &= cargo_fmt ( context, project_root. as_path ( ) ) ?;
40
43
success &= cargo_fmt ( context, & project_root. join ( "clippy_dev" ) ) ?;
41
44
success &= cargo_fmt ( context, & project_root. join ( "rustc_tools_util" ) ) ?;
@@ -69,6 +72,9 @@ pub fn run(check: bool, verbose: bool) {
69
72
CliError :: ProjectRootNotFound => {
70
73
eprintln ! ( "error: Can't determine root of project. Please run inside a Clippy working dir." ) ;
71
74
} ,
75
+ CliError :: RustfmtNotInstalled => {
76
+ eprintln ! ( "error: rustfmt nightly is not installed." ) ;
77
+ } ,
72
78
CliError :: WalkDirError ( err) => {
73
79
eprintln ! ( "error: {}" , err) ;
74
80
} ,
@@ -139,6 +145,29 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
139
145
Ok ( success)
140
146
}
141
147
148
+ fn rustfmt_test ( context : & FmtContext ) -> Result < ( ) , CliError > {
149
+ let program = "rustfmt" ;
150
+ let dir = std:: env:: current_dir ( ) ?;
151
+ let args = & [ "+nightly" , "--version" ] ;
152
+
153
+ if context. verbose {
154
+ println ! ( "{}" , format_command( & program, & dir, args) ) ;
155
+ }
156
+
157
+ let output = Command :: new ( & program) . current_dir ( & dir) . args ( args. iter ( ) ) . output ( ) ?;
158
+
159
+ if output. status . success ( ) {
160
+ Ok ( ( ) )
161
+ } else if std:: str:: from_utf8 ( & output. stderr )
162
+ . unwrap_or ( "" )
163
+ . starts_with ( "error: 'rustfmt' is not installed" )
164
+ {
165
+ Err ( CliError :: RustfmtNotInstalled )
166
+ } else {
167
+ Err ( CliError :: CommandFailed ( format_command ( & program, & dir, args) ) )
168
+ }
169
+ }
170
+
142
171
fn rustfmt ( context : & FmtContext , path : & Path ) -> Result < bool , CliError > {
143
172
let mut args = vec ! [ "+nightly" . as_ref( ) , path. as_os_str( ) ] ;
144
173
if context. check {
0 commit comments