From b4eba12047220c7ebbc17476cb64fad5c73b280d Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 14 Dec 2018 17:23:49 +1300 Subject: [PATCH 1/5] Remove a bogus `expect` It's possible to hit this when using `rustup update --force` --- src/rustup-dist/src/manifestation.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rustup-dist/src/manifestation.rs b/src/rustup-dist/src/manifestation.rs index 30ee8d42c4..14cf5684b4 100644 --- a/src/rustup-dist/src/manifestation.rs +++ b/src/rustup-dist/src/manifestation.rs @@ -649,7 +649,10 @@ impl Update { let package = new_manifest.get_package(&component.short_name_in_manifest())?; let target_package = package.get_target(component.target.as_ref())?; - let bins = target_package.bins.as_ref().expect("components available"); + let bins = match target_package.bins { + None => continue, + Some(ref bins) => bins, + }; let c_u_h = if let (Some(url), Some(hash)) = (bins.xz_url.clone(), bins.xz_hash.clone()) { (component.clone(), Format::Xz, url, hash) From 5a062cebc0d1a456dcef7e8cf1ffd62a9d55ac15 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 14 Dec 2018 20:48:53 +1300 Subject: [PATCH 2/5] add test --- tests/cli-v2.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index 173d360a0f..9626dcd0a2 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -837,3 +837,22 @@ fn update_unavailable_std() { ); }); } + +#[test] +fn update_unavailable_force() { + setup(&|config| { + let ref trip = TargetTriple::from_build(); + expect_ok(config, &["rustup", "update", "nightly"]); + expect_ok(config, &["rustup", "component", "add", "rls", "--toolchain", "nightly"]); + make_component_unavailable(config, "rls-preview", trip); + expect_err( + config, + &["rustup", "update", "nightly"], + &format!( + "component 'rls' for target '{}' is unavailable for download", + trip + ), + ); + expect_ok(config, &["rustup", "update", "nightly", "--force"]); + }); +} From 79c0312feb8dff06995cb67684452558809c5fee Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 14 Dec 2018 17:28:36 +1300 Subject: [PATCH 3/5] Address FIXME in test --- tests/cli-misc.rs | 4 +--- tests/cli-v2.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index c227149ec7..ae0517822a 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -549,14 +549,12 @@ fn rls_exists_in_toolchain() { #[test] fn rls_does_not_exist_in_toolchain() { setup(&|config| { - // FIXME: If rls exists in the toolchain, this should suggest a command - // to run to install it expect_ok(config, &["rustup", "default", "stable"]); expect_err( config, &["rls", "--version"], &format!( - "'rls{}' is not installed for the toolchain 'stable-{}'", + "'rls{}' is not installed for the toolchain 'stable-{}'\nTo install, run `rustup component add rls`", EXE_SUFFIX, this_host_triple(), ), diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index 9626dcd0a2..d07da23d1d 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -843,7 +843,17 @@ fn update_unavailable_force() { setup(&|config| { let ref trip = TargetTriple::from_build(); expect_ok(config, &["rustup", "update", "nightly"]); - expect_ok(config, &["rustup", "component", "add", "rls", "--toolchain", "nightly"]); + expect_ok( + config, + &[ + "rustup", + "component", + "add", + "rls", + "--toolchain", + "nightly", + ], + ); make_component_unavailable(config, "rls-preview", trip); expect_err( config, From eda23b6cea96db2eb875ab708d281fc0a58a2846 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 9 Jan 2019 09:44:25 +1300 Subject: [PATCH 4/5] Address failing test ...by being smarter about finding components from binary names --- src/rustup/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rustup/lib.rs b/src/rustup/lib.rs index ceefb512fc..a785ca26fc 100644 --- a/src/rustup/lib.rs +++ b/src/rustup/lib.rs @@ -39,7 +39,15 @@ pub static TOOLS: &'static [&'static str] = &[ pub static DUP_TOOLS: &'static [&'static str] = &["rustfmt", "cargo-fmt"]; fn component_for_bin(binary: &str) -> Option<&'static str> { - match binary { + use std::env::consts::EXE_SUFFIX; + + let binary_prefix = match binary.find(EXE_SUFFIX) { + _ if EXE_SUFFIX.is_empty() => binary, + Some(i) => &binary[..i], + None => binary, + }; + + match binary_prefix { "rustc" | "rustdoc" => Some("rustc"), "cargo" => Some("cargo"), "rust-lldb" => Some("lldb-preview"), From c97f490c4ffdeda25bab608b7ede720f7a6558f5 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 9 Jan 2019 09:50:56 +1300 Subject: [PATCH 5/5] Address some deprecation warnings --- build.rs | 2 +- src/download/tests/support/mod.rs | 4 ++-- src/rustup-cli/common.rs | 2 +- src/rustup-cli/rustup_mode.rs | 2 +- src/rustup/config.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index b1508194ba..07b983a0c5 100644 --- a/build.rs +++ b/build.rs @@ -30,7 +30,7 @@ fn main() { // (git not installed or if this is not a git repository) just return an empty string. fn commit_info() -> String { match (commit_hash(), commit_date()) { - (Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim_right(), date), + (Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim_end(), date), _ => String::new(), } } diff --git a/src/download/tests/support/mod.rs b/src/download/tests/support/mod.rs index c8c2b65612..143ce2b508 100644 --- a/src/download/tests/support/mod.rs +++ b/src/download/tests/support/mod.rs @@ -70,9 +70,9 @@ fn serve_contents( // extract range "bytes={start}-" let range = range.to_str().expect("unexpected Range header"); assert!(range.starts_with("bytes=")); - let range = range.trim_left_matches("bytes="); + let range = range.trim_start_matches("bytes="); assert!(range.ends_with("-")); - let range = range.trim_right_matches("-"); + let range = range.trim_end_matches("-"); assert_eq!(range.split("-").count(), 1); let start: u64 = range.parse().expect("unexpected Range header"); diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index eb6f31777d..d436e4633c 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -256,7 +256,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String { .expect("Child::stdout requested but not present"); let mut line = String::new(); if BufReader::new(out).read_line(&mut line).is_ok() { - let lineend = line.trim_right_matches(&['\r', '\n'][..]).len(); + let lineend = line.trim_end_matches(&['\r', '\n'][..]).len(); line.truncate(lineend); line1 = Some(line); } diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index 7a9ca215ed..bd07cfa462 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -734,7 +734,7 @@ fn show(cfg: &Cfg) -> Result<()> { } }, Err(err) => { - if let Some(cause) = err.cause() { + if let Some(cause) = err.source() { println!("(error: {}, {})", err, cause); } else { println!("(error: {})", err); diff --git a/src/rustup/config.rs b/src/rustup/config.rs index 96230ae4f8..d92b2259ea 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -86,7 +86,7 @@ impl Cfg { .and_then(utils::if_not_empty) .map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned) .as_ref() - .trim_right_matches("/dist") + .trim_end_matches("/dist") .to_owned() } };