rustc_const_eval::check_consts::qualifs

Trait Qualif

Source
pub trait Qualif {
    const ANALYSIS_NAME: &'static str;
    const IS_CLEARED_ON_MOVE: bool = false;
    const ALLOW_PROMOTED: bool = false;

    // Required methods
    fn in_qualifs(qualifs: &ConstQualifs) -> bool;
    fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool;
    fn is_structural_in_adt_value<'tcx>(
        cx: &ConstCx<'_, 'tcx>,
        adt: AdtDef<'tcx>,
    ) -> bool;
}
Expand description

A “qualif”(-ication) is a way to look for something “bad” in the MIR that would disqualify some code for promotion or prevent it from evaluating at compile time.

Normally, we would determine what qualifications apply to each type and error when an illegal operation is performed on such a type. However, this was found to be too imprecise, especially in the presence of enums. If only a single variant of an enum has a certain qualification, we needn’t reject code unless it actually constructs and operates on the qualified variant.

To accomplish this, const-checking and promotion use a value-based analysis (as opposed to a type-based one). Qualifications propagate structurally across variables: If a local (or a projection of a local) is assigned a qualified value, that local itself becomes qualified.

Required Associated Constants§

Source

const ANALYSIS_NAME: &'static str

The name of the file used to debug the dataflow analysis that computes this qualif.

Provided Associated Constants§

Source

const IS_CLEARED_ON_MOVE: bool = false

Whether this Qualif is cleared when a local is moved from.

Source

const ALLOW_PROMOTED: bool = false

Whether this Qualif might be evaluated after the promotion and can encounter a promoted.

Required Methods§

Source

fn in_qualifs(qualifs: &ConstQualifs) -> bool

Extracts the field of ConstQualifs that corresponds to this Qualif.

Source

fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool

Returns true if any value of the given type could possibly have this Qualif.

This function determines Qualifs when we cannot do a value-based analysis. Since qualif propagation is context-insensitive, this includes function arguments and values returned from a call to another function.

It also determines the Qualifs for primitive types.

Source

fn is_structural_in_adt_value<'tcx>( cx: &ConstCx<'_, 'tcx>, adt: AdtDef<'tcx>, ) -> bool

Returns true if the Qualif is structural in an ADT’s fields, i.e. if we may recurse into an operand value to determine whether it has this Qualif.

If this returns false, in_any_value_of_ty will be invoked to determine the final qualif for this ADT.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Qualif for HasMutInterior

Source§

const ANALYSIS_NAME: &'static str = "flow_has_mut_interior"

Source§

impl Qualif for NeedsDrop

Source§

const ANALYSIS_NAME: &'static str = "flow_needs_drop"

Source§

const IS_CLEARED_ON_MOVE: bool = true

Source§

const ALLOW_PROMOTED: bool = true

Source§

impl Qualif for NeedsNonConstDrop

Source§

const ANALYSIS_NAME: &'static str = "flow_needs_nonconst_drop"

Source§

const IS_CLEARED_ON_MOVE: bool = true

Source§

const ALLOW_PROMOTED: bool = true