diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-10 23:26:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-10 23:26:38 -0700 |
| commit | 3a6209cd706179f7cb639f5688adad5b0dd3ad1c (patch) | |
| tree | 5016fb491c336b82ba9f19960fbfec92088c1e0e | |
| parent | 2da709ea212871674800c3808e548d756cdca249 (diff) | |
| parent | 481988b0832de4b28fd1f4a52f0df2801f62bda8 (diff) | |
| download | rust-3a6209cd706179f7cb639f5688adad5b0dd3ad1c.tar.gz rust-3a6209cd706179f7cb639f5688adad5b0dd3ad1c.zip | |
Rollup merge of #74100 - lzutao:strip-bootstrap, r=Mark-Simulacrum
Use str::strip* in bootstrap This is technically a breaking change, replacing the use of `trim_start_matches` with `strip_prefix`. However, because in `rustc -Vv` output there are no lines starting with multiple "release:", this should go unnoticed in practice.
| -rw-r--r-- | src/bootstrap/compile.rs | 9 | ||||
| -rw-r--r-- | src/bootstrap/lib.rs | 11 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 84545dcedb6..9b4926f28d4 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -963,10 +963,11 @@ pub fn run_cargo( .collect::<Vec<_>>(); for (prefix, extension, expected_len) in toplevel { let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| { - filename.starts_with(&prefix[..]) - && filename[prefix.len()..].starts_with('-') - && filename.ends_with(&extension[..]) - && meta.len() == expected_len + meta.len() == expected_len + && filename + .strip_prefix(&prefix[..]) + .map(|s| s.starts_with('-') && s.ends_with(&extension[..])) + .unwrap_or(false) }); let max = candidates .max_by_key(|&&(_, _, ref metadata)| FileTime::from_last_modification_time(metadata)); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index b9738894486..783a64c3581 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -436,10 +436,9 @@ impl Build { output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose")); let local_release = local_version_verbose .lines() - .filter(|x| x.starts_with("release:")) + .filter_map(|x| x.strip_prefix("release:")) .next() .unwrap() - .trim_start_matches("release:") .trim(); let my_version = channel::CFG_RELEASE_NUM; if local_release.split('.').take(2).eq(my_version.split('.').take(2)) { @@ -1089,10 +1088,10 @@ impl Build { let toml_file_name = self.src.join(&format!("src/tools/{}/Cargo.toml", package)); let toml = t!(fs::read_to_string(&toml_file_name)); for line in toml.lines() { - let prefix = "version = \""; - let suffix = "\""; - if line.starts_with(prefix) && line.ends_with(suffix) { - return line[prefix.len()..line.len() - suffix.len()].to_string(); + if let Some(stripped) = + line.strip_prefix("version = \"").and_then(|s| s.strip_suffix("\"")) + { + return stripped.to_owned(); } } |
