diff options
author | Florian Diebold <[email protected]> | 2019-11-15 20:00:27 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-11-16 12:11:29 +0000 |
commit | 9c2a9a9a0635e53466749fdedcdc5a371e658cde (patch) | |
tree | 904a60eca279975874c6c890109eb3c852347da0 /crates/ra_hir/src/ty | |
parent | e21b82e035050570a8d8e77ebe8b50f7d34ad251 (diff) |
Use Chalk's dyn/impl trait support
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 11 |
3 files changed, 16 insertions, 13 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 9aad2d3fe..d20aeaacf 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -228,14 +228,10 @@ fn iterate_trait_method_candidates<T>( | |||
228 | 'traits: for t in traits { | 228 | 'traits: for t in traits { |
229 | let data = t.trait_data(db); | 229 | let data = t.trait_data(db); |
230 | 230 | ||
231 | // FIXME this is a bit of a hack, since Chalk should say the same thing | ||
232 | // anyway, but currently Chalk doesn't implement `dyn/impl Trait` yet | ||
233 | let inherently_implemented = ty.value.inherent_trait() == Some(t); | ||
234 | |||
235 | // we'll be lazy about checking whether the type implements the | 231 | // we'll be lazy about checking whether the type implements the |
236 | // trait, but if we find out it doesn't, we'll skip the rest of the | 232 | // trait, but if we find out it doesn't, we'll skip the rest of the |
237 | // iteration | 233 | // iteration |
238 | let mut known_implemented = inherently_implemented; | 234 | let mut known_implemented = false; |
239 | for &item in data.items() { | 235 | for &item in data.items() { |
240 | if !is_valid_candidate(db, name, mode, item) { | 236 | if !is_valid_candidate(db, name, mode, item) { |
241 | continue; | 237 | continue; |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 9a26e02fa..838cb4d23 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -3983,11 +3983,11 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) { | |||
3983 | [180; 183) 'bar': fn bar() -> impl Trait<u64> | 3983 | [180; 183) 'bar': fn bar() -> impl Trait<u64> |
3984 | [180; 185) 'bar()': impl Trait<u64> | 3984 | [180; 185) 'bar()': impl Trait<u64> |
3985 | [191; 192) 'x': impl Trait<u64> | 3985 | [191; 192) 'x': impl Trait<u64> |
3986 | [191; 198) 'x.foo()': {unknown} | 3986 | [191; 198) 'x.foo()': u64 |
3987 | [204; 205) 'y': &impl Trait<u64> | 3987 | [204; 205) 'y': &impl Trait<u64> |
3988 | [204; 211) 'y.foo()': {unknown} | 3988 | [204; 211) 'y.foo()': u64 |
3989 | [217; 218) 'z': impl Trait<u64> | 3989 | [217; 218) 'z': impl Trait<u64> |
3990 | [217; 224) 'z.foo()': {unknown} | 3990 | [217; 224) 'z.foo()': u64 |
3991 | [230; 231) 'x': impl Trait<u64> | 3991 | [230; 231) 'x': impl Trait<u64> |
3992 | [230; 238) 'x.foo2()': i64 | 3992 | [230; 238) 'x.foo2()': i64 |
3993 | [244; 245) 'y': &impl Trait<u64> | 3993 | [244; 245) 'y': &impl Trait<u64> |
@@ -4033,11 +4033,11 @@ fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) { | |||
4033 | [177; 180) 'bar': fn bar() -> dyn Trait<u64> | 4033 | [177; 180) 'bar': fn bar() -> dyn Trait<u64> |
4034 | [177; 182) 'bar()': dyn Trait<u64> | 4034 | [177; 182) 'bar()': dyn Trait<u64> |
4035 | [188; 189) 'x': dyn Trait<u64> | 4035 | [188; 189) 'x': dyn Trait<u64> |
4036 | [188; 195) 'x.foo()': {unknown} | 4036 | [188; 195) 'x.foo()': u64 |
4037 | [201; 202) 'y': &dyn Trait<u64> | 4037 | [201; 202) 'y': &dyn Trait<u64> |
4038 | [201; 208) 'y.foo()': {unknown} | 4038 | [201; 208) 'y.foo()': u64 |
4039 | [214; 215) 'z': dyn Trait<u64> | 4039 | [214; 215) 'z': dyn Trait<u64> |
4040 | [214; 221) 'z.foo()': {unknown} | 4040 | [214; 221) 'z.foo()': u64 |
4041 | [227; 228) 'x': dyn Trait<u64> | 4041 | [227; 228) 'x': dyn Trait<u64> |
4042 | [227; 235) 'x.foo2()': i64 | 4042 | [227; 235) 'x.foo2()': i64 |
4043 | [241; 242) 'y': &dyn Trait<u64> | 4043 | [241; 242) 'y': &dyn Trait<u64> |
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index e39e8aaca..81a378bac 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -68,8 +68,15 @@ impl ToChalk for Ty { | |||
68 | } | 68 | } |
69 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(), | 69 | Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(), |
70 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), | 70 | Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), |
71 | // FIXME use Chalk's Dyn/Opaque once the bugs with that are fixed | 71 | Ty::Dyn(predicates) => { |
72 | Ty::Unknown | Ty::Dyn(_) | Ty::Opaque(_) => { | 72 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); |
73 | chalk_ir::TyData::Dyn(make_binders(where_clauses, 1)).intern() | ||
74 | } | ||
75 | Ty::Opaque(predicates) => { | ||
76 | let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); | ||
77 | chalk_ir::TyData::Opaque(make_binders(where_clauses, 1)).intern() | ||
78 | } | ||
79 | Ty::Unknown => { | ||
73 | let parameters = Vec::new(); | 80 | let parameters = Vec::new(); |
74 | let name = TypeName::Error; | 81 | let name = TypeName::Error; |
75 | chalk_ir::ApplicationTy { name, parameters }.cast().intern() | 82 | chalk_ir::ApplicationTy { name, parameters }.cast().intern() |