aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-22 12:31:30 +0000
committerGitHub <[email protected]>2020-02-22 12:31:30 +0000
commit2cbe8a4c4be2a69b27c248ab96341c2336f983cd (patch)
treeee1a32b47f889ed132a314286cd90a07f3700216 /crates/ra_hir_ty/src/traits.rs
parent7836720f2e9a7fa01ae09ff9d51413ecd5877139 (diff)
parent5a6e770f99d1549432c1e8a1abb1aada09ad2590 (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/traits.rs')
-rw-r--r--crates/ra_hir_ty/src/traits.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs
index e83449957..2317fcac3 100644
--- a/crates/ra_hir_ty/src/traits.rs
+++ b/crates/ra_hir_ty/src/traits.rs
@@ -335,6 +335,12 @@ pub struct ClosureFnTraitImplData {
335 fn_trait: FnTrait, 335 fn_trait: FnTrait,
336} 336}
337 337
338#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
339pub struct UnsizeToSuperTraitObjectData {
340 trait_: TraitId,
341 super_trait: TraitId,
342}
343
338/// An impl. Usually this comes from an impl block, but some built-in types get 344/// An impl. Usually this comes from an impl block, but some built-in types get
339/// synthetic impls. 345/// synthetic impls.
340#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 346#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -343,6 +349,12 @@ pub enum Impl {
343 ImplBlock(ImplId), 349 ImplBlock(ImplId),
344 /// Closure types implement the Fn traits synthetically. 350 /// Closure types implement the Fn traits synthetically.
345 ClosureFnTraitImpl(ClosureFnTraitImplData), 351 ClosureFnTraitImpl(ClosureFnTraitImplData),
352 /// [T; n]: Unsize<[T]>
353 UnsizeArray,
354 /// T: Unsize<dyn Trait> where T: Trait
355 UnsizeToTraitObject(TraitId),
356 /// dyn Trait: Unsize<dyn SuperTrait> if Trait: SuperTrait
357 UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData),
346} 358}
347/// This exists just for Chalk, because our ImplIds are only unique per module. 359/// This exists just for Chalk, because our ImplIds are only unique per module.
348#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 360#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]