Skip to content

Commit bcc1c2b

Browse files
authored
Merge pull request #1576 from nrc/comp
Fix a panic when a component is missing
2 parents be16639 + c97f490 commit bcc1c2b

File tree

9 files changed

+49
-11
lines changed

9 files changed

+49
-11
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
// (git not installed or if this is not a git repository) just return an empty string.
3131
fn commit_info() -> String {
3232
match (commit_hash(), commit_date()) {
33-
(Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim_right(), date),
33+
(Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim_end(), date),
3434
_ => String::new(),
3535
}
3636
}

src/download/tests/support/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ fn serve_contents(
7070
// extract range "bytes={start}-"
7171
let range = range.to_str().expect("unexpected Range header");
7272
assert!(range.starts_with("bytes="));
73-
let range = range.trim_left_matches("bytes=");
73+
let range = range.trim_start_matches("bytes=");
7474
assert!(range.ends_with("-"));
75-
let range = range.trim_right_matches("-");
75+
let range = range.trim_end_matches("-");
7676
assert_eq!(range.split("-").count(), 1);
7777
let start: u64 = range.parse().expect("unexpected Range header");
7878

src/rustup-cli/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub fn rustc_version(toolchain: &Toolchain) -> String {
256256
.expect("Child::stdout requested but not present");
257257
let mut line = String::new();
258258
if BufReader::new(out).read_line(&mut line).is_ok() {
259-
let lineend = line.trim_right_matches(&['\r', '\n'][..]).len();
259+
let lineend = line.trim_end_matches(&['\r', '\n'][..]).len();
260260
line.truncate(lineend);
261261
line1 = Some(line);
262262
}

src/rustup-cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn show(cfg: &Cfg) -> Result<()> {
734734
}
735735
},
736736
Err(err) => {
737-
if let Some(cause) = err.cause() {
737+
if let Some(cause) = err.source() {
738738
println!("(error: {}, {})", err, cause);
739739
} else {
740740
println!("(error: {})", err);

src/rustup-dist/src/manifestation.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,10 @@ impl Update {
649649
let package = new_manifest.get_package(&component.short_name_in_manifest())?;
650650
let target_package = package.get_target(component.target.as_ref())?;
651651

652-
let bins = target_package.bins.as_ref().expect("components available");
652+
let bins = match target_package.bins {
653+
None => continue,
654+
Some(ref bins) => bins,
655+
};
653656
let c_u_h = if let (Some(url), Some(hash)) = (bins.xz_url.clone(), bins.xz_hash.clone())
654657
{
655658
(component.clone(), Format::Xz, url, hash)

src/rustup/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Cfg {
8686
.and_then(utils::if_not_empty)
8787
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
8888
.as_ref()
89-
.trim_right_matches("/dist")
89+
.trim_end_matches("/dist")
9090
.to_owned()
9191
}
9292
};

src/rustup/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ pub static TOOLS: &'static [&'static str] = &[
3939
pub static DUP_TOOLS: &'static [&'static str] = &["rustfmt", "cargo-fmt"];
4040

4141
fn component_for_bin(binary: &str) -> Option<&'static str> {
42-
match binary {
42+
use std::env::consts::EXE_SUFFIX;
43+
44+
let binary_prefix = match binary.find(EXE_SUFFIX) {
45+
_ if EXE_SUFFIX.is_empty() => binary,
46+
Some(i) => &binary[..i],
47+
None => binary,
48+
};
49+
50+
match binary_prefix {
4351
"rustc" | "rustdoc" => Some("rustc"),
4452
"cargo" => Some("cargo"),
4553
"rust-lldb" => Some("lldb-preview"),

tests/cli-misc.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,12 @@ fn rls_exists_in_toolchain() {
549549
#[test]
550550
fn rls_does_not_exist_in_toolchain() {
551551
setup(&|config| {
552-
// FIXME: If rls exists in the toolchain, this should suggest a command
553-
// to run to install it
554552
expect_ok(config, &["rustup", "default", "stable"]);
555553
expect_err(
556554
config,
557555
&["rls", "--version"],
558556
&format!(
559-
"'rls{}' is not installed for the toolchain 'stable-{}'",
557+
"'rls{}' is not installed for the toolchain 'stable-{}'\nTo install, run `rustup component add rls`",
560558
EXE_SUFFIX,
561559
this_host_triple(),
562560
),

tests/cli-v2.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,32 @@ fn update_unavailable_std() {
837837
);
838838
});
839839
}
840+
841+
#[test]
842+
fn update_unavailable_force() {
843+
setup(&|config| {
844+
let ref trip = TargetTriple::from_build();
845+
expect_ok(config, &["rustup", "update", "nightly"]);
846+
expect_ok(
847+
config,
848+
&[
849+
"rustup",
850+
"component",
851+
"add",
852+
"rls",
853+
"--toolchain",
854+
"nightly",
855+
],
856+
);
857+
make_component_unavailable(config, "rls-preview", trip);
858+
expect_err(
859+
config,
860+
&["rustup", "update", "nightly"],
861+
&format!(
862+
"component 'rls' for target '{}' is unavailable for download",
863+
trip
864+
),
865+
);
866+
expect_ok(config, &["rustup", "update", "nightly", "--force"]);
867+
});
868+
}

0 commit comments

Comments
 (0)