@@ -14,6 +14,7 @@ use std::str::{self, FromStr};
14
14
use std:: sync:: LazyLock ;
15
15
use std:: { cmp, fmt, fs, iter} ;
16
16
17
+ use externs:: { ExternOpt , split_extern_opt} ;
17
18
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap } ;
18
19
use rustc_data_structures:: stable_hasher:: { StableOrd , ToStableHashKey } ;
19
20
use rustc_errors:: emitter:: HumanReadableErrorType ;
@@ -39,6 +40,7 @@ use crate::utils::CanonicalizedPath;
39
40
use crate :: { EarlyDiagCtxt , HashStableContext , Session , filesearch, lint} ;
40
41
41
42
mod cfg;
43
+ mod externs;
42
44
mod native_libs;
43
45
pub mod sigpipe;
44
46
@@ -2188,44 +2190,13 @@ pub fn parse_externs(
2188
2190
matches : & getopts:: Matches ,
2189
2191
unstable_opts : & UnstableOptions ,
2190
2192
) -> Externs {
2191
- fn is_ascii_ident ( string : & str ) -> bool {
2192
- let mut chars = string. chars ( ) ;
2193
- if let Some ( start) = chars. next ( )
2194
- && ( start. is_ascii_alphabetic ( ) || start == '_' )
2195
- {
2196
- chars. all ( |char| char. is_ascii_alphanumeric ( ) || char == '_' )
2197
- } else {
2198
- false
2199
- }
2200
- }
2201
-
2202
2193
let is_unstable_enabled = unstable_opts. unstable_options ;
2203
2194
let mut externs: BTreeMap < String , ExternEntry > = BTreeMap :: new ( ) ;
2204
2195
for arg in matches. opt_strs ( "extern" ) {
2205
- let ( name, path) = match arg. split_once ( '=' ) {
2206
- None => ( arg, None ) ,
2207
- Some ( ( name, path) ) => ( name. to_string ( ) , Some ( Path :: new ( path) ) ) ,
2208
- } ;
2209
- let ( options, name) = match name. split_once ( ':' ) {
2210
- None => ( None , name) ,
2211
- Some ( ( opts, name) ) => ( Some ( opts) , name. to_string ( ) ) ,
2212
- } ;
2213
-
2214
- if !is_ascii_ident ( & name) {
2215
- let mut error = early_dcx. early_struct_fatal ( format ! (
2216
- "crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
2217
- ) ) ;
2218
- let adjusted_name = name. replace ( '-' , "_" ) ;
2219
- if is_ascii_ident ( & adjusted_name) {
2220
- #[ allow( rustc:: diagnostic_outside_of_impl) ] // FIXME
2221
- error. help ( format ! (
2222
- "consider replacing the dashes with underscores: `{adjusted_name}`"
2223
- ) ) ;
2224
- }
2225
- error. emit ( ) ;
2226
- }
2196
+ let ExternOpt { crate_name : name, path, options } =
2197
+ split_extern_opt ( early_dcx, & arg) . unwrap_or_else ( |e| e. emit ( ) ) ;
2227
2198
2228
- let path = path. map ( |p| CanonicalizedPath :: new ( p) ) ;
2199
+ let path = path. map ( |p| CanonicalizedPath :: new ( p. as_path ( ) ) ) ;
2229
2200
2230
2201
let entry = externs. entry ( name. to_owned ( ) ) ;
2231
2202
0 commit comments