From 463df6720cc8d2c7176a48a0ca8f4e333016a16a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 21 Feb 2020 23:06:18 +0100 Subject: Fix wrong handling of bare `dyn Trait` exposed by canonicalizer fix The self type in the `dyn Trait` trait ref should always be ^0, but we didn't put that in there in the bare case. --- crates/ra_hir_ty/src/lower.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/lower.rs') diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 52da34574..0e6efa971 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -239,7 +239,9 @@ impl Ty { ) -> Ty { let ty = match resolution { TypeNs::TraitId(trait_) => { - let trait_ref = TraitRef::from_resolved_path(ctx, trait_, resolved_segment, None); + // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there + let self_ty = if remaining_segments.len() == 0 { Some(Ty::Bound(0)) } else { None }; + let trait_ref = TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty); return if remaining_segments.len() == 1 { let segment = remaining_segments.first().unwrap(); let associated_ty = associated_type_by_name_including_super_traits( -- cgit v1.2.3 From 3e106c77ff76c39be49444165eac805d32666e41 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 22 Feb 2020 13:14:39 +0100 Subject: Rework find_super_trait_path to protect against cycles --- crates/ra_hir_ty/src/lower.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/lower.rs') diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 0e6efa971..092977e93 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -241,7 +241,8 @@ impl Ty { TypeNs::TraitId(trait_) => { // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there let self_ty = if remaining_segments.len() == 0 { Some(Ty::Bound(0)) } else { None }; - let trait_ref = TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty); + let trait_ref = + TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty); return if remaining_segments.len() == 1 { let segment = remaining_segments.first().unwrap(); let associated_ty = associated_type_by_name_including_super_traits( -- cgit v1.2.3