[−][src]Struct rustc_trait_selection::infer::InferCtxt
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: usizeTrack 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
impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx>[src]
pub fn type_is_copy_modulo_regions(
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span
) -> bool[src]
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
span: Span
) -> bool
pub 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]
&self,
span: Span,
body_id: HirId,
param_env: ParamEnv<'tcx>,
value: T
) -> InferOk<'tcx, T> where
T: TypeFoldable<'tcx>,
Normalizes associated types in value, potentially returning
new obligations that must further be processed.
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]
pub 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]
&self,
parent_def_id: LocalDefId,
body_id: HirId,
param_env: ParamEnv<'tcx>,
value: T,
value_span: Span
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)>
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-- theDefIdof the function in which the opaque type is definedbody_id-- the body-id with which the resulting obligations should be associatedparam_env-- the in-scope parameter environment to be used for obligationsvalue-- the value within which we are instantiating opaque typesvalue_span-- the span where the value came from, used in error reporting
pub fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(
&self,
opaque_types: &OpaqueTypeMap<'tcx>,
free_region_relations: &FRR
)[src]
&self,
opaque_types: &OpaqueTypeMap<'tcx>,
free_region_relations: &FRR
)
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 byinstantiate_opaque_typesfree_region_relations-- something that can be used to relate the free regions ('a) that appear in the impl trait.
pub fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
&self,
def_id: DefId,
opaque_defn: &OpaqueTypeDecl<'tcx>,
mode: GenerateMemberConstraints,
free_region_relations: &FRR
)[src]
&self,
def_id: DefId,
opaque_defn: &OpaqueTypeDecl<'tcx>,
mode: GenerateMemberConstraints,
free_region_relations: &FRR
)
See constrain_opaque_types for documentation.
pub fn generate_member_constraint(
&self,
concrete_ty: Ty<'tcx>,
opaque_defn: &OpaqueTypeDecl<'tcx>,
opaque_type_def_id: DefId,
first_own_region: usize
)[src]
&self,
concrete_ty: Ty<'tcx>,
opaque_defn: &OpaqueTypeDecl<'tcx>,
opaque_type_def_id: DefId,
first_own_region: usize
)
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.
pub fn member_constraint_feature_gate(
&self,
opaque_defn: &OpaqueTypeDecl<'tcx>,
opaque_type_def_id: DefId,
conflict1: Region<'tcx>,
conflict2: Region<'tcx>
) -> bool[src]
&self,
opaque_defn: &OpaqueTypeDecl<'tcx>,
opaque_type_def_id: DefId,
conflict1: Region<'tcx>,
conflict2: Region<'tcx>
) -> bool
Member constraints are presently feature-gated except for async-await. We expect to lift this once we've had a bit more time.
pub fn infer_opaque_definition_from_instantiation(
&self,
def_id: DefId,
substs: SubstsRef<'tcx>,
instantiated_ty: Ty<'tcx>,
span: Span
) -> Ty<'tcx>[src]
&self,
def_id: DefId,
substs: SubstsRef<'tcx>,
instantiated_ty: Ty<'tcx>,
span: Span
) -> Ty<'tcx>
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, theimpl Traittypesubsts, the substs used to instantiate this opaque typeinstantiated_ty, the inferred type C1 -- fully resolved, lifted version ofopaque_defn.concrete_ty
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]
pub(crate) fn impl_similar_to(
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> Option<DefId>[src]
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> Option<DefId>
pub(crate) 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
pub(crate) fn on_unimplemented_note(
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> OnUnimplementedNote[src]
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> OnUnimplementedNote
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]
pub fn suggest_restricting_param_bound(
&self,
err: &mut DiagnosticBuilder<'_>,
trait_ref: PolyTraitRef<'tcx>,
body_id: HirId
)[src]
&self,
err: &mut DiagnosticBuilder<'_>,
trait_ref: PolyTraitRef<'tcx>,
body_id: HirId
)
pub fn suggest_dereferences(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
points_at_arg: bool
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
points_at_arg: bool
)
When after several dereferencing, the reference satisfies the trait binding. This function provides dereference suggestion for this specific situation.
pub fn get_closure_name(
&self,
def_id: DefId,
err: &mut DiagnosticBuilder<'_>,
msg: &str
) -> Option<String>[src]
&self,
def_id: DefId,
err: &mut DiagnosticBuilder<'_>,
msg: &str
) -> Option<String>
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.
pub fn suggest_fn_call(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>,
points_at_arg: bool
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>,
points_at_arg: bool
)
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.
pub fn suggest_add_reference_to_arg(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: &Binder<TraitRef<'tcx>>,
points_at_arg: bool,
has_custom_message: bool
) -> bool[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: &Binder<TraitRef<'tcx>>,
points_at_arg: bool,
has_custom_message: bool
) -> bool
pub fn suggest_remove_reference(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>
)
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.
pub fn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>,
points_at_arg: bool
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: Binder<TraitRef<'tcx>>,
points_at_arg: bool
)
Check if the trait bound is implemented for a different mutability and note it in the final error.
pub fn suggest_semicolon_removal(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
span: Span,
trait_ref: Binder<TraitRef<'tcx>>
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'_>,
span: Span,
trait_ref: Binder<TraitRef<'tcx>>
)
pub fn return_type_span(
&self,
obligation: &PredicateObligation<'tcx>
) -> Option<Span>[src]
&self,
obligation: &PredicateObligation<'tcx>
) -> Option<Span>
pub fn suggest_impl_trait(
&self,
err: &mut DiagnosticBuilder<'_>,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_ref: Binder<TraitRef<'tcx>>
) -> bool[src]
&self,
err: &mut DiagnosticBuilder<'_>,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_ref: Binder<TraitRef<'tcx>>
) -> bool
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.
pub fn point_at_returns_when_relevant(
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>
)[src]
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>
)
pub fn report_closure_arg_mismatch(
&self,
span: Span,
found_span: Option<Span>,
expected_ref: PolyTraitRef<'tcx>,
found: PolyTraitRef<'tcx>
) -> DiagnosticBuilder<'tcx>[src]
&self,
span: Span,
found_span: Option<Span>,
expected_ref: PolyTraitRef<'tcx>,
found: PolyTraitRef<'tcx>
) -> DiagnosticBuilder<'tcx>
pub fn suggest_fully_qualified_path(
&self,
err: &mut DiagnosticBuilder<'_>,
def_id: DefId,
span: Span,
trait_ref: DefId
)[src]
&self,
err: &mut DiagnosticBuilder<'_>,
def_id: DefId,
span: Span,
trait_ref: DefId
)
pub fn maybe_note_obligation_cause_for_async_await(
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>
) -> bool[src]
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>
) -> bool
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.
pub 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]
&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>>
)
Unconditionally adds the diagnostic note described in
maybe_note_obligation_cause_for_async_await's documentation comment.
pub fn note_obligation_cause_code<T>(
&self,
err: &mut DiagnosticBuilder<'_>,
predicate: &T,
cause_code: &ObligationCauseCode<'tcx>,
obligated_types: &mut Vec<&TyS<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>
) where
T: Display, [src]
&self,
err: &mut DiagnosticBuilder<'_>,
predicate: &T,
cause_code: &ObligationCauseCode<'tcx>,
obligated_types: &mut Vec<&TyS<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>
) where
T: Display,
pub fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>)[src]
pub fn suggest_await_before_try(
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>,
trait_ref: Binder<TraitRef<'tcx>>,
span: Span
)[src]
&self,
err: &mut DiagnosticBuilder<'_>,
obligation: &PredicateObligation<'tcx>,
trait_ref: Binder<TraitRef<'tcx>>,
span: Span
)
impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx>[src]
pub fn report_fulfillment_errors(
&self,
errors: &[FulfillmentError<'tcx>],
body_id: Option<BodyId>,
fallback_has_occurred: bool
)[src]
&self,
errors: &[FulfillmentError<'tcx>],
body_id: Option<BodyId>,
fallback_has_occurred: bool
)
pub fn report_overflow_error<T>(
&self,
obligation: &Obligation<'tcx, T>,
suggest_increasing_limit: bool
) -> ! where
T: Display + TypeFoldable<'tcx>, [src]
&self,
obligation: &Obligation<'tcx, T>,
suggest_increasing_limit: bool
) -> ! where
T: Display + TypeFoldable<'tcx>,
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.
pub fn report_overflow_error_cycle(
&self,
cycle: &[PredicateObligation<'tcx>]
) -> ![src]
&self,
cycle: &[PredicateObligation<'tcx>]
) -> !
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).
pub fn report_selection_error(
&self,
obligation: &PredicateObligation<'tcx>,
error: &SelectionError<'tcx>,
fallback_has_occurred: bool,
points_at_arg: bool
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
error: &SelectionError<'tcx>,
fallback_has_occurred: bool,
points_at_arg: bool
)
pub fn get_fn_like_arguments(
&self,
node: Node<'_>
) -> Option<(Span, Vec<ArgKind>)>[src]
&self,
node: Node<'_>
) -> Option<(Span, Vec<ArgKind>)>
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.
pub 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]
&self,
span: Span,
found_span: Option<Span>,
expected_args: Vec<ArgKind>,
found_args: Vec<ArgKind>,
is_closure: bool
) -> DiagnosticBuilder<'tcx>
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]
pub fn predicate_may_hold(&self, obligation: &PredicateObligation<'tcx>) -> bool[src]
Evaluates whether the predicate can be satisfied (by any means)
in the given ParamEnv.
pub fn predicate_must_hold_considering_regions(
&self,
obligation: &PredicateObligation<'tcx>
) -> bool[src]
&self,
obligation: &PredicateObligation<'tcx>
) -> bool
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.
pub fn predicate_must_hold_modulo_regions(
&self,
obligation: &PredicateObligation<'tcx>
) -> bool[src]
&self,
obligation: &PredicateObligation<'tcx>
) -> bool
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.
pub fn evaluate_obligation(
&self,
obligation: &PredicateObligation<'tcx>
) -> Result<EvaluationResult, OverflowError>[src]
&self,
obligation: &PredicateObligation<'tcx>
) -> Result<EvaluationResult, OverflowError>
Evaluate a given predicate, capturing overflow and propagating it back.
pub fn evaluate_obligation_no_overflow(
&self,
obligation: &PredicateObligation<'tcx>
) -> EvaluationResult[src]
&self,
obligation: &PredicateObligation<'tcx>
) -> EvaluationResult
impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx>[src]
pub fn implied_outlives_bounds(
&self,
param_env: ParamEnv<'tcx>,
body_id: HirId,
ty: Ty<'tcx>,
span: Span
) -> Vec<OutlivesBound<'tcx>>[src]
&self,
param_env: ParamEnv<'tcx>,
body_id: HirId,
ty: Ty<'tcx>,
span: Span
) -> Vec<OutlivesBound<'tcx>>
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 scopebody_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 abug!occurs.
impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx>[src]
pub(in traits::error_reporting) fn error_implies(
&self,
cond: Predicate<'tcx>,
error: Predicate<'tcx>
) -> bool[src]
&self,
cond: Predicate<'tcx>,
error: Predicate<'tcx>
) -> bool
pub(in traits::error_reporting) fn report_fulfillment_error(
&self,
error: &FulfillmentError<'tcx>,
body_id: Option<BodyId>,
fallback_has_occurred: bool
)[src]
&self,
error: &FulfillmentError<'tcx>,
body_id: Option<BodyId>,
fallback_has_occurred: bool
)
pub(in traits::error_reporting) fn report_projection_error(
&self,
obligation: &PredicateObligation<'tcx>,
error: &MismatchedProjectionTypes<'tcx>
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
error: &MismatchedProjectionTypes<'tcx>
)
pub(in traits::error_reporting) fn fuzzy_match_tys(
&self,
a: Ty<'tcx>,
b: Ty<'tcx>
) -> bool[src]
&self,
a: Ty<'tcx>,
b: Ty<'tcx>
) -> bool
pub(in traits::error_reporting) fn describe_generator(
&self,
body_id: BodyId
) -> Option<&'static str>[src]
&self,
body_id: BodyId
) -> Option<&'static str>
pub(in traits::error_reporting) fn find_similar_impl_candidates(
&self,
trait_ref: PolyTraitRef<'tcx>
) -> Vec<TraitRef<'tcx>>[src]
&self,
trait_ref: PolyTraitRef<'tcx>
) -> Vec<TraitRef<'tcx>>
pub(in traits::error_reporting) fn report_similar_impl_candidates(
&self,
impl_candidates: Vec<TraitRef<'tcx>>,
err: &mut DiagnosticBuilder<'_>
)[src]
&self,
impl_candidates: Vec<TraitRef<'tcx>>,
err: &mut DiagnosticBuilder<'_>
)
pub(in traits::error_reporting) fn get_parent_trait_ref(
&self,
code: &ObligationCauseCode<'tcx>
) -> Option<(String, Option<Span>)>[src]
&self,
code: &ObligationCauseCode<'tcx>
) -> Option<(String, Option<Span>)>
Gets the parent trait chain start
pub(in traits::error_reporting) fn note_version_mismatch(
&self,
err: &mut DiagnosticBuilder<'_>,
trait_ref: &PolyTraitRef<'tcx>
)[src]
&self,
err: &mut DiagnosticBuilder<'_>,
trait_ref: &PolyTraitRef<'tcx>
)
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
pub(in traits::error_reporting) fn mk_trait_obligation_with_new_self_ty(
&self,
param_env: ParamEnv<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
new_self_ty: Ty<'tcx>
) -> PredicateObligation<'tcx>[src]
&self,
param_env: ParamEnv<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
new_self_ty: Ty<'tcx>
) -> PredicateObligation<'tcx>
pub(in traits::error_reporting) fn maybe_report_ambiguity(
&self,
obligation: &PredicateObligation<'tcx>,
body_id: Option<BodyId>
)[src]
&self,
obligation: &PredicateObligation<'tcx>,
body_id: Option<BodyId>
)
pub(in traits::error_reporting) fn predicate_can_apply(
&self,
param_env: ParamEnv<'tcx>,
pred: PolyTraitRef<'tcx>
) -> bool[src]
&self,
param_env: ParamEnv<'tcx>,
pred: PolyTraitRef<'tcx>
) -> bool
Returns true if the trait predicate may apply for some assignment
to the type parameters.
pub(in traits::error_reporting) fn note_obligation_cause(
&self,
err: &mut DiagnosticBuilder<'tcx>,
obligation: &PredicateObligation<'tcx>
)[src]
&self,
err: &mut DiagnosticBuilder<'tcx>,
obligation: &PredicateObligation<'tcx>
)
pub(in traits::error_reporting) fn suggest_unsized_bound_if_applicable(
&self,
err: &mut DiagnosticBuilder<'tcx>,
obligation: &PredicateObligation<'tcx>
)[src]
&self,
err: &mut DiagnosticBuilder<'tcx>,
obligation: &PredicateObligation<'tcx>
)
pub(in traits::error_reporting) fn is_recursive_obligation(
&self,
obligated_types: &mut Vec<&TyS<'tcx>>,
cause_code: &ObligationCauseCode<'tcx>
) -> bool[src]
&self,
obligated_types: &mut Vec<&TyS<'tcx>>,
cause_code: &ObligationCauseCode<'tcx>
) -> bool
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,
'tcx: 'a,
impl<'a, 'tcx> !UnwindSafe for InferCtxt<'a, 'tcx>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.