Skip to content

Commit dba9416

Browse files
committed
Move is_ascii_ident to where it's used.
1 parent f8ce186 commit dba9416

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,17 @@ pub fn parse_externs(
24562456
matches: &getopts::Matches,
24572457
unstable_opts: &UnstableOptions,
24582458
) -> Externs {
2459+
fn is_ascii_ident(string: &str) -> bool {
2460+
let mut chars = string.chars();
2461+
if let Some(start) = chars.next()
2462+
&& (start.is_ascii_alphabetic() || start == '_')
2463+
{
2464+
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
2465+
} else {
2466+
false
2467+
}
2468+
}
2469+
24592470
let is_unstable_enabled = unstable_opts.unstable_options;
24602471
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
24612472
for arg in matches.opt_strs("extern") {
@@ -2468,12 +2479,12 @@ pub fn parse_externs(
24682479
Some((opts, name)) => (Some(opts), name.to_string()),
24692480
};
24702481

2471-
if !crate::utils::is_ascii_ident(&name) {
2482+
if !is_ascii_ident(&name) {
24722483
let mut error = handler.early_struct_error(format!(
24732484
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
24742485
));
24752486
let adjusted_name = name.replace('-', "_");
2476-
if crate::utils::is_ascii_ident(&adjusted_name) {
2487+
if is_ascii_ident(&adjusted_name) {
24772488
error.help(format!(
24782489
"consider replacing the dashes with underscores: `{adjusted_name}`"
24792490
));

compiler/rustc_session/src/utils.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,3 @@ pub fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
158158

159159
if !result.is_empty() { Some((result, excluded_cargo_defaults)) } else { None }
160160
}
161-
162-
pub(crate) fn is_ascii_ident(string: &str) -> bool {
163-
let mut chars = string.chars();
164-
if let Some(start) = chars.next()
165-
&& (start.is_ascii_alphabetic() || start == '_')
166-
{
167-
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
168-
} else {
169-
false
170-
}
171-
}

0 commit comments

Comments
 (0)