Skip to main content

intersection_or_single

Function intersection_or_single 

Source
pub fn intersection_or_single(
    db: &dyn TypeDatabase,
    types: Vec<TypeId>,
) -> TypeId
Expand description

Reduces a vector of types to an intersection, single type, or NEVER.

This helper eliminates the common pattern:

if types.is_empty() {
    TypeId::NEVER
} else if types.len() == 1 {
    types[0]
} else {
    db.intersection(types)
}

§Examples

let narrowed = intersection_or_single(db, instance_types);