Description
In debugging some #[cfg(<feature>)]
issues, I discovered that there's a mismatch in how features are handled by the json_project
module vs. the CfgOptions
struct:
in ra_config/src/lib.rs:23
pub struct CfgOptions {
atoms: FxHashSet<SmolStr>,
key_values: FxHashSet<(SmolStr, SmolStr)>,
}
and in ra_project/src/json_project:19
pub struct Crate {
pub(crate) root_module: PathBuf,
pub(crate) edition: Edition,
pub(crate) deps: Vec<Dep>,
pub(crate) atom_cfgs: FxHashSet<String>,
pub(crate) key_value_cfgs: FxHashMap<String, String>,
pub(crate) out_dir: Option<PathBuf>,
pub(crate) proc_macro_dylib_path: Option<PathBuf>,
}
CfgOptions.key_values
is a HashSet<(String, String)>
, while Crate.key_value_cfg
is a HashMap<String, String>
.
The result being that the json_project configuration path only excepts a single feature (or a single value for any named kind of item in the cfg).
I have a quick fix together that switches Crate.key_value_cfg
over to a HashSet<(String, String>)
to match the CfgOptions, but it needs a different json structure:
Instead of:
"key_value_cfgs": {
"feature": "alloc",
"feature": "default",
"feature": "i128_support",
},
(which when parsed results in a ("feature", "i128_support")
tuple as the only "feature" that was loaded),
it becomes:
"key_value_cfgs": [
["feature" , "alloc"],
["feature" , "default"],
["feature" , "i128_support"],
],
But that's a breaking change with respect to anyone currently using the json config method, the old json fails to be parsed entirely. Anyone using it will need to update their json files to match, at the same time, or I can write a custom Deserialize
impl that will support both (and can later be removed in favor of the
I have a couple questions:
- Is making
key_value_cfgs
a hashset of(String, String)
the right change? - Is a custom
Deserialize
impl that bridges the gap for users welcome? - Where can I put the unit-tests for this? (in the same file?)