@@ -7,13 +7,14 @@ use rustc_data_structures::sync;
77use rustc_metadata:: { load_symbol_from_dylib, DylibError } ;
88use rustc_parse:: validate_attr;
99use rustc_session as session;
10- use rustc_session:: config:: { self , Cfg , CrateType , OutFileName , OutputFilenames , OutputTypes } ;
10+ use rustc_session:: config:: { Cfg , OutFileName , OutputFilenames , OutputTypes } ;
1111use rustc_session:: filesearch:: sysroot_candidates;
1212use rustc_session:: lint:: { self , BuiltinLintDiagnostics , LintBuffer } ;
13- use rustc_session:: { filesearch, output , Session } ;
13+ use rustc_session:: { filesearch, Session } ;
1414use rustc_span:: edit_distance:: find_best_match_for_name;
1515use rustc_span:: edition:: Edition ;
16- use rustc_span:: symbol:: { sym, Symbol } ;
16+ use rustc_span:: symbol:: sym;
17+ use session:: output:: { categorize_crate_type, CRATE_TYPES } ;
1718use session:: EarlyDiagCtxt ;
1819use std:: env;
1920use std:: env:: consts:: { DLL_PREFIX , DLL_SUFFIX } ;
@@ -378,67 +379,6 @@ pub(crate) fn check_attr_crate_type(
378379 }
379380}
380381
381- const CRATE_TYPES : & [ ( Symbol , CrateType ) ] = & [
382- ( sym:: rlib, CrateType :: Rlib ) ,
383- ( sym:: dylib, CrateType :: Dylib ) ,
384- ( sym:: cdylib, CrateType :: Cdylib ) ,
385- ( sym:: lib, config:: default_lib_output ( ) ) ,
386- ( sym:: staticlib, CrateType :: Staticlib ) ,
387- ( sym:: proc_dash_macro, CrateType :: ProcMacro ) ,
388- ( sym:: bin, CrateType :: Executable ) ,
389- ] ;
390-
391- fn categorize_crate_type ( s : Symbol ) -> Option < CrateType > {
392- Some ( CRATE_TYPES . iter ( ) . find ( |( key, _) | * key == s) ?. 1 )
393- }
394-
395- pub fn collect_crate_types ( session : & Session , attrs : & [ ast:: Attribute ] ) -> Vec < CrateType > {
396- // If we're generating a test executable, then ignore all other output
397- // styles at all other locations
398- if session. opts . test {
399- return vec ! [ CrateType :: Executable ] ;
400- }
401-
402- // Only check command line flags if present. If no types are specified by
403- // command line, then reuse the empty `base` Vec to hold the types that
404- // will be found in crate attributes.
405- // JUSTIFICATION: before wrapper fn is available
406- #[ allow( rustc:: bad_opt_access) ]
407- let mut base = session. opts . crate_types . clone ( ) ;
408- if base. is_empty ( ) {
409- let attr_types = attrs. iter ( ) . filter_map ( |a| {
410- if a. has_name ( sym:: crate_type)
411- && let Some ( s) = a. value_str ( )
412- {
413- categorize_crate_type ( s)
414- } else {
415- None
416- }
417- } ) ;
418- base. extend ( attr_types) ;
419- if base. is_empty ( ) {
420- base. push ( output:: default_output_for_target ( session) ) ;
421- } else {
422- base. sort ( ) ;
423- base. dedup ( ) ;
424- }
425- }
426-
427- base. retain ( |crate_type| {
428- if output:: invalid_output_for_target ( session, * crate_type) {
429- session. dcx ( ) . emit_warn ( errors:: UnsupportedCrateTypeForTarget {
430- crate_type : * crate_type,
431- target_triple : & session. opts . target_triple ,
432- } ) ;
433- false
434- } else {
435- true
436- }
437- } ) ;
438-
439- base
440- }
441-
442382fn multiple_output_types_to_stdout (
443383 output_types : & OutputTypes ,
444384 single_output_file_is_stdout : bool ,
0 commit comments