diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 85d4dc05c..676ed3ac9 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -227,6 +227,9 @@ pub enum Ty { | |||
227 | /// A tuple type. For example, `(i32, bool)`. | 227 | /// A tuple type. For example, `(i32, bool)`. |
228 | Tuple(Arc<[Ty]>), | 228 | Tuple(Arc<[Ty]>), |
229 | 229 | ||
230 | /// A array type. For example, `[i32]`. | ||
231 | Array(Arc<[Ty]>), | ||
232 | |||
230 | // The projection of an associated type. For example, | 233 | // The projection of an associated type. For example, |
231 | // `<T as Trait<..>>::N`.pub | 234 | // `<T as Trait<..>>::N`.pub |
232 | // Projection(ProjectionTy), | 235 | // Projection(ProjectionTy), |
@@ -414,6 +417,16 @@ impl fmt::Display for Ty { | |||
414 | .to_fmt(f) | 417 | .to_fmt(f) |
415 | } | 418 | } |
416 | } | 419 | } |
420 | Ty::Array(ts) => { | ||
421 | if ts.len() == 1 { | ||
422 | write!(f, "[{},]", ts[0]) | ||
423 | } else { | ||
424 | join(ts.iter()) | ||
425 | .surround_with("[", "]") | ||
426 | .separator(", ") | ||
427 | .to_fmt(f) | ||
428 | } | ||
429 | } | ||
417 | Ty::FnPtr(sig) => { | 430 | Ty::FnPtr(sig) => { |
418 | join(sig.input.iter()) | 431 | join(sig.input.iter()) |
419 | .surround_with("fn(", ")") | 432 | .surround_with("fn(", ")") |
@@ -1101,7 +1114,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1101 | } | 1114 | } |
1102 | 1115 | ||
1103 | Ty::Tuple(Arc::from(ty_vec)) | 1116 | Ty::Tuple(Arc::from(ty_vec)) |
1104 | } | 1117 | }, |
1118 | Expr::Array { exprs } => { | ||
1119 | let mut ty_vec = Vec::with_capacity(exprs.len()); | ||
1120 | for arg in exprs.iter() { | ||
1121 | ty_vec.push(self.infer_expr(*arg, &Expectation::none())); | ||
1122 | } | ||
1123 | |||
1124 | Ty::Array(Arc::from(ty_vec)) | ||
1125 | }, | ||
1105 | Expr::Literal(lit) => match lit { | 1126 | Expr::Literal(lit) => match lit { |
1106 | Literal::Bool(..) => Ty::Bool, | 1127 | Literal::Bool(..) => Ty::Bool, |
1107 | Literal::String(..) => Ty::Ref(Arc::new(Ty::Str), Mutability::Shared), | 1128 | Literal::String(..) => Ty::Ref(Arc::new(Ty::Str), Mutability::Shared), |