aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/autoderef.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-01-06 18:51:42 +0000
committerFlorian Diebold <[email protected]>2019-01-07 13:54:23 +0000
commit7bb279b365e54ee0051e09ead5aa157ff6be917b (patch)
tree7a495d68453ea1e3c7a726e97bbbe19f9bc90532 /crates/ra_hir/src/ty/autoderef.rs
parenta6071c9f4c8441b4b8f2e970bc055d66cc9be5f0 (diff)
Implement autoderef for field accesses
Diffstat (limited to 'crates/ra_hir/src/ty/autoderef.rs')
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
new file mode 100644
index 000000000..24a386558
--- /dev/null
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -0,0 +1,21 @@
1//! In certain situations, rust automatically inserts derefs as necessary: For
2//! example, field accesses `foo.bar` still work when `foo` is actually a
3//! reference to a type with the field `bar`. This is an approximation of the
4//! logic in rustc (which lives in librustc_typeck/check/autoderef.rs).
5
6use ra_syntax::algo::generate;
7
8use crate::HirDatabase;
9use super::Ty;
10
11impl Ty {
12 /// Iterates over the possible derefs of `ty`.
13 pub fn autoderef<'a>(self, db: &'a impl HirDatabase) -> impl Iterator<Item = Ty> + 'a {
14 generate(Some(self), move |ty| ty.autoderef_step(db))
15 }
16
17 fn autoderef_step(&self, _db: &impl HirDatabase) -> Option<Ty> {
18 // TODO Deref::deref
19 self.builtin_deref()
20 }
21}