Struct rustc_borrowck::InferCtxt[−][src]

pub(crate) struct InferCtxt<'a, 'tcx> {
Show 14 fields pub tcx: TyCtxt<'tcx>, pub defining_use_anchor: LocalDefId, pub in_progress_typeck_results: Option<&'a RefCell<TypeckResults<'tcx>>>, pub inner: RefCell<InferCtxtInner<'tcx>>, skip_leak_check: Cell<bool>, lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>, pub selection_cache: Cache<(ConstnessAnd<ParamEnvAnd<'tcx, TraitRef<'tcx>>>, ImplPolarity), Result<Option<SelectionCandidate<'tcx>>, SelectionError<'tcx>>>, pub evaluation_cache: Cache<(ParamEnvAnd<'tcx, ConstnessAnd<Binder<'tcx, TraitRef<'tcx>>>>, ImplPolarity), EvaluationResult>, pub reported_trait_errors: RefCell<HashMap<Span, Vec<Predicate<'tcx>, Global>, BuildHasherDefault<FxHasher>>>, pub reported_closure_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>, tainted_by_errors_flag: Cell<bool>, err_count_on_creation: usize, in_snapshot: Cell<bool>, universe: Cell<UniverseIndex>,
}

Fields

tcx: TyCtxt<'tcx>defining_use_anchor: LocalDefId

The DefId of the item in whose context we are performing inference or typeck. It is used to check whether an opaque type use is a defining use.

in_progress_typeck_results: Option<&'a RefCell<TypeckResults<'tcx>>>

During type-checking/inference of a body, in_progress_typeck_results contains a reference to the typeck results being built up, which are used for reading closure kinds/signatures as they are inferred, and for error reporting logic to read arbitrary node types.

inner: RefCell<InferCtxtInner<'tcx>>skip_leak_check: Cell<bool>

If set, this flag causes us to skip the ‘leak check’ during higher-ranked subtyping operations. This flag is a temporary one used to manage the removal of the leak-check: for the time being, we still run the leak-check, but we issue warnings. This flag can only be set to true when entering a snapshot.

lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>

Once region inference is done, the values for each variable.

selection_cache: Cache<(ConstnessAnd<ParamEnvAnd<'tcx, TraitRef<'tcx>>>, ImplPolarity), Result<Option<SelectionCandidate<'tcx>>, SelectionError<'tcx>>>

Caches the results of trait selection. This cache is used for things that have to do with the parameters in scope.

evaluation_cache: Cache<(ParamEnvAnd<'tcx, ConstnessAnd<Binder<'tcx, TraitRef<'tcx>>>>, ImplPolarity), EvaluationResult>

Caches the results of trait evaluation.

reported_trait_errors: RefCell<HashMap<Span, Vec<Predicate<'tcx>, Global>, BuildHasherDefault<FxHasher>>>

the set of predicates on which errors have been reported, to avoid reporting the same error twice.

reported_closure_mismatch: RefCell<HashSet<(Span, Option<Span>), BuildHasherDefault<FxHasher>>>tainted_by_errors_flag: Cell<bool>

When an error occurs, we want to avoid reporting “derived” errors that are due to this original failure. Normally, we handle this with the err_count_on_creation count, which basically just tracks how many errors were reported when we started type-checking a fn and checks to see if any new errors have been reported since then. Not great, but it works.

However, when errors originated in other passes – notably resolve – this heuristic breaks down. Therefore, we have this auxiliary flag that one can set whenever one creates a type-error that is due to an error in a prior pass.

Don’t read this flag directly, call is_tainted_by_errors() and set_tainted_by_errors().

err_count_on_creation: usize

Track how many errors were reported when this infcx is created. If the number of errors increases, that’s also a sign (line tained_by_errors) to avoid reporting certain kinds of errors.

in_snapshot: Cell<bool>

This flag is true while there is an active snapshot.

universe: Cell<UniverseIndex>

What is the innermost universe we have created? Starts out as UniverseIndex::root() but grows from there as we enter universal quantifiers.

N.B., at present, we exclude the universal quantifiers on the item we are type-checking, and just consider those names as part of the root universe. So this would only get incremented when we enter into a higher-ranked (for<..>) type or trait bound.

Trait Implementations

Finds late-bound regions that do not appear in the parameter listing and adds them to the indices vector. Typically, we identify late-bound regions as we process the inputs and outputs of the closure/function. However, sometimes there are late-bound regions which do not appear in the fn parameters but which are nonetheless in scope. The simplest case of this are unused functions, like fn foo<’a>() { } (see e.g., #51351). Despite not being used, users can still reference these regions (e.g., let x: &’a u32 = &22;), so we need to create entries for them and store them in the indices map. This code iterates over the complete set of late-bound regions and checks for any that we have not yet seen, adding them to the inputs vector.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 760 bytes