aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-30 20:02:55 +0100
committerAleksey Kladov <[email protected]>2020-07-30 20:02:55 +0100
commitf95f425ae4199e814e6956be1d9bb59a14758c07 (patch)
treedd3503a2be3a6699a6b111844dbcdc85b37e2425 /crates/ra_hir_def/src
parent2e2642efccd5855e4158b01a006e7884a96982bb (diff)
Use ty to access most TypeRefs
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/adt.rs2
-rw-r--r--crates/ra_hir_def/src/body/lower.rs8
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs6
-rw-r--r--crates/ra_hir_def/src/path/lower.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs14
5 files changed, 15 insertions, 17 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index f8523d03f..6cb56a1cd 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -234,7 +234,7 @@ fn lower_struct(
234 || Either::Left(fd.clone()), 234 || Either::Left(fd.clone()),
235 || FieldData { 235 || FieldData {
236 name: Name::new_tuple_field(i), 236 name: Name::new_tuple_field(i),
237 type_ref: TypeRef::from_ast_opt(&ctx, fd.type_ref()), 237 type_ref: TypeRef::from_ast_opt(&ctx, fd.ty()),
238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 238 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
239 }, 239 },
240 ); 240 );
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 288ca76c3..827ced4ad 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -432,7 +432,7 @@ impl ExprCollector<'_> {
432 } 432 }
433 ast::Expr::CastExpr(e) => { 433 ast::Expr::CastExpr(e) => {
434 let expr = self.collect_expr_opt(e.expr()); 434 let expr = self.collect_expr_opt(e.expr());
435 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.type_ref()); 435 let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr) 436 self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
437 } 437 }
438 ast::Expr::RefExpr(e) => { 438 ast::Expr::RefExpr(e) => {
@@ -471,10 +471,8 @@ impl ExprCollector<'_> {
471 arg_types.push(type_ref); 471 arg_types.push(type_ref);
472 } 472 }
473 } 473 }
474 let ret_type = e 474 let ret_type =
475 .ret_type() 475 e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&self.ctx(), it));
476 .and_then(|r| r.type_ref())
477 .map(|it| TypeRef::from_ast(&self.ctx(), it));
478 let body = self.collect_expr_opt(e.body()); 476 let body = self.collect_expr_opt(e.body());
479 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr) 477 self.alloc_expr(Expr::Lambda { args, arg_types, ret_type, body }, syntax_ptr)
480 } 478 }
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs
index f0ced1f79..feb31579e 100644
--- a/crates/ra_hir_def/src/item_tree/lower.rs
+++ b/crates/ra_hir_def/src/item_tree/lower.rs
@@ -228,7 +228,7 @@ impl Ctx {
228 fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleField) -> Field { 228 fn lower_tuple_field(&mut self, idx: usize, field: &ast::TupleField) -> Field {
229 let name = Name::new_tuple_field(idx); 229 let name = Name::new_tuple_field(idx);
230 let visibility = self.lower_visibility(field); 230 let visibility = self.lower_visibility(field);
231 let type_ref = self.lower_type_ref_opt(field.type_ref()); 231 let type_ref = self.lower_type_ref_opt(field.ty());
232 let res = Field { name, type_ref, visibility }; 232 let res = Field { name, type_ref, visibility };
233 res 233 res
234 } 234 }
@@ -317,7 +317,7 @@ impl Ctx {
317 } 317 }
318 } 318 }
319 319
320 let ret_type = match func.ret_type().and_then(|rt| rt.type_ref()) { 320 let ret_type = match func.ret_type().and_then(|rt| rt.ty()) {
321 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref), 321 Some(type_ref) => TypeRef::from_ast(&self.body_ctx, type_ref),
322 _ => TypeRef::unit(), 322 _ => TypeRef::unit(),
323 }; 323 };
@@ -352,7 +352,7 @@ impl Ctx {
352 type_alias: &ast::TypeAlias, 352 type_alias: &ast::TypeAlias,
353 ) -> Option<FileItemTreeId<TypeAlias>> { 353 ) -> Option<FileItemTreeId<TypeAlias>> {
354 let name = type_alias.name()?.as_name(); 354 let name = type_alias.name()?.as_name();
355 let type_ref = type_alias.type_ref().map(|it| self.lower_type_ref(&it)); 355 let type_ref = type_alias.ty().map(|it| self.lower_type_ref(&it));
356 let visibility = self.lower_visibility(type_alias); 356 let visibility = self.lower_visibility(type_alias);
357 let bounds = self.lower_type_bounds(type_alias); 357 let bounds = self.lower_type_bounds(type_alias);
358 let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias); 358 let generic_params = self.lower_generic_params(GenericsOwner::TypeAlias, type_alias);
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index dfab15948..07d17916a 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -196,7 +196,7 @@ fn lower_generic_args_from_fn_path(
196 args.push(arg); 196 args.push(arg);
197 } 197 }
198 if let Some(ret_type) = ret_type { 198 if let Some(ret_type) = ret_type {
199 let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.type_ref()); 199 let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty());
200 bindings.push(AssociatedTypeBinding { 200 bindings.push(AssociatedTypeBinding {
201 name: name![Output], 201 name: name![Output],
202 type_ref: Some(type_ref), 202 type_ref: Some(type_ref),
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 4059302df..a5dc10eac 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -82,7 +82,7 @@ impl TypeRef {
82 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 82 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
83 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { 83 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self {
84 match node { 84 match node {
85 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 85 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
86 ast::TypeRef::TupleType(inner) => { 86 ast::TypeRef::TupleType(inner) => {
87 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) 87 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect())
88 } 88 }
@@ -96,18 +96,18 @@ impl TypeRef {
96 .unwrap_or(TypeRef::Error) 96 .unwrap_or(TypeRef::Error)
97 } 97 }
98 ast::TypeRef::PointerType(inner) => { 98 ast::TypeRef::PointerType(inner) => {
99 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 99 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
100 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 100 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
101 TypeRef::RawPtr(Box::new(inner_ty), mutability) 101 TypeRef::RawPtr(Box::new(inner_ty), mutability)
102 } 102 }
103 ast::TypeRef::ArrayType(inner) => { 103 ast::TypeRef::ArrayType(inner) => {
104 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 104 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
105 } 105 }
106 ast::TypeRef::SliceType(inner) => { 106 ast::TypeRef::SliceType(inner) => {
107 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 107 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
108 } 108 }
109 ast::TypeRef::ReferenceType(inner) => { 109 ast::TypeRef::ReferenceType(inner) => {
110 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 110 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
111 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 111 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
112 TypeRef::Reference(Box::new(inner_ty), mutability) 112 TypeRef::Reference(Box::new(inner_ty), mutability)
113 } 113 }
@@ -115,7 +115,7 @@ impl TypeRef {
115 ast::TypeRef::FnPointerType(inner) => { 115 ast::TypeRef::FnPointerType(inner) => {
116 let ret_ty = inner 116 let ret_ty = inner
117 .ret_type() 117 .ret_type()
118 .and_then(|rt| rt.type_ref()) 118 .and_then(|rt| rt.ty())
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 is_varargs = false;
@@ -132,7 +132,7 @@ impl TypeRef {
132 TypeRef::Fn(params, is_varargs) 132 TypeRef::Fn(params, is_varargs)
133 } 133 }
134 // for types are close enough for our purposes to the inner type for now... 134 // for types are close enough for our purposes to the inner type for now...
135 ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 135 ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
136 ast::TypeRef::ImplTraitType(inner) => { 136 ast::TypeRef::ImplTraitType(inner) => {
137 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) 137 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
138 } 138 }