From 53f7149d4510137111ed810803e9529157537288 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Fri, 7 May 2021 23:35:43 +0300
Subject: [PATCH] internal: expose cfg attrs from hir::Crate

---
 Cargo.lock            | 1 +
 crates/cfg/src/lib.rs | 2 +-
 crates/hir/Cargo.toml | 1 +
 crates/hir/src/lib.rs | 5 +++++
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Cargo.lock b/Cargo.lock
index f3a512a8a79..0e1234b721c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -480,6 +480,7 @@ version = "0.0.0"
 dependencies = [
  "arrayvec",
  "base_db",
+ "cfg",
  "either",
  "hir_def",
  "hir_expand",
diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs
index d88ecf8b091..59fd388809c 100644
--- a/crates/cfg/src/lib.rs
+++ b/crates/cfg/src/lib.rs
@@ -13,7 +13,7 @@ use tt::SmolStr;
 pub use cfg_expr::{CfgAtom, CfgExpr};
 pub use dnf::DnfExpr;
 
-/// Configuration options used for conditional compilition on items with `cfg` attributes.
+/// Configuration options used for conditional compilation on items with `cfg` attributes.
 /// We have two kind of options in different namespaces: atomic options like `unix`, and
 /// key-value options like `target_arch="x86"`.
 ///
diff --git a/crates/hir/Cargo.toml b/crates/hir/Cargo.toml
index 9e329656fe3..560b1523893 100644
--- a/crates/hir/Cargo.toml
+++ b/crates/hir/Cargo.toml
@@ -25,3 +25,4 @@ hir_expand = { path = "../hir_expand", version = "0.0.0" }
 hir_def = { path = "../hir_def", version = "0.0.0" }
 hir_ty = { path = "../hir_ty", version = "0.0.0" }
 tt = { path = "../tt", version = "0.0.0" }
+cfg = { path = "../cfg", version = "0.0.0" }
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index f876339decb..ac23e385ee7 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -89,6 +89,7 @@ pub use crate::{
 // Generally, a refactoring which *removes* a name from this list is a good
 // idea!
 pub use {
+    cfg::{CfgAtom, CfgExpr, CfgOptions},
     hir_def::{
         adt::StructKind,
         attr::{Attr, Attrs, AttrsWithOwner, Documentation},
@@ -215,6 +216,10 @@ impl Crate {
 
         doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
     }
+
+    pub fn cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
+        db.crate_graph()[self.id].cfg_options.clone()
+    }
 }
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]