Skip to main content

Union

Struct Union 

Source
pub struct Union {
    pub types: AtomicVec,
    pub possibly_undefined: bool,
    pub from_docblock: bool,
}

Fields§

§types: AtomicVec§possibly_undefined: bool

The variable holding this type may not be initialized at this point.

§from_docblock: bool

This union originated from a docblock annotation rather than inference.

Implementations§

Source§

impl Union

Source

pub fn empty() -> Self

Source

pub fn single(atomic: Atomic) -> Self

Source

pub fn mixed() -> Self

Source

pub fn void() -> Self

Source

pub fn never() -> Self

Source

pub fn null() -> Self

Source

pub fn bool() -> Self

Source

pub fn int() -> Self

Source

pub fn float() -> Self

Source

pub fn string() -> Self

Source

pub fn nullable(atomic: Atomic) -> Self

T|null

Source

pub fn from_vec(atomics: Vec<Atomic>) -> Self

Build a union from multiple atomics, de-duplicating on the fly.

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_single(&self) -> bool

Source

pub fn is_nullable(&self) -> bool

Source

pub fn is_mixed(&self) -> bool

Source

pub fn is_never(&self) -> bool

Source

pub fn is_void(&self) -> bool

Source

pub fn can_be_falsy(&self) -> bool

Source

pub fn can_be_truthy(&self) -> bool

Source

pub fn contains<F: Fn(&Atomic) -> bool>(&self, f: F) -> bool

Source

pub fn has_named_object(&self, fqcn: &str) -> bool

Source

pub fn add_type(&mut self, atomic: Atomic)

Add an atomic to this union, skipping duplicates. Subsumption rules: anything ⊆ TMixed; TLiteralInt ⊆ TInt; etc.

Source

pub fn remove_null(&self) -> Union

Remove null from the union (e.g. after a null check).

Source

pub fn remove_false(&self) -> Union

Remove false from the union.

Source

pub fn narrow_to_truthy(&self) -> Union

Keep only truthy atomics (e.g. after if ($x)).

Source

pub fn narrow_to_falsy(&self) -> Union

Keep only falsy atomics (e.g. after if (!$x)).

Source

pub fn narrow_instanceof(&self, class: &str) -> Union

Narrow this type as if $x instanceof ClassName is true.

The instanceof check guarantees the value IS an instance of class, so we replace any object / mixed constituents with the specific named object. Scalar constituents are dropped (they can never satisfy instanceof).

Source

pub fn narrow_to_string(&self) -> Union

Narrow as if is_string($x) is true.

Source

pub fn narrow_to_int(&self) -> Union

Narrow as if is_int($x) is true.

Source

pub fn narrow_to_float(&self) -> Union

Narrow as if is_float($x) is true.

Source

pub fn narrow_to_bool(&self) -> Union

Narrow as if is_bool($x) is true.

Source

pub fn narrow_to_null(&self) -> Union

Narrow as if is_null($x) is true.

Source

pub fn narrow_to_array(&self) -> Union

Narrow as if is_array($x) is true.

Source

pub fn narrow_to_object(&self) -> Union

Narrow as if is_object($x) is true.

Source

pub fn narrow_to_callable(&self) -> Union

Narrow as if is_callable($x) is true.

Source

pub fn merge(a: &Union, b: &Union) -> Union

Merge two unions at a branch join point (e.g. after if/else). The result is the union of all types in both.

Source

pub fn intersect_with(&self, other: &Union) -> Union

Intersect with another union: keep only types present in other, widening where self contains mixed (which is compatible with everything). Used for match-arm subject narrowing.

Source

pub fn substitute_templates(&self, bindings: &HashMap<Arc<str>, Union>) -> Union

Replace template param references with their resolved types.

Source

pub fn is_subtype_of_simple(&self, other: &Union) -> bool

Returns true if every atomic in self is a subtype of some atomic in other. Does not require a Codebase (no inheritance check); use the codebase-aware version in mir-analyzer for full checks.

Source

pub fn possibly_undefined(self) -> Self

Mark this union as possibly-undefined and return it.

Source

pub fn from_docblock(self) -> Self

Mark this union as coming from a docblock annotation.

Trait Implementations§

Source§

impl Clone for Union

Source§

fn clone(&self) -> Union

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Union

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Union

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Union

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Union

Source§

fn eq(&self, other: &Union) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Union

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Union

Auto Trait Implementations§

§

impl Freeze for Union

§

impl RefUnwindSafe for Union

§

impl Send for Union

§

impl Sync for Union

§

impl Unpin for Union

§

impl UnsafeUnpin for Union

§

impl UnwindSafe for Union

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,