diff options
author | Florian Diebold <[email protected]> | 2020-05-08 21:12:16 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-05-08 21:14:01 +0100 |
commit | a3d866e776f43c1ae717740bf0c507f4d9fe47cb (patch) | |
tree | e82b33ba64c1e0b36b33470d4d516200c2924d49 /crates/ra_hir_ty/src/lib.rs | |
parent | f9ec7cebef732fbc9d4849d87d325efef5faadea (diff) |
Handle coercing function types to function pointers in match
E.g. in
```rust
match x {
1 => function1,
2 => function2,
}
```
we need to try coercing both to pointers. Turns out this is a special case in
rustc as well (see the link in the comment).
Diffstat (limited to 'crates/ra_hir_ty/src/lib.rs')
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 3e5f38d0d..e8f3482fe 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -683,6 +683,12 @@ impl Ty { | |||
683 | pub fn unit() -> Self { | 683 | pub fn unit() -> Self { |
684 | Ty::apply(TypeCtor::Tuple { cardinality: 0 }, Substs::empty()) | 684 | Ty::apply(TypeCtor::Tuple { cardinality: 0 }, Substs::empty()) |
685 | } | 685 | } |
686 | pub fn fn_ptr(sig: FnSig) -> Self { | ||
687 | Ty::apply( | ||
688 | TypeCtor::FnPtr { num_args: sig.params().len() as u16 }, | ||
689 | Substs(sig.params_and_return), | ||
690 | ) | ||
691 | } | ||
686 | 692 | ||
687 | pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { | 693 | pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { |
688 | match self { | 694 | match self { |