diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-24 22:12:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-24 22:12:26 +0100 |
commit | c7420ddaaa76741d1eebe393406b38ba5596e54a (patch) | |
tree | ff9c2f3c665ef95ebf509dc69ff82d39ec42d176 /crates/ra_hir/src/code_model.rs | |
parent | 36fb3f53d712a11b7e3fc4bbd92094d1c8f19522 (diff) | |
parent | 6a8670665032f6103ca14e38ed9106126b20063d (diff) |
Merge #1845
1845: Closure types r=flodiebold a=flodiebold
This adds types for closures and makes them implement the `Fn` traits (we don't currently care or try to infer `Fn` vs. `FnMut` vs. `FnOnce`; this would require move analysis, I think).
This requires some changes in Chalk; one is that we need to know the self type when asked for impls, so we can synthesize `Fn` trait impls for closures; but also there's a problem that prevents us from normalizing the closure output type correctly that I _think_ will be fixed on the Chalk side (basically, we ask too early and try to solve `Normalize(<?1 as FnOnce<(u32,)>>::Output => ?0)` -- note the variable in the self type -- and instead of an ambiguous answer, we get back that it can't be solved, so we don't try again. Niko mentioned he's making all goals where the self type is unconstrained flounder, which I think would mean this would be ambiguous).
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 12399c6ac..99c247a0b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -551,6 +551,14 @@ impl DefWithBody { | |||
551 | DefWithBody::Static(s) => s.resolver(db), | 551 | DefWithBody::Static(s) => s.resolver(db), |
552 | } | 552 | } |
553 | } | 553 | } |
554 | |||
555 | pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> { | ||
556 | match self { | ||
557 | DefWithBody::Const(c) => c.krate(db), | ||
558 | DefWithBody::Function(f) => f.krate(db), | ||
559 | DefWithBody::Static(s) => s.krate(db), | ||
560 | } | ||
561 | } | ||
554 | } | 562 | } |
555 | 563 | ||
556 | pub trait HasBody: Copy { | 564 | pub trait HasBody: Copy { |
@@ -671,6 +679,10 @@ impl Function { | |||
671 | self.id.module(db) | 679 | self.id.module(db) |
672 | } | 680 | } |
673 | 681 | ||
682 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | ||
683 | self.module(db).krate(db) | ||
684 | } | ||
685 | |||
674 | pub fn name(self, db: &impl HirDatabase) -> Name { | 686 | pub fn name(self, db: &impl HirDatabase) -> Name { |
675 | self.data(db).name.clone() | 687 | self.data(db).name.clone() |
676 | } | 688 | } |
@@ -745,6 +757,10 @@ impl Const { | |||
745 | self.id.module(db) | 757 | self.id.module(db) |
746 | } | 758 | } |
747 | 759 | ||
760 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | ||
761 | self.module(db).krate(db) | ||
762 | } | ||
763 | |||
748 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 764 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
749 | db.const_data(self) | 765 | db.const_data(self) |
750 | } | 766 | } |
@@ -824,6 +840,10 @@ impl Static { | |||
824 | self.id.module(db) | 840 | self.id.module(db) |
825 | } | 841 | } |
826 | 842 | ||
843 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | ||
844 | self.module(db).krate(db) | ||
845 | } | ||
846 | |||
827 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { | 847 | pub fn data(self, db: &impl HirDatabase) -> Arc<ConstData> { |
828 | db.static_data(self) | 848 | db.static_data(self) |
829 | } | 849 | } |