Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,50 @@ impl DefWithBody {
acc.push(diag.into())
}
}

/// Returns an iterator over the inferred types of all expressions in this body.
///
/// Returns `None` for builtin derive impl methods which don't have inference data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like calling out builtin derive impls like that. Instead we should just return an empty iterator for them (they behave as if they have no body).

pub fn expression_types<'db>(
self,
db: &'db dyn HirDatabase,
) -> Option<impl Iterator<Item = Type<'db>>> {
let def_id = self.id()?;
let infer = InferenceResult::for_body(db, def_id);
let resolver = def_id.resolver(db);

Some(
infer.expression_types().map(move |(_, ty)| Type::new_with_resolver(db, &resolver, ty)),
)
}

/// Returns an iterator over the inferred types of all patterns in this body.
///
/// Returns `None` for builtin derive impl methods which don't have inference data.
pub fn pattern_types<'db>(
self,
db: &'db dyn HirDatabase,
) -> Option<impl Iterator<Item = Type<'db>>> {
let def_id = self.id()?;
let infer = InferenceResult::for_body(db, def_id);
let resolver = def_id.resolver(db);

Some(infer.pattern_types().map(move |(_, ty)| Type::new_with_resolver(db, &resolver, ty)))
}

/// Returns an iterator over the inferred types of all bindings in this body.
///
/// Returns `None` for builtin derive impl methods which don't have inference data.
pub fn binding_types<'db>(
self,
db: &'db dyn HirDatabase,
) -> Option<impl Iterator<Item = Type<'db>>> {
let def_id = self.id()?;
let infer = InferenceResult::for_body(db, def_id);
let resolver = def_id.resolver(db);

Some(infer.binding_types().map(move |(_, ty)| Type::new_with_resolver(db, &resolver, ty)))
}
}

fn expr_store_diagnostics<'db>(
Expand Down