aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/type_ref.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_hir_def/src/type_ref.rs
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_hir_def/src/type_ref.rs')
-rw-r--r--crates/ra_hir_def/src/type_ref.rs48
1 files changed, 22 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index e90b2a0b9..6f7884ffe 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -1,7 +1,6 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3 3use ra_syntax::ast::{self};
4use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner};
5 4
6use crate::{body::LowerCtx, path::Path}; 5use crate::{body::LowerCtx, path::Path};
7 6
@@ -80,14 +79,14 @@ pub enum TypeBound {
80 79
81impl TypeRef { 80impl TypeRef {
82 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 81 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
83 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::TypeRef) -> Self { 82 pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
84 match node { 83 match node {
85 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 84 ast::Type::ParenType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
86 ast::TypeRef::TupleType(inner) => { 85 ast::Type::TupleType(inner) => {
87 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect()) 86 TypeRef::Tuple(inner.fields().map(|it| TypeRef::from_ast(ctx, it)).collect())
88 } 87 }
89 ast::TypeRef::NeverType(..) => TypeRef::Never, 88 ast::Type::NeverType(..) => TypeRef::Never,
90 ast::TypeRef::PathType(inner) => { 89 ast::Type::PathType(inner) => {
91 // FIXME: Use `Path::from_src` 90 // FIXME: Use `Path::from_src`
92 inner 91 inner
93 .path() 92 .path()
@@ -95,27 +94,27 @@ impl TypeRef {
95 .map(TypeRef::Path) 94 .map(TypeRef::Path)
96 .unwrap_or(TypeRef::Error) 95 .unwrap_or(TypeRef::Error)
97 } 96 }
98 ast::TypeRef::PointerType(inner) => { 97 ast::Type::PtrType(inner) => {
99 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 98 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
100 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 99 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
101 TypeRef::RawPtr(Box::new(inner_ty), mutability) 100 TypeRef::RawPtr(Box::new(inner_ty), mutability)
102 } 101 }
103 ast::TypeRef::ArrayType(inner) => { 102 ast::Type::ArrayType(inner) => {
104 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 103 TypeRef::Array(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
105 } 104 }
106 ast::TypeRef::SliceType(inner) => { 105 ast::Type::SliceType(inner) => {
107 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.type_ref()))) 106 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(&ctx, inner.ty())))
108 } 107 }
109 ast::TypeRef::ReferenceType(inner) => { 108 ast::Type::RefType(inner) => {
110 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.type_ref()); 109 let inner_ty = TypeRef::from_ast_opt(&ctx, inner.ty());
111 let mutability = Mutability::from_mutable(inner.mut_token().is_some()); 110 let mutability = Mutability::from_mutable(inner.mut_token().is_some());
112 TypeRef::Reference(Box::new(inner_ty), mutability) 111 TypeRef::Reference(Box::new(inner_ty), mutability)
113 } 112 }
114 ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, 113 ast::Type::InferType(_inner) => TypeRef::Placeholder,
115 ast::TypeRef::FnPointerType(inner) => { 114 ast::Type::FnPtrType(inner) => {
116 let ret_ty = inner 115 let ret_ty = inner
117 .ret_type() 116 .ret_type()
118 .and_then(|rt| rt.type_ref()) 117 .and_then(|rt| rt.ty())
119 .map(|it| TypeRef::from_ast(ctx, it)) 118 .map(|it| TypeRef::from_ast(ctx, it))
120 .unwrap_or_else(|| TypeRef::Tuple(Vec::new())); 119 .unwrap_or_else(|| TypeRef::Tuple(Vec::new()));
121 let mut is_varargs = false; 120 let mut is_varargs = false;
@@ -124,10 +123,7 @@ impl TypeRef {
124 is_varargs = param.dotdotdot_token().is_some(); 123 is_varargs = param.dotdotdot_token().is_some();
125 } 124 }
126 125
127 pl.params() 126 pl.params().map(|p| p.ty()).map(|it| TypeRef::from_ast_opt(&ctx, it)).collect()
128 .map(|p| p.ascribed_type())
129 .map(|it| TypeRef::from_ast_opt(&ctx, it))
130 .collect()
131 } else { 127 } else {
132 Vec::new() 128 Vec::new()
133 }; 129 };
@@ -135,17 +131,17 @@ impl TypeRef {
135 TypeRef::Fn(params, is_varargs) 131 TypeRef::Fn(params, is_varargs)
136 } 132 }
137 // for types are close enough for our purposes to the inner type for now... 133 // for types are close enough for our purposes to the inner type for now...
138 ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.type_ref()), 134 ast::Type::ForType(inner) => TypeRef::from_ast_opt(&ctx, inner.ty()),
139 ast::TypeRef::ImplTraitType(inner) => { 135 ast::Type::ImplTraitType(inner) => {
140 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) 136 TypeRef::ImplTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
141 } 137 }
142 ast::TypeRef::DynTraitType(inner) => { 138 ast::Type::DynTraitType(inner) => {
143 TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list())) 139 TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
144 } 140 }
145 } 141 }
146 } 142 }
147 143
148 pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::TypeRef>) -> Self { 144 pub(crate) fn from_ast_opt(ctx: &LowerCtx, node: Option<ast::Type>) -> Self {
149 if let Some(node) = node { 145 if let Some(node) = node {
150 TypeRef::from_ast(ctx, node) 146 TypeRef::from_ast(ctx, node)
151 } else { 147 } else {