Skip to content

Fix a panic when a component is missing #1576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/download/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/rustup-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
};
Expand Down
10 changes: 9 additions & 1 deletion src/rustup/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 1 addition & 3 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
Expand Down
29 changes: 29 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,3 +837,32 @@ 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"]);
});
}