@@ -149,23 +149,6 @@ pub fn main() {
149
149
150
150
let dep_path = env:: current_dir ( ) . expect ( "current dir is not readable" ) . join ( "target" ) . join ( "debug" ) . join ( "deps" ) ;
151
151
152
- let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
153
- let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
154
- let sys_root = if let ( Some ( home) , Some ( toolchain) ) = ( home, toolchain) {
155
- format ! ( "{}/toolchains/{}" , home, toolchain)
156
- } else {
157
- option_env ! ( "SYSROOT" )
158
- . map ( |s| s. to_owned ( ) )
159
- . or ( Command :: new ( "rustc" )
160
- . arg ( "--print" )
161
- . arg ( "sysroot" )
162
- . output ( )
163
- . ok ( )
164
- . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
165
- . map ( |s| s. trim ( ) . to_owned ( ) ) )
166
- . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" )
167
- } ;
168
-
169
152
if let Some ( "clippy" ) = std:: env:: args ( ) . nth ( 1 ) . as_ref ( ) . map ( AsRef :: as_ref) {
170
153
// this arm is executed on the initial call to `cargo clippy`
171
154
@@ -201,11 +184,11 @@ pub fn main() {
201
184
let args = std:: env:: args ( ) . skip ( 2 ) ;
202
185
if let Some ( first) = target. kind . get ( 0 ) {
203
186
if target. kind . len ( ) > 1 || first. ends_with ( "lib" ) {
204
- if let Err ( code) = process ( std:: iter:: once ( "--lib" . to_owned ( ) ) . chain ( args) , & dep_path, & sys_root ) {
187
+ if let Err ( code) = process ( std:: iter:: once ( "--lib" . to_owned ( ) ) . chain ( args) , & dep_path) {
205
188
std:: process:: exit ( code) ;
206
189
}
207
190
} else if [ "bin" , "example" , "test" , "bench" ] . contains ( & & * * first) {
208
- if let Err ( code) = process ( vec ! [ format!( "--{}" , first) , target. name] . into_iter ( ) . chain ( args) , & dep_path, & sys_root ) {
191
+ if let Err ( code) = process ( vec ! [ format!( "--{}" , first) , target. name] . into_iter ( ) . chain ( args) , & dep_path) {
209
192
std:: process:: exit ( code) ;
210
193
}
211
194
}
@@ -216,6 +199,23 @@ pub fn main() {
216
199
} else {
217
200
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC` env var set to itself
218
201
202
+ let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
203
+ let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
204
+ let sys_root = if let ( Some ( home) , Some ( toolchain) ) = ( home, toolchain) {
205
+ format ! ( "{}/toolchains/{}" , home, toolchain)
206
+ } else {
207
+ option_env ! ( "SYSROOT" )
208
+ . map ( |s| s. to_owned ( ) )
209
+ . or ( Command :: new ( "rustc" )
210
+ . arg ( "--print" )
211
+ . arg ( "sysroot" )
212
+ . output ( )
213
+ . ok ( )
214
+ . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
215
+ . map ( |s| s. trim ( ) . to_owned ( ) ) )
216
+ . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" )
217
+ } ;
218
+
219
219
// this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly
220
220
// without having to pass --sysroot or anything
221
221
let mut args: Vec < String > = if env:: args ( ) . any ( |s| s == "--sysroot" ) {
@@ -239,7 +239,7 @@ pub fn main() {
239
239
}
240
240
}
241
241
242
- fn process < P , I > ( old_args : I , dep_path : P , sysroot : & str ) -> Result < ( ) , i32 >
242
+ fn process < P , I > ( old_args : I , dep_path : P ) -> Result < ( ) , i32 >
243
243
where P : AsRef < Path > ,
244
244
I : Iterator < Item = String >
245
245
{
@@ -256,8 +256,6 @@ fn process<P, I>(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
256
256
}
257
257
args. push ( "-L" . to_owned ( ) ) ;
258
258
args. push ( dep_path. as_ref ( ) . to_string_lossy ( ) . into_owned ( ) ) ;
259
- args. push ( String :: from ( "--sysroot" ) ) ;
260
- args. push ( sysroot. to_owned ( ) ) ;
261
259
args. push ( "-Zno-trans" . to_owned ( ) ) ;
262
260
args. push ( "--cfg" . to_owned ( ) ) ;
263
261
args. push ( r#"feature="cargo-clippy""# . to_owned ( ) ) ;
0 commit comments