use super::types::PropertyKind;
use super::types::Property;
pub fn with_kind<'tcx>(property: &Property<'tcx>, kind: PropertyKind) -> Property<'tcx> {
Property {
kind,
args: property.args.clone(),
contract_kind: property.contract_kind,
null_guard: None,
or_alternatives: Vec::new(),
}
}
pub fn primitive_components(kind: &PropertyKind) -> Option<&'static [PropertyKind]> {
Some(match kind {
PropertyKind::Deref => &[PropertyKind::Allocated, PropertyKind::InBound],
PropertyKind::Ptr2Ref => &[PropertyKind::Init, PropertyKind::Align, PropertyKind::Alias],
PropertyKind::Layout => &[PropertyKind::Allocated],
_ => return None,
})
}
pub fn kind_implies(declared: &PropertyKind, required: &PropertyKind) -> bool {
if declared == required {
return true;
}
if matches!(declared, PropertyKind::Init) && matches!(required, PropertyKind::Typed) {
return true;
}
if matches!(declared, PropertyKind::InBound)
&& matches!(required, PropertyKind::Allocated)
{
return true;
}
if matches!(declared, PropertyKind::ValidPtr)
&& matches!(required, PropertyKind::Allocated | PropertyKind::InBound)
{
return true;
}
if let Some(primitives) = primitive_components(declared) {
if primitives.contains(required) {
return true;
}
}
false
}