Auto merge of #14874 - Veykril:crate-cfg, r=Veykril
expand: Change how `#![cfg(FALSE)]` behaves on crate root Closes https://github.com/rust-lang/rust-analyzer/issues/14769
This commit is contained in:
commit
2f840c2236
@ -202,6 +202,7 @@ pub fn cfg(&self) -> Option<CfgExpr> {
|
||||
None => Some(first),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool {
|
||||
match self.cfg() {
|
||||
None => true,
|
||||
|
@ -290,16 +290,16 @@ fn seed_with_top_level(&mut self) {
|
||||
let module_id = self.def_map.root;
|
||||
|
||||
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);
|
||||
|
||||
// Process other crate-level attributes.
|
||||
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() {
|
||||
Some(name) => name,
|
||||
None => continue,
|
||||
|
@ -309,6 +309,14 @@ pub fn parse_path_comma_token_tree<'a>(
|
||||
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user