diff options
author | Jonas Schievink <[email protected]> | 2020-07-14 17:23:45 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-07-14 19:27:47 +0100 |
commit | a09d48380204fa948a3af397dc2188b93bf5793f (patch) | |
tree | e38436638e0987a8ed2d68a646a35080a5e4c6d3 /crates/ra_hir_def/src | |
parent | 3f2ab436f45a4fae32514756736055819ead2baa (diff) |
Thread varargs through r-a
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/item_tree/lower.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 13 |
4 files changed, 22 insertions, 3 deletions
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 { | |||
27 | /// can be called as a method. | 27 | /// can be called as a method. |
28 | pub has_self_param: bool, | 28 | pub has_self_param: bool, |
29 | pub is_unsafe: bool, | 29 | pub is_unsafe: bool, |
30 | pub is_varargs: bool, | ||
30 | pub visibility: RawVisibility, | 31 | pub visibility: RawVisibility, |
31 | } | 32 | } |
32 | 33 | ||
@@ -43,6 +44,7 @@ impl FunctionData { | |||
43 | attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), | 44 | attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), |
44 | has_self_param: func.has_self_param, | 45 | has_self_param: func.has_self_param, |
45 | is_unsafe: func.is_unsafe, | 46 | is_unsafe: func.is_unsafe, |
47 | is_varargs: func.is_varargs, | ||
46 | visibility: item_tree[func.visibility].clone(), | 48 | visibility: item_tree[func.visibility].clone(), |
47 | }) | 49 | }) |
48 | } | 50 | } |
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 { | |||
503 | pub has_self_param: bool, | 503 | pub has_self_param: bool, |
504 | pub is_unsafe: bool, | 504 | pub is_unsafe: bool, |
505 | pub params: Box<[TypeRef]>, | 505 | pub params: Box<[TypeRef]>, |
506 | pub is_varargs: bool, | ||
506 | pub ret_type: TypeRef, | 507 | pub ret_type: TypeRef, |
507 | pub ast_id: FileAstId<ast::FnDef>, | 508 | pub ast_id: FileAstId<ast::FnDef>, |
508 | } | 509 | } |
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 { | |||
313 | params.push(type_ref); | 313 | params.push(type_ref); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | |||
317 | let mut is_varargs = false; | ||
318 | if let Some(params) = func.param_list() { | ||
319 | if let Some(last) = params.params().last() { | ||
320 | is_varargs = last.dotdotdot_token().is_some(); | ||
321 | } | ||
322 | } | ||
323 | |||
316 | let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) { | 324 | let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) { |
317 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), | 325 | Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), |
318 | _ => TypeRef::unit(), | 326 | _ => TypeRef::unit(), |
@@ -334,6 +342,7 @@ impl Ctx { | |||
334 | has_self_param, | 342 | has_self_param, |
335 | is_unsafe: func.unsafe_token().is_some(), | 343 | is_unsafe: func.unsafe_token().is_some(), |
336 | params: params.into_boxed_slice(), | 344 | params: params.into_boxed_slice(), |
345 | is_varargs, | ||
337 | ret_type, | 346 | ret_type, |
338 | ast_id, | 347 | ast_id, |
339 | }; | 348 | }; |
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 { | |||
63 | Array(Box<TypeRef> /*, Expr*/), | 63 | Array(Box<TypeRef> /*, Expr*/), |
64 | Slice(Box<TypeRef>), | 64 | Slice(Box<TypeRef>), |
65 | /// A fn pointer. Last element of the vector is the return type. | 65 | /// A fn pointer. Last element of the vector is the return type. |
66 | Fn(Vec<TypeRef>), | 66 | Fn(Vec<TypeRef>, bool /*varargs*/), |
67 | // For | 67 | // For |
68 | ImplTrait(Vec<TypeBound>), | 68 | ImplTrait(Vec<TypeBound>), |
69 | DynTrait(Vec<TypeBound>), | 69 | DynTrait(Vec<TypeBound>), |
@@ -118,7 +118,12 @@ impl TypeRef { | |||
118 | .and_then(|rt| rt.type_ref()) | 118 | .and_then(|rt| rt.type_ref()) |
119 | .map(|it| TypeRef::from_ast(ctx, it)) | 119 | .map(|it| TypeRef::from_ast(ctx, it)) |
120 | .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); | 120 | .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); |
121 | let mut is_varargs = false; | ||
121 | let mut params = if let Some(pl) = inner.param_list() { | 122 | let mut params = if let Some(pl) = inner.param_list() { |
123 | if let Some(param) = pl.params().last() { | ||
124 | is_varargs = param.dotdotdot_token().is_some(); | ||
125 | } | ||
126 | |||
122 | pl.params() | 127 | pl.params() |
123 | .map(|p| p.ascribed_type()) | 128 | .map(|p| p.ascribed_type()) |
124 | .map(|it| TypeRef::from_ast_opt(&ctx, it)) | 129 | .map(|it| TypeRef::from_ast_opt(&ctx, it)) |
@@ -127,7 +132,7 @@ impl TypeRef { | |||
127 | Vec::new() | 132 | Vec::new() |
128 | }; | 133 | }; |
129 | params.push(ret_ty); | 134 | params.push(ret_ty); |
130 | TypeRef::Fn(params) | 135 | TypeRef::Fn(params, is_varargs) |
131 | } | 136 | } |
132 | // for types are close enough for our purposes to the inner type for now... | 137 | // for types are close enough for our purposes to the inner type for now... |
133 | ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), | 138 | ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), |
@@ -158,7 +163,9 @@ impl TypeRef { | |||
158 | fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) { | 163 | fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) { |
159 | f(type_ref); | 164 | f(type_ref); |
160 | match type_ref { | 165 | match type_ref { |
161 | TypeRef::Fn(types) | TypeRef::Tuple(types) => types.iter().for_each(|t| go(t, f)), | 166 | TypeRef::Fn(types, _) | TypeRef::Tuple(types) => { |
167 | types.iter().for_each(|t| go(t, f)) | ||
168 | } | ||
162 | TypeRef::RawPtr(type_ref, _) | 169 | TypeRef::RawPtr(type_ref, _) |
163 | | TypeRef::Reference(type_ref, _) | 170 | | TypeRef::Reference(type_ref, _) |
164 | | TypeRef::Array(type_ref) | 171 | | TypeRef::Array(type_ref) |