mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
expand: Change how #![cfg(FALSE)]
behaves on crate root
This commit is contained in:
parent
54129fa113
commit
74d6826858
3 changed files with 14 additions and 5 deletions
|
@ -202,6 +202,7 @@ impl Attrs {
|
||||||
None => Some(first),
|
None => Some(first),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool {
|
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool {
|
||||||
match self.cfg() {
|
match self.cfg() {
|
||||||
None => true,
|
None => true,
|
||||||
|
|
|
@ -290,16 +290,16 @@ impl DefCollector<'_> {
|
||||||
let module_id = self.def_map.root;
|
let module_id = self.def_map.root;
|
||||||
|
|
||||||
let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate);
|
let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate);
|
||||||
if let Some(cfg) = attrs.cfg() {
|
|
||||||
if self.cfg_options.check(&cfg) == Some(false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.inject_prelude(&attrs);
|
self.inject_prelude(&attrs);
|
||||||
|
|
||||||
// Process other crate-level attributes.
|
// Process other crate-level attributes.
|
||||||
for attr in &*attrs {
|
for attr in &*attrs {
|
||||||
|
if let Some(cfg) = attr.cfg() {
|
||||||
|
if self.cfg_options.check(&cfg) == Some(false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
let attr_name = match attr.path.as_ident() {
|
let attr_name = match attr.path.as_ident() {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
None => continue,
|
None => continue,
|
||||||
|
|
|
@ -309,6 +309,14 @@ impl Attr {
|
||||||
|
|
||||||
Some(paths)
|
Some(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cfg(&self) -> Option<CfgExpr> {
|
||||||
|
if *self.path.as_ident()? == crate::name![cfg] {
|
||||||
|
self.token_tree_value().map(CfgExpr::parse)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_attrs(
|
pub fn collect_attrs(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue