@@ -95,30 +95,29 @@ pub enum ForceAllTargets {
95
95
No ,
96
96
}
97
97
98
- /// Flag to indicate if features are requested for a build dependency or not.
99
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash ) ]
98
+ /// Flag to indicate if features are requested for a certain type of dependency.
99
+ ///
100
+ /// This is primarily used for constructing a [`PackageFeaturesKey`] to decouple
101
+ /// activated features of the same package with different types of dependency.
102
+ #[ derive( Default , Copy , Clone , Debug , PartialEq , Eq , Ord , PartialOrd , Hash ) ]
100
103
pub enum FeaturesFor {
101
- /// If `Some(target)` is present, we represent an artifact target .
102
- /// Otherwise any other normal or dev dependency.
103
- NormalOrDevOrArtifactTarget ( Option < CompileTarget > ) ,
104
+ /// Normal or dev dependency .
105
+ # [ default ]
106
+ NormalOrDev ,
104
107
/// Build dependency or proc-macro.
105
108
HostDep ,
106
- }
107
-
108
- impl Default for FeaturesFor {
109
- fn default ( ) -> Self {
110
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
111
- }
109
+ /// Any dependency with both artifact and target specified.
110
+ ///
111
+ /// That is, `dep = { …, artifact = <crate-type>, target = <triple> }`
112
+ ArtifactDep ( CompileTarget ) ,
112
113
}
113
114
114
115
impl std:: fmt:: Display for FeaturesFor {
115
116
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
116
117
match self {
117
118
FeaturesFor :: HostDep => f. write_str ( "host" ) ,
118
- FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) => {
119
- f. write_str ( & target. rustc_target ( ) )
120
- }
121
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None ) => Ok ( ( ) ) ,
119
+ FeaturesFor :: ArtifactDep ( target) => f. write_str ( & target. rustc_target ( ) ) ,
120
+ FeaturesFor :: NormalOrDev => Ok ( ( ) ) ,
122
121
}
123
122
}
124
123
}
@@ -128,7 +127,7 @@ impl FeaturesFor {
128
127
if for_host {
129
128
FeaturesFor :: HostDep
130
129
} else {
131
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
130
+ FeaturesFor :: NormalOrDev
132
131
}
133
132
}
134
133
@@ -137,12 +136,12 @@ impl FeaturesFor {
137
136
artifact_target : Option < CompileTarget > ,
138
137
) -> FeaturesFor {
139
138
match artifact_target {
140
- Some ( target) => FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ,
139
+ Some ( target) => FeaturesFor :: ArtifactDep ( target) ,
141
140
None => {
142
141
if for_host {
143
142
FeaturesFor :: HostDep
144
143
} else {
145
- FeaturesFor :: NormalOrDevOrArtifactTarget ( None )
144
+ FeaturesFor :: NormalOrDev
146
145
}
147
146
}
148
147
}
@@ -769,11 +768,11 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
769
768
self . target_data
770
769
. dep_platform_activated ( dep, CompileKind :: Host )
771
770
}
772
- ( _, FeaturesFor :: NormalOrDevOrArtifactTarget ( None ) ) => self
771
+ ( _, FeaturesFor :: NormalOrDev ) => self
773
772
. requested_targets
774
773
. iter ( )
775
774
. any ( |kind| self . target_data . dep_platform_activated ( dep, * kind) ) ,
776
- ( _, FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ) => self
775
+ ( _, FeaturesFor :: ArtifactDep ( target) ) => self
777
776
. target_data
778
777
. dep_platform_activated ( dep, CompileKind :: Target ( target) ) ,
779
778
}
@@ -832,17 +831,15 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
832
831
artifact. is_lib ( ) ,
833
832
artifact. target ( ) . map ( |target| match target {
834
833
ArtifactTarget :: Force ( target) => {
835
- vec ! [ FeaturesFor :: NormalOrDevOrArtifactTarget ( Some ( target) ) ]
834
+ vec ! [ FeaturesFor :: ArtifactDep ( target) ]
836
835
}
837
836
ArtifactTarget :: BuildDependencyAssumeTarget => self
838
837
. requested_targets
839
838
. iter ( )
840
839
. filter_map ( |kind| match kind {
841
840
CompileKind :: Host => None ,
842
841
CompileKind :: Target ( target) => {
843
- Some ( FeaturesFor :: NormalOrDevOrArtifactTarget (
844
- Some ( * target) ,
845
- ) )
842
+ Some ( FeaturesFor :: ArtifactDep ( * target) )
846
843
}
847
844
} )
848
845
. collect ( ) ,
0 commit comments