aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/type_ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/type_ref.rs')
-rw-r--r--crates/ra_hir/src/type_ref.rs35
1 files changed, 20 insertions, 15 deletions
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs
index 8536ae44a..b92a0b55a 100644
--- a/crates/ra_hir/src/type_ref.rs
+++ b/crates/ra_hir/src/type_ref.rs
@@ -57,28 +57,33 @@ pub enum TypeRef {
57impl TypeRef { 57impl TypeRef {
58 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 58 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
59 pub(crate) fn from_ast(node: ast::TypeRef) -> Self { 59 pub(crate) fn from_ast(node: ast::TypeRef) -> Self {
60 use ra_syntax::ast::TypeRefKind::*; 60 match node {
61 match node.kind() { 61 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
62 ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), 62 ast::TypeRef::TupleType(inner) => {
63 TupleType(inner) => TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()), 63 TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect())
64 NeverType(..) => TypeRef::Never, 64 }
65 PathType(inner) => { 65 ast::TypeRef::NeverType(..) => TypeRef::Never,
66 ast::TypeRef::PathType(inner) => {
66 inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) 67 inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error)
67 } 68 }
68 PointerType(inner) => { 69 ast::TypeRef::PointerType(inner) => {
69 let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); 70 let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
70 let mutability = Mutability::from_mutable(inner.is_mut()); 71 let mutability = Mutability::from_mutable(inner.is_mut());
71 TypeRef::RawPtr(Box::new(inner_ty), mutability) 72 TypeRef::RawPtr(Box::new(inner_ty), mutability)
72 } 73 }
73 ArrayType(inner) => TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))), 74 ast::TypeRef::ArrayType(inner) => {
74 SliceType(inner) => TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))), 75 TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref())))
75 ReferenceType(inner) => { 76 }
77 ast::TypeRef::SliceType(inner) => {
78 TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref())))
79 }
80 ast::TypeRef::ReferenceType(inner) => {
76 let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); 81 let inner_ty = TypeRef::from_ast_opt(inner.type_ref());
77 let mutability = Mutability::from_mutable(inner.is_mut()); 82 let mutability = Mutability::from_mutable(inner.is_mut());
78 TypeRef::Reference(Box::new(inner_ty), mutability) 83 TypeRef::Reference(Box::new(inner_ty), mutability)
79 } 84 }
80 PlaceholderType(_inner) => TypeRef::Placeholder, 85 ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder,
81 FnPointerType(inner) => { 86 ast::TypeRef::FnPointerType(inner) => {
82 let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref())); 87 let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref()));
83 let mut params = if let Some(pl) = inner.param_list() { 88 let mut params = if let Some(pl) = inner.param_list() {
84 pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect() 89 pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect()
@@ -89,9 +94,9 @@ impl TypeRef {
89 TypeRef::Fn(params) 94 TypeRef::Fn(params)
90 } 95 }
91 // for types are close enough for our purposes to the inner type for now... 96 // for types are close enough for our purposes to the inner type for now...
92 ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()), 97 ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
93 ImplTraitType(_inner) => TypeRef::Error, 98 ast::TypeRef::ImplTraitType(_inner) => TypeRef::Error,
94 DynTraitType(_inner) => TypeRef::Error, 99 ast::TypeRef::DynTraitType(_inner) => TypeRef::Error,
95 } 100 }
96 } 101 }
97 102