diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-12 19:35:06 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-12 19:35:06 +0100 |
commit | d8b621cf26b59ff5ae9379b50fc822590b6a3a4e (patch) | |
tree | 381f2d4a92db5cdfd35c9e76d5c6b11bcb247c41 /crates/ra_hir/src/ty | |
parent | 5c09c5949a94012b5ae95735dc8c086efd5039e4 (diff) | |
parent | 63e1e63a9160d28597a8d77fd83c43a2c90d3f6b (diff) |
Merge #1832
1832: start cleaning up the resolution r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 46 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 2 |
2 files changed, 12 insertions, 36 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 1057bbbec..3970c49e3 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -34,7 +34,7 @@ use super::{ | |||
34 | }; | 34 | }; |
35 | use crate::{ | 35 | use crate::{ |
36 | adt::VariantDef, | 36 | adt::VariantDef, |
37 | code_model::{ModuleDef::Trait, TypeAlias}, | 37 | code_model::TypeAlias, |
38 | db::HirDatabase, | 38 | db::HirDatabase, |
39 | diagnostics::DiagnosticSink, | 39 | diagnostics::DiagnosticSink, |
40 | expr::{ | 40 | expr::{ |
@@ -43,12 +43,9 @@ use crate::{ | |||
43 | }, | 43 | }, |
44 | generics::{GenericParams, HasGenericParams}, | 44 | generics::{GenericParams, HasGenericParams}, |
45 | name, | 45 | name, |
46 | nameres::{Namespace, PerNs}, | 46 | nameres::Namespace, |
47 | path::{GenericArg, GenericArgs, PathKind, PathSegment}, | 47 | path::{GenericArg, GenericArgs, PathKind, PathSegment}, |
48 | resolve::{ | 48 | resolve::{Resolution, Resolver}, |
49 | Resolution::{self, Def}, | ||
50 | Resolver, | ||
51 | }, | ||
52 | ty::infer::diagnostics::InferenceDiagnostic, | 49 | ty::infer::diagnostics::InferenceDiagnostic, |
53 | type_ref::{Mutability, TypeRef}, | 50 | type_ref::{Mutability, TypeRef}, |
54 | AdtDef, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path, | 51 | AdtDef, ConstData, DefWithBody, FnData, Function, HasBody, ImplItem, ModuleDef, Name, Path, |
@@ -1460,12 +1457,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1460 | ], | 1457 | ], |
1461 | }; | 1458 | }; |
1462 | 1459 | ||
1463 | match self.resolver.resolve_path_segments(self.db, &into_iter_path).into_fully_resolved() { | 1460 | let trait_ = self.resolver.resolve_known_trait(self.db, &into_iter_path)?; |
1464 | PerNs { types: Some(Def(Trait(trait_))), .. } => { | 1461 | trait_.associated_type_by_name(self.db, &name::ITEM) |
1465 | Some(trait_.associated_type_by_name(self.db, &name::ITEM)?) | ||
1466 | } | ||
1467 | _ => None, | ||
1468 | } | ||
1469 | } | 1462 | } |
1470 | 1463 | ||
1471 | fn resolve_ops_try_ok(&self) -> Option<TypeAlias> { | 1464 | fn resolve_ops_try_ok(&self) -> Option<TypeAlias> { |
@@ -1478,12 +1471,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1478 | ], | 1471 | ], |
1479 | }; | 1472 | }; |
1480 | 1473 | ||
1481 | match self.resolver.resolve_path_segments(self.db, &ops_try_path).into_fully_resolved() { | 1474 | let trait_ = self.resolver.resolve_known_trait(self.db, &ops_try_path)?; |
1482 | PerNs { types: Some(Def(Trait(trait_))), .. } => { | 1475 | trait_.associated_type_by_name(self.db, &name::OK) |
1483 | Some(trait_.associated_type_by_name(self.db, &name::OK)?) | ||
1484 | } | ||
1485 | _ => None, | ||
1486 | } | ||
1487 | } | 1476 | } |
1488 | 1477 | ||
1489 | fn resolve_future_future_output(&self) -> Option<TypeAlias> { | 1478 | fn resolve_future_future_output(&self) -> Option<TypeAlias> { |
@@ -1496,16 +1485,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1496 | ], | 1485 | ], |
1497 | }; | 1486 | }; |
1498 | 1487 | ||
1499 | match self | 1488 | let trait_ = self.resolver.resolve_known_trait(self.db, &future_future_path)?; |
1500 | .resolver | 1489 | trait_.associated_type_by_name(self.db, &name::OUTPUT) |
1501 | .resolve_path_segments(self.db, &future_future_path) | ||
1502 | .into_fully_resolved() | ||
1503 | { | ||
1504 | PerNs { types: Some(Def(Trait(trait_))), .. } => { | ||
1505 | Some(trait_.associated_type_by_name(self.db, &name::OUTPUT)?) | ||
1506 | } | ||
1507 | _ => None, | ||
1508 | } | ||
1509 | } | 1490 | } |
1510 | 1491 | ||
1511 | fn resolve_boxed_box(&self) -> Option<AdtDef> { | 1492 | fn resolve_boxed_box(&self) -> Option<AdtDef> { |
@@ -1517,13 +1498,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1517 | PathSegment { name: name::BOX_TYPE, args_and_bindings: None }, | 1498 | PathSegment { name: name::BOX_TYPE, args_and_bindings: None }, |
1518 | ], | 1499 | ], |
1519 | }; | 1500 | }; |
1520 | 1501 | let struct_ = self.resolver.resolve_known_struct(self.db, &boxed_box_path)?; | |
1521 | match self.resolver.resolve_path_segments(self.db, &boxed_box_path).into_fully_resolved() { | 1502 | Some(AdtDef::Struct(struct_)) |
1522 | PerNs { types: Some(Def(ModuleDef::Struct(struct_))), .. } => { | ||
1523 | Some(AdtDef::Struct(struct_)) | ||
1524 | } | ||
1525 | _ => None, | ||
1526 | } | ||
1527 | } | 1503 | } |
1528 | } | 1504 | } |
1529 | 1505 | ||
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 061229842..e67525a74 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -86,7 +86,7 @@ impl Ty { | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self { | 89 | pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Ty { |
90 | // Resolve the path (in type namespace) | 90 | // Resolve the path (in type namespace) |
91 | let (resolution, remaining_index) = resolver.resolve_path_segments(db, path).into_inner(); | 91 | let (resolution, remaining_index) = resolver.resolve_path_segments(db, path).into_inner(); |
92 | let resolution = resolution.take_types(); | 92 | let resolution = resolution.take_types(); |