@@ -17,8 +17,9 @@ use rustc_driver::{driver, CompilerCalls, RustcDefaultCalls, Compilation};
17
17
use rustc:: session:: { config, Session } ;
18
18
use rustc:: session:: config:: { Input , ErrorOutputType } ;
19
19
use std:: path:: PathBuf ;
20
- use std:: process:: Command ;
20
+ use std:: process:: { self , Command } ;
21
21
use syntax:: ast;
22
+ use std:: io:: { self , Write } ;
22
23
23
24
use clippy_lints:: utils:: cargo;
24
25
@@ -141,6 +142,12 @@ fn show_help() {
141
142
println ! ( "{}" , CARGO_CLIPPY_HELP ) ;
142
143
}
143
144
145
+ #[ allow( print_stdout) ]
146
+ fn show_version ( ) {
147
+ println ! ( "{}" , env!( "CARGO_PKG_VERSION" ) ) ;
148
+ }
149
+
150
+ #[ cfg_attr( feature = "cargo-clippy" , allow( print_stdout) ) ]
144
151
pub fn main ( ) {
145
152
use std:: env;
146
153
@@ -154,7 +161,7 @@ pub fn main() {
154
161
return ;
155
162
}
156
163
if std:: env:: args ( ) . any ( |a| a == "--version" || a == "-V" ) {
157
- println ! ( "{}" , env! ( "CARGO_PKG_VERSION" ) ) ;
164
+ show_version ( ) ;
158
165
return ;
159
166
}
160
167
@@ -165,7 +172,12 @@ pub fn main() {
165
172
166
173
let manifest_path_arg = std:: env:: args ( ) . skip ( 2 ) . find ( |val| val. starts_with ( "--manifest-path=" ) ) ;
167
174
168
- let mut metadata = cargo:: metadata ( manifest_path_arg. as_ref ( ) . map ( AsRef :: as_ref) ) . expect ( "could not obtain cargo metadata" ) ;
175
+ let mut metadata = if let Ok ( metadata) = cargo:: metadata ( manifest_path_arg. as_ref ( ) . map ( AsRef :: as_ref) ) {
176
+ metadata
177
+ } else {
178
+ let _ = io:: stderr ( ) . write_fmt ( format_args ! ( "error: Could not obtain cargo metadata." ) ) ;
179
+ process:: exit ( 101 ) ;
180
+ } ;
169
181
170
182
assert_eq ! ( metadata. version, 1 ) ;
171
183
0 commit comments