mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-13 18:37:33 +00:00
Move features into potential_cfg_options
This commit is contained in:
parent
284483b347
commit
ae823aa23f
@ -128,10 +128,10 @@ impl ChangeFixture {
|
||||
file_id,
|
||||
meta.edition,
|
||||
Some(crate_name.clone().into()),
|
||||
meta.cfg.clone(),
|
||||
meta.cfg,
|
||||
meta.env,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||
assert!(prev.is_none());
|
||||
@ -158,10 +158,10 @@ impl ChangeFixture {
|
||||
crate_root,
|
||||
Edition::Edition2018,
|
||||
Some(CrateName::new("test").unwrap().into()),
|
||||
default_cfg.clone(),
|
||||
default_cfg,
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
} else {
|
||||
for (from, to) in crate_deps {
|
||||
@ -188,6 +188,7 @@ impl ChangeFixture {
|
||||
Edition::Edition2021,
|
||||
Some(CrateDisplayName::from_canonical_name("core".to_string())),
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Vec::new(),
|
||||
);
|
||||
|
@ -189,10 +189,10 @@ pub struct CrateData {
|
||||
/// `Dependency` matters), this name should only be used for UI.
|
||||
pub display_name: Option<CrateDisplayName>,
|
||||
pub cfg_options: CfgOptions,
|
||||
pub potential_cfg_options: CfgOptions,
|
||||
pub env: Env,
|
||||
pub dependencies: Vec<Dependency>,
|
||||
pub proc_macro: Vec<ProcMacro>,
|
||||
pub features: FxHashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
@ -220,19 +220,19 @@ impl CrateGraph {
|
||||
edition: Edition,
|
||||
display_name: Option<CrateDisplayName>,
|
||||
cfg_options: CfgOptions,
|
||||
potential_cfg_options: CfgOptions,
|
||||
env: Env,
|
||||
proc_macro: Vec<ProcMacro>,
|
||||
features: FxHashMap<String, Vec<String>>,
|
||||
) -> CrateId {
|
||||
let data = CrateData {
|
||||
root_file_id: file_id,
|
||||
edition,
|
||||
display_name,
|
||||
cfg_options,
|
||||
potential_cfg_options,
|
||||
env,
|
||||
proc_macro,
|
||||
dependencies: Vec::new(),
|
||||
features,
|
||||
};
|
||||
let crate_id = CrateId(self.arena.len() as u32);
|
||||
let prev = self.arena.insert(crate_id, data);
|
||||
@ -507,27 +507,27 @@ mod tests {
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate3 = graph.add_crate_root(
|
||||
FileId(3u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
|
||||
assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
|
||||
@ -542,18 +542,18 @@ mod tests {
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
|
||||
assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err());
|
||||
@ -567,27 +567,27 @@ mod tests {
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate3 = graph.add_crate_root(
|
||||
FileId(3u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
|
||||
assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
|
||||
@ -601,18 +601,18 @@ mod tests {
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
let crate2 = graph.add_crate_root(
|
||||
FileId(2u32),
|
||||
Edition2018,
|
||||
None,
|
||||
CfgOptions::default(),
|
||||
CfgOptions::default(),
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
assert!(graph
|
||||
.add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2)
|
||||
|
@ -234,8 +234,8 @@ impl Crate {
|
||||
db.crate_graph()[self.id].cfg_options.clone()
|
||||
}
|
||||
|
||||
pub fn features(&self, db: &dyn HirDatabase) -> Vec<String> {
|
||||
db.crate_graph()[self.id].features.iter().map(|(feat, _)| feat.clone()).collect()
|
||||
pub fn potential_cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
|
||||
db.crate_graph()[self.id].potential_cfg_options.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,10 +217,10 @@ impl Analysis {
|
||||
file_id,
|
||||
Edition::Edition2018,
|
||||
None,
|
||||
cfg_options.clone(),
|
||||
cfg_options,
|
||||
Env::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
);
|
||||
change.change_file(file_id, Some(Arc::new(text)));
|
||||
change.set_crate_graph(crate_graph);
|
||||
|
@ -26,20 +26,6 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
.find(|t| matches!(t.kind(), SyntaxKind::IDENT));
|
||||
|
||||
match previous.as_ref().map(|p| p.text()) {
|
||||
Some("feature") => {
|
||||
ctx.krate.map(|krate| {
|
||||
krate.features(ctx.db).iter().for_each(|f| {
|
||||
let mut item = CompletionItem::new(
|
||||
CompletionKind::Attribute,
|
||||
ctx.source_range(),
|
||||
f.clone(),
|
||||
);
|
||||
item.insert_text(format!(r#""{}""#, f));
|
||||
|
||||
acc.add(item.build())
|
||||
})
|
||||
});
|
||||
}
|
||||
Some("target_arch") => KNOWN_ARCH.iter().for_each(add_completion),
|
||||
Some("target_env") => KNOWN_ENV.iter().for_each(add_completion),
|
||||
Some("target_os") => KNOWN_OS.iter().for_each(add_completion),
|
||||
@ -47,7 +33,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
Some("target_endian") => ["little", "big"].iter().for_each(add_completion),
|
||||
Some(name) => {
|
||||
ctx.krate.map(|krate| {
|
||||
krate.cfg(ctx.db).get_cfg_values(&name).iter().for_each(|s| {
|
||||
krate.potential_cfg(ctx.db).get_cfg_values(&name).iter().for_each(|s| {
|
||||
let mut item = CompletionItem::new(
|
||||
CompletionKind::Attribute,
|
||||
ctx.source_range(),
|
||||
@ -61,7 +47,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
}
|
||||
None => {
|
||||
ctx.krate.map(|krate| {
|
||||
krate.cfg(ctx.db).get_cfg_keys().iter().for_each(|s| {
|
||||
krate.potential_cfg(ctx.db).get_cfg_keys().iter().for_each(|s| {
|
||||
let item = CompletionItem::new(
|
||||
CompletionKind::Attribute,
|
||||
ctx.source_range(),
|
||||
|
@ -384,10 +384,10 @@ fn project_json_to_crate_graph(
|
||||
file_id,
|
||||
krate.edition,
|
||||
krate.display_name.clone(),
|
||||
cfg_options.clone(),
|
||||
cfg_options,
|
||||
env,
|
||||
proc_macro.unwrap_or_default(),
|
||||
Default::default(),
|
||||
),
|
||||
)
|
||||
})
|
||||
@ -581,9 +581,9 @@ fn detached_files_to_crate_graph(
|
||||
Edition::Edition2018,
|
||||
display_name,
|
||||
cfg_options.clone(),
|
||||
cfg_options.clone(),
|
||||
Env::default(),
|
||||
Vec::new(),
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
for (name, krate) in public_deps.iter() {
|
||||
@ -721,14 +721,21 @@ fn add_target_crate_root(
|
||||
.unwrap_or_default();
|
||||
|
||||
let display_name = CrateDisplayName::from_canonical_name(cargo_name.to_string());
|
||||
let mut potential_cfg_options = cfg_options.clone();
|
||||
potential_cfg_options.extend(
|
||||
pkg.features
|
||||
.iter()
|
||||
.map(|feat| CfgFlag::KeyValue { key: "feature".into(), value: feat.0.into() }),
|
||||
);
|
||||
|
||||
let crate_id = crate_graph.add_crate_root(
|
||||
file_id,
|
||||
edition,
|
||||
Some(display_name),
|
||||
cfg_options,
|
||||
potential_cfg_options,
|
||||
env,
|
||||
proc_macro,
|
||||
pkg.features.clone(),
|
||||
);
|
||||
|
||||
crate_id
|
||||
@ -756,9 +763,9 @@ fn sysroot_to_crate_graph(
|
||||
Edition::Edition2018,
|
||||
Some(display_name),
|
||||
cfg_options.clone(),
|
||||
cfg_options.clone(),
|
||||
env,
|
||||
proc_macro,
|
||||
Default::default(),
|
||||
);
|
||||
Some((krate, crate_id))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user