]> git.lizzy.rs Git - rust.git/commitdiff
Support `#[cfg]` on all associated items
authorJonas Schievink <jonasschievink@gmail.com>
Thu, 18 Mar 2021 00:28:40 +0000 (01:28 +0100)
committerJonas Schievink <jonasschievink@gmail.com>
Thu, 18 Mar 2021 00:28:55 +0000 (01:28 +0100)
crates/hir_def/src/data.rs
crates/hir_ty/src/tests/simple.rs

index e976e419ebc7c42af1cafa82ce5867b3621eb3b6..2c70b3bc0e6cdc666f5e859d3401f78c0943efd5 100644 (file)
@@ -256,17 +256,17 @@ fn collect_items(
 
     let mut items = Vec::new();
     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 {
             AssocItem::Function(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);
                 items.push((item.name.clone(), def.into()));
             }
-            // FIXME: cfg?
             AssocItem::Const(id) => {
                 let item = &item_tree[id];
                 let name = match item.name.clone() {
index f5069eba51bfe72be8c7ad4a763f5aebe9c4ea62..bcc43ed700e9376bc8dec6bc69fe356853804dc3 100644 (file)
@@ -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}
+}
+    "#,
+    )
+}