pub fn apply_contextual_type(
interner: &dyn TypeDatabase,
expr_type: TypeId,
contextual_type: Option<TypeId>,
) -> TypeIdExpand description
Apply contextual type to infer a more specific type.
This implements bidirectional type inference:
- If
expr_typeis any/unknown/error, use contextual type - If
expr_typeis a literal and contextual type is a union containing that literal’s base type, preserve literal - If
expr_typeis assignable to contextual type and is more specific, useexpr_type - Otherwise, prefer
expr_type(don’t widen to contextual type)