@@ -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 ) ) ;
0 commit comments