diff options
-rw-r--r-- | crates/hir_def/src/data.rs | 15 | ||||
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index f9bb0c6da..e976e419e 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs | |||
@@ -36,18 +36,25 @@ impl FunctionData { | |||
36 | pub(crate) fn fn_data_query(db: &dyn DefDatabase, func: FunctionId) -> Arc<FunctionData> { | 36 | pub(crate) fn fn_data_query(db: &dyn DefDatabase, func: FunctionId) -> Arc<FunctionData> { |
37 | let loc = func.lookup(db); | 37 | let loc = func.lookup(db); |
38 | let krate = loc.container.module(db).krate; | 38 | let krate = loc.container.module(db).krate; |
39 | let crate_graph = db.crate_graph(); | ||
40 | let cfg_options = &crate_graph[krate].cfg_options; | ||
39 | let item_tree = db.item_tree(loc.id.file_id); | 41 | let item_tree = db.item_tree(loc.id.file_id); |
40 | let func = &item_tree[loc.id.value]; | 42 | let func = &item_tree[loc.id.value]; |
41 | let is_varargs = func | 43 | |
44 | let enabled_params = func | ||
42 | .params | 45 | .params |
43 | .clone() | 46 | .clone() |
44 | .last() | 47 | .filter(|¶m| item_tree.attrs(db, krate, param.into()).is_cfg_enabled(cfg_options)); |
48 | |||
49 | // If last cfg-enabled param is a `...` param, it's a varargs function. | ||
50 | let is_varargs = enabled_params | ||
51 | .clone() | ||
52 | .next_back() | ||
45 | .map_or(false, |param| matches!(item_tree[param], Param::Varargs)); | 53 | .map_or(false, |param| matches!(item_tree[param], Param::Varargs)); |
46 | 54 | ||
47 | Arc::new(FunctionData { | 55 | Arc::new(FunctionData { |
48 | name: func.name.clone(), | 56 | name: func.name.clone(), |
49 | params: func | 57 | params: enabled_params |
50 | .params | ||
51 | .clone() | 58 | .clone() |
52 | .filter_map(|id| match &item_tree[id] { | 59 | .filter_map(|id| match &item_tree[id] { |
53 | Param::Normal(ty) => Some(item_tree[*ty].clone()), | 60 | Param::Normal(ty) => Some(item_tree[*ty].clone()), |
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index c14da95ab..90df3d929 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -824,6 +824,12 @@ impl<T> Iterator for IdRange<T> { | |||
824 | } | 824 | } |
825 | } | 825 | } |
826 | 826 | ||
827 | impl<T> DoubleEndedIterator for IdRange<T> { | ||
828 | fn next_back(&mut self) -> Option<Self::Item> { | ||
829 | self.range.next_back().map(|raw| Idx::from_raw(raw.into())) | ||
830 | } | ||
831 | } | ||
832 | |||
827 | impl<T> fmt::Debug for IdRange<T> { | 833 | impl<T> fmt::Debug for IdRange<T> { |
828 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 834 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
829 | f.debug_tuple(&format!("IdRange::<{}>", type_name::<T>())).field(&self.range).finish() | 835 | f.debug_tuple(&format!("IdRange::<{}>", type_name::<T>())).field(&self.range).finish() |