mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
Support #[cfg]
on all associated items
This commit is contained in:
parent
62c059ea74
commit
94b3b32c98
2 changed files with 24 additions and 5 deletions
|
@ -256,17 +256,17 @@ fn collect_items(
|
||||||
|
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
for item in assoc_items {
|
for item in assoc_items {
|
||||||
|
let attrs = item_tree.attrs(db, module.krate, ModItem::from(item).into());
|
||||||
|
if !attrs.is_cfg_enabled(&cfg_options) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
match item {
|
match item {
|
||||||
AssocItem::Function(id) => {
|
AssocItem::Function(id) => {
|
||||||
let item = &item_tree[id];
|
let item = &item_tree[id];
|
||||||
let attrs = item_tree.attrs(db, module.krate, ModItem::from(id).into());
|
|
||||||
if !attrs.is_cfg_enabled(&cfg_options) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let def = FunctionLoc { container, id: ItemTreeId::new(file_id, id) }.intern(db);
|
let def = FunctionLoc { container, id: ItemTreeId::new(file_id, id) }.intern(db);
|
||||||
items.push((item.name.clone(), def.into()));
|
items.push((item.name.clone(), def.into()));
|
||||||
}
|
}
|
||||||
// FIXME: cfg?
|
|
||||||
AssocItem::Const(id) => {
|
AssocItem::Const(id) => {
|
||||||
let item = &item_tree[id];
|
let item = &item_tree[id];
|
||||||
let name = match item.name.clone() {
|
let name = match item.name.clone() {
|
||||||
|
|
|
@ -2545,3 +2545,22 @@ fn test() {
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cfgd_out_assoc_items() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
#[cfg(FALSE)]
|
||||||
|
const C: S = S;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
S::C;
|
||||||
|
//^^^^ {unknown}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue