Trait rustc_mir::transform::check_consts::qualifs::Qualif[−][src]

pub trait Qualif {
    const ANALYSIS_NAME: &'static str;
    const IS_CLEARED_ON_MOVE: bool;

    fn in_qualifs(qualifs: &ConstQualifs) -> bool;
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool;
fn in_adt_inherently<'tcx>(
        cx: &ConstCx<'_, 'tcx>,
        adt: &'tcx AdtDef,
        substs: SubstsRef<'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.

Associated Constants

const ANALYSIS_NAME: &'static str[src]

Expand description

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

const IS_CLEARED_ON_MOVE: bool[src]

Expand description

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

Loading content...

Required methods

fn in_qualifs(qualifs: &ConstQualifs) -> bool[src]

Expand description

Extracts the field of ConstQualifs that corresponds to this Qualif.

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

Expand description

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-insenstive, this includes function arguments and values returned from a call to another function.

It also determines the Qualifs for primitive types.

fn in_adt_inherently<'tcx>(
    cx: &ConstCx<'_, 'tcx>,
    adt: &'tcx AdtDef,
    substs: SubstsRef<'tcx>
) -> bool
[src]

Expand description

Returns true if this Qualif is inherent to the given struct or enum.

By default, Qualifs propagate into ADTs in a structural way: An ADT only becomes qualified if part of it is assigned a value with that Qualif. However, some ADTs always have a certain Qualif, regardless of whether their fields have it. For example, a type with a custom Drop impl is inherently NeedsDrop.

Returning true for in_adt_inherently but false for in_any_value_of_ty is unsound.

Loading content...

Implementors

impl Qualif for CustomEq[src]

const ANALYSIS_NAME: &'static str[src]

fn in_qualifs(qualifs: &ConstQualifs) -> bool[src]

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

fn in_adt_inherently<'tcx>(
    cx: &ConstCx<'_, 'tcx>,
    adt: &'tcx AdtDef,
    substs: SubstsRef<'tcx>
) -> bool
[src]

impl Qualif for HasMutInterior[src]

const ANALYSIS_NAME: &'static str[src]

fn in_qualifs(qualifs: &ConstQualifs) -> bool[src]

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

fn in_adt_inherently<'tcx>(
    cx: &ConstCx<'_, 'tcx>,
    adt: &'tcx AdtDef,
    _: SubstsRef<'tcx>
) -> bool
[src]

impl Qualif for NeedsDrop[src]

const ANALYSIS_NAME: &'static str[src]

const IS_CLEARED_ON_MOVE: bool[src]

fn in_qualifs(qualifs: &ConstQualifs) -> bool[src]

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

fn in_adt_inherently<'tcx>(
    cx: &ConstCx<'_, 'tcx>,
    adt: &'tcx AdtDef,
    _: SubstsRef<'tcx>
) -> bool
[src]

Loading content...