diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 108 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 7 |
6 files changed, 57 insertions, 71 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 57d112f74..d87fe7049 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::Cancelable; | ||
4 | use ra_syntax::{ | 3 | use ra_syntax::{ |
5 | SyntaxNode, | 4 | SyntaxNode, |
6 | ast::{self, NameOwner, StructFlavor, AstNode} | 5 | ast::{self, NameOwner, StructFlavor, AstNode} |
@@ -18,8 +17,8 @@ impl Struct { | |||
18 | Struct { def_id } | 17 | Struct { def_id } |
19 | } | 18 | } |
20 | 19 | ||
21 | pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | 20 | pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> { |
22 | Ok(db.struct_data(self.def_id).variant_data.clone()) | 21 | db.struct_data(self.def_id).variant_data.clone() |
23 | } | 22 | } |
24 | } | 23 | } |
25 | 24 | ||
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 7ccd29e2f..d0c455d0a 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -160,7 +160,7 @@ impl StructField { | |||
160 | pub fn name(&self) -> &Name { | 160 | pub fn name(&self) -> &Name { |
161 | &self.name | 161 | &self.name |
162 | } | 162 | } |
163 | pub fn ty(&self, db: &impl HirDatabase) -> Cancelable<Option<Ty>> { | 163 | pub fn ty(&self, db: &impl HirDatabase) -> Option<Ty> { |
164 | db.type_for_field(self.struct_.def_id, self.name.clone()) | 164 | db.type_for_field(self.struct_.def_id, self.name.clone()) |
165 | } | 165 | } |
166 | } | 166 | } |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 161a5e714..4a2b0b3dc 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -57,12 +57,12 @@ pub trait HirDatabase: SyntaxDatabase | |||
57 | use fn crate::ty::infer; | 57 | use fn crate::ty::infer; |
58 | } | 58 | } |
59 | 59 | ||
60 | fn type_for_def(def_id: DefId) -> Cancelable<Ty> { | 60 | fn type_for_def(def_id: DefId) -> Ty { |
61 | type TypeForDefQuery; | 61 | type TypeForDefQuery; |
62 | use fn crate::ty::type_for_def; | 62 | use fn crate::ty::type_for_def; |
63 | } | 63 | } |
64 | 64 | ||
65 | fn type_for_field(def_id: DefId, field: Name) -> Cancelable<Option<Ty>> { | 65 | fn type_for_field(def_id: DefId, field: Name) -> Option<Ty> { |
66 | type TypeForFieldQuery; | 66 | type TypeForFieldQuery; |
67 | use fn crate::ty::type_for_field; | 67 | use fn crate::ty::type_for_field; |
68 | } | 68 | } |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index e5f8ffc2e..37fc8643a 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -271,28 +271,28 @@ impl Ty { | |||
271 | module: &Module, | 271 | module: &Module, |
272 | impl_block: Option<&ImplBlock>, | 272 | impl_block: Option<&ImplBlock>, |
273 | type_ref: &TypeRef, | 273 | type_ref: &TypeRef, |
274 | ) -> Cancelable<Self> { | 274 | ) -> Self { |
275 | Ok(match type_ref { | 275 | match type_ref { |
276 | TypeRef::Never => Ty::Never, | 276 | TypeRef::Never => Ty::Never, |
277 | TypeRef::Tuple(inner) => { | 277 | TypeRef::Tuple(inner) => { |
278 | let inner_tys = inner | 278 | let inner_tys = inner |
279 | .iter() | 279 | .iter() |
280 | .map(|tr| Ty::from_hir(db, module, impl_block, tr)) | 280 | .map(|tr| Ty::from_hir(db, module, impl_block, tr)) |
281 | .collect::<Cancelable<Vec<_>>>()?; | 281 | .collect::<Vec<_>>(); |
282 | Ty::Tuple(inner_tys.into()) | 282 | Ty::Tuple(inner_tys.into()) |
283 | } | 283 | } |
284 | TypeRef::Path(path) => Ty::from_hir_path(db, module, impl_block, path)?, | 284 | TypeRef::Path(path) => Ty::from_hir_path(db, module, impl_block, path), |
285 | TypeRef::RawPtr(inner, mutability) => { | 285 | TypeRef::RawPtr(inner, mutability) => { |
286 | let inner_ty = Ty::from_hir(db, module, impl_block, inner)?; | 286 | let inner_ty = Ty::from_hir(db, module, impl_block, inner); |
287 | Ty::RawPtr(Arc::new(inner_ty), *mutability) | 287 | Ty::RawPtr(Arc::new(inner_ty), *mutability) |
288 | } | 288 | } |
289 | TypeRef::Array(_inner) => Ty::Unknown, // TODO | 289 | TypeRef::Array(_inner) => Ty::Unknown, // TODO |
290 | TypeRef::Slice(inner) => { | 290 | TypeRef::Slice(inner) => { |
291 | let inner_ty = Ty::from_hir(db, module, impl_block, inner)?; | 291 | let inner_ty = Ty::from_hir(db, module, impl_block, inner); |
292 | Ty::Slice(Arc::new(inner_ty)) | 292 | Ty::Slice(Arc::new(inner_ty)) |
293 | } | 293 | } |
294 | TypeRef::Reference(inner, mutability) => { | 294 | TypeRef::Reference(inner, mutability) => { |
295 | let inner_ty = Ty::from_hir(db, module, impl_block, inner)?; | 295 | let inner_ty = Ty::from_hir(db, module, impl_block, inner); |
296 | Ty::Ref(Arc::new(inner_ty), *mutability) | 296 | Ty::Ref(Arc::new(inner_ty), *mutability) |
297 | } | 297 | } |
298 | TypeRef::Placeholder => Ty::Unknown, | 298 | TypeRef::Placeholder => Ty::Unknown, |
@@ -300,7 +300,7 @@ impl Ty { | |||
300 | let mut inner_tys = params | 300 | let mut inner_tys = params |
301 | .iter() | 301 | .iter() |
302 | .map(|tr| Ty::from_hir(db, module, impl_block, tr)) | 302 | .map(|tr| Ty::from_hir(db, module, impl_block, tr)) |
303 | .collect::<Cancelable<Vec<_>>>()?; | 303 | .collect::<Vec<_>>(); |
304 | let return_ty = inner_tys | 304 | let return_ty = inner_tys |
305 | .pop() | 305 | .pop() |
306 | .expect("TypeRef::Fn should always have at least return type"); | 306 | .expect("TypeRef::Fn should always have at least return type"); |
@@ -311,7 +311,7 @@ impl Ty { | |||
311 | Ty::FnPtr(Arc::new(sig)) | 311 | Ty::FnPtr(Arc::new(sig)) |
312 | } | 312 | } |
313 | TypeRef::Error => Ty::Unknown, | 313 | TypeRef::Error => Ty::Unknown, |
314 | }) | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | pub(crate) fn from_hir_opt( | 317 | pub(crate) fn from_hir_opt( |
@@ -319,10 +319,8 @@ impl Ty { | |||
319 | module: &Module, | 319 | module: &Module, |
320 | impl_block: Option<&ImplBlock>, | 320 | impl_block: Option<&ImplBlock>, |
321 | type_ref: Option<&TypeRef>, | 321 | type_ref: Option<&TypeRef>, |
322 | ) -> Cancelable<Self> { | 322 | ) -> Self { |
323 | type_ref | 323 | type_ref.map_or(Ty::Unknown, |t| Ty::from_hir(db, module, impl_block, t)) |
324 | .map(|t| Ty::from_hir(db, module, impl_block, t)) | ||
325 | .unwrap_or(Ok(Ty::Unknown)) | ||
326 | } | 324 | } |
327 | 325 | ||
328 | pub(crate) fn from_hir_path( | 326 | pub(crate) fn from_hir_path( |
@@ -330,19 +328,19 @@ impl Ty { | |||
330 | module: &Module, | 328 | module: &Module, |
331 | impl_block: Option<&ImplBlock>, | 329 | impl_block: Option<&ImplBlock>, |
332 | path: &Path, | 330 | path: &Path, |
333 | ) -> Cancelable<Self> { | 331 | ) -> Self { |
334 | if let Some(name) = path.as_ident() { | 332 | if let Some(name) = path.as_ident() { |
335 | if let Some(int_ty) = primitive::UncertainIntTy::from_name(name) { | 333 | if let Some(int_ty) = primitive::UncertainIntTy::from_name(name) { |
336 | return Ok(Ty::Int(int_ty)); | 334 | return Ty::Int(int_ty); |
337 | } else if let Some(float_ty) = primitive::UncertainFloatTy::from_name(name) { | 335 | } else if let Some(float_ty) = primitive::UncertainFloatTy::from_name(name) { |
338 | return Ok(Ty::Float(float_ty)); | 336 | return Ty::Float(float_ty); |
339 | } else if name.as_known_name() == Some(KnownName::SelfType) { | 337 | } else if name.as_known_name() == Some(KnownName::SelfType) { |
340 | return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); | 338 | return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type())); |
341 | } else if let Some(known) = name.as_known_name() { | 339 | } else if let Some(known) = name.as_known_name() { |
342 | match known { | 340 | match known { |
343 | KnownName::Bool => return Ok(Ty::Bool), | 341 | KnownName::Bool => return Ty::Bool, |
344 | KnownName::Char => return Ok(Ty::Char), | 342 | KnownName::Char => return Ty::Char, |
345 | KnownName::Str => return Ok(Ty::Str), | 343 | KnownName::Str => return Ty::Str, |
346 | _ => {} | 344 | _ => {} |
347 | } | 345 | } |
348 | } | 346 | } |
@@ -352,10 +350,9 @@ impl Ty { | |||
352 | let resolved = if let Some(r) = module.resolve_path(db, path).take_types() { | 350 | let resolved = if let Some(r) = module.resolve_path(db, path).take_types() { |
353 | r | 351 | r |
354 | } else { | 352 | } else { |
355 | return Ok(Ty::Unknown); | 353 | return Ty::Unknown; |
356 | }; | 354 | }; |
357 | let ty = db.type_for_def(resolved)?; | 355 | db.type_for_def(resolved) |
358 | Ok(ty) | ||
359 | } | 356 | } |
360 | 357 | ||
361 | pub fn unit() -> Self { | 358 | pub fn unit() -> Self { |
@@ -445,7 +442,7 @@ impl fmt::Display for Ty { | |||
445 | 442 | ||
446 | /// Compute the declared type of a function. This should not need to look at the | 443 | /// Compute the declared type of a function. This should not need to look at the |
447 | /// function body. | 444 | /// function body. |
448 | fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | 445 | fn type_for_fn(db: &impl HirDatabase, f: Function) -> Ty { |
449 | let signature = f.signature(db); | 446 | let signature = f.signature(db); |
450 | let module = f.module(db); | 447 | let module = f.module(db); |
451 | let impl_block = f.impl_block(db); | 448 | let impl_block = f.impl_block(db); |
@@ -454,38 +451,38 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | |||
454 | .params() | 451 | .params() |
455 | .iter() | 452 | .iter() |
456 | .map(|tr| Ty::from_hir(db, &module, impl_block.as_ref(), tr)) | 453 | .map(|tr| Ty::from_hir(db, &module, impl_block.as_ref(), tr)) |
457 | .collect::<Cancelable<Vec<_>>>()?; | 454 | .collect::<Vec<_>>(); |
458 | let output = Ty::from_hir(db, &module, impl_block.as_ref(), signature.ret_type())?; | 455 | let output = Ty::from_hir(db, &module, impl_block.as_ref(), signature.ret_type()); |
459 | let sig = FnSig { input, output }; | 456 | let sig = FnSig { input, output }; |
460 | Ok(Ty::FnPtr(Arc::new(sig))) | 457 | Ty::FnPtr(Arc::new(sig)) |
461 | } | 458 | } |
462 | 459 | ||
463 | fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { | 460 | fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty { |
464 | Ok(Ty::Adt { | 461 | Ty::Adt { |
465 | def_id: s.def_id(), | 462 | def_id: s.def_id(), |
466 | name: s.name(db).unwrap_or_else(Name::missing), | 463 | name: s.name(db).unwrap_or_else(Name::missing), |
467 | }) | 464 | } |
468 | } | 465 | } |
469 | 466 | ||
470 | pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> { | 467 | pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty { |
471 | Ok(Ty::Adt { | 468 | Ty::Adt { |
472 | def_id: s.def_id(), | 469 | def_id: s.def_id(), |
473 | name: s.name(db).unwrap_or_else(Name::missing), | 470 | name: s.name(db).unwrap_or_else(Name::missing), |
474 | }) | 471 | } |
475 | } | 472 | } |
476 | 473 | ||
477 | pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> { | 474 | pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Ty { |
478 | let enum_parent = ev.parent_enum(db); | 475 | let enum_parent = ev.parent_enum(db); |
479 | 476 | ||
480 | type_for_enum(db, enum_parent) | 477 | type_for_enum(db, enum_parent) |
481 | } | 478 | } |
482 | 479 | ||
483 | pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { | 480 | pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Ty { |
484 | let def = def_id.resolve(db); | 481 | let def = def_id.resolve(db); |
485 | match def { | 482 | match def { |
486 | Def::Module(..) => { | 483 | Def::Module(..) => { |
487 | log::debug!("trying to get type for module {:?}", def_id); | 484 | log::debug!("trying to get type for module {:?}", def_id); |
488 | Ok(Ty::Unknown) | 485 | Ty::Unknown |
489 | } | 486 | } |
490 | Def::Function(f) => type_for_fn(db, f), | 487 | Def::Function(f) => type_for_fn(db, f), |
491 | Def::Struct(s) => type_for_struct(db, s), | 488 | Def::Struct(s) => type_for_struct(db, s), |
@@ -497,19 +494,15 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<T | |||
497 | def_id, | 494 | def_id, |
498 | def | 495 | def |
499 | ); | 496 | ); |
500 | Ok(Ty::Unknown) | 497 | Ty::Unknown |
501 | } | 498 | } |
502 | } | 499 | } |
503 | } | 500 | } |
504 | 501 | ||
505 | pub(super) fn type_for_field( | 502 | pub(super) fn type_for_field(db: &impl HirDatabase, def_id: DefId, field: Name) -> Option<Ty> { |
506 | db: &impl HirDatabase, | ||
507 | def_id: DefId, | ||
508 | field: Name, | ||
509 | ) -> Cancelable<Option<Ty>> { | ||
510 | let def = def_id.resolve(db); | 503 | let def = def_id.resolve(db); |
511 | let variant_data = match def { | 504 | let variant_data = match def { |
512 | Def::Struct(s) => s.variant_data(db)?, | 505 | Def::Struct(s) => s.variant_data(db), |
513 | Def::EnumVariant(ev) => ev.variant_data(db), | 506 | Def::EnumVariant(ev) => ev.variant_data(db), |
514 | // TODO: unions | 507 | // TODO: unions |
515 | _ => panic!( | 508 | _ => panic!( |
@@ -519,13 +512,8 @@ pub(super) fn type_for_field( | |||
519 | }; | 512 | }; |
520 | let module = def_id.module(db); | 513 | let module = def_id.module(db); |
521 | let impl_block = def_id.impl_block(db); | 514 | let impl_block = def_id.impl_block(db); |
522 | let type_ref = ctry!(variant_data.get_field_type_ref(&field)); | 515 | let type_ref = variant_data.get_field_type_ref(&field)?; |
523 | Ok(Some(Ty::from_hir( | 516 | Some(Ty::from_hir(db, &module, impl_block.as_ref(), &type_ref)) |
524 | db, | ||
525 | &module, | ||
526 | impl_block.as_ref(), | ||
527 | &type_ref, | ||
528 | )?)) | ||
529 | } | 517 | } |
530 | 518 | ||
531 | /// The result of type inference: A mapping from expressions and patterns to types. | 519 | /// The result of type inference: A mapping from expressions and patterns to types. |
@@ -702,7 +690,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
702 | self.type_of_pat.insert(pat, ty); | 690 | self.type_of_pat.insert(pat, ty); |
703 | } | 691 | } |
704 | 692 | ||
705 | fn make_ty(&self, type_ref: &TypeRef) -> Cancelable<Ty> { | 693 | fn make_ty(&self, type_ref: &TypeRef) -> Ty { |
706 | Ty::from_hir(self.db, &self.module, self.impl_block.as_ref(), type_ref) | 694 | Ty::from_hir(self.db, &self.module, self.impl_block.as_ref(), type_ref) |
707 | } | 695 | } |
708 | 696 | ||
@@ -861,7 +849,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
861 | 849 | ||
862 | // resolve in module | 850 | // resolve in module |
863 | let resolved = ctry!(self.module.resolve_path(self.db, &path).take_values()); | 851 | let resolved = ctry!(self.module.resolve_path(self.db, &path).take_values()); |
864 | let ty = self.db.type_for_def(resolved)?; | 852 | let ty = self.db.type_for_def(resolved); |
865 | let ty = self.insert_type_vars(ty); | 853 | let ty = self.insert_type_vars(ty); |
866 | Ok(Some(ty)) | 854 | Ok(Some(ty)) |
867 | } | 855 | } |
@@ -879,11 +867,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
879 | }; | 867 | }; |
880 | Ok(match def_id.resolve(self.db) { | 868 | Ok(match def_id.resolve(self.db) { |
881 | Def::Struct(s) => { | 869 | Def::Struct(s) => { |
882 | let ty = type_for_struct(self.db, s)?; | 870 | let ty = type_for_struct(self.db, s); |
883 | (ty, Some(def_id)) | 871 | (ty, Some(def_id)) |
884 | } | 872 | } |
885 | Def::EnumVariant(ev) => { | 873 | Def::EnumVariant(ev) => { |
886 | let ty = type_for_enum_variant(self.db, ev)?; | 874 | let ty = type_for_enum_variant(self.db, ev); |
887 | (ty, Some(def_id)) | 875 | (ty, Some(def_id)) |
888 | } | 876 | } |
889 | _ => (Ty::Unknown, None), | 877 | _ => (Ty::Unknown, None), |
@@ -964,7 +952,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
964 | let method_ty = match resolved { | 952 | let method_ty = match resolved { |
965 | Some(def_id) => { | 953 | Some(def_id) => { |
966 | self.write_method_resolution(expr, def_id); | 954 | self.write_method_resolution(expr, def_id); |
967 | self.db.type_for_def(def_id)? | 955 | self.db.type_for_def(def_id) |
968 | } | 956 | } |
969 | None => Ty::Unknown, | 957 | None => Ty::Unknown, |
970 | }; | 958 | }; |
@@ -1024,7 +1012,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1024 | for field in fields { | 1012 | for field in fields { |
1025 | let field_ty = if let Some(def_id) = def_id { | 1013 | let field_ty = if let Some(def_id) = def_id { |
1026 | self.db | 1014 | self.db |
1027 | .type_for_field(def_id, field.name.clone())? | 1015 | .type_for_field(def_id, field.name.clone()) |
1028 | .unwrap_or(Ty::Unknown) | 1016 | .unwrap_or(Ty::Unknown) |
1029 | } else { | 1017 | } else { |
1030 | Ty::Unknown | 1018 | Ty::Unknown |
@@ -1047,7 +1035,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1047 | i.and_then(|i| fields.get(i).cloned()).map(Ok) | 1035 | i.and_then(|i| fields.get(i).cloned()).map(Ok) |
1048 | } | 1036 | } |
1049 | Ty::Adt { def_id, .. } => { | 1037 | Ty::Adt { def_id, .. } => { |
1050 | transpose(self.db.type_for_field(def_id, name.clone())) | 1038 | transpose(Ok(self.db.type_for_field(def_id, name.clone()))) |
1051 | } | 1039 | } |
1052 | _ => None, | 1040 | _ => None, |
1053 | }) | 1041 | }) |
@@ -1061,7 +1049,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1061 | Expr::Cast { expr, type_ref } => { | 1049 | Expr::Cast { expr, type_ref } => { |
1062 | let _inner_ty = self.infer_expr(*expr, &Expectation::none())?; | 1050 | let _inner_ty = self.infer_expr(*expr, &Expectation::none())?; |
1063 | let cast_ty = | 1051 | let cast_ty = |
1064 | Ty::from_hir(self.db, &self.module, self.impl_block.as_ref(), type_ref)?; | 1052 | Ty::from_hir(self.db, &self.module, self.impl_block.as_ref(), type_ref); |
1065 | let cast_ty = self.insert_type_vars(cast_ty); | 1053 | let cast_ty = self.insert_type_vars(cast_ty); |
1066 | // TODO check the cast... | 1054 | // TODO check the cast... |
1067 | cast_ty | 1055 | cast_ty |
@@ -1154,7 +1142,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1154 | &self.module, | 1142 | &self.module, |
1155 | self.impl_block.as_ref(), | 1143 | self.impl_block.as_ref(), |
1156 | type_ref.as_ref(), | 1144 | type_ref.as_ref(), |
1157 | )?; | 1145 | ); |
1158 | let decl_ty = self.insert_type_vars(decl_ty); | 1146 | let decl_ty = self.insert_type_vars(decl_ty); |
1159 | let ty = if let Some(expr) = initializer { | 1147 | let ty = if let Some(expr) = initializer { |
1160 | let expr_ty = self.infer_expr(*expr, &Expectation::has_type(decl_ty))?; | 1148 | let expr_ty = self.infer_expr(*expr, &Expectation::has_type(decl_ty))?; |
@@ -1181,12 +1169,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1181 | fn collect_fn_signature(&mut self, signature: &FnSignature) -> Cancelable<()> { | 1169 | fn collect_fn_signature(&mut self, signature: &FnSignature) -> Cancelable<()> { |
1182 | let body = Arc::clone(&self.body); // avoid borrow checker problem | 1170 | let body = Arc::clone(&self.body); // avoid borrow checker problem |
1183 | for (type_ref, pat) in signature.params().iter().zip(body.params()) { | 1171 | for (type_ref, pat) in signature.params().iter().zip(body.params()) { |
1184 | let ty = self.make_ty(type_ref)?; | 1172 | let ty = self.make_ty(type_ref); |
1185 | let ty = self.insert_type_vars(ty); | 1173 | let ty = self.insert_type_vars(ty); |
1186 | self.write_pat_ty(*pat, ty); | 1174 | self.write_pat_ty(*pat, ty); |
1187 | } | 1175 | } |
1188 | self.return_ty = { | 1176 | self.return_ty = { |
1189 | let ty = self.make_ty(signature.ret_type())?; | 1177 | let ty = self.make_ty(signature.ret_type()); |
1190 | let ty = self.insert_type_vars(ty); | 1178 | let ty = self.insert_type_vars(ty); |
1191 | ty | 1179 | ty |
1192 | }; | 1180 | }; |
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 94c5124a9..0676a989d 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -65,7 +65,7 @@ impl CrateImplBlocks { | |||
65 | // ignore for now | 65 | // ignore for now |
66 | } else { | 66 | } else { |
67 | let target_ty = | 67 | let target_ty = |
68 | Ty::from_hir(db, &module, Some(&impl_block), impl_data.target_type())?; | 68 | Ty::from_hir(db, &module, Some(&impl_block), impl_data.target_type()); |
69 | if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { | 69 | if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { |
70 | self.impls | 70 | self.impls |
71 | .entry(target_ty_fp) | 71 | .entry(target_ty_fp) |
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index cb86ba9a3..30a0a3924 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -17,13 +17,13 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca | |||
17 | }; | 17 | }; |
18 | let receiver_ty = infer_result[expr].clone(); | 18 | let receiver_ty = infer_result[expr].clone(); |
19 | if !ctx.is_call { | 19 | if !ctx.is_call { |
20 | complete_fields(acc, ctx, receiver_ty.clone())?; | 20 | complete_fields(acc, ctx, receiver_ty.clone()); |
21 | } | 21 | } |
22 | complete_methods(acc, ctx, receiver_ty)?; | 22 | complete_methods(acc, ctx, receiver_ty)?; |
23 | Ok(()) | 23 | Ok(()) |
24 | } | 24 | } |
25 | 25 | ||
26 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { | 26 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
27 | for receiver in receiver.autoderef(ctx.db) { | 27 | for receiver in receiver.autoderef(ctx.db) { |
28 | match receiver { | 28 | match receiver { |
29 | Ty::Adt { def_id, .. } => { | 29 | Ty::Adt { def_id, .. } => { |
@@ -35,7 +35,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
35 | field.name().to_string(), | 35 | field.name().to_string(), |
36 | ) | 36 | ) |
37 | .kind(CompletionItemKind::Field) | 37 | .kind(CompletionItemKind::Field) |
38 | .set_detail(field.ty(ctx.db)?.map(|ty| ty.to_string())) | 38 | .set_detail(field.ty(ctx.db).map(|ty| ty.to_string())) |
39 | .add_to(acc); | 39 | .add_to(acc); |
40 | } | 40 | } |
41 | } | 41 | } |
@@ -53,7 +53,6 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
53 | _ => {} | 53 | _ => {} |
54 | }; | 54 | }; |
55 | } | 55 | } |
56 | Ok(()) | ||
57 | } | 56 | } |
58 | 57 | ||
59 | fn complete_methods( | 58 | fn complete_methods( |