Dogfood 'str_split_once() with compiler/
This commit is contained in:
parent
0f6f2d681b
commit
12db2225b6
7 changed files with 83 additions and 89 deletions
|
@ -1296,8 +1296,10 @@ fn parse_output_types(
|
|||
if !debugging_opts.parse_only {
|
||||
for list in matches.opt_strs("emit") {
|
||||
for output_type in list.split(',') {
|
||||
let mut parts = output_type.splitn(2, '=');
|
||||
let shorthand = parts.next().unwrap();
|
||||
let (shorthand, path) = match output_type.split_once('=') {
|
||||
None => (output_type, None),
|
||||
Some((shorthand, path)) => (shorthand, Some(PathBuf::from(path))),
|
||||
};
|
||||
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
|
||||
early_error(
|
||||
error_format,
|
||||
|
@ -1308,7 +1310,6 @@ fn parse_output_types(
|
|||
),
|
||||
)
|
||||
});
|
||||
let path = parts.next().map(PathBuf::from);
|
||||
output_types.insert(output_type, path);
|
||||
}
|
||||
}
|
||||
|
@ -1452,11 +1453,10 @@ fn parse_opt_level(
|
|||
let max_c = matches
|
||||
.opt_strs_pos("C")
|
||||
.into_iter()
|
||||
.flat_map(
|
||||
|(i, s)| {
|
||||
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||
},
|
||||
)
|
||||
.flat_map(|(i, s)| {
|
||||
// NB: This can match a string without `=`.
|
||||
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||
})
|
||||
.max();
|
||||
if max_o > max_c {
|
||||
OptLevel::Default
|
||||
|
@ -1491,11 +1491,10 @@ fn select_debuginfo(
|
|||
let max_c = matches
|
||||
.opt_strs_pos("C")
|
||||
.into_iter()
|
||||
.flat_map(
|
||||
|(i, s)| {
|
||||
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||
},
|
||||
)
|
||||
.flat_map(|(i, s)| {
|
||||
// NB: This can match a string without `=`.
|
||||
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||
})
|
||||
.max();
|
||||
if max_g > max_c {
|
||||
DebugInfo::Full
|
||||
|
@ -1528,23 +1527,26 @@ fn parse_libs(
|
|||
.map(|s| {
|
||||
// Parse string of the form "[KIND=]lib[:new_name]",
|
||||
// where KIND is one of "dylib", "framework", "static".
|
||||
let mut parts = s.splitn(2, '=');
|
||||
let kind = parts.next().unwrap();
|
||||
let (name, kind) = match (parts.next(), kind) {
|
||||
(None, name) => (name, NativeLibKind::Unspecified),
|
||||
(Some(name), "dylib") => (name, NativeLibKind::Dylib),
|
||||
(Some(name), "framework") => (name, NativeLibKind::Framework),
|
||||
(Some(name), "static") => (name, NativeLibKind::StaticBundle),
|
||||
(Some(name), "static-nobundle") => (name, NativeLibKind::StaticNoBundle),
|
||||
(_, s) => {
|
||||
early_error(
|
||||
error_format,
|
||||
&format!(
|
||||
"unknown library kind `{}`, expected \
|
||||
one of dylib, framework, or static",
|
||||
s
|
||||
),
|
||||
);
|
||||
let (name, kind) = match s.split_once('=') {
|
||||
None => (s, NativeLibKind::Unspecified),
|
||||
Some((kind, name)) => {
|
||||
let kind = match kind {
|
||||
"dylib" => NativeLibKind::Dylib,
|
||||
"framework" => NativeLibKind::Framework,
|
||||
"static" => NativeLibKind::StaticBundle,
|
||||
"static-nobundle" => NativeLibKind::StaticNoBundle,
|
||||
s => {
|
||||
early_error(
|
||||
error_format,
|
||||
&format!(
|
||||
"unknown library kind `{}`, expected \
|
||||
one of dylib, framework, or static",
|
||||
s
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
(name.to_string(), kind)
|
||||
}
|
||||
};
|
||||
if kind == NativeLibKind::StaticNoBundle
|
||||
|
@ -1556,10 +1558,11 @@ fn parse_libs(
|
|||
accepted on the nightly compiler",
|
||||
);
|
||||
}
|
||||
let mut name_parts = name.splitn(2, ':');
|
||||
let name = name_parts.next().unwrap();
|
||||
let new_name = name_parts.next();
|
||||
(name.to_owned(), new_name.map(|n| n.to_owned()), kind)
|
||||
let (name, new_name) = match name.split_once(':') {
|
||||
None => (name, None),
|
||||
Some((name, new_name)) => (name.to_string(), Some(new_name.to_owned())),
|
||||
};
|
||||
(name, new_name, kind)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -1580,20 +1583,13 @@ pub fn parse_externs(
|
|||
let is_unstable_enabled = debugging_opts.unstable_options;
|
||||
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
|
||||
for arg in matches.opt_strs("extern") {
|
||||
let mut parts = arg.splitn(2, '=');
|
||||
let name = parts
|
||||
.next()
|
||||
.unwrap_or_else(|| early_error(error_format, "--extern value must not be empty"));
|
||||
let path = parts.next().map(|s| s.to_string());
|
||||
|
||||
let mut name_parts = name.splitn(2, ':');
|
||||
let first_part = name_parts.next();
|
||||
let second_part = name_parts.next();
|
||||
let (options, name) = match (first_part, second_part) {
|
||||
(Some(opts), Some(name)) => (Some(opts), name),
|
||||
(Some(name), None) => (None, name),
|
||||
(None, None) => early_error(error_format, "--extern name must not be empty"),
|
||||
_ => unreachable!(),
|
||||
let (name, path) = match arg.split_once('=') {
|
||||
None => (arg, None),
|
||||
Some((name, path)) => (name.to_string(), Some(path.to_string())),
|
||||
};
|
||||
let (options, name) = match name.split_once(':') {
|
||||
None => (None, name),
|
||||
Some((opts, name)) => (Some(opts), name.to_string()),
|
||||
};
|
||||
|
||||
let entry = externs.entry(name.to_owned());
|
||||
|
@ -1682,17 +1678,12 @@ fn parse_remap_path_prefix(
|
|||
matches
|
||||
.opt_strs("remap-path-prefix")
|
||||
.into_iter()
|
||||
.map(|remap| {
|
||||
let mut parts = remap.rsplitn(2, '='); // reverse iterator
|
||||
let to = parts.next();
|
||||
let from = parts.next();
|
||||
match (from, to) {
|
||||
(Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
|
||||
_ => early_error(
|
||||
error_format,
|
||||
"--remap-path-prefix must contain '=' between FROM and TO",
|
||||
),
|
||||
}
|
||||
.map(|remap| match remap.rsplit_once('=') {
|
||||
None => early_error(
|
||||
error_format,
|
||||
"--remap-path-prefix must contain '=' between FROM and TO",
|
||||
),
|
||||
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue