@@ -2456,6 +2456,17 @@ pub fn parse_externs(
2456
2456
matches : & getopts:: Matches ,
2457
2457
unstable_opts : & UnstableOptions ,
2458
2458
) -> 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
+
2459
2470
let is_unstable_enabled = unstable_opts. unstable_options ;
2460
2471
let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2461
2472
for arg in matches. opt_strs ( "extern" ) {
@@ -2468,12 +2479,12 @@ pub fn parse_externs(
2468
2479
Some ( ( opts, name) ) => ( Some ( opts) , name. to_string ( ) ) ,
2469
2480
} ;
2470
2481
2471
- if !crate :: utils :: is_ascii_ident ( & name) {
2482
+ if !is_ascii_ident ( & name) {
2472
2483
let mut error = handler. early_struct_error ( format ! (
2473
2484
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
2474
2485
) ) ;
2475
2486
let adjusted_name = name. replace ( '-' , "_" ) ;
2476
- if crate :: utils :: is_ascii_ident ( & adjusted_name) {
2487
+ if is_ascii_ident ( & adjusted_name) {
2477
2488
error. help ( format ! (
2478
2489
"consider replacing the dashes with underscores: `{adjusted_name}`"
2479
2490
) ) ;
0 commit comments