aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-16 18:55:40 +0000
committerLukas Wirth <[email protected]>2021-03-16 18:55:40 +0000
commit3daa302cd39c779cae0b096972f2fdc3e67e214c (patch)
tree42e7863ce6844d72d5e09426e9e27c3cd9d48747
parentacc6458390eb7ed5947fe8b6a0628b4a9018fad1 (diff)
Fix attribute index assignment in cfg_attr resolution
-rw-r--r--crates/hir_def/src/attr.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index 505c4cd17..683c37023 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -136,16 +136,15 @@ impl RawAttrs {
136 let new_attrs = self 136 let new_attrs = self
137 .iter() 137 .iter()
138 .flat_map(|attr| -> SmallVec<[_; 1]> { 138 .flat_map(|attr| -> SmallVec<[_; 1]> {
139 let attr = attr.clone();
140 let is_cfg_attr = 139 let is_cfg_attr =
141 attr.path.as_ident().map_or(false, |name| *name == hir_expand::name![cfg_attr]); 140 attr.path.as_ident().map_or(false, |name| *name == hir_expand::name![cfg_attr]);
142 if !is_cfg_attr { 141 if !is_cfg_attr {
143 return smallvec![attr]; 142 return smallvec![attr.clone()];
144 } 143 }
145 144
146 let subtree = match &attr.input { 145 let subtree = match &attr.input {
147 Some(AttrInput::TokenTree(it)) => it, 146 Some(AttrInput::TokenTree(it)) => it,
148 _ => return smallvec![attr], 147 _ => return smallvec![attr.clone()],
149 }; 148 };
150 149
151 // Input subtree is: `(cfg, $(attr),+)` 150 // Input subtree is: `(cfg, $(attr),+)`
@@ -157,11 +156,14 @@ impl RawAttrs {
157 let cfg = parts.next().unwrap(); 156 let cfg = parts.next().unwrap();
158 let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() }; 157 let cfg = Subtree { delimiter: subtree.delimiter, token_trees: cfg.to_vec() };
159 let cfg = CfgExpr::parse(&cfg); 158 let cfg = CfgExpr::parse(&cfg);
159 let index = attr.index;
160 let attrs = parts.filter(|a| !a.is_empty()).filter_map(|attr| { 160 let attrs = parts.filter(|a| !a.is_empty()).filter_map(|attr| {
161 let tree = Subtree { delimiter: None, token_trees: attr.to_vec() }; 161 let tree = Subtree { delimiter: None, token_trees: attr.to_vec() };
162 let attr = ast::Attr::parse(&format!("#[{}]", tree)).ok()?; 162 let attr = ast::Attr::parse(&format!("#[{}]", tree)).ok()?;
163 let hygiene = Hygiene::new_unhygienic(); // FIXME 163 // FIXME hygiene
164 Attr::from_src(attr, &hygiene) 164 let hygiene = Hygiene::new_unhygienic();
165 // FIXME same index is assigned to multiple attributes
166 Attr::from_src(attr, &hygiene).map(|attr| Attr { index, ..attr })
165 }); 167 });
166 168
167 let cfg_options = &crate_graph[krate].cfg_options; 169 let cfg_options = &crate_graph[krate].cfg_options;