From a09d48380204fa948a3af397dc2188b93bf5793f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 14 Jul 2020 18:23:45 +0200 Subject: Thread varargs through r-a --- crates/ra_hir_def/src/data.rs | 2 ++ crates/ra_hir_def/src/item_tree.rs | 1 + crates/ra_hir_def/src/item_tree/lower.rs | 9 +++++++++ crates/ra_hir_def/src/type_ref.rs | 13 ++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index aa335f1e3..88a8ef9bf 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -27,6 +27,7 @@ pub struct FunctionData { /// can be called as a method. pub has_self_param: bool, pub is_unsafe: bool, + pub is_varargs: bool, pub visibility: RawVisibility, } @@ -43,6 +44,7 @@ impl FunctionData { attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), has_self_param: func.has_self_param, is_unsafe: func.is_unsafe, + is_varargs: func.is_varargs, visibility: item_tree[func.visibility].clone(), }) } diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 3e603bd55..da79d8ffd 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -503,6 +503,7 @@ pub struct Function { pub has_self_param: bool, pub is_unsafe: bool, pub params: Box<[TypeRef]>, + pub is_varargs: bool, pub ret_type: TypeRef, pub ast_id: FileAstId, } diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index 4182a9e3b..f79b8fca3 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -313,6 +313,14 @@ impl Ctx { params.push(type_ref); } } + + let mut is_varargs = false; + if let Some(params) = func.param_list() { + if let Some(last) = params.params().last() { + is_varargs = last.dotdotdot_token().is_some(); + } + } + let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) { Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), _ => TypeRef::unit(), @@ -334,6 +342,7 @@ impl Ctx { has_self_param, is_unsafe: func.unsafe_token().is_some(), params: params.into_boxed_slice(), + is_varargs, ret_type, ast_id, }; diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 86a77b704..e90b2a0b9 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs @@ -63,7 +63,7 @@ pub enum TypeRef { Array(Box /*, Expr*/), Slice(Box), /// A fn pointer. Last element of the vector is the return type. - Fn(Vec), + Fn(Vec, bool /*varargs*/), // For ImplTrait(Vec), DynTrait(Vec), @@ -118,7 +118,12 @@ impl TypeRef { .and_then(|rt| rt.type_ref()) .map(|it| TypeRef::from_ast(ctx, it)) .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); + let mut is_varargs = false; let mut params = if let Some(pl) = inner.param_list() { + if let Some(param) = pl.params().last() { + is_varargs = param.dotdotdot_token().is_some(); + } + pl.params() .map(|p| p.ascribed_type()) .map(|it| TypeRef::from_ast_opt(&ctx, it)) @@ -127,7 +132,7 @@ impl TypeRef { Vec::new() }; params.push(ret_ty); - TypeRef::Fn(params) + TypeRef::Fn(params, is_varargs) } // for types are close enough for our purposes to the inner type for now... ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), @@ -158,7 +163,9 @@ impl TypeRef { fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) { f(type_ref); match type_ref { - TypeRef::Fn(types) | TypeRef::Tuple(types) => types.iter().for_each(|t| go(t, f)), + TypeRef::Fn(types, _) | TypeRef::Tuple(types) => { + types.iter().for_each(|t| go(t, f)) + } TypeRef::RawPtr(type_ref, _) | TypeRef::Reference(type_ref, _) | TypeRef::Array(type_ref) -- cgit v1.2.3