Struct rustc_lint::middle::infer::InferCtxtUnstable
[-] [+]
[src]
pub struct InferCtxt<'a, 'tcx> where 'tcx: 'a {
pub tcx: &'a ctxt<'tcx>,
// some fields omitted
}
Fields
tcx |
Methods
impl<'a, 'tcx> InferCtxt<'a, 'tcx>
fn freshen<T>(&self, t: T) -> T where T: TypeFoldable<'tcx>
fn type_var_diverges(&'a self, ty: &TyS) -> bool
fn freshener(&'b self) -> TypeFreshener<'b, 'tcx>
fn type_is_unconstrained_numeric(&'a self, ty: &TyS) -> UnconstrainedNumeric
fn equate(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) -> Equate<'a, 'tcx>
fn sub(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) -> Sub<'a, 'tcx>
fn lub(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) -> Lub<'a, 'tcx>
fn glb(&'a self, a_is_expected: bool, trace: TypeTrace<'tcx>) -> Glb<'a, 'tcx>
fn commit_unconditionally<R, F>(&self, f: F) -> R where F: FnOnce() -> R
Execute f
and commit the bindings
fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where F: FnOnce(&CombinedSnapshot) -> Result<T, E>
Execute f
and commit the bindings if closure f
returns Ok(_)
fn commit_regions_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where F: FnOnce() -> Result<T, E>
Execute f
and commit only the region bindings if successful.
The function f must be very careful not to leak any non-region
variables that get created.
fn probe<R, F>(&self, f: F) -> R where F: FnOnce(&CombinedSnapshot) -> R
Execute f
then unroll any bindings it creates
fn add_given(&self, sub: FreeRegion, sup: RegionVid)
fn sub_types(&self, a_is_expected: bool, origin: TypeOrigin, a: &'tcx TyS<'tcx>, b: &'tcx TyS<'tcx>) -> Result<(), type_err<'tcx>>
fn eq_types(&self, a_is_expected: bool, origin: TypeOrigin, a: &'tcx TyS<'tcx>, b: &'tcx TyS<'tcx>) -> Result<(), type_err<'tcx>>
fn sub_trait_refs(&self, a_is_expected: bool, origin: TypeOrigin, a: Rc<TraitRef<'tcx>>, b: Rc<TraitRef<'tcx>>) -> Result<(), type_err<'tcx>>
fn sub_poly_trait_refs(&self, a_is_expected: bool, origin: TypeOrigin, a: Binder<Rc<TraitRef<'tcx>>>, b: Binder<Rc<TraitRef<'tcx>>>) -> Result<(), type_err<'tcx>>
fn construct_skolemized_subst(&self, generics: &Generics<'tcx>, snapshot: &CombinedSnapshot) -> (Substs<'tcx>, HashMap<BoundRegion, Region, DefaultState<FnvHasher>>)
See higher_ranked::construct_skolemized_subst
fn skolemize_late_bound_regions<T>(&self, value: &Binder<T>, snapshot: &CombinedSnapshot) -> (T, HashMap<BoundRegion, Region, DefaultState<FnvHasher>>) where T: TypeFoldable<'tcx> + Repr<'tcx>
See higher_ranked::skolemize_late_bound_regions
fn leak_check(&self, skol_map: &HashMap<BoundRegion, Region, DefaultState<FnvHasher>>, snapshot: &CombinedSnapshot) -> Result<(), type_err<'tcx>>
See higher_ranked::leak_check
fn plug_leaks<T>(&self, skol_map: HashMap<BoundRegion, Region, DefaultState<FnvHasher>>, snapshot: &CombinedSnapshot, value: &T) -> T where T: TypeFoldable<'tcx> + Repr<'tcx>
See higher_ranked::plug_leaks
fn equality_predicate(&self, span: Span, predicate: &Binder<EquatePredicate<'tcx>>) -> Result<(), type_err<'tcx>>
fn region_outlives_predicate(&self, span: Span, predicate: &Binder<OutlivesPredicate<Region, Region>>) -> Result<(), type_err<'tcx>>
fn next_ty_var_id(&self, diverging: bool) -> TyVid
fn next_ty_var(&self) -> &'tcx TyS<'tcx>
fn next_diverging_ty_var(&self) -> &'tcx TyS<'tcx>
fn next_ty_vars(&self, n: usize) -> Vec<&'tcx TyS<'tcx>>
fn next_int_var_id(&self) -> IntVid
fn next_float_var_id(&self) -> FloatVid
fn next_region_var(&self, origin: RegionVariableOrigin) -> Region
fn region_vars_for_defs(&self, span: Span, defs: &[RegionParameterDef]) -> Vec<Region>
fn fresh_substs_for_generics(&self, span: Span, generics: &Generics<'tcx>) -> Substs<'tcx>
Given a set of generics defined on a type or impl, returns a substitution mapping each type/region parameter to a fresh inference variable.
fn fresh_substs_for_trait(&self, span: Span, generics: &Generics<'tcx>, self_ty: &'tcx TyS<'tcx>) -> Substs<'tcx>
Given a set of generics defined on a trait, returns a substitution mapping each output
type/region parameter to a fresh inference variable, and mapping the self type to
self_ty
.
fn fresh_bound_region(&self, debruijn: DebruijnIndex) -> Region
fn resolve_regions_and_report_errors(&self, free_regions: &FreeRegionMap, subject_node_id: u32)
fn ty_to_string(&self, t: &'tcx TyS<'tcx>) -> String
fn tys_to_string(&self, ts: &[&'tcx TyS<'tcx>]) -> String
fn trait_ref_to_string(&self, t: &Rc<TraitRef<'tcx>>) -> String
fn shallow_resolve(&self, typ: &'tcx TyS<'tcx>) -> &'tcx TyS<'tcx>
fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T where T: TypeFoldable<'tcx>
Where possible, replaces type/int/float variables in
value
with their final value. Note that region variables
are unaffected. If a type 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.
fn fully_resolve<T>(&self, value: &T) -> Result<T, fixup_err> where T: TypeFoldable<'tcx>
Attempts to resolve all type/region 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.
fn type_error_message_str<M>(&self, sp: Span, mk_msg: M, actual_ty: String, err: Option<&type_err<'tcx>>) where M: FnOnce(Option<String>, String) -> String
fn type_error_message_str_with_expected<M>(&self, sp: Span, mk_msg: M, expected_ty: Option<&'tcx TyS<'tcx>>, actual_ty: String, err: Option<&type_err<'tcx>>) where M: FnOnce(Option<String>, String) -> String
fn type_error_message<M>(&self, sp: Span, mk_msg: M, actual_ty: &'tcx TyS<'tcx>, err: Option<&type_err<'tcx>>) where M: FnOnce(String) -> String
fn report_mismatched_types(&self, span: Span, expected: &'tcx TyS<'tcx>, actual: &'tcx TyS<'tcx>, err: &type_err<'tcx>)
fn replace_late_bound_regions_with_fresh_var<T>(&self, span: Span, lbrct: LateBoundRegionConversionTime, value: &Binder<T>) -> (T, HashMap<BoundRegion, Region, DefaultState<FnvHasher>>) where T: TypeFoldable<'tcx> + Repr<'tcx>
fn verify_generic_bound(&self, origin: SubregionOrigin<'tcx>, kind: GenericKind<'tcx>, a: Region, bs: Vec<Region>)
See verify_generic_bound
method in region_inference
fn can_equate<'b, T>(&'b self, a: &T, b: &T) -> Result<(), type_err<'tcx>> where T: Relate<'b, 'tcx> + Repr<'tcx>
Trait Implementations
impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx>
fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) -> Vec<RegionResolutionError<'tcx>>
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &type_err<'tcx>)
fn report_and_explain_type_error(&self, trace: TypeTrace<'tcx>, terr: &type_err<'tcx>)
fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<String>
Returns a string of the form "expected {}
, found {}
", or None if this is a derived
error.
fn expected_found_str<T>(&self, exp_found: &expected_found<T>) -> Option<String> where T: Resolvable<'tcx> + UserString<'tcx>
fn report_generic_bound_failure(&self, origin: SubregionOrigin<'tcx>, bound_kind: GenericKind<'tcx>, sub: Region, _sups: Vec<Region>)
fn report_concrete_failure(&self, origin: SubregionOrigin<'tcx>, sub: Region, sup: Region)
fn report_sub_sup_conflict(&self, var_origin: RegionVariableOrigin, sub_origin: SubregionOrigin<'tcx>, sub_region: Region, sup_origin: SubregionOrigin<'tcx>, sup_region: Region)
fn report_sup_sup_conflict(&self, var_origin: RegionVariableOrigin, origin1: SubregionOrigin<'tcx>, region1: Region, origin2: SubregionOrigin<'tcx>, region2: Region)
fn report_processed_errors(&self, var_origins: &[RegionVariableOrigin], trace_origins: &[(TypeTrace<'tcx>, type_err<'tcx>)], same_regions: &[SameRegions])
fn give_suggestion(&self, same_regions: &[SameRegions])
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx>
fn give_expl_lifetime_param(&self, decl: &FnDecl, unsafety: Unsafety, ident: Ident, opt_explicit_self: Option<&ExplicitSelf_>, generics: &Generics, span: Span)
fn report_inference_failure(&self, var_origin: RegionVariableOrigin)
fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>)
impl<'a, 'tcx> InferCtxtExt for InferCtxt<'a, 'tcx>
fn tainted_regions(&self, snapshot: &CombinedSnapshot, r: Region) -> Vec<Region>
fn region_vars_confined_to_snapshot(&self, snapshot: &CombinedSnapshot) -> Vec<RegionVid>
Returns the set of region variables that do not affect any
types/regions which existed before snapshot
was
started. This is used in the sub/lub/glb computations. The
idea here is that when we are computing lub/glb of two
regions, we sometimes create intermediate region variables.
Those region variables may touch some of the skolemized or
other "forbidden" regions we created to replace bound
regions, but they don't really represent an "external"
constraint.
However, sometimes fresh variables are created for other purposes too, and those may represent an external constraint. In particular, when a type variable is instantiated, we create region variables for all the regions that appear within, and if that type variable pre-existed the snapshot, then those region variables represent external constraints.
An example appears in the unit test
sub_free_bound_false_infer
. In this test, we want to
know whether
fn(_#0t) <: for<'a> fn(&'a int)
Note that the subtype has a type variable. Because the type variable can't be instantiated with a region that is bound in the fn signature, this comparison ought to fail. But if we're not careful, it will succeed.
The reason is that when we walk through the subtyping
algorith, we begin by replacing 'a
with a skolemized
variable '1
. We then have fn(_#0t) <: fn(&'1 int)
. This
can be made true by unifying _#0t
with &'1 int
. In the
process, we create a fresh variable for the skolemized
region, '$2
, and hence we have that _#0t == &'$2 int
. However, because '$2
was created during the sub
computation, if we're not careful we will erroneously
assume it is one of the transient region variables
representing a lub/glb internally. Not good.
To prevent this, we check for type variables which were unified during the snapshot, and say that any region variable created during the snapshot but which finds its way into a type variable is considered to "escape" the snapshot.