@@ -20,7 +20,7 @@ use toml::{Value, value::Table};
20
20
21
21
use self :: cargo:: { Root , Subcommand } ;
22
22
use self :: errors:: * ;
23
- use self :: rustc:: { TargetList , VersionMetaExt } ;
23
+ use self :: rustc:: { ChannelExt , TargetList , VersionMetaExt } ;
24
24
25
25
#[ allow( non_camel_case_types) ]
26
26
#[ derive( Debug , Clone , PartialEq ) ]
@@ -208,7 +208,7 @@ pub fn main() {
208
208
209
209
fn run ( ) -> Result < ExitStatus > {
210
210
let target_list = rustc:: target_list ( false ) ?;
211
- let args = cli:: parse ( & target_list) ;
211
+ let args = cli:: parse ( & target_list) ? ;
212
212
213
213
if args. all . iter ( ) . any ( |a| a == "--version" || a == "-V" ) &&
214
214
args. subcommand . is_none ( ) {
@@ -228,9 +228,19 @@ fn run() -> Result<ExitStatus> {
228
228
. unwrap_or_else ( || Target :: from ( host. triple ( ) , & target_list) ) ;
229
229
let toml = toml ( & root) ?;
230
230
231
- let sysroot = rustc:: sysroot ( & host, & target, verbose) ?;
232
- let toolchain = sysroot. file_name ( ) . and_then ( |file_name| file_name. to_str ( ) )
231
+ let mut sysroot = rustc:: sysroot ( & host, & target, verbose) ?;
232
+ let default_toolchain = sysroot. file_name ( ) . and_then ( |file_name| file_name. to_str ( ) )
233
233
. ok_or ( "couldn't get toolchain name" ) ?;
234
+ let toolchain = if let Some ( channel) = args. channel {
235
+ [ channel. to_string ( ) ] . iter ( ) . map ( |c| c. as_str ( ) ) . chain (
236
+ default_toolchain. splitn ( 2 , '-' ) . skip ( 1 )
237
+ )
238
+ . collect :: < Vec < _ > > ( )
239
+ . join ( "-" )
240
+ } else {
241
+ default_toolchain. to_string ( )
242
+ } ;
243
+ sysroot. set_file_name ( & toolchain) ;
234
244
235
245
let installed_toolchains = rustup:: installed_toolchains ( verbose) ?;
236
246
@@ -250,13 +260,13 @@ fn run() -> Result<ExitStatus> {
250
260
251
261
if !uses_xargo && !available_targets. is_installed ( & target) {
252
262
rustup:: install ( & target, & toolchain, verbose) ?;
253
- } else if !rustup:: component_is_installed ( "rust-src" , toolchain, verbose) ? {
254
- rustup:: install_component ( "rust-src" , toolchain, verbose) ?;
263
+ } else if !rustup:: component_is_installed ( "rust-src" , & toolchain, verbose) ? {
264
+ rustup:: install_component ( "rust-src" , & toolchain, verbose) ?;
255
265
}
256
266
257
267
if args. subcommand . map ( |sc| sc == Subcommand :: Clippy ) . unwrap_or ( false ) &&
258
- !rustup:: component_is_installed ( "clippy" , toolchain, verbose) ? {
259
- rustup:: install_component ( "clippy" , toolchain, verbose) ?;
268
+ !rustup:: component_is_installed ( "clippy" , & toolchain, verbose) ? {
269
+ rustup:: install_component ( "clippy" , & toolchain, verbose) ?;
260
270
}
261
271
262
272
let needs_interpreter = args. subcommand . map ( |sc| sc. needs_interpreter ( ) ) . unwrap_or ( false ) ;
0 commit comments