Dogfood 'str_split_once() with compiler/
This commit is contained in:
parent
0f6f2d681b
commit
12db2225b6
7 changed files with 83 additions and 89 deletions
|
@ -28,6 +28,7 @@ Rust MIR: a lowered representation of Rust.
|
||||||
#![feature(or_patterns)]
|
#![feature(or_patterns)]
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
#![feature(control_flow_enum)]
|
#![feature(control_flow_enum)]
|
||||||
|
#![feature(str_split_once)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -148,23 +148,19 @@ impl DebugOptions {
|
||||||
|
|
||||||
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
|
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
|
||||||
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
|
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
|
||||||
let mut setting = setting_str.splitn(2, '=');
|
let (option, value) = match setting_str.split_once('=') {
|
||||||
match setting.next() {
|
None => (setting_str, None),
|
||||||
Some(option) if option == "allow_unused_expressions" => {
|
Some((k, v)) => (k, Some(v)),
|
||||||
allow_unused_expressions = bool_option_val(option, setting.next());
|
};
|
||||||
debug!(
|
if option == "allow_unused_expressions" {
|
||||||
"{} env option `allow_unused_expressions` is set to {}",
|
allow_unused_expressions = bool_option_val(option, value);
|
||||||
RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions
|
debug!(
|
||||||
);
|
"{} env option `allow_unused_expressions` is set to {}",
|
||||||
}
|
RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions
|
||||||
Some(option) if option == "counter_format" => {
|
);
|
||||||
if let Some(strval) = setting.next() {
|
} else if option == "counter_format" {
|
||||||
counter_format = counter_format_option_val(strval);
|
match value {
|
||||||
debug!(
|
None => {
|
||||||
"{} env option `counter_format` is set to {:?}",
|
|
||||||
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
bug!(
|
bug!(
|
||||||
"`{}` option in environment variable {} requires one or more \
|
"`{}` option in environment variable {} requires one or more \
|
||||||
plus-separated choices (a non-empty subset of \
|
plus-separated choices (a non-empty subset of \
|
||||||
|
@ -173,14 +169,20 @@ impl DebugOptions {
|
||||||
RUSTC_COVERAGE_DEBUG_OPTIONS
|
RUSTC_COVERAGE_DEBUG_OPTIONS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
Some(val) => {
|
||||||
Some("") => {}
|
counter_format = counter_format_option_val(val);
|
||||||
Some(invalid) => bug!(
|
debug!(
|
||||||
|
"{} env option `counter_format` is set to {:?}",
|
||||||
|
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
bug!(
|
||||||
"Unsupported setting `{}` in environment variable {}",
|
"Unsupported setting `{}` in environment variable {}",
|
||||||
invalid,
|
option,
|
||||||
RUSTC_COVERAGE_DEBUG_OPTIONS
|
RUSTC_COVERAGE_DEBUG_OPTIONS
|
||||||
),
|
)
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1296,8 +1296,10 @@ fn parse_output_types(
|
||||||
if !debugging_opts.parse_only {
|
if !debugging_opts.parse_only {
|
||||||
for list in matches.opt_strs("emit") {
|
for list in matches.opt_strs("emit") {
|
||||||
for output_type in list.split(',') {
|
for output_type in list.split(',') {
|
||||||
let mut parts = output_type.splitn(2, '=');
|
let (shorthand, path) = match output_type.split_once('=') {
|
||||||
let shorthand = parts.next().unwrap();
|
None => (output_type, None),
|
||||||
|
Some((shorthand, path)) => (shorthand, Some(PathBuf::from(path))),
|
||||||
|
};
|
||||||
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
|
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
|
||||||
early_error(
|
early_error(
|
||||||
error_format,
|
error_format,
|
||||||
|
@ -1308,7 +1310,6 @@ fn parse_output_types(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let path = parts.next().map(PathBuf::from);
|
|
||||||
output_types.insert(output_type, path);
|
output_types.insert(output_type, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1452,11 +1453,10 @@ fn parse_opt_level(
|
||||||
let max_c = matches
|
let max_c = matches
|
||||||
.opt_strs_pos("C")
|
.opt_strs_pos("C")
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(
|
.flat_map(|(i, s)| {
|
||||||
|(i, s)| {
|
// NB: This can match a string without `=`.
|
||||||
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
|
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.max();
|
.max();
|
||||||
if max_o > max_c {
|
if max_o > max_c {
|
||||||
OptLevel::Default
|
OptLevel::Default
|
||||||
|
@ -1491,11 +1491,10 @@ fn select_debuginfo(
|
||||||
let max_c = matches
|
let max_c = matches
|
||||||
.opt_strs_pos("C")
|
.opt_strs_pos("C")
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(
|
.flat_map(|(i, s)| {
|
||||||
|(i, s)| {
|
// NB: This can match a string without `=`.
|
||||||
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
|
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.max();
|
.max();
|
||||||
if max_g > max_c {
|
if max_g > max_c {
|
||||||
DebugInfo::Full
|
DebugInfo::Full
|
||||||
|
@ -1528,23 +1527,26 @@ fn parse_libs(
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
// Parse string of the form "[KIND=]lib[:new_name]",
|
// Parse string of the form "[KIND=]lib[:new_name]",
|
||||||
// where KIND is one of "dylib", "framework", "static".
|
// where KIND is one of "dylib", "framework", "static".
|
||||||
let mut parts = s.splitn(2, '=');
|
let (name, kind) = match s.split_once('=') {
|
||||||
let kind = parts.next().unwrap();
|
None => (s, NativeLibKind::Unspecified),
|
||||||
let (name, kind) = match (parts.next(), kind) {
|
Some((kind, name)) => {
|
||||||
(None, name) => (name, NativeLibKind::Unspecified),
|
let kind = match kind {
|
||||||
(Some(name), "dylib") => (name, NativeLibKind::Dylib),
|
"dylib" => NativeLibKind::Dylib,
|
||||||
(Some(name), "framework") => (name, NativeLibKind::Framework),
|
"framework" => NativeLibKind::Framework,
|
||||||
(Some(name), "static") => (name, NativeLibKind::StaticBundle),
|
"static" => NativeLibKind::StaticBundle,
|
||||||
(Some(name), "static-nobundle") => (name, NativeLibKind::StaticNoBundle),
|
"static-nobundle" => NativeLibKind::StaticNoBundle,
|
||||||
(_, s) => {
|
s => {
|
||||||
early_error(
|
early_error(
|
||||||
error_format,
|
error_format,
|
||||||
&format!(
|
&format!(
|
||||||
"unknown library kind `{}`, expected \
|
"unknown library kind `{}`, expected \
|
||||||
one of dylib, framework, or static",
|
one of dylib, framework, or static",
|
||||||
s
|
s
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
(name.to_string(), kind)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if kind == NativeLibKind::StaticNoBundle
|
if kind == NativeLibKind::StaticNoBundle
|
||||||
|
@ -1556,10 +1558,11 @@ fn parse_libs(
|
||||||
accepted on the nightly compiler",
|
accepted on the nightly compiler",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let mut name_parts = name.splitn(2, ':');
|
let (name, new_name) = match name.split_once(':') {
|
||||||
let name = name_parts.next().unwrap();
|
None => (name, None),
|
||||||
let new_name = name_parts.next();
|
Some((name, new_name)) => (name.to_string(), Some(new_name.to_owned())),
|
||||||
(name.to_owned(), new_name.map(|n| n.to_owned()), kind)
|
};
|
||||||
|
(name, new_name, kind)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -1580,20 +1583,13 @@ pub fn parse_externs(
|
||||||
let is_unstable_enabled = debugging_opts.unstable_options;
|
let is_unstable_enabled = debugging_opts.unstable_options;
|
||||||
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
|
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
|
||||||
for arg in matches.opt_strs("extern") {
|
for arg in matches.opt_strs("extern") {
|
||||||
let mut parts = arg.splitn(2, '=');
|
let (name, path) = match arg.split_once('=') {
|
||||||
let name = parts
|
None => (arg, None),
|
||||||
.next()
|
Some((name, path)) => (name.to_string(), Some(path.to_string())),
|
||||||
.unwrap_or_else(|| early_error(error_format, "--extern value must not be empty"));
|
};
|
||||||
let path = parts.next().map(|s| s.to_string());
|
let (options, name) = match name.split_once(':') {
|
||||||
|
None => (None, name),
|
||||||
let mut name_parts = name.splitn(2, ':');
|
Some((opts, name)) => (Some(opts), name.to_string()),
|
||||||
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 entry = externs.entry(name.to_owned());
|
let entry = externs.entry(name.to_owned());
|
||||||
|
@ -1682,17 +1678,12 @@ fn parse_remap_path_prefix(
|
||||||
matches
|
matches
|
||||||
.opt_strs("remap-path-prefix")
|
.opt_strs("remap-path-prefix")
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|remap| {
|
.map(|remap| match remap.rsplit_once('=') {
|
||||||
let mut parts = remap.rsplitn(2, '='); // reverse iterator
|
None => early_error(
|
||||||
let to = parts.next();
|
error_format,
|
||||||
let from = parts.next();
|
"--remap-path-prefix must contain '=' between FROM and TO",
|
||||||
match (from, to) {
|
),
|
||||||
(Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
|
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
|
||||||
_ => early_error(
|
|
||||||
error_format,
|
|
||||||
"--remap-path-prefix must contain '=' between FROM and TO",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(once_cell)]
|
#![feature(once_cell)]
|
||||||
#![feature(or_patterns)]
|
#![feature(or_patterns)]
|
||||||
|
#![feature(str_split_once)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
|
@ -179,9 +179,10 @@ macro_rules! options {
|
||||||
{
|
{
|
||||||
let mut op = $defaultfn();
|
let mut op = $defaultfn();
|
||||||
for option in matches.opt_strs($prefix) {
|
for option in matches.opt_strs($prefix) {
|
||||||
let mut iter = option.splitn(2, '=');
|
let (key, value) = match option.split_once('=') {
|
||||||
let key = iter.next().unwrap();
|
None => (option, None),
|
||||||
let value = iter.next();
|
Some((k, v)) => (k.to_string(), Some(v)),
|
||||||
|
};
|
||||||
let option_to_lookup = key.replace("-", "_");
|
let option_to_lookup = key.replace("-", "_");
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for &(candidate, setter, type_desc, _) in $stat {
|
for &(candidate, setter, type_desc, _) in $stat {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(associated_type_bounds)]
|
#![feature(associated_type_bounds)]
|
||||||
#![feature(exhaustive_patterns)]
|
#![feature(exhaustive_patterns)]
|
||||||
|
#![feature(str_split_once)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_macros;
|
extern crate rustc_macros;
|
||||||
|
|
|
@ -54,10 +54,7 @@ fn macos_deployment_target() -> (u32, u32) {
|
||||||
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
|
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
|
||||||
let version = deployment_target
|
let version = deployment_target
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|s| {
|
.and_then(|s| s.split_once('.'))
|
||||||
let mut i = s.splitn(2, '.');
|
|
||||||
i.next().and_then(|a| i.next().map(|b| (a, b)))
|
|
||||||
})
|
|
||||||
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok());
|
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok());
|
||||||
|
|
||||||
version.unwrap_or((10, 7))
|
version.unwrap_or((10, 7))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue