diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-22 12:31:30 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-22 12:31:30 +0000 |
commit | 2cbe8a4c4be2a69b27c248ab96341c2336f983cd (patch) | |
tree | ee1a32b47f889ed132a314286cd90a07f3700216 /crates/ra_hir_ty/src/lower.rs | |
parent | 7836720f2e9a7fa01ae09ff9d51413ecd5877139 (diff) | |
parent | 5a6e770f99d1549432c1e8a1abb1aada09ad2590 (diff) |
Merge #3263
3263: Implement unsizing coercions using Chalk r=matklad a=flodiebold
These are coercions like `&[T; n] -> &[T]`, which are handled by the `Unsize` and `CoerceUnsized` traits. The impls for `Unsize` are all built in to the compiler and require special handling, so we need to provide them to Chalk.
This adds the following `Unsize` impls:
- `Unsize<[T]> for [T; _]`
- `Unsize<dyn Trait> for T where T: Trait`
- `Unsize<dyn SuperTrait> for dyn SubTrait`
Hence we are still missing the 'unsizing the last field of a generic struct' case.
Co-authored-by: Florian Diebold <[email protected]>
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/lower.rs')
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 52da34574..092977e93 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -239,7 +239,10 @@ impl Ty { | |||
239 | ) -> Ty { | 239 | ) -> Ty { |
240 | let ty = match resolution { | 240 | let ty = match resolution { |
241 | TypeNs::TraitId(trait_) => { | 241 | TypeNs::TraitId(trait_) => { |
242 | let trait_ref = TraitRef::from_resolved_path(ctx, trait_, resolved_segment, None); | 242 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there |
243 | let self_ty = if remaining_segments.len() == 0 { Some(Ty::Bound(0)) } else { None }; | ||
244 | let trait_ref = | ||
245 | TraitRef::from_resolved_path(ctx, trait_, resolved_segment, self_ty); | ||
243 | return if remaining_segments.len() == 1 { | 246 | return if remaining_segments.len() == 1 { |
244 | let segment = remaining_segments.first().unwrap(); | 247 | let segment = remaining_segments.first().unwrap(); |
245 | let associated_ty = associated_type_by_name_including_super_traits( | 248 | let associated_ty = associated_type_by_name_including_super_traits( |