|
2 | 2 |
|
3 | 3 | use std::{borrow::Cow, convert::identity, hash::Hash, ops};
|
4 | 4 |
|
5 |
| -use base_db::Crate; |
6 | 5 | use cfg::{CfgExpr, CfgOptions};
|
7 | 6 | use either::Either;
|
8 | 7 | use hir_expand::{
|
@@ -56,12 +55,12 @@ impl Attrs {
|
56 | 55 | (**self).iter().find(|attr| attr.id == id)
|
57 | 56 | }
|
58 | 57 |
|
59 |
| - pub(crate) fn expand_cfg_attr( |
60 |
| - db: &dyn DefDatabase, |
61 |
| - krate: Crate, |
| 58 | + pub(crate) fn expand_cfg_attr<'db>( |
| 59 | + db: &'db dyn DefDatabase, |
| 60 | + cfg_options: impl FnOnce() -> &'db CfgOptions, |
62 | 61 | raw_attrs: RawAttrs,
|
63 | 62 | ) -> Attrs {
|
64 |
| - Attrs(raw_attrs.expand_cfg_attr(db, krate)) |
| 63 | + Attrs(raw_attrs.expand_cfg_attr(db, cfg_options)) |
65 | 64 | }
|
66 | 65 |
|
67 | 66 | pub(crate) fn is_cfg_enabled_for(
|
@@ -105,35 +104,32 @@ impl Attrs {
|
105 | 104 | ) -> Arc<ArenaMap<LocalFieldId, Attrs>> {
|
106 | 105 | let _p = tracing::info_span!("fields_attrs_query").entered();
|
107 | 106 | let mut res = ArenaMap::default();
|
108 |
| - let (fields, file_id, krate) = match v { |
| 107 | + let (fields, file_id, module) = match v { |
109 | 108 | VariantId::EnumVariantId(it) => {
|
110 | 109 | let loc = it.lookup(db);
|
111 |
| - let krate = loc.parent.lookup(db).container.krate(db); |
112 | 110 | let source = loc.source(db);
|
113 |
| - (source.value.field_list(), source.file_id, krate) |
| 111 | + (source.value.field_list(), source.file_id, loc.parent.lookup(db).container) |
114 | 112 | }
|
115 | 113 | VariantId::StructId(it) => {
|
116 | 114 | let loc = it.lookup(db);
|
117 |
| - let krate = loc.container.krate(db); |
118 | 115 | let source = loc.source(db);
|
119 |
| - (source.value.field_list(), source.file_id, krate) |
| 116 | + (source.value.field_list(), source.file_id, loc.container) |
120 | 117 | }
|
121 | 118 | VariantId::UnionId(it) => {
|
122 | 119 | let loc = it.lookup(db);
|
123 |
| - let krate = loc.container.krate(db); |
124 | 120 | let source = loc.source(db);
|
125 | 121 | (
|
126 | 122 | source.value.record_field_list().map(ast::FieldList::RecordFieldList),
|
127 | 123 | source.file_id,
|
128 |
| - krate, |
| 124 | + loc.container, |
129 | 125 | )
|
130 | 126 | }
|
131 | 127 | };
|
132 | 128 | let Some(fields) = fields else {
|
133 | 129 | return Arc::new(res);
|
134 | 130 | };
|
135 | 131 |
|
136 |
| - let cfg_options = krate.cfg_options(db); |
| 132 | + let cfg_options = module.krate(db).cfg_options(db); |
137 | 133 | let span_map = db.span_map(file_id);
|
138 | 134 |
|
139 | 135 | match fields {
|
@@ -544,7 +540,7 @@ impl AttrsWithOwner {
|
544 | 540 | tree.top_level_raw_attrs().clone()
|
545 | 541 | }
|
546 | 542 | };
|
547 |
| - Attrs::expand_cfg_attr(db, module.krate(db), raw_attrs) |
| 543 | + Attrs::expand_cfg_attr(db, || module.krate(db).cfg_options(db), raw_attrs) |
548 | 544 | }
|
549 | 545 | AttrDefId::FieldId(it) => db.fields_attrs(it.parent)[it.local_id].clone(),
|
550 | 546 | AttrDefId::EnumVariantId(it) => attrs_from_ast_id_loc(db, it),
|
|
0 commit comments