diff options
author | Florian Diebold <[email protected]> | 2019-09-09 21:10:58 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-09-24 22:05:12 +0100 |
commit | 3b06faad26fdb1485c542970374ff8bbcb0e01c4 (patch) | |
tree | 370ec4c128b6160b2fd72351eb3875f04e3a94fd /crates/ra_hir/src/ty/traits.rs | |
parent | 619a8185a607b216c64b58d230c3949ccef98a37 (diff) |
Make closures impl closure traits
Diffstat (limited to 'crates/ra_hir/src/ty/traits.rs')
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index c0c132809..8e256341d 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -9,7 +9,7 @@ use ra_prof::profile; | |||
9 | use rustc_hash::FxHashSet; | 9 | use rustc_hash::FxHashSet; |
10 | 10 | ||
11 | use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; | 11 | use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; |
12 | use crate::{db::HirDatabase, Crate, ImplBlock, Trait}; | 12 | use crate::{db::HirDatabase, expr::ExprId, Crate, DefWithBody, ImplBlock, Trait}; |
13 | 13 | ||
14 | use self::chalk::{from_chalk, ToChalk}; | 14 | use self::chalk::{from_chalk, ToChalk}; |
15 | 15 | ||
@@ -252,3 +252,37 @@ pub enum Guidance { | |||
252 | /// There's no useful information to feed back to type inference | 252 | /// There's no useful information to feed back to type inference |
253 | Unknown, | 253 | Unknown, |
254 | } | 254 | } |
255 | |||
256 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
257 | pub enum FnTrait { | ||
258 | FnOnce, | ||
259 | FnMut, | ||
260 | Fn, | ||
261 | } | ||
262 | |||
263 | impl FnTrait { | ||
264 | fn lang_item_name(self) -> &'static str { | ||
265 | match self { | ||
266 | FnTrait::FnOnce => "fn_once", | ||
267 | FnTrait::FnMut => "fn_mut", | ||
268 | FnTrait::Fn => "fn", | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | |||
273 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
274 | pub struct ClosureFnTraitImplData { | ||
275 | def: DefWithBody, | ||
276 | expr: ExprId, | ||
277 | fn_trait: FnTrait, | ||
278 | } | ||
279 | |||
280 | /// An impl. Usually this comes from an impl block, but some built-in types get | ||
281 | /// synthetic impls. | ||
282 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
283 | pub enum Impl { | ||
284 | /// A normal impl from an impl block. | ||
285 | ImplBlock(ImplBlock), | ||
286 | /// Closure types implement the Fn traits synthetically. | ||
287 | ClosureFnTraitImpl(ClosureFnTraitImplData), | ||
288 | } | ||