pub struct InferCtxt<'a, 'tcx> {
Show 14 fields pub tcx: TyCtxt, pub defining_use_anchor: Option<LocalDefId>, pub in_progress_typeck_results: Option<&RefCell<TypeckResults>>, pub inner: RefCell<InferCtxtInner>, skip_leak_check: Cell<bool>, lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions>>, pub selection_cache: Cache<ParamEnvAnd<TraitPredicate>, Result<Option<SelectionCandidate>, SelectionError>>, pub evaluation_cache: Cache<ParamEnvAnd<Binder<TraitPredicate>>, EvaluationResult>, pub reported_trait_errors: RefCell<HashMap<Span, Vec<Predicate, 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: TyCtxtdefining_use_anchor: Option<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.

If it is None, we can’t resolve opaque types here and need to bubble up the obligation. This frequently happens for short lived InferCtxt within queries. The opaque type obligations are forwarded to the outside until the end up in an InferCtxt for typeck or borrowck.

in_progress_typeck_results: Option<&RefCell<TypeckResults>>

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>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>>

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

selection_cache: Cache<ParamEnvAnd<TraitPredicate>, Result<Option<SelectionCandidate>, SelectionError>>

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<Binder<TraitPredicate>>, EvaluationResult>

Caches the results of trait evaluation.

reported_trait_errors: RefCell<HashMap<Span, Vec<Predicate, 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

Normalizes associated types in value, potentially returning new obligations that must further be processed.

Check whether a ty implements given trait(trait_def_id). The inputs are: Read more

Given the fully resolved, instantiated type for an opaque type, i.e., the value of an inference variable like C1 or C2 (*), computes the “definition type” for an opaque type definition – that is, the inferred value of Foo1<'x> or Foo2<'x> that we would conceptually use in its definition:

type Foo1<'x> = impl Bar<'x> = AAA; <-- this type AAA
type Foo2<'x> = impl Bar<'x> = BBB; <-- or this type BBB
fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }

Note that these values are defined in terms of a distinct set of generic parameters ('x instead of 'a) from C1 or C2. The main purpose of this function is to do that translation.

(*) C1 and C2 were introduced in the comments on constrain_opaque_type. Read that comment for more context.

Parameters
  • def_id, the impl Trait type
  • substs, the substs used to instantiate this opaque type
  • instantiated_ty, the inferred type C1 – fully resolved, lifted version of opaque_defn.concrete_ty

Used to set on_unimplemented’s ItemContext to be the enclosing (async) block/function/closure

When after several dereferencing, the reference satisfies the trait binding. This function provides dereference suggestion for this specific situation.

Given a closure’s DefId, return the given name of the closure.

This doesn’t account for reassignments, but it’s only used for suggestions.

We tried to apply the bound to an fn or closure. Check whether calling it would evaluate to a type that would satisfy the trait binding. If it would, suggest calling it: bar(foo) → bar(foo()). This case is very likely to be hit if foo is async.

Whenever references are used by mistake, like for (i, e) in &vec.iter().enumerate(), suggest removing these references until we reach a type that implements the trait.

Check if the trait bound is implemented for a different mutability and note it in the final error.

If all conditions are met to identify a returned dyn Trait, suggest using impl Trait if applicable and signal that the error has been expanded appropriately and needs to be emitted.

Adds an async-await specific note to the diagnostic when the future does not implement an auto trait because of a captured type.

note: future does not implement `Qux` as this value is used across an await
  --> $DIR/issue-64130-3-other.rs:17:5
   |
LL |     let x = Foo;
   |         - has type `Foo`
LL |     baz().await;
   |     ^^^^^^^^^^^ await occurs here, with `x` maybe used later
LL | }
   | - `x` is later dropped here

When the diagnostic does not implement Send or Sync specifically, then the diagnostic is “replaced” with a different message and a more specific error.

error: future cannot be sent between threads safely
  --> $DIR/issue-64130-2-send.rs:21:5
   |
LL | fn is_send<T: Send>(t: T) { }
   |               ---- required by this bound in `is_send`
...
LL |     is_send(bar());
   |     ^^^^^^^ future returned by `bar` is not send
   |
   = help: within `impl std::future::Future`, the trait `std::marker::Send` is not
           implemented for `Foo`
note: future is not send as this value is used across an await
  --> $DIR/issue-64130-2-send.rs:15:5
   |
LL |     let x = Foo;
   |         - has type `Foo`
LL |     baz().await;
   |     ^^^^^^^^^^^ await occurs here, with `x` maybe used later
LL | }
   | - `x` is later dropped here

Returns true if an async-await specific note was added to the diagnostic.

Unconditionally adds the diagnostic note described in maybe_note_obligation_cause_for_async_await’s documentation comment.

Suggest to await before try: future? => future.await?

Reports that an overflow has occurred and halts compilation. We halt compilation unconditionally because it is important that overflows never be masked – they basically represent computations whose result could not be truly determined and thus we can’t say if the program type checks or not – and they are unusual occurrences in any case.

Reports that a cycle was detected which led to overflow and halts compilation. This is equivalent to report_overflow_error except that we can give a more helpful error message (and, in particular, we do not suggest increasing the overflow limit, which is not going to help).

Given some node representing a fn-like thing in the HIR map, returns a span and ArgKind information that describes the arguments it expects. This can be supplied to report_arg_count_mismatch.

Reports an error when the number of arguments needed by a trait match doesn’t match the number that the expression provides.

The root_obligation parameter should be the root_obligation field from a FulfillmentError. If no FulfillmentError is available, then it should be the same as obligation. Read more

Evaluates whether the predicate can be satisfied (by any means) in the given ParamEnv.

Evaluates whether the predicate can be satisfied in the given ParamEnv, and returns false if not certain. However, this is not entirely accurate if inference variables are involved.

This version may conservatively fail when outlives obligations are required.

Evaluates whether the predicate can be satisfied in the given ParamEnv, and returns false if not certain. However, this is not entirely accurate if inference variables are involved.

This version ignores all outlives constraints.

Evaluate a given predicate, capturing overflow and propagating it back.

Gets the parent trait chain start

If the Self type of the unsatisfied trait trait_ref implements a trait with the same path as trait_ref, a help message about a probable version mismatch is added to err

Returns true if the trait predicate may apply for some assignment to the type parameters.

Creates a PredicateObligation with new_self_ty replacing the existing type in the trait_ref. Read more

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