提交 481988b0 编写于 作者: L Lzu Tao

Use str::strip* in bootstrap

This commit replaces the use of `trim_start_matches`
because in `rustc -Vv` output there are no lines
starting with multiple "release:".
上级 e59b08e6
...@@ -963,10 +963,11 @@ pub fn run_cargo( ...@@ -963,10 +963,11 @@ pub fn run_cargo(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for (prefix, extension, expected_len) in toplevel { for (prefix, extension, expected_len) in toplevel {
let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| { let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
filename.starts_with(&prefix[..]) meta.len() == expected_len
&& filename[prefix.len()..].starts_with('-') && filename
&& filename.ends_with(&extension[..]) .strip_prefix(&prefix[..])
&& meta.len() == expected_len .map(|s| s.starts_with('-') && s.ends_with(&extension[..]))
.unwrap_or(false)
}); });
let max = candidates let max = candidates
.max_by_key(|&&(_, _, ref metadata)| FileTime::from_last_modification_time(metadata)); .max_by_key(|&&(_, _, ref metadata)| FileTime::from_last_modification_time(metadata));
......
...@@ -436,10 +436,9 @@ pub fn new(config: Config) -> Build { ...@@ -436,10 +436,9 @@ pub fn new(config: Config) -> Build {
output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose")); output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
let local_release = local_version_verbose let local_release = local_version_verbose
.lines() .lines()
.filter(|x| x.starts_with("release:")) .filter_map(|x| x.strip_prefix("release:"))
.next() .next()
.unwrap() .unwrap()
.trim_start_matches("release:")
.trim(); .trim();
let my_version = channel::CFG_RELEASE_NUM; let my_version = channel::CFG_RELEASE_NUM;
if local_release.split('.').take(2).eq(my_version.split('.').take(2)) { if local_release.split('.').take(2).eq(my_version.split('.').take(2)) {
...@@ -1089,10 +1088,10 @@ fn release_num(&self, package: &str) -> String { ...@@ -1089,10 +1088,10 @@ fn release_num(&self, package: &str) -> String {
let toml_file_name = self.src.join(&format!("src/tools/{}/Cargo.toml", package)); let toml_file_name = self.src.join(&format!("src/tools/{}/Cargo.toml", package));
let toml = t!(fs::read_to_string(&toml_file_name)); let toml = t!(fs::read_to_string(&toml_file_name));
for line in toml.lines() { for line in toml.lines() {
let prefix = "version = \""; if let Some(stripped) =
let suffix = "\""; line.strip_prefix("version = \"").and_then(|s| s.strip_suffix("\""))
if line.starts_with(prefix) && line.ends_with(suffix) { {
return line[prefix.len()..line.len() - suffix.len()].to_string(); return stripped.to_owned();
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册