@@ -716,6 +716,45 @@ fn print_flowgraph<W:io::Writer>(analysis: CrateAnalysis,
716
716
717
717
pub fn collect_crate_types ( session : & Session ,
718
718
attrs : & [ ast:: Attribute ] ) -> Vec < config:: CrateType > {
719
+ // Unconditionally collect crate types from attributes to make them used
720
+ let attr_types: Vec < config:: CrateType > = attrs. iter ( ) . filter_map ( |a| {
721
+ if a. check_name ( "crate_type" ) {
722
+ match a. value_str ( ) {
723
+ Some ( ref n) if n. equiv ( & ( "rlib" ) ) => {
724
+ Some ( config:: CrateTypeRlib )
725
+ }
726
+ Some ( ref n) if n. equiv ( & ( "dylib" ) ) => {
727
+ Some ( config:: CrateTypeDylib )
728
+ }
729
+ Some ( ref n) if n. equiv ( & ( "lib" ) ) => {
730
+ Some ( config:: default_lib_output ( ) )
731
+ }
732
+ Some ( ref n) if n. equiv ( & ( "staticlib" ) ) => {
733
+ Some ( config:: CrateTypeStaticlib )
734
+ }
735
+ Some ( ref n) if n. equiv ( & ( "bin" ) ) => Some ( config:: CrateTypeExecutable ) ,
736
+ Some ( _) => {
737
+ session. add_lint ( lint:: UnknownCrateType ,
738
+ ast:: CRATE_NODE_ID ,
739
+ a. span ,
740
+ "invalid `crate_type` \
741
+ value". to_strbuf ( ) ) ;
742
+ None
743
+ }
744
+ _ => {
745
+ session. add_lint ( lint:: UnknownCrateType ,
746
+ ast:: CRATE_NODE_ID ,
747
+ a. span ,
748
+ "`crate_type` requires a \
749
+ value". to_strbuf ( ) ) ;
750
+ None
751
+ }
752
+ }
753
+ } else {
754
+ None
755
+ }
756
+ } ) . collect ( ) ;
757
+
719
758
// If we're generating a test executable, then ignore all other output
720
759
// styles at all other locations
721
760
if session. opts . test {
@@ -729,44 +768,7 @@ pub fn collect_crate_types(session: &Session,
729
768
if base. len ( ) > 0 {
730
769
return base
731
770
} else {
732
- let iter = attrs. iter ( ) . filter_map ( |a| {
733
- if a. name ( ) . equiv ( & ( "crate_type" ) ) {
734
- match a. value_str ( ) {
735
- Some ( ref n) if n. equiv ( & ( "rlib" ) ) => {
736
- Some ( config:: CrateTypeRlib )
737
- }
738
- Some ( ref n) if n. equiv ( & ( "dylib" ) ) => {
739
- Some ( config:: CrateTypeDylib )
740
- }
741
- Some ( ref n) if n. equiv ( & ( "lib" ) ) => {
742
- Some ( config:: default_lib_output ( ) )
743
- }
744
- Some ( ref n) if n. equiv ( & ( "staticlib" ) ) => {
745
- Some ( config:: CrateTypeStaticlib )
746
- }
747
- Some ( ref n) if n. equiv ( & ( "bin" ) ) => Some ( config:: CrateTypeExecutable ) ,
748
- Some ( _) => {
749
- session. add_lint ( lint:: UnknownCrateType ,
750
- ast:: CRATE_NODE_ID ,
751
- a. span ,
752
- "invalid `crate_type` \
753
- value". to_strbuf ( ) ) ;
754
- None
755
- }
756
- _ => {
757
- session. add_lint ( lint:: UnknownCrateType ,
758
- ast:: CRATE_NODE_ID ,
759
- a. span ,
760
- "`crate_type` requires a \
761
- value". to_strbuf ( ) ) ;
762
- None
763
- }
764
- }
765
- } else {
766
- None
767
- }
768
- } ) ;
769
- base. extend ( iter) ;
771
+ base. extend ( attr_types. move_iter ( ) ) ;
770
772
if base. len ( ) == 0 {
771
773
base. push ( config:: CrateTypeExecutable ) ;
772
774
}
0 commit comments