Skip to content

Commit 6860b64

Browse files
bors[bot]matklad
andauthored
Merge #8753
8753: internal: expose cfg attrs from hir::Crate r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents ba86203 + 53f7149 commit 6860b64

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cfg/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tt::SmolStr;
1313
pub use cfg_expr::{CfgAtom, CfgExpr};
1414
pub use dnf::DnfExpr;
1515

16-
/// Configuration options used for conditional compilition on items with `cfg` attributes.
16+
/// Configuration options used for conditional compilation on items with `cfg` attributes.
1717
/// We have two kind of options in different namespaces: atomic options like `unix`, and
1818
/// key-value options like `target_arch="x86"`.
1919
///

crates/hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ hir_expand = { path = "../hir_expand", version = "0.0.0" }
2525
hir_def = { path = "../hir_def", version = "0.0.0" }
2626
hir_ty = { path = "../hir_ty", version = "0.0.0" }
2727
tt = { path = "../tt", version = "0.0.0" }
28+
cfg = { path = "../cfg", version = "0.0.0" }

crates/hir/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub use crate::{
8989
// Generally, a refactoring which *removes* a name from this list is a good
9090
// idea!
9191
pub use {
92+
cfg::{CfgAtom, CfgExpr, CfgOptions},
9293
hir_def::{
9394
adt::StructKind,
9495
attr::{Attr, Attrs, AttrsWithOwner, Documentation},
@@ -215,6 +216,10 @@ impl Crate {
215216

216217
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
217218
}
219+
220+
pub fn cfg(&self, db: &dyn HirDatabase) -> CfgOptions {
221+
db.crate_graph()[self.id].cfg_options.clone()
222+
}
218223
}
219224

220225
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)