@@ -7,14 +7,15 @@ use rustc_data_structures::sync;
7
7
use rustc_metadata:: { load_symbol_from_dylib, DylibError } ;
8
8
use rustc_parse:: validate_attr;
9
9
use rustc_session as session;
10
- use rustc_session:: config:: { self , Cfg , CrateType , OutFileName , OutputFilenames , OutputTypes } ;
10
+ use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes } ;
11
11
use rustc_session:: filesearch:: sysroot_candidates;
12
12
use rustc_session:: lint:: { self , BuiltinLintDiag , LintBuffer } ;
13
- use rustc_session:: { filesearch, output , Session } ;
13
+ use rustc_session:: { filesearch, Session } ;
14
14
use rustc_span:: edit_distance:: find_best_match_for_name;
15
15
use rustc_span:: edition:: Edition ;
16
- use rustc_span:: symbol:: { sym, Symbol } ;
16
+ use rustc_span:: symbol:: sym;
17
17
use rustc_target:: spec:: Target ;
18
+ use session:: output:: { categorize_crate_type, CRATE_TYPES } ;
18
19
use session:: EarlyDiagCtxt ;
19
20
use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
20
21
use std:: path:: { Path , PathBuf } ;
@@ -399,67 +400,6 @@ pub(crate) fn check_attr_crate_type(
399
400
}
400
401
}
401
402
402
- const CRATE_TYPES : & [ ( Symbol , CrateType ) ] = & [
403
- ( sym:: rlib, CrateType :: Rlib ) ,
404
- ( sym:: dylib, CrateType :: Dylib ) ,
405
- ( sym:: cdylib, CrateType :: Cdylib ) ,
406
- ( sym:: lib, config:: default_lib_output ( ) ) ,
407
- ( sym:: staticlib, CrateType :: Staticlib ) ,
408
- ( sym:: proc_dash_macro, CrateType :: ProcMacro ) ,
409
- ( sym:: bin, CrateType :: Executable ) ,
410
- ] ;
411
-
412
- fn categorize_crate_type ( s : Symbol ) -> Option < CrateType > {
413
- Some ( CRATE_TYPES . iter ( ) . find ( |( key, _) | * key == s) ?. 1 )
414
- }
415
-
416
- pub fn collect_crate_types ( session : & Session , attrs : & [ ast:: Attribute ] ) -> Vec < CrateType > {
417
- // If we're generating a test executable, then ignore all other output
418
- // styles at all other locations
419
- if session. opts . test {
420
- return vec ! [ CrateType :: Executable ] ;
421
- }
422
-
423
- // Only check command line flags if present. If no types are specified by
424
- // command line, then reuse the empty `base` Vec to hold the types that
425
- // will be found in crate attributes.
426
- // JUSTIFICATION: before wrapper fn is available
427
- #[ allow( rustc:: bad_opt_access) ]
428
- let mut base = session. opts . crate_types . clone ( ) ;
429
- if base. is_empty ( ) {
430
- let attr_types = attrs. iter ( ) . filter_map ( |a| {
431
- if a. has_name ( sym:: crate_type)
432
- && let Some ( s) = a. value_str ( )
433
- {
434
- categorize_crate_type ( s)
435
- } else {
436
- None
437
- }
438
- } ) ;
439
- base. extend ( attr_types) ;
440
- if base. is_empty ( ) {
441
- base. push ( output:: default_output_for_target ( session) ) ;
442
- } else {
443
- base. sort ( ) ;
444
- base. dedup ( ) ;
445
- }
446
- }
447
-
448
- base. retain ( |crate_type| {
449
- if output:: invalid_output_for_target ( session, * crate_type) {
450
- session. dcx ( ) . emit_warn ( errors:: UnsupportedCrateTypeForTarget {
451
- crate_type : * crate_type,
452
- target_triple : & session. opts . target_triple ,
453
- } ) ;
454
- false
455
- } else {
456
- true
457
- }
458
- } ) ;
459
-
460
- base
461
- }
462
-
463
403
fn multiple_output_types_to_stdout (
464
404
output_types : & OutputTypes ,
465
405
single_output_file_is_stdout : bool ,
0 commit comments