rust-analyzer/crates/ra_hir/src/ty/autoderef.rs

22 lines
734 B
Rust
Raw Normal View History

//! In certain situations, rust automatically inserts derefs as necessary: for
2019-01-06 18:51:42 +00:00
//! example, field accesses `foo.bar` still work when `foo` is actually a
//! reference to a type with the field `bar`. This is an approximation of the
//! logic in rustc (which lives in librustc_typeck/check/autoderef.rs).
use ra_syntax::algo::generate;
use crate::HirDatabase;
use super::Ty;
impl Ty {
/// Iterates over the possible derefs of `ty`.
pub fn autoderef<'a>(self, db: &'a impl HirDatabase) -> impl Iterator<Item = Ty> + 'a {
generate(Some(self), move |ty| ty.autoderef_step(db))
}
fn autoderef_step(&self, _db: &impl HirDatabase) -> Option<Ty> {
2019-03-23 07:53:48 +00:00
// FIXME Deref::deref
2019-01-06 18:51:42 +00:00
self.builtin_deref()
}
}