From 9c2a9a9a0635e53466749fdedcdc5a371e658cde Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 15 Nov 2019 21:00:27 +0100 Subject: Use Chalk's dyn/impl trait support --- crates/ra_hir/src/ty/method_resolution.rs | 6 +----- crates/ra_hir/src/ty/tests.rs | 12 ++++++------ crates/ra_hir/src/ty/traits/chalk.rs | 11 +++++++++-- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir/src/ty') 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( 'traits: for t in traits { let data = t.trait_data(db); - // FIXME this is a bit of a hack, since Chalk should say the same thing - // anyway, but currently Chalk doesn't implement `dyn/impl Trait` yet - let inherently_implemented = ty.value.inherent_trait() == Some(t); - // we'll be lazy about checking whether the type implements the // trait, but if we find out it doesn't, we'll skip the rest of the // iteration - let mut known_implemented = inherently_implemented; + let mut known_implemented = false; for &item in data.items() { if !is_valid_candidate(db, name, mode, item) { 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, y: &impl Trait) { [180; 183) 'bar': fn bar() -> impl Trait [180; 185) 'bar()': impl Trait [191; 192) 'x': impl Trait - [191; 198) 'x.foo()': {unknown} + [191; 198) 'x.foo()': u64 [204; 205) 'y': &impl Trait - [204; 211) 'y.foo()': {unknown} + [204; 211) 'y.foo()': u64 [217; 218) 'z': impl Trait - [217; 224) 'z.foo()': {unknown} + [217; 224) 'z.foo()': u64 [230; 231) 'x': impl Trait [230; 238) 'x.foo2()': i64 [244; 245) 'y': &impl Trait @@ -4033,11 +4033,11 @@ fn test(x: dyn Trait, y: &dyn Trait) { [177; 180) 'bar': fn bar() -> dyn Trait [177; 182) 'bar()': dyn Trait [188; 189) 'x': dyn Trait - [188; 195) 'x.foo()': {unknown} + [188; 195) 'x.foo()': u64 [201; 202) 'y': &dyn Trait - [201; 208) 'y.foo()': {unknown} + [201; 208) 'y.foo()': u64 [214; 215) 'z': dyn Trait - [214; 221) 'z.foo()': {unknown} + [214; 221) 'z.foo()': u64 [227; 228) 'x': dyn Trait [227; 235) 'x.foo2()': i64 [241; 242) 'y': &dyn Trait 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 { } Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx as usize).intern(), Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"), - // FIXME use Chalk's Dyn/Opaque once the bugs with that are fixed - Ty::Unknown | Ty::Dyn(_) | Ty::Opaque(_) => { + Ty::Dyn(predicates) => { + let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); + chalk_ir::TyData::Dyn(make_binders(where_clauses, 1)).intern() + } + Ty::Opaque(predicates) => { + let where_clauses = predicates.iter().cloned().map(|p| p.to_chalk(db)).collect(); + chalk_ir::TyData::Opaque(make_binders(where_clauses, 1)).intern() + } + Ty::Unknown => { let parameters = Vec::new(); let name = TypeName::Error; chalk_ir::ApplicationTy { name, parameters }.cast().intern() -- cgit v1.2.3