Panic about unreachable code when running "rustup install nightly"
Seems like the "install" command doesn't exist anymore, when I look at the --help message. In that case, I guess there are two bugs: one is that the README file still claims rustup install nightly is the way to go, another one is that using unreachable!() for error handling is not very user friendly.
$ rustup --version
rustup 0.1.10 (fd90642 2016-05-09)
$ RUST_BACKTRACE=1 rustup install nightly
thread '<main>' panicked at 'internal error: entered unreachable code', src/rustup-cli/rustup_mode.rs:84
stack backtrace:
1: 0x7f336cde3600 - std::sys::backtrace::tracing::imp::write::h9fb600083204ae7f
2: 0x7f336cdeb89b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hca543c34f11229ac
3: 0x7f336cdeb523 - std::panicking::default_hook::hc2c969e7453d080c
4: 0x7f336cdcfb7f - std::sys_common::unwind::begin_unwind_inner::h30e12d15ce2b2e25
5: 0x7f336ca3ceaf - std::sys_common::unwind::begin_unwind::h65390c63b501d6ed
6: 0x7f336ca25167 - rustup_init::rustup_mode::main::h904c4ed7acbad99d
7: 0x7f336ca1d5c5 - rustup_init::run_multirust::h70cbf6663515e18b
8: 0x7f336ca1ca41 - rustup_init::main::h81d74e5ca7cf36c2
9: 0x7f336cdeb164 - std::sys_common::unwind::try::try_fn::h04c0c89e4add6cc4
10: 0x7f336cde294b - __rust_try
11: 0x7f336cdeabab - std::rt::lang_start::h61f4934e780b4dfc
12: 0x7f336bd80ec4 - __libc_start_main
13: 0x7f336ca1c928 - <unknown>
Looks like it was re-added to the clap config, but the code wasn't updated to handle that subcommand. (We don't use unreachable!() for handling the case where a command is not recognised - it's just because of the mismatch)
Using the new App::alias[es] feature in v2.5.1 is designed to somewhat eliminate that case.
A short example is, defining a subcommand, then checking for its existing:
let m = App::new("test-case")
.subcommand(SubCommand::with_name("install"))
.get_matches();
match m.subcommand_name() {
Some("install") => /* .. */,
_ => unreachable!(),
}
Then imagine you add a synonym add for install
let m = App::new("test-case")
.subcommand(SubCommand::with_name("install"))
.subcommand(SubCommand::with_name("add"))
.get_matches();
// forget to add anything here...
match m.subcommand_name() {
Some("install") => /* .. */,
_ => unreachable!(), // Error
}
The new version:
let m = App::new("test-case")
.subcommand(SubCommand::with_name("install")
.alias("add"))
.get_matches();
// forget to add anything here...
match m.subcommand_name() {
Some("install") => /* .. */,
_ => unreachable!(), // no error, everything goes to "install" automatically
}
I've got a patch in that fixes this along with the Windows bustage. Testing in dev now and should deploy tonight.
Fixed.