Skip to content

Commit 0f04023

Browse files
committed
lint and format
1 parent fc0770b commit 0f04023

8 files changed

Lines changed: 179 additions & 91 deletions

File tree

src/cfg_eval.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,10 @@ impl RustcCfgEvaluator {
9696

9797
fn validate_supported(expr: &Expression) -> eyre::Result<()> {
9898
for pred in expr.predicates() {
99-
match pred {
100-
Predicate::Feature(_) => {
101-
eyre::bail!(
102-
"cfg expressions using `feature = \"...\"` are not supported in cargo-feature-combinations target overrides"
103-
)
104-
}
105-
_ => {}
99+
if let Predicate::Feature(_) = pred {
100+
eyre::bail!(
101+
"cfg expressions using `feature = \"...\"` are not supported in cargo-feature-combinations target overrides"
102+
)
106103
}
107104
}
108105
Ok(())
@@ -134,25 +131,21 @@ impl CfgEvaluator for RustcCfgEvaluator {
134131
// on rustc output rather than builtin target tables.
135132
match tp {
136133
cfg_expr::expr::TargetPredicate::Arch(a) => {
137-
set.has_kv("target_arch", &a.to_string())
138-
}
139-
cfg_expr::expr::TargetPredicate::Os(o) => set.has_kv("target_os", &o.to_string()),
140-
cfg_expr::expr::TargetPredicate::Env(e) => {
141-
set.has_kv("target_env", &e.to_string())
134+
set.has_kv("target_arch", a.as_ref())
142135
}
136+
cfg_expr::expr::TargetPredicate::Os(o) => set.has_kv("target_os", o.as_ref()),
137+
cfg_expr::expr::TargetPredicate::Env(e) => set.has_kv("target_env", e.as_ref()),
143138
cfg_expr::expr::TargetPredicate::Family(f) => {
144-
set.has_kv("target_family", &f.to_string())
139+
set.has_kv("target_family", f.as_ref())
145140
}
146141
cfg_expr::expr::TargetPredicate::Vendor(v) => {
147-
set.has_kv("target_vendor", &v.to_string())
148-
}
149-
cfg_expr::expr::TargetPredicate::Abi(a) => {
150-
set.has_kv("target_abi", &a.to_string())
142+
set.has_kv("target_vendor", v.as_ref())
151143
}
144+
cfg_expr::expr::TargetPredicate::Abi(a) => set.has_kv("target_abi", a.as_ref()),
152145
cfg_expr::expr::TargetPredicate::Endian(e) => {
153146
set.has_kv("target_endian", endian_str(e))
154147
}
155-
cfg_expr::expr::TargetPredicate::Panic(p) => set.has_kv("panic", &p.to_string()),
148+
cfg_expr::expr::TargetPredicate::Panic(p) => set.has_kv("panic", p.as_ref()),
156149
cfg_expr::expr::TargetPredicate::PointerWidth(w) => {
157150
set.has_kv("target_pointer_width", &w.to_string())
158151
}
@@ -184,13 +177,20 @@ mod test {
184177
let host = crate::target::RustcTargetDetector.detect_target(&Vec::new())?;
185178

186179
// Host must match its own arch.
187-
let cfg_set = std::process::Command::new("rustc").args(["--print", "cfg"]).output()?;
180+
let cfg_set = std::process::Command::new("rustc")
181+
.args(["--print", "cfg"])
182+
.output()?;
188183
assert!(cfg_set.status.success());
189184
let stdout = String::from_utf8_lossy(&cfg_set.stdout);
190185
let arch = stdout
191186
.lines()
192-
.find_map(|l| l.strip_prefix("target_arch=\"").and_then(|r| r.strip_suffix("\"")))
193-
.ok_or_else(|| eyre::eyre!("expected rustc --print cfg output to contain target_arch"))?;
187+
.find_map(|l| {
188+
l.strip_prefix("target_arch=\"")
189+
.and_then(|r| r.strip_suffix("\""))
190+
})
191+
.ok_or_else(|| {
192+
eyre::eyre!("expected rustc --print cfg output to contain target_arch")
193+
})?;
194194

195195
let expr = format!("cfg(target_arch = \"{arch}\")");
196196
assert!(eval.matches(&expr, &host)?);

src/config.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/// Patch types for set-like configuration fields.
12
pub mod patch;
3+
/// Configuration resolution logic (merge base config with target overrides).
24
pub mod resolve;
35

46
use self::patch::{FeatureSetVecPatch, StringSetPatch};
@@ -14,6 +16,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
1416
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
1517
pub struct Config {
1618
#[serde(default)]
19+
/// Feature sets that must be tested in isolation.
1720
pub isolated_feature_sets: Vec<HashSet<String>>,
1821
/// Formerly named `denylist`
1922
#[serde(default)]
@@ -55,10 +58,13 @@ pub struct Config {
5558
#[serde(default)]
5659
pub include_feature_sets: Vec<HashSet<String>>,
5760
#[serde(default)]
61+
/// Explicitly allowed feature sets.
5862
pub allow_feature_sets: Vec<HashSet<String>>,
5963
#[serde(default)]
64+
/// When enabled, disallow generating the empty feature set.
6065
pub no_empty_feature_set: bool,
6166
#[serde(default)]
67+
/// Arbitrary user-defined matrix values forwarded to the runner.
6268
pub matrix: HashMap<String, serde_json::Value>,
6369

6470
/// Target-specific configuration overrides.
@@ -67,6 +73,7 @@ pub struct Config {
6773
#[serde(default)]
6874
pub target: BTreeMap<String, TargetOverride>,
6975
#[serde(flatten)]
76+
/// Deprecated configuration keys (kept for backwards compatibility).
7077
pub deprecated: DeprecatedConfig,
7178
}
7279

@@ -82,40 +89,55 @@ pub struct TargetOverride {
8289
pub replace: bool,
8390

8491
#[serde(default)]
92+
/// Patch operations for [`Config::isolated_feature_sets`].
8593
pub isolated_feature_sets: Option<FeatureSetVecPatch>,
8694
#[serde(default)]
95+
/// Patch operations for [`Config::exclude_features`].
8796
pub exclude_features: Option<StringSetPatch>,
8897
#[serde(default)]
98+
/// Patch operations for [`Config::include_features`].
8999
pub include_features: Option<StringSetPatch>,
90100
#[serde(default)]
101+
/// Patch operations for [`Config::only_features`].
91102
pub only_features: Option<StringSetPatch>,
92103
#[serde(default)]
104+
/// Override for [`Config::skip_optional_dependencies`].
93105
pub skip_optional_dependencies: Option<bool>,
94106
#[serde(default)]
107+
/// Patch operations for [`Config::exclude_feature_sets`].
95108
pub exclude_feature_sets: Option<FeatureSetVecPatch>,
96109
#[serde(default)]
110+
/// Patch operations for [`Config::include_feature_sets`].
97111
pub include_feature_sets: Option<FeatureSetVecPatch>,
98112
#[serde(default)]
113+
/// Patch operations for [`Config::allow_feature_sets`].
99114
pub allow_feature_sets: Option<FeatureSetVecPatch>,
100115
#[serde(default)]
116+
/// Override for [`Config::no_empty_feature_set`].
101117
pub no_empty_feature_set: Option<bool>,
102118
#[serde(default)]
119+
/// Merge override for [`Config::matrix`].
103120
pub matrix: Option<HashMap<String, serde_json::Value>>,
104121
}
105122

106123
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
124+
/// Workspace-wide configuration for `cargo-feature-combinations`.
107125
pub struct WorkspaceConfig {
108126
/// List of package names to exclude from the workspace analysis.
109127
#[serde(default)]
110128
pub exclude_packages: HashSet<String>,
111129
}
112130

113131
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
132+
/// Deprecated configuration keys kept for backwards compatibility.
114133
pub struct DeprecatedConfig {
115134
#[serde(default)]
135+
/// Former name of [`Config::exclude_feature_sets`].
116136
pub skip_feature_sets: Vec<HashSet<String>>,
117137
#[serde(default)]
138+
/// Former name of [`Config::exclude_features`].
118139
pub denylist: HashSet<String>,
119140
#[serde(default)]
141+
/// Former name of [`Config::include_feature_sets`].
120142
pub exact_combinations: Vec<HashSet<String>>,
121143
}

src/config/patch.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ pub enum StringSetPatch {
1717
/// Explicit patch syntax: `key = { override = [...], add = [...], remove = [...] }`.
1818
Patch {
1919
#[serde(default)]
20+
/// If present, replace the entire value instead of applying add/remove.
2021
r#override: Option<HashSet<String>>,
2122
#[serde(default)]
23+
/// Values to add to the base set.
2224
add: HashSet<String>,
2325
#[serde(default)]
26+
/// Values to remove from the base set.
2427
remove: HashSet<String>,
2528
},
2629
}
2730

2831
impl StringSetPatch {
2932
#[must_use]
33+
/// Return the override value, if the patch is an override.
3034
pub fn override_value(&self) -> Option<&HashSet<String>> {
3135
match self {
3236
Self::Override(v) => Some(v),
@@ -35,26 +39,27 @@ impl StringSetPatch {
3539
}
3640

3741
#[must_use]
42+
/// Return the set of values to add.
3843
pub fn add_values(&self) -> &HashSet<String> {
39-
static EMPTY: std::sync::LazyLock<HashSet<String>> =
40-
std::sync::LazyLock::new(HashSet::new);
44+
static EMPTY: std::sync::LazyLock<HashSet<String>> = std::sync::LazyLock::new(HashSet::new);
4145
match self {
4246
Self::Override(_) => &EMPTY,
4347
Self::Patch { add, .. } => add,
4448
}
4549
}
4650

4751
#[must_use]
52+
/// Return the set of values to remove.
4853
pub fn remove_values(&self) -> &HashSet<String> {
49-
static EMPTY: std::sync::LazyLock<HashSet<String>> =
50-
std::sync::LazyLock::new(HashSet::new);
54+
static EMPTY: std::sync::LazyLock<HashSet<String>> = std::sync::LazyLock::new(HashSet::new);
5155
match self {
5256
Self::Override(_) => &EMPTY,
5357
Self::Patch { remove, .. } => remove,
5458
}
5559
}
5660

5761
#[must_use]
62+
/// Return `true` if the patch contains any add/remove operations.
5863
pub fn has_add_or_remove(&self) -> bool {
5964
!self.add_values().is_empty() || !self.remove_values().is_empty()
6065
}
@@ -69,16 +74,20 @@ pub enum FeatureSetVecPatch {
6974
/// Explicit patch syntax.
7075
Patch {
7176
#[serde(default)]
77+
/// If present, replace the entire list instead of applying add/remove.
7278
r#override: Option<Vec<HashSet<String>>>,
7379
#[serde(default)]
80+
/// Feature sets to append.
7481
add: Vec<HashSet<String>>,
7582
#[serde(default)]
83+
/// Feature sets to remove.
7684
remove: Vec<HashSet<String>>,
7785
},
7886
}
7987

8088
impl FeatureSetVecPatch {
8189
#[must_use]
90+
/// Return the override value, if the patch is an override.
8291
pub fn override_value(&self) -> Option<&Vec<HashSet<String>>> {
8392
match self {
8493
Self::Override(v) => Some(v),
@@ -87,6 +96,7 @@ impl FeatureSetVecPatch {
8796
}
8897

8998
#[must_use]
99+
/// Return the feature sets to add.
90100
pub fn add_values(&self) -> &[HashSet<String>] {
91101
static EMPTY: std::sync::LazyLock<Vec<HashSet<String>>> =
92102
std::sync::LazyLock::new(Vec::new);
@@ -97,6 +107,7 @@ impl FeatureSetVecPatch {
97107
}
98108

99109
#[must_use]
110+
/// Return the feature sets to remove.
100111
pub fn remove_values(&self) -> &[HashSet<String>] {
101112
static EMPTY: std::sync::LazyLock<Vec<HashSet<String>>> =
102113
std::sync::LazyLock::new(Vec::new);
@@ -107,6 +118,7 @@ impl FeatureSetVecPatch {
107118
}
108119

109120
#[must_use]
121+
/// Return `true` if the patch contains any add/remove operations.
110122
pub fn has_add_or_remove(&self) -> bool {
111123
!self.add_values().is_empty() || !self.remove_values().is_empty()
112124
}

0 commit comments

Comments
 (0)