@@ -20,7 +20,7 @@ use toml::{Value, value::Table};
2020
2121use self :: cargo:: { Root , Subcommand } ;
2222use self :: errors:: * ;
23- use self :: rustc:: { TargetList , VersionMetaExt } ;
23+ use self :: rustc:: { ChannelExt , TargetList , VersionMetaExt } ;
2424
2525#[ allow( non_camel_case_types) ]
2626#[ derive( Debug , Clone , PartialEq ) ]
@@ -208,7 +208,7 @@ pub fn main() {
208208
209209fn run ( ) -> Result < ExitStatus > {
210210 let target_list = rustc:: target_list ( false ) ?;
211- let args = cli:: parse ( & target_list) ;
211+ let args = cli:: parse ( & target_list) ? ;
212212
213213 if args. all . iter ( ) . any ( |a| a == "--version" || a == "-V" ) &&
214214 args. subcommand . is_none ( ) {
@@ -228,9 +228,19 @@ fn run() -> Result<ExitStatus> {
228228 . unwrap_or_else ( || Target :: from ( host. triple ( ) , & target_list) ) ;
229229 let toml = toml ( & root) ?;
230230
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 ( ) )
233233 . 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) ;
234244
235245 let installed_toolchains = rustup:: installed_toolchains ( verbose) ?;
236246
@@ -250,13 +260,13 @@ fn run() -> Result<ExitStatus> {
250260
251261 if !uses_xargo && !available_targets. is_installed ( & target) {
252262 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) ?;
255265 }
256266
257267 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) ?;
260270 }
261271
262272 let needs_interpreter = args. subcommand . map ( |sc| sc. needs_interpreter ( ) ) . unwrap_or ( false ) ;
0 commit comments