@@ -102,30 +102,29 @@ pub enum ForceAllTargets {
102
102
No ,
103
103
}
104
104
105
- /// Flag to indicate if features are requested for a build dependency or not.
106
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash ) ]
105
+ /// Flag to indicate if features are requested for a certain type of dependency.
106
+ ///
107
+ /// This is primarily used for constructing a [`PackageFeaturesKey`] to decouple
108
+ /// activated features of the same package with different types of dependency.
109
+ #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash ) ]
107
110
pub enum FeaturesFor {
108
- /// If `Some(target)` is present, we represent an artifact target .
109
- /// Otherwise any other normal or dev dependency.
110
- NormalOrDevOrArtifactTarget ( Option < CompileTarget > ) ,
111
+ /// Normal or dev dependency .
112
+ # [ default ]
113
+ NormalOrDev ,
111
114
/// Build dependency or proc-macro.
112
115
HostDep ,
113
- }
114
-
115
- impl Default for FeaturesFor {
116
- fn default ( ) -> Self {
117
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
118
- }
116
+ /// Any dependency with both artifact and target specified.
117
+ ///
118
+ /// That is, `dep = { …, artifact = <crate-type>, target = <triple> }`
119
+ ArtifactDep ( CompileTarget ) ,
119
120
}
120
121
121
122
impl std:: fmt:: Display for FeaturesFor {
122
123
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
123
124
match self {
124
125
FeaturesFor :: HostDep => f. write_str ( "host" ) ,
125
- FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) => {
126
- f. write_str ( & target. rustc_target ( ) )
127
- }
128
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None ) => Ok ( ( ) ) ,
126
+ FeaturesFor :: ArtifactDep ( target) => f. write_str ( & target. rustc_target ( ) ) ,
127
+ FeaturesFor :: NormalOrDev => Ok ( ( ) ) ,
129
128
}
130
129
}
131
130
}
@@ -135,7 +134,7 @@ impl FeaturesFor {
135
134
if for_host {
136
135
FeaturesFor :: HostDep
137
136
} else {
138
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
137
+ FeaturesFor :: NormalOrDev
139
138
}
140
139
}
141
140
@@ -144,12 +143,12 @@ impl FeaturesFor {
144
143
artifact_target : Option < CompileTarget > ,
145
144
) -> FeaturesFor {
146
145
match artifact_target {
147
- Some ( target) => FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ,
146
+ Some ( target) => FeaturesFor :: ArtifactDep ( target) ,
148
147
None => {
149
148
if for_host {
150
149
FeaturesFor :: HostDep
151
150
} else {
152
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
151
+ FeaturesFor :: NormalOrDev
153
152
}
154
153
}
155
154
}
@@ -786,11 +785,11 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
786
785
self . target_data
787
786
. dep_platform_activated ( dep, CompileKind :: Host )
788
787
}
789
- ( _, FeaturesFor :: NormalOrDevOrArtifactTarget ( None ) ) => self
788
+ ( _, FeaturesFor :: NormalOrDev ) => self
790
789
. requested_targets
791
790
. iter ( )
792
791
. any ( |kind| self . target_data . dep_platform_activated ( dep, * kind) ) ,
793
- ( _, FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ) => self
792
+ ( _, FeaturesFor :: ArtifactDep ( target) ) => self
794
793
. target_data
795
794
. dep_platform_activated ( dep, CompileKind :: Target ( target) ) ,
796
795
}
@@ -849,17 +848,15 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
849
848
artifact. is_lib ( ) ,
850
849
artifact. target ( ) . map ( |target| match target {
851
850
ArtifactTarget :: Force ( target) => {
852
- vec ! [ FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ]
851
+ vec ! [ FeaturesFor :: ArtifactDep ( target) ]
853
852
}
854
853
ArtifactTarget :: BuildDependencyAssumeTarget => self
855
854
. requested_targets
856
855
. iter ( )
857
856
. filter_map ( |kind| match kind {
858
857
CompileKind :: Host => None ,
859
858
CompileKind :: Target ( target) => {
860
- Some ( FeaturesFor :: NormalOrDevOrArtifactTarget (
861
- Some ( * target) ,
862
- ) )
859
+ Some ( FeaturesFor :: ArtifactDep ( * target) )
863
860
}
864
861
} )
865
862
. collect ( ) ,
0 commit comments