[−][src]Struct rustc_trait_selection::infer::InferCtxt

pub struct InferCtxt<'a, 'tcx> {
    pub tcx: TyCtxt<'tcx>,
    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<ParamEnvAnd<'tcx, TraitRef<'tcx>>, Result<Option<SelectionCandidate<'tcx>>, SelectionError<'tcx>>>,
    pub evaluation_cache: Cache<ParamEnvAnd<'tcx, Binder<TraitRef<'tcx>>>, EvaluationResult>,
    pub reported_trait_errors: RefCell<HashMap<Span, Vec<Predicate<'tcx>>, 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>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<ParamEnvAnd<'tcx, TraitRef<'tcx>>, 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, Binder<TraitRef<'tcx>>>, EvaluationResult>

Caches the results of trait evaluation.

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

Implementations

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn at(
    &'a self,
    cause: &'a ObligationCause<'tcx>,
    param_env: ParamEnv<'tcx>
) -> At<'a, 'tcx>
[src]

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx>[src]

pub fn canonicalize_query<V>(
    &self,
    value: &V,
    query_state: &mut OriginalQueryValues<'tcx>
) -> Canonical<'tcx, V> where
    V: TypeFoldable<'tcx>, 
[src]

Canonicalizes a query value V. When we canonicalize a query, we not only canonicalize unbound inference variables, but we also replace all free regions whatsoever. So for example a query like T: Trait<'static> would be canonicalized to

T: Trait<'?0>

with a mapping M that maps '?0 to 'static.

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

pub fn canonicalize_response<V>(&self, value: &V) -> Canonical<'tcx, V> where
    V: TypeFoldable<'tcx>, 
[src]

Canonicalizes a query response V. When we canonicalize a query response, we only canonicalize unbound inference variables, and we leave other free regions alone. So, continuing with the example from canonicalize_query, if there was an input query T: Trait<'static>, it would have been canonicalized to

T: Trait<'?0>

with a mapping M that maps '?0 to 'static. But if we found that there exists only one possible impl of Trait, and it looks like

impl<T> Trait<'static> for T { .. }

then we would prepare a query result R that (among other things) includes a mapping to '?0 := 'static. When canonicalizing this query result R, we would leave this reference to 'static alone.

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

pub fn canonicalize_user_type_annotation<V>(
    &self,
    value: &V
) -> Canonical<'tcx, V> where
    V: TypeFoldable<'tcx>, 
[src]

pub fn canonicalize_hr_query_hack<V>(
    &self,
    value: &V,
    query_state: &mut OriginalQueryValues<'tcx>
) -> Canonical<'tcx, V> where
    V: TypeFoldable<'tcx>, 
[src]

A hacky variant of canonicalize_query that does not canonicalize 'static. Unfortunately, the existing leak check treats 'static differently in some cases (see also #33684), so if we are performing an operation that may need to prove "leak-check" related things, we leave 'static alone.

'static is also special cased when winnowing candidates when selecting implementation candidates, so we also have to leave 'static alone for queries that do selection.

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx>[src]

pub fn make_canonicalized_query_response<T>(
    &self,
    inference_vars: CanonicalVarValues<'tcx>,
    answer: T,
    fulfill_cx: &mut (dyn TraitEngine<'tcx> + 'tcx)
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, T>>, NoSolution> where
    T: Debug + TypeFoldable<'tcx>,
    Canonical<'tcx, QueryResponse<'tcx, T>>: ArenaAllocatable<'tcx, Canonical<'tcx, QueryResponse<'tcx, T>>>, 
[src]

This method is meant to be invoked as the final step of a canonical query implementation. It is given:

  • the instantiated variables inference_vars created from the query key
  • the result answer of the query
  • a fulfillment context fulfill_cx that may contain various obligations which have yet to be proven.

Given this, the function will process the obligations pending in fulfill_cx:

  • If all the obligations can be proven successfully, it will package up any resulting region obligations (extracted from infcx) along with the fully resolved value answer into a query result (which is then itself canonicalized).
  • If some obligations can be neither proven nor disproven, then the same thing happens, but the resulting query is marked as ambiguous.
  • Finally, if any of the obligations result in a hard error, then Err(NoSolution) is returned.

pub fn make_query_response_ignoring_pending_obligations<T>(
    &self,
    inference_vars: CanonicalVarValues<'tcx>,
    answer: T
) -> Canonical<'tcx, QueryResponse<'tcx, T>> where
    T: Debug + TypeFoldable<'tcx>, 
[src]

A version of make_canonicalized_query_response that does not pack in obligations, for contexts that want to drop pending obligations instead of treating them as an ambiguity (e.g. typeck "probing" contexts).

If you DO want to keep track of pending obligations (which include all region obligations, so this includes all cases that care about regions) with this function, you have to do it yourself, by e.g., having them be a part of the answer.

pub fn instantiate_query_response_and_region_obligations<R>(
    &self,
    cause: &ObligationCause<'tcx>,
    param_env: ParamEnv<'tcx>,
    original_values: &OriginalQueryValues<'tcx>,
    query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>
) -> Result<InferOk<'tcx, R>, TypeError<'tcx>> where
    R: Debug + TypeFoldable<'tcx>, 
[src]

Given the (canonicalized) result to a canonical query, instantiates the result so it can be used, plugging in the values from the canonical query. (Note that the result may have been ambiguous; you should check the certainty level of the query before applying this function.)

To get a good understanding of what is happening here, check out the chapter in the rustc dev guide.

pub fn instantiate_nll_query_response_and_region_obligations<R>(
    &self,
    cause: &ObligationCause<'tcx>,
    param_env: ParamEnv<'tcx>,
    original_values: &OriginalQueryValues<'tcx>,
    query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
    output_query_region_constraints: &mut QueryRegionConstraints<'tcx>
) -> Result<InferOk<'tcx, R>, TypeError<'tcx>> where
    R: Debug + TypeFoldable<'tcx>, 
[src]

An alternative to instantiate_query_response_and_region_obligations that is more efficient for NLL. NLL is a bit more advanced in the "transition to chalk" than the rest of the compiler. During the NLL type check, all of the "processing" of types and things happens in queries -- the NLL checker itself is only interested in the region obligations ('a: 'b or T: 'b) that come out of these queries, which it wants to convert into MIR-based constraints and solve. Therefore, it is most convenient for the NLL Type Checker to directly consume the QueryOutlivesConstraint values that arise from doing a query. This is contrast to other parts of the compiler, which would prefer for those QueryOutlivesConstraint to be converted into the older infcx-style constraints (e.g., calls to sub_regions or register_region_obligation).

Therefore, instantiate_nll_query_response_and_region_obligations performs the same basic operations as instantiate_query_response_and_region_obligations but it returns its result differently:

  • It creates a substitution S that maps from the original query variables to the values computed in the query result. If any errors arise, they are propagated back as an Err result.
  • In the case of a successful substitution, we will append QueryOutlivesConstraint values onto the output_query_region_constraints vector for the solver to use (if an error arises, some values may also be pushed, but they should be ignored).
  • It can happen (though it rarely does currently) that equating types and things will give rise to subobligations that must be processed. In this case, those subobligations are propagated back in the return value.
  • Finally, the query result (of type R) is propagated back, after applying the substitution S.

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx>[src]

pub fn instantiate_canonical_with_fresh_inference_vars<T>(
    &self,
    span: Span,
    canonical: &Canonical<'tcx, T>
) -> (T, CanonicalVarValues<'tcx>) where
    T: TypeFoldable<'tcx>, 
[src]

Creates a substitution S for the canonical value with fresh inference variables and applies it to the canonical value. Returns both the instantiated result and the substitution S.

This is only meant to be invoked as part of constructing an inference context at the start of a query (see InferCtxtBuilder::enter_with_canonical). It basically brings the canonical value "into scope" within your new infcx.

At the end of processing, the substitution S (once canonicalized) then represents the values that you computed for each of the canonical inputs to your query.

impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx>[src]

pub fn super_combine_tys<R>(
    &self,
    relation: &mut R,
    a: &'tcx TyS<'tcx>,
    b: &'tcx TyS<'tcx>
) -> Result<&'tcx TyS<'tcx>, TypeError<'tcx>> where
    R: TypeRelation<'tcx>, 
[src]

pub fn super_combine_consts<R>(
    &self,
    relation: &mut R,
    a: &'tcx Const<'tcx>,
    b: &'tcx Const<'tcx>
) -> Result<&'tcx Const<'tcx>, TypeError<'tcx>> where
    R: ConstEquateRelation<'tcx>, 
[src]

pub fn unify_const_variable(
    &self,
    vid_is_expected: bool,
    vid: ConstVid<'tcx>,
    value: &'tcx Const<'tcx>
) -> Result<&'tcx Const<'tcx>, TypeError<'tcx>>
[src]

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn extract_type_name(
    &self,
    ty: &'tcx TyS<'tcx>,
    highlight: Option<RegionHighlightMode>
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>)
[src]

pub fn need_type_info_err(
    &self,
    body_id: Option<BodyId>,
    span: Span,
    ty: &'tcx TyS<'tcx>,
    error_code: TypeAnnotationNeeded
) -> DiagnosticBuilder<'tcx>
[src]

pub fn need_type_info_err_const(
    &self,
    body_id: Option<BodyId>,
    span: Span,
    ct: &'tcx Const<'tcx>,
    error_code: TypeAnnotationNeeded
) -> DiagnosticBuilder<'tcx>
[src]

pub fn need_type_info_err_in_generator(
    &self,
    kind: GeneratorKind,
    span: Span,
    ty: &'tcx TyS<'tcx>
) -> DiagnosticBuilder<'tcx>
[src]

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx>[src]

pub fn try_report_nice_region_error(
    &self,
    error: &RegionResolutionError<'tcx>
) -> bool
[src]

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)[src]

pub fn note_type_err(
    &self,
    diag: &mut DiagnosticBuilder<'tcx>,
    cause: &ObligationCause<'tcx>,
    secondary_span: Option<(Span, String)>,
    values: Option<ValuePairs<'tcx>>,
    terr: &TypeError<'tcx>
)
[src]

pub fn report_and_explain_type_error(
    &self,
    trace: TypeTrace<'tcx>,
    terr: &TypeError<'tcx>
) -> DiagnosticBuilder<'tcx>
[src]

pub fn report_generic_bound_failure(
    &self,
    span: Span,
    origin: Option<SubregionOrigin<'tcx>>,
    bound_kind: GenericKind<'tcx>,
    sub: &'tcx RegionKind
)
[src]

pub fn construct_generic_bound_failure(
    &self,
    span: Span,
    origin: Option<SubregionOrigin<'tcx>>,
    bound_kind: GenericKind<'tcx>,
    sub: &'tcx RegionKind
) -> DiagnosticBuilder<'a>
[src]

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn fudge_inference_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where
    F: FnOnce() -> Result<T, E>,
    T: TypeFoldable<'tcx>, 
[src]

This rather funky routine is used while processing expected types. What happens here is that we want to propagate a coercion through the return type of a fn to its argument. Consider the type of Option::Some, which is basically for<T> fn(T) -> Option<T>. So if we have an expression Some(&[1, 2, 3]), and that has the expected type Option<&[u32]>, we would like to type check &[1, 2, 3] with the expectation of &[u32]. This will cause us to coerce from &[u32; 3] to &[u32] and make the users life more pleasant.

The way we do this is using fudge_inference_if_ok. What the routine actually does is to start a snapshot and execute the closure f. In our example above, what this closure will do is to unify the expectation (Option<&[u32]>) with the actual return type (Option<?T>, where ?T represents the variable instantiated for T). This will cause ?T to be unified with &?a [u32], where ?a is a fresh lifetime variable. The input type (?T) is then returned by f().

At this point, fudge_inference_if_ok will normalize all type variables, converting ?T to &?a [u32] and end the snapshot. The problem is that we can't just return this type out, because it references the region variable ?a, and that region variable was popped when we popped the snapshot.

So what we do is to keep a list (region_vars, in the code below) of region variables created during the snapshot (here, ?a). We fold the return value and replace any such regions with a new region variable (e.g., ?b) and return the result (&?b [u32]). This can then be used as the expectation for the fn argument.

The important point here is that, for soundness purposes, the regions in question are not particularly important. We will use the expected types to guide coercions, but we will still type-check the resulting types from those coercions against the actual types (?T, Option<?T>) -- and remember that after the snapshot is popped, the variable ?T is no longer unified.

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn replace_bound_vars_with_placeholders<T>(
    &self,
    binder: &Binder<T>
) -> (T, BTreeMap<BoundRegion, &'tcx RegionKind>) where
    T: TypeFoldable<'tcx>, 
[src]

Replaces all regions (resp. types) bound by binder with placeholder regions (resp. types) and return a map indicating which bound-region placeholder region. This is the first step of checking subtyping when higher-ranked things are involved.

Important: You have to be careful to not leak these placeholders, for more information about how placeholders and HRTBs work, see the rustc dev guide.

pub fn leak_check(
    &self,
    overly_polymorphic: bool,
    snapshot: &CombinedSnapshot<'_, 'tcx>
) -> Result<(), TypeError<'tcx>>
[src]

See infer::region_constraints::RegionConstraintCollector::leak_check.

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx>[src]

pub fn register_region_obligation(
    &self,
    body_id: HirId,
    obligation: RegionObligation<'tcx>
)
[src]

Registers that the given region obligation must be resolved from within the scope of body_id. These regions are enqueued and later processed by regionck, when full type information is available (see region_obligations field for more information).

pub fn register_region_obligation_with_cause(
    &self,
    sup_type: &'tcx TyS<'tcx>,
    sub_region: &'tcx RegionKind,
    cause: &ObligationCause<'tcx>
)
[src]

pub fn take_registered_region_obligations(
    &self
) -> Vec<(HirId, RegionObligation<'tcx>)>
[src]

Trait queries just want to pass back type obligations "as is"

pub fn process_registered_region_obligations(
    &self,
    region_bound_pairs_map: &HashMap<HirId, Vec<(&'tcx RegionKind, GenericKind<'tcx>)>, BuildHasherDefault<FxHasher>>,
    implicit_region_bound: Option<&'tcx RegionKind>,
    param_env: ParamEnv<'tcx>
)
[src]

Process the region obligations that must be proven (during regionck) for the given body_id, given information about the region bounds in scope and so forth. This function must be invoked for all relevant body-ids before region inference is done (or else an assert will fire).

See the region_obligations field of InferCtxt for some comments about how this function fits into the overall expected flow of the inferencer. The key point is that it is invoked after all type-inference variables have been bound -- towards the end of regionck. This also ensures that the region-bound-pairs are available (see comments above regarding closures).

Parameters

  • region_bound_pairs: the set of region bounds implied by the parameters and where-clauses. In particular, each pair ('a, K) in this list tells us that the bounds in scope indicate that K: 'a, where K is either a generic parameter like T or a projection like T::Item.
  • implicit_region_bound: if some, this is a region bound that is considered to hold for all type parameters (the function body).
  • param_env is the parameter environment for the enclosing function.
  • body_id is the body-id whose region obligations are being processed.

Returns

This function may have to perform normalizations, and hence it returns an InferOk with subobligations that must be processed.

pub fn type_must_outlive(
    &self,
    region_bound_pairs: &Vec<(&'tcx RegionKind, GenericKind<'tcx>)>,
    implicit_region_bound: Option<&'tcx RegionKind>,
    param_env: ParamEnv<'tcx>,
    origin: SubregionOrigin<'tcx>,
    ty: &'tcx TyS<'tcx>,
    region: &'tcx RegionKind
)
[src]

Processes a single ad-hoc region obligation that was not registered in advance.

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn is_in_snapshot(&self) -> bool[src]

pub fn freshen<T>(&self, t: T) -> T where
    T: TypeFoldable<'tcx>, 
[src]

pub fn type_var_diverges(&'a self, ty: &TyS<'_>) -> bool[src]

pub fn freshener(&'b self) -> TypeFreshener<'b, 'tcx>[src]

pub fn type_is_unconstrained_numeric(
    &'a self,
    ty: &TyS<'_>
) -> UnconstrainedNumeric
[src]

pub fn unsolved_variables(&self) -> Vec<&'tcx TyS<'tcx>>[src]

pub fn save_and_restore_in_snapshot_flag<F, R>(&self, func: F) -> R where
    F: FnOnce(&InferCtxt<'a, 'tcx>) -> R, 
[src]

Clear the "currently in a snapshot" flag, invoke the closure, then restore the flag to its original value. This flag is a debugging measure designed to detect cases where we start a snapshot, create type variables, and register obligations which may involve those type variables in the fulfillment cx, potentially leaving "dangling type variables" behind. In such cases, an assertion will fail when attempting to register obligations, within a snapshot. Very useful, much better than grovelling through megabytes of RUSTC_LOG output.

HOWEVER, in some cases the flag is unhelpful. In particular, we sometimes create a "mini-fulfilment-cx" in which we enroll obligations. As long as this fulfillment cx is fully drained before we return, this is not a problem, as there won't be any escaping obligations in the main cx. In those cases, you can use this function.

pub fn commit_unconditionally<R, F>(&self, f: F) -> R where
    F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R, 
[src]

Executes f and commit the bindings.

pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where
    F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> Result<T, E>, 
[src]

Execute f and commit the bindings if closure f returns Ok(_).

pub fn probe<R, F>(&self, f: F) -> R where
    F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R, 
[src]

Execute f then unroll any bindings it creates.

pub fn probe_maybe_skip_leak_check<R, F>(&self, should_skip: bool, f: F) -> R where
    F: FnOnce(&CombinedSnapshot<'a, 'tcx>) -> R, 
[src]

If should_skip is true, then execute f then unroll any bindings it creates.

pub fn region_constraints_added_in_snapshot(
    &self,
    snapshot: &CombinedSnapshot<'a, 'tcx>
) -> Option<bool>
[src]

Scan the constraints produced since snapshot began and returns:

  • None -- if none of them involve "region outlives" constraints
  • Some(true) -- if there are 'a: 'b constraints where 'a or 'b is a placeholder
  • Some(false) -- if there are 'a: 'b constraints but none involve placeholders

pub fn add_given(&self, sub: &'tcx RegionKind, sup: RegionVid)[src]

pub fn can_sub<T>(
    &self,
    param_env: ParamEnv<'tcx>,
    a: T,
    b: T
) -> Result<(), TypeError<'tcx>> where
    T: ToTrace<'tcx>, 
[src]

pub fn can_eq<T>(
    &self,
    param_env: ParamEnv<'tcx>,
    a: T,
    b: T
) -> Result<(), TypeError<'tcx>> where
    T: ToTrace<'tcx>, 
[src]

pub fn sub_regions(
    &self,
    origin: SubregionOrigin<'tcx>,
    a: &'tcx RegionKind,
    b: &'tcx RegionKind
)
[src]

pub fn member_constraint(
    &self,
    opaque_type_def_id: DefId,
    definition_span: Span,
    hidden_ty: &'tcx TyS<'tcx>,
    region: &'tcx RegionKind,
    in_regions: &Rc<Vec<&'tcx RegionKind>>
)
[src]

Require that the region r be equal to one of the regions in the set regions.

pub fn subtype_predicate(
    &self,
    cause: &ObligationCause<'tcx>,
    param_env: ParamEnv<'tcx>,
    predicate: Binder<SubtypePredicate<'tcx>>
) -> Option<Result<InferOk<'tcx, ()>, TypeError<'tcx>>>
[src]

pub fn region_outlives_predicate(
    &self,
    cause: &ObligationCause<'tcx>,
    predicate: Binder<OutlivesPredicate<&'tcx RegionKind, &'tcx RegionKind>>
) -> Result<(), TypeError<'tcx>>
[src]

pub fn next_ty_var_id(
    &self,
    diverging: bool,
    origin: TypeVariableOrigin
) -> TyVid
[src]

pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> &'tcx TyS<'tcx>[src]

pub fn next_ty_var_in_universe(
    &self,
    origin: TypeVariableOrigin,
    universe: UniverseIndex
) -> &'tcx TyS<'tcx>
[src]

pub fn next_diverging_ty_var(
    &self,
    origin: TypeVariableOrigin
) -> &'tcx TyS<'tcx>
[src]

pub fn next_const_var(
    &self,
    ty: &'tcx TyS<'tcx>,
    origin: ConstVariableOrigin
) -> &'tcx Const<'tcx>
[src]

pub fn next_const_var_in_universe(
    &self,
    ty: &'tcx TyS<'tcx>,
    origin: ConstVariableOrigin,
    universe: UniverseIndex
) -> &'tcx Const<'tcx>
[src]

pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx>[src]

pub fn next_int_var(&self) -> &'tcx TyS<'tcx>[src]

pub fn next_float_var(&self) -> &'tcx TyS<'tcx>[src]

pub fn next_region_var(&self, origin: RegionVariableOrigin) -> &'tcx RegionKind[src]

Creates a fresh region variable with the next available index. The variable will be created in the maximum universe created thus far, allowing it to name any region created thus far.

pub fn next_region_var_in_universe(
    &self,
    origin: RegionVariableOrigin,
    universe: UniverseIndex
) -> &'tcx RegionKind
[src]

Creates a fresh region variable with the next available index in the given universe; typically, you can use next_region_var and just use the maximal universe.

pub fn num_region_vars(&self) -> usize[src]

Number of region variables created so far.

pub fn next_nll_region_var(
    &self,
    origin: NLLRegionVariableOrigin
) -> &'tcx RegionKind
[src]

Just a convenient wrapper of next_region_var for using during NLL.

pub fn next_nll_region_var_in_universe(
    &self,
    origin: NLLRegionVariableOrigin,
    universe: UniverseIndex
) -> &'tcx RegionKind
[src]

Just a convenient wrapper of next_region_var for using during NLL.

pub fn var_for_def(
    &self,
    span: Span,
    param: &GenericParamDef
) -> GenericArg<'tcx>
[src]

pub fn fresh_substs_for_item(
    &self,
    span: Span,
    def_id: DefId
) -> &'tcx List<GenericArg<'tcx>>
[src]

Given a set of generics defined on a type or impl, returns a substitution mapping each type/region parameter to a fresh inference variable.

pub fn is_tainted_by_errors(&self) -> bool[src]

Returns true if errors have been reported since this infcx was created. This is sometimes used as a heuristic to skip reporting errors that often occur as a result of earlier errors, but where it's hard to be 100% sure (e.g., unresolved inference variables, regionck errors).

pub fn set_tainted_by_errors(&self)[src]

Set the "tainted by errors" flag to true. We call this when we observe an error from a prior pass.

pub fn resolve_regions_and_report_errors(
    &self,
    region_context: DefId,
    outlives_env: &OutlivesEnvironment<'tcx>,
    mode: RegionckMode
)
[src]

Process the region constraints and report any errors that result. After this, no more unification operations should be done -- or the compiler will panic -- but it is legal to use resolve_vars_if_possible as well as fully_resolve.

pub fn take_and_reset_region_constraints(&self) -> RegionConstraintData<'tcx>[src]

Obtains (and clears) the current set of region constraints. The inference context is still usable: further unifications will simply add new constraints.

This method is not meant to be used with normal lexical region resolution. Rather, it is used in the NLL mode as a kind of interim hack: basically we run normal type-check and generate region constraints as normal, but then we take them and translate them into the form that the NLL solver understands. See the NLL module for mode details.

pub fn with_region_constraints<R>(
    &self,
    op: impl FnOnce(&RegionConstraintData<'tcx>) -> R
) -> R
[src]

Gives temporary access to the region constraint data.

pub fn take_region_var_origins(&self) -> IndexVec<RegionVid, RegionVariableInfo>[src]

Takes ownership of the list of variable regions. This implies that all the region constraints have already been taken, and hence that resolve_regions_and_report_errors can never be called. This is used only during NLL processing to "hand off" ownership of the set of region variables into the NLL region context.

pub fn ty_to_string(&self, t: &'tcx TyS<'tcx>) -> String[src]

pub fn tys_to_string(&self, ts: &[&'tcx TyS<'tcx>]) -> String[src]

pub fn trait_ref_to_string(&self, t: &TraitRef<'tcx>) -> String[src]

pub fn probe_ty_var(&self, vid: TyVid) -> Result<&'tcx TyS<'tcx>, UniverseIndex>[src]

If TyVar(vid) resolves to a type, return that type. Else, return the universe index of TyVar(vid).

pub fn shallow_resolve<T>(&self, value: T) -> T where
    T: TypeFoldable<'tcx>, 
[src]

Resolve any type variables found in value -- but only one level. So, if the variable ?X is bound to some type Foo<?Y>, then this would return Foo<?Y> (but ?Y may itself be bound to a type).

Useful when you only need to inspect the outermost level of the type and don't care about nested types (or perhaps you will be resolving them as well, e.g. in a loop).

pub fn root_var(&self, var: TyVid) -> TyVid[src]

pub fn resolve_vars_if_possible<T>(&self, value: &T) -> T where
    T: TypeFoldable<'tcx>, 
[src]

Where possible, replaces type/const variables in value with their final value. Note that region variables are unaffected. If a type/const variable has not been unified, it is left as is. This is an idempotent operation that does not affect inference state in any way and so you can do it at will.

pub fn unresolved_type_vars<T>(
    &self,
    value: &T
) -> Option<(&'tcx TyS<'tcx>, Option<Span>)> where
    T: TypeFoldable<'tcx>, 
[src]

Returns the first unresolved variable contained in T. In the process of visiting T, this will resolve (where possible) type variables in T, but it never constructs the final, resolved type, so it's more efficient than resolve_vars_if_possible().

pub fn probe_const_var(
    &self,
    vid: ConstVid<'tcx>
) -> Result<&'tcx Const<'tcx>, UniverseIndex>
[src]

pub fn fully_resolve<T>(&self, value: &T) -> Result<T, FixupError<'tcx>> where
    T: TypeFoldable<'tcx>, 
[src]

Attempts to resolve all type/region/const variables in value. Region inference must have been run already (e.g., by calling resolve_regions_and_report_errors). If some variable was never unified, an Err results.

This method is idempotent, but it not typically not invoked except during the writeback phase.

pub fn type_error_struct_with_diag<M>(
    &self,
    sp: Span,
    mk_diag: M,
    actual_ty: &'tcx TyS<'tcx>
) -> DiagnosticBuilder<'tcx> where
    M: FnOnce(String) -> DiagnosticBuilder<'tcx>, 
[src]

pub fn report_mismatched_types(
    &self,
    cause: &ObligationCause<'tcx>,
    expected: &'tcx TyS<'tcx>,
    actual: &'tcx TyS<'tcx>,
    err: TypeError<'tcx>
) -> DiagnosticBuilder<'tcx>
[src]

pub fn report_mismatched_consts(
    &self,
    cause: &ObligationCause<'tcx>,
    expected: &'tcx Const<'tcx>,
    actual: &'tcx Const<'tcx>,
    err: TypeError<'tcx>
) -> DiagnosticBuilder<'tcx>
[src]

pub fn replace_bound_vars_with_fresh_vars<T>(
    &self,
    span: Span,
    lbrct: LateBoundRegionConversionTime,
    value: &Binder<T>
) -> (T, BTreeMap<BoundRegion, &'tcx RegionKind>) where
    T: TypeFoldable<'tcx>, 
[src]

pub fn verify_generic_bound(
    &self,
    origin: SubregionOrigin<'tcx>,
    kind: GenericKind<'tcx>,
    a: &'tcx RegionKind,
    bound: VerifyBound<'tcx>
)
[src]

pub fn closure_kind(
    &self,
    closure_substs: &'tcx List<GenericArg<'tcx>>
) -> Option<ClosureKind>
[src]

Obtains the latest type of the given closure; this may be a closure in the current function, in which case its ClosureKind may not yet be known.

pub fn clear_caches(&self)[src]

Clears the selection, evaluation, and projection caches. This is useful when repeatedly attempting to select an Obligation while changing only its ParamEnv, since FulfillmentContext doesn't use probing.

pub fn create_next_universe(&self) -> UniverseIndex[src]

Creates and return a fresh universe that extends all previous universes. Updates self.universe to that new universe.

pub fn const_eval_resolve(
    &self,
    param_env: ParamEnv<'tcx>,
    def: WithOptConstParam<DefId>,
    substs: &'tcx List<GenericArg<'tcx>>,
    promoted: Option<Promoted>,
    span: Option<Span>
) -> Result<ConstValue<'tcx>, ErrorHandled>
[src]

Resolves and evaluates a constant.

The constant can be located on a trait like <A as B>::C, in which case the given substitutions and environment are used to resolve the constant. Alternatively if the constant has generic parameters in scope the substitutions are used to evaluate the value of the constant. For example in fn foo<T>() { let _ = [0; bar::<T>()]; } the repeat count constant bar::<T>() requires a substitution for T, if the substitution for T is still too generic for the constant to be evaluated then Err(ErrorHandled::TooGeneric) is returned.

This handles inferences variables within both param_env and substs by performing the operation on their respective canonical forms.

pub fn ty_or_const_infer_var_changed(
    &self,
    infer_var: TyOrConstInferVar<'tcx>
) -> bool
[src]

ty_or_const_infer_var_changed is equivalent to one of these two:

  • shallow_resolve(ty) != ty (where ty.kind = ty::Infer(_))
  • shallow_resolve(ct) != ct (where ct.kind = ty::ConstKind::Infer(_))

However, ty_or_const_infer_var_changed is more efficient. It's always inlined, despite being large, because it has only two call sites that are extremely hot (both in traits::fulfill's checking of stalled_on inference variables), and it handles both Ty and ty::Const without having to resort to storing full GenericArgs in stalled_on.

impl<'a, 'tcx> InferCtxt<'a, 'tcx>[src]

pub fn report_extra_impl_obligation(
    &self,
    error_span: Span,
    item_name: Symbol,
    _impl_item_def_id: DefId,
    trait_item_def_id: DefId,
    requirement: &dyn Display
) -> DiagnosticBuilder<'tcx>
[src]

Trait Implementations

impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx>[src]

fn partially_normalize_associated_types_in<T>(
    &self,
    span: Span,
    body_id: HirId,
    param_env: ParamEnv<'tcx>,
    value: &T
) -> InferOk<'tcx, T> where
    T: TypeFoldable<'tcx>, 
[src]

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

impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]

fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
    &self,
    parent_def_id: LocalDefId,
    body_id: HirId,
    param_env: ParamEnv<'tcx>,
    value: &T,
    value_span: Span
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>
[src]

Replaces all opaque types in value with fresh inference variables and creates appropriate obligations. For example, given the input:

impl Iterator<Item = impl Debug>

this method would create two type variables, ?0 and ?1. It would return the type ?0 but also the obligations:

?0: Iterator<Item = ?1>
?1: Debug

Moreover, it returns a OpaqueTypeMap that would map ?0 to info about the impl Iterator<..> type and ?1 to info about the impl Debug type.

Parameters

  • parent_def_id -- the DefId of the function in which the opaque type is defined
  • body_id -- the body-id with which the resulting obligations should be associated
  • param_env -- the in-scope parameter environment to be used for obligations
  • value -- the value within which we are instantiating opaque types
  • value_span -- the span where the value came from, used in error reporting

fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(
    &self,
    opaque_types: &OpaqueTypeMap<'tcx>,
    free_region_relations: &FRR
)
[src]

Given the map opaque_types containing the opaque impl Trait types whose underlying, hidden types are being inferred, this method adds constraints to the regions appearing in those underlying hidden types to ensure that they at least do not refer to random scopes within the current function. These constraints are not (quite) sufficient to guarantee that the regions are actually legal values; that final condition is imposed after region inference is done.

The Problem

Let's work through an example to explain how it works. Assume the current function is as follows:

fn foo<'a, 'b>(..) -> (impl Bar<'a>, impl Bar<'b>)

Here, we have two impl Trait types whose values are being inferred (the impl Bar<'a> and the impl Bar<'b>). Conceptually, this is sugar for a setup where we define underlying opaque types (Foo1, Foo2) and then, in the return type of foo, we reference those definitions:

type Foo1<'x> = impl Bar<'x>;
type Foo2<'x> = impl Bar<'x>;
fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
                   //  ^^^^ ^^
                   //  |    |
                   //  |    substs
                   //  def_id

As indicating in the comments above, each of those references is (in the compiler) basically a substitution (substs) applied to the type of a suitable def_id (which identifies Foo1 or Foo2).

Now, at this point in compilation, what we have done is to replace each of the references (Foo1<'a>, Foo2<'b>) with fresh inference variables C1 and C2. We wish to use the values of these variables to infer the underlying types of Foo1 and Foo2. That is, this gives rise to higher-order (pattern) unification constraints like:

for<'a> (Foo1<'a> = C1)
for<'b> (Foo1<'b> = C2)

For these equation to be satisfiable, the types C1 and C2 can only refer to a limited set of regions. For example, C1 can only refer to 'static and 'a, and C2 can only refer to 'static and 'b. The job of this function is to impose that constraint.

Up to this point, C1 and C2 are basically just random type inference variables, and hence they may contain arbitrary regions. In fact, it is fairly likely that they do! Consider this possible definition of foo:

fn foo<'a, 'b>(x: &'a i32, y: &'b i32) -> (impl Bar<'a>, impl Bar<'b>) {
        (&*x, &*y)
    }

Here, the values for the concrete types of the two impl traits will include inference variables:

&'0 i32
&'1 i32

Ordinarily, the subtyping rules would ensure that these are sufficiently large. But since impl Bar<'a> isn't a specific type per se, we don't get such constraints by default. This is where this function comes into play. It adds extra constraints to ensure that all the regions which appear in the inferred type are regions that could validly appear.

This is actually a bit of a tricky constraint in general. We want to say that each variable (e.g., '0) can only take on values that were supplied as arguments to the opaque type (e.g., 'a for Foo1<'a>) or 'static, which is always in scope. We don't have a constraint quite of this kind in the current region checker.

The Solution

We generally prefer to make <= constraints, since they integrate best into the region solver. To do that, we find the "minimum" of all the arguments that appear in the substs: that is, some region which is less than all the others. In the case of Foo1<'a>, that would be 'a (it's the only choice, after all). Then we apply that as a least bound to the variables (e.g., 'a <= '0).

In some cases, there is no minimum. Consider this example:

fn baz<'a, 'b>() -> impl Trait<'a, 'b> { ... }

Here we would report a more complex "in constraint", like 'r in ['a, 'b, 'static] (where 'r is some region appearing in the hidden type).

Constrain regions, not the hidden concrete type

Note that generating constraints on each region Rc is not the same as generating an outlives constraint on Tc iself. For example, if we had a function like this:

fn foo<'a, T>(x: &'a u32, y: T) -> impl Foo<'a> {
  (x, y)
}

// Equivalent to:
type FooReturn<'a, T> = impl Foo<'a>;
fn foo<'a, T>(..) -> FooReturn<'a, T> { .. }

then the hidden type Tc would be (&'0 u32, T) (where '0 is an inference variable). If we generated a constraint that Tc: 'a, then this would incorrectly require that T: 'a -- but this is not necessary, because the opaque type we create will be allowed to reference T. So we only generate a constraint that '0: 'a.

The free_region_relations parameter

The free_region_relations argument is used to find the "minimum" of the regions supplied to a given opaque type. It must be a relation that can answer whether 'a <= 'b, where 'a and 'b are regions that appear in the "substs" for the opaque type references (the <'a> in Foo1<'a>).

Note that we do not impose the constraints based on the generic regions from the Foo1 definition (e.g., 'x). This is because the constraints we are imposing here is basically the concern of the one generating the constraining type C1, which is the current function. It also means that we can take "implied bounds" into account in some cases:

trait SomeTrait<'a, 'b> { }
fn foo<'a, 'b>(_: &'a &'b u32) -> impl SomeTrait<'a, 'b> { .. }

Here, the fact that 'b: 'a is known only because of the implied bounds from the &'a &'b u32 parameter, and is not "inherent" to the opaque type definition.

Parameters

  • opaque_types -- the map produced by instantiate_opaque_types
  • free_region_relations -- something that can be used to relate the free regions ('a) that appear in the impl trait.

fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
    &self,
    def_id: DefId,
    opaque_defn: &OpaqueTypeDecl<'tcx>,
    mode: GenerateMemberConstraints,
    free_region_relations: &FRR
)
[src]

See constrain_opaque_types for documentation.

fn generate_member_constraint(
    &self,
    concrete_ty: Ty<'tcx>,
    opaque_defn: &OpaqueTypeDecl<'tcx>,
    opaque_type_def_id: DefId,
    first_own_region: usize
)
[src]

As a fallback, we sometimes generate an "in constraint". For a case like impl Foo<'a, 'b>, where 'a and 'b cannot be related, we would generate a constraint 'r in ['a, 'b, 'static] for each region 'r that appears in the hidden type (i.e., it must be equal to 'a, 'b, or 'static).

conflict1 and conflict2 are the two region bounds that we detected which were unrelated. They are used for diagnostics.

fn member_constraint_feature_gate(
    &self,
    opaque_defn: &OpaqueTypeDecl<'tcx>,
    opaque_type_def_id: DefId,
    conflict1: Region<'tcx>,
    conflict2: Region<'tcx>
) -> bool
[src]

Member constraints are presently feature-gated except for async-await. We expect to lift this once we've had a bit more time.

fn infer_opaque_definition_from_instantiation(
    &self,
    def_id: DefId,
    substs: SubstsRef<'tcx>,
    instantiated_ty: Ty<'tcx>,
    span: Span
) -> Ty<'tcx>
[src]

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

impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]

fn describe_enclosure(&self, hir_id: HirId) -> Option<&'static str>[src]

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

impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]

fn suggest_dereferences(
    &self,
    obligation: &PredicateObligation<'tcx>,
    err: &mut DiagnosticBuilder<'tcx>,
    trait_ref: &PolyTraitRef<'tcx>,
    points_at_arg: bool
)
[src]

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

fn get_closure_name(
    &self,
    def_id: DefId,
    err: &mut DiagnosticBuilder<'_>,
    msg: &str
) -> Option<String>
[src]

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.

fn suggest_fn_call(
    &self,
    obligation: &PredicateObligation<'tcx>,
    err: &mut DiagnosticBuilder<'_>,
    trait_ref: &Binder<TraitRef<'tcx>>,
    points_at_arg: bool
)
[src]

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.

fn suggest_remove_reference(
    &self,
    obligation: &PredicateObligation<'tcx>,
    err: &mut DiagnosticBuilder<'_>,
    trait_ref: &Binder<TraitRef<'tcx>>
)
[src]

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.

fn suggest_change_mut(
    &self,
    obligation: &PredicateObligation<'tcx>,
    err: &mut DiagnosticBuilder<'_>,
    trait_ref: &Binder<TraitRef<'tcx>>,
    points_at_arg: bool
)
[src]

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

fn suggest_impl_trait(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    span: Span,
    obligation: &PredicateObligation<'tcx>,
    trait_ref: &Binder<TraitRef<'tcx>>
) -> bool
[src]

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.

fn maybe_note_obligation_cause_for_async_await(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    obligation: &PredicateObligation<'tcx>
) -> bool
[src]

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.

fn note_obligation_cause_for_async_await(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    interior_or_upvar_span: GeneratorInteriorOrUpvar,
    interior_extra_info: Option<(Option<Span>, Span, Option<HirId>, Option<Span>)>,
    inner_generator_body: Option<&Body<'tcx>>,
    outer_generator: Option<DefId>,
    trait_ref: TraitRef<'tcx>,
    target_ty: Ty<'tcx>,
    typeck_results: &TypeckResults<'tcx>,
    obligation: &PredicateObligation<'tcx>,
    next_code: Option<&ObligationCauseCode<'tcx>>
)
[src]

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

impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]

fn report_overflow_error<T>(
    &self,
    obligation: &Obligation<'tcx, T>,
    suggest_increasing_limit: bool
) -> ! where
    T: Display + TypeFoldable<'tcx>, 
[src]

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.

fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ![src]

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

fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)>[src]

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.

fn report_arg_count_mismatch(
    &self,
    span: Span,
    found_span: Option<Span>,
    expected_args: Vec<ArgKind>,
    found_args: Vec<ArgKind>,
    is_closure: bool
) -> DiagnosticBuilder<'tcx>
[src]

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

impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx>[src]

fn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool[src]

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

fn predicate_must_hold_considering_regions(
    &self,
    obligation: &PredicateObligation<'tcx>
) -> bool
[src]

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.

fn predicate_must_hold_modulo_regions(
    &self,
    obligation: &PredicateObligation<'tcx>
) -> bool
[src]

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.

fn evaluate_obligation(
    &self,
    obligation: &PredicateObligation<'tcx>
) -> Result<EvaluationResult, OverflowError>
[src]

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

impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx>[src]

fn implied_outlives_bounds(
    &self,
    param_env: ParamEnv<'tcx>,
    body_id: HirId,
    ty: Ty<'tcx>,
    span: Span
) -> Vec<OutlivesBound<'tcx>>
[src]

Implied bounds are region relationships that we deduce automatically. The idea is that (e.g.) a caller must check that a function's argument types are well-formed immediately before calling that fn, and hence the callee can assume that its argument types are well-formed. This may imply certain relationships between generic parameters. For example:

fn foo<'a,T>(x: &'a T)

can only be called with a 'a and T such that &'a T is WF. For &'a T to be WF, T: 'a must hold. So we can assume T: 'a.

Parameters

  • param_env, the where-clauses in scope
  • body_id, the body-id to use when normalizing assoc types. Note that this may cause outlives obligations to be injected into the inference context with this body-id.
  • ty, the type that we are supposed to assume is WF.
  • span, a span to use when normalizing, hopefully not important, might be useful if a bug! occurs.

impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx>[src]

fn get_parent_trait_ref(
    &self,
    code: &ObligationCauseCode<'tcx>
) -> Option<(String, Option<Span>)>
[src]

Gets the parent trait chain start

fn note_version_mismatch(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    trait_ref: &PolyTraitRef<'tcx>
)
[src]

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

fn predicate_can_apply(
    &self,
    param_env: ParamEnv<'tcx>,
    pred: PolyTraitRef<'tcx>
) -> bool
[src]

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

Auto Trait Implementations

impl<'a, 'tcx> !RefUnwindSafe for InferCtxt<'a, 'tcx>

impl<'a, 'tcx> !Send for InferCtxt<'a, 'tcx>

impl<'a, 'tcx> !Sync for InferCtxt<'a, 'tcx>

impl<'a, 'tcx> Unpin for InferCtxt<'a, 'tcx> where
    'tcx: 'a, 

impl<'a, 'tcx> !UnwindSafe for InferCtxt<'a, 'tcx>

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]