add universes to type inference variables

This commit is contained in:
Niko Matsakis
2017-07-17 16:16:14 -04:00
committed by Sean Griffin
parent 44d992984a
commit 13efaf0481
21 changed files with 132 additions and 55 deletions
+2 -1
View File
@@ -600,7 +600,8 @@ fn fold_anon_ty(
return anon_defn.concrete_ty;
}
let span = tcx.def_span(def_id);
let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
let ty_var = infcx.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(span));
let predicates_of = tcx.predicates_of(def_id);
let bounds = predicates_of.instantiate(tcx, substs);
+2 -2
View File
@@ -407,7 +407,7 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
drop(variables);
self.relate(&u, &u)
}
TypeVariableValue::Unknown { .. } => {
TypeVariableValue::Unknown { universe } => {
match self.ambient_variance {
// Invariant: no need to make a fresh type variable.
ty::Invariant => return Ok(t),
@@ -424,7 +424,7 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
}
let origin = *variables.var_origin(vid);
let new_var_id = variables.new_var(false, origin);
let new_var_id = variables.new_var(universe, false, origin);
let u = self.tcx().mk_var(new_var_id);
debug!("generalize: replacing original vid={:?} with new={:?}",
vid, u);
+5 -1
View File
@@ -141,7 +141,11 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
// This variable was created during the
// fudging. Recreate it with a fresh variable
// here.
self.infcx.next_ty_var(origin)
//
// The ROOT universe is fine because we only
// ever invoke this routine at the
// "item-level" of inference.
self.infcx.next_ty_var(ty::UniverseIndex::ROOT, origin)
}
}
}
+8 -4
View File
@@ -88,13 +88,17 @@ pub fn super_lattice_tys<'a, 'gcx, 'tcx, L>(this: &mut L,
// is (e.g.) `Box<i32>`. A more obvious solution might be to
// iterate on the subtype obligations that are returned, but I
// think this suffices. -nmatsakis
(&ty::TyInfer(TyVar(..)), _) => {
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
(&ty::TyInfer(TyVar(a_vid)), _) => {
let universe = infcx.type_variables.borrow_mut().probe(a_vid).universe().unwrap();
let v = infcx.next_ty_var(universe,
TypeVariableOrigin::LatticeVariable(this.cause().span));
this.relate_bound(v, b, a)?;
Ok(v)
}
(_, &ty::TyInfer(TyVar(..))) => {
let v = infcx.next_ty_var(TypeVariableOrigin::LatticeVariable(this.cause().span));
(_, &ty::TyInfer(TyVar(b_vid))) => {
let universe = infcx.type_variables.borrow_mut().probe(b_vid).universe().unwrap();
let v = infcx.next_ty_var(universe,
TypeVariableOrigin::LatticeVariable(this.cause().span));
this.relate_bound(v, a, b)?;
Ok(v)
}
+15 -8
View File
@@ -1015,18 +1015,22 @@ pub fn region_outlives_predicate(&self,
})
}
pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid {
pub fn next_ty_var_id(&self,
universe: ty::UniverseIndex,
diverging: bool,
origin: TypeVariableOrigin)
-> TyVid {
self.type_variables
.borrow_mut()
.new_var(diverging, origin)
.new_var(universe, diverging, origin)
}
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_var(self.next_ty_var_id(false, origin))
pub fn next_ty_var(&self, universe: ty::UniverseIndex, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_var(self.next_ty_var_id(universe, false, origin))
}
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_var(self.next_ty_var_id(true, origin))
pub fn next_diverging_ty_var(&self, universe: ty::UniverseIndex, origin: TypeVariableOrigin) -> Ty<'tcx> {
self.tcx.mk_var(self.next_ty_var_id(universe, true, origin))
}
pub fn next_int_var_id(&self) -> IntVid {
@@ -1081,12 +1085,14 @@ pub fn region_var_for_def(&self,
/// use an inference variable for `C` with `[T, U]`
/// as the substitutions for the default, `(T, U)`.
pub fn type_var_for_def(&self,
universe: ty::UniverseIndex,
span: Span,
def: &ty::TypeParameterDef)
-> Ty<'tcx> {
let ty_var_id = self.type_variables
.borrow_mut()
.new_var(false,
.new_var(universe,
false,
TypeVariableOrigin::TypeParameterDefinition(span, def.name));
self.tcx.mk_var(ty_var_id)
@@ -1095,13 +1101,14 @@ pub fn type_var_for_def(&self,
/// 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 fresh_substs_for_item(&self,
universe: ty::UniverseIndex,
span: Span,
def_id: DefId)
-> &'tcx Substs<'tcx> {
Substs::for_item(self.tcx, def_id, |def, _| {
self.region_var_for_def(span, def)
}, |def, _| {
self.type_var_for_def(span, def)
self.type_var_for_def(universe, span, def)
})
}
+26 -4
View File
@@ -12,6 +12,7 @@
use syntax_pos::Span;
use ty::{self, Ty};
use std::cmp;
use std::marker::PhantomData;
use std::u32;
use rustc_data_structures::fx::FxHashMap;
@@ -81,10 +82,18 @@ struct TypeVariableData {
#[derive(Copy, Clone, Debug)]
pub enum TypeVariableValue<'tcx> {
Known { value: Ty<'tcx> },
Unknown,
Unknown { universe: ty::UniverseIndex },
}
#[derive(Copy, Clone, Debug)]
pub enum ProbeTyValue<'tcx> {
Ty(Ty<'tcx>),
Vid(ty::TyVid),
}
impl<'tcx> TypeVariableValue<'tcx> {
/// If this value is known, returns the type it is known to be.
/// Otherwise, `None`.
pub fn known(&self) -> Option<Ty<'tcx>> {
match *self {
TypeVariableValue::Unknown { .. } => None,
@@ -92,6 +101,14 @@ pub fn known(&self) -> Option<Ty<'tcx>> {
}
}
/// If this value is unknown, returns the universe, otherwise `None`.
pub fn universe(&self) -> Option<ty::UniverseIndex> {
match *self {
TypeVariableValue::Unknown { universe } => Some(universe),
TypeVariableValue::Known { .. } => None,
}
}
pub fn is_unknown(&self) -> bool {
match *self {
TypeVariableValue::Unknown { .. } => true,
@@ -178,10 +195,11 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
/// The code in this module doesn't care, but it can be useful
/// for improving error messages.
pub fn new_var(&mut self,
universe: ty::UniverseIndex,
diverging: bool,
origin: TypeVariableOrigin)
-> ty::TyVid {
let eq_key = self.eq_relations.new_key(TypeVariableValue::Unknown);
let eq_key = self.eq_relations.new_key(TypeVariableValue::Unknown { universe });
let sub_key = self.sub_relations.new_key(());
assert_eq!(eq_key.vid, sub_key);
@@ -388,8 +406,12 @@ fn unify_values(value1: &Self, value2: &Self) -> Result<Self, ut::NoError> {
(&TypeVariableValue::Known { .. }, &TypeVariableValue::Unknown { .. }) => Ok(*value1),
(&TypeVariableValue::Unknown { .. }, &TypeVariableValue::Known { .. }) => Ok(*value2),
// If both sides are *unknown*, it hardly matters, does it?
(&TypeVariableValue::Unknown, &TypeVariableValue::Unknown) => Ok(*value1),
// If both sides are unknown, we need to pick the most restrictive universe.
(&TypeVariableValue::Unknown { universe: universe1 },
&TypeVariableValue::Unknown { universe: universe2 }) => {
let universe = cmp::min(universe1, universe2);
Ok(TypeVariableValue::Unknown { universe })
}
}
}
}
+3 -1
View File
@@ -92,7 +92,9 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, '
-> ty::ImplHeader<'tcx>
{
let tcx = selcx.tcx();
let impl_substs = selcx.infcx().fresh_substs_for_item(DUMMY_SP, impl_def_id);
let impl_substs = selcx.infcx().fresh_substs_for_item(param_env.universe,
DUMMY_SP,
impl_def_id);
let header = ty::ImplHeader {
impl_def_id,
+13 -4
View File
@@ -292,7 +292,9 @@ fn impl_similar_to(&self,
self.tcx.for_each_relevant_impl(
trait_ref.def_id, trait_self_ty, |def_id| {
let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
let impl_substs = self.fresh_substs_for_item(param_env.universe,
obligation.cause.span,
def_id);
let impl_trait_ref = tcx
.impl_trait_ref(def_id)
.unwrap()
@@ -1194,6 +1196,7 @@ fn predicate_can_apply(&self,
-> bool {
struct ParamToVarFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
var_map: FxHashMap<Ty<'tcx>, Ty<'tcx>>
}
@@ -1203,9 +1206,14 @@ fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx }
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::TyParam(ty::ParamTy {name, ..}) = ty.sty {
let infcx = self.infcx;
self.var_map.entry(ty).or_insert_with(||
infcx.next_ty_var(
TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP, name)))
let param_env = self.param_env;
self.var_map
.entry(ty)
.or_insert_with(|| {
let origin = TypeVariableOrigin::TypeParameterDefinition(DUMMY_SP,
name);
infcx.next_ty_var(param_env.universe, origin)
})
} else {
ty.super_fold_with(self)
}
@@ -1217,6 +1225,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
infcx: self,
param_env,
var_map: FxHashMap()
});
+2
View File
@@ -469,6 +469,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
let tcx = selcx.infcx().tcx;
let def_id = projection_ty.item_def_id;
let ty_var = selcx.infcx().next_ty_var(
param_env.universe,
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
let projection = ty::Binder(ty::ProjectionPredicate {
projection_ty,
@@ -789,6 +790,7 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
let tcx = selcx.infcx().tcx;
let def_id = projection_ty.item_def_id;
let new_value = selcx.infcx().next_ty_var(
param_env.universe,
TypeVariableOrigin::NormalizeProjectionType(tcx.def_span(def_id)));
Normalized {
value: new_value,
+2 -1
View File
@@ -3111,7 +3111,8 @@ fn match_impl(&mut self,
snapshot);
let skol_obligation_trait_ref = skol_obligation.trait_ref;
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span,
let impl_substs = self.infcx.fresh_substs_for_item(obligation.param_env.universe,
obligation.cause.span,
impl_def_id);
let impl_trait_ref = impl_trait_ref.subst(self.tcx(),
+1 -1
View File
@@ -221,7 +221,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
target_impl: DefId)
-> Result<&'tcx Substs<'tcx>, ()> {
let selcx = &mut SelectionContext::new(&infcx);
let target_substs = infcx.fresh_substs_for_item(DUMMY_SP, target_impl);
let target_substs = infcx.fresh_substs_for_item(param_env.universe, DUMMY_SP, target_impl);
let (target_trait_ref, mut obligations) = impl_trait_ref_and_oblig(selcx,
param_env,
target_impl,
+8 -3
View File
@@ -329,6 +329,7 @@ pub fn check_pat_walk(
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(
// FIXME: MiscVariable for now, obtaining the span and name information
// from all tuple elements isn't trivial.
ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(pat.span)));
let element_tys = tcx.mk_type_list(element_tys_iter);
let pat_ty = tcx.mk_ty(ty::TyTuple(element_tys, false));
@@ -339,7 +340,8 @@ pub fn check_pat_walk(
pat_ty
}
PatKind::Box(ref inner) => {
let inner_ty = self.next_ty_var(TypeVariableOrigin::TypeInference(inner.span));
let inner_ty = self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(inner.span));
let uniq_ty = tcx.mk_box(inner_ty);
if self.check_dereferencable(pat.span, expected, &inner) {
@@ -372,6 +374,7 @@ pub fn check_pat_walk(
}
_ => {
let inner_ty = self.next_ty_var(
ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(inner.span));
let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
let region = self.next_region_var(infer::PatternRegion(pat.span));
@@ -630,7 +633,8 @@ pub fn check_match(&self,
// ...but otherwise we want to use any supertype of the
// discriminant. This is sort of a workaround, see note (*) in
// `check_pat` for some details.
discrim_ty = self.next_ty_var(TypeVariableOrigin::TypeInference(discrim.span));
discrim_ty = self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(discrim.span));
self.check_expr_has_type_or_error(discrim, discrim_ty);
};
@@ -691,7 +695,8 @@ pub fn check_match(&self,
// arm for inconsistent arms or to the whole match when a `()` type
// is required).
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_nil() => ety,
_ => self.next_ty_var(TypeVariableOrigin::MiscVariable(expr.span)),
_ => self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(expr.span)),
};
CoerceMany::with_coercion_sites(coerce_first, arms)
};
+2 -1
View File
@@ -110,7 +110,8 @@ fn check_closure(
|_, _| span_bug!(expr.span, "closure has region param"),
|_, _| {
self.infcx
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span))
.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::ClosureSynthetic(expr.span))
},
);
let substs = ty::ClosureSubsts { substs };
+2 -1
View File
@@ -177,6 +177,7 @@ fn coerce(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
// micro-optimization: no need for this if `b` is
// already resolved in some way.
let diverging_ty = self.next_diverging_ty_var(
ty::UniverseIndex::ROOT,
TypeVariableOrigin::AdjustmentType(self.cause.span));
self.unify_and(&b, &diverging_ty, simple(Adjust::NeverToAny))
} else {
@@ -510,7 +511,7 @@ fn coerce_unsized(&self, source: Ty<'tcx>, target: Ty<'tcx>) -> CoerceResult<'tc
// We only have the latter, so we use an inference variable
// for the former and let type inference do the rest.
let origin = TypeVariableOrigin::MiscVariable(self.cause.span);
let coerce_target = self.next_ty_var(origin);
let coerce_target = self.next_ty_var(ty::UniverseIndex::ROOT, origin);
let mut coercion = self.unify_and(coerce_target, target, |target| {
let unsize = Adjustment {
kind: Adjust::Unsize,
+1 -1
View File
@@ -90,7 +90,7 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
let drop_impl_span = tcx.def_span(drop_impl_did);
let fresh_impl_substs =
infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did);
infcx.fresh_substs_for_item(ty::UniverseIndex::ROOT, drop_impl_span, drop_impl_did);
let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs);
let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id);
+2 -2
View File
@@ -259,7 +259,7 @@ fn fresh_receiver_substs(&mut self,
// the process we will unify the transformed-self-type
// of the method with the actual type in order to
// unify some of these variables.
self.fresh_substs_for_item(self.span, trait_def_id)
self.fresh_substs_for_item(ty::UniverseIndex::ROOT, self.span, trait_def_id)
}
probe::WhereClausePick(ref poly_trait_ref) => {
@@ -336,7 +336,7 @@ fn instantiate_method_substs(&mut self,
{
self.to_ty(ast_ty)
} else {
self.type_var_for_def(self.span, def)
self.type_var_for_def(ty::UniverseIndex::ROOT, self.span, def)
}
})
}
+1 -1
View File
@@ -255,7 +255,7 @@ pub fn lookup_method_in_trait(&self,
} else if let Some(ref input_types) = opt_input_types {
input_types[def.index as usize - 1]
} else {
self.type_var_for_def(span, def)
self.type_var_for_def(ty::UniverseIndex::ROOT, span, def)
}
});
+5 -2
View File
@@ -730,7 +730,9 @@ pub fn matches_return_type(&self,
Def::Method(def_id) => {
let fty = self.tcx.fn_sig(def_id);
self.probe(|_| {
let substs = self.fresh_substs_for_item(self.span, method.def_id);
let substs = self.fresh_substs_for_item(ty::UniverseIndex::ROOT,
self.span,
method.def_id);
let fty = fty.subst(self.tcx, substs);
let (fty, _) = self.replace_late_bound_regions_with_fresh_var(
self.span, infer::FnCall, &fty);
@@ -1309,7 +1311,7 @@ fn xform_method_sig(&self,
if i < substs.len() {
substs.type_at(i)
} else {
self.type_var_for_def(self.span, def)
self.type_var_for_def(ty::UniverseIndex::ROOT, self.span, def)
}
});
xform_fn_sig.subst(self.tcx, substs)
@@ -1326,6 +1328,7 @@ fn fresh_item_substs(&self, def_id: DefId) -> &'tcx Substs<'tcx> {
def_id,
|_, _| self.tcx.types.re_erased,
|_, _| self.next_ty_var(
ty::UniverseIndex::ROOT,
TypeVariableOrigin::SubstitutionPlaceholder(
self.tcx.def_span(def_id))))
}
+2 -1
View File
@@ -54,7 +54,8 @@ fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
self.autoderef(span, ty).any(|(ty, _)| {
self.probe(|_| {
let fn_once_substs = tcx.mk_substs_trait(ty,
&[self.next_ty_var(TypeVariableOrigin::MiscVariable(span))]);
&[self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(span))]);
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
let poly_trait_ref = trait_ref.to_poly_trait_ref();
let obligation =
+24 -13
View File
@@ -362,7 +362,8 @@ fn only_has_type(self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) -> Option<Ty<'tcx>> {
/// hard constraint exists, creates a fresh type variable.
fn coercion_target_type(self, fcx: &FnCtxt<'a, 'gcx, 'tcx>, span: Span) -> Ty<'tcx> {
self.only_has_type(fcx)
.unwrap_or_else(|| fcx.next_ty_var(TypeVariableOrigin::MiscVariable(span)))
.unwrap_or_else(|| fcx.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(span)))
}
}
@@ -921,7 +922,8 @@ fn assign(&mut self, span: Span, nid: ast::NodeId, ty_opt: Option<Ty<'tcx>>) ->
match ty_opt {
None => {
// infer the variable's type
let var_ty = self.fcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
let var_ty = self.fcx.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(span));
self.fcx.locals.borrow_mut().insert(nid, var_ty);
var_ty
}
@@ -1025,7 +1027,8 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
let span = body.value.span;
if body.is_generator && can_be_generator.is_some() {
let yield_ty = fcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
let yield_ty = fcx.next_ty_var(fcx.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(span)));
fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType);
fcx.yield_ty = Some(yield_ty);
}
@@ -1058,7 +1061,8 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
// This ensures that all nested generators appear before the entry of this generator.
// resolve_generator_interiors relies on this property.
let gen_ty = if can_be_generator.is_some() && body.is_generator {
let witness = fcx.next_ty_var(TypeVariableOrigin::MiscVariable(span));
let witness = fcx.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(span));
let interior = ty::GeneratorInterior {
witness,
movable: can_be_generator.unwrap() == hir::GeneratorMovability::Movable,
@@ -1096,6 +1100,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
let mut actual_return_ty = coercion.complete(&fcx);
if actual_return_ty.is_never() {
actual_return_ty = fcx.next_diverging_ty_var(
ty::UniverseIndex::ROOT,
TypeVariableOrigin::DivergingFn(span));
}
fcx.demand_suptype(span, ret_ty, actual_return_ty);
@@ -1687,13 +1692,14 @@ fn re_infer(&self, span: Span, def: Option<&ty::RegionParameterDef>)
}
fn ty_infer(&self, span: Span) -> Ty<'tcx> {
self.next_ty_var(TypeVariableOrigin::TypeInference(span))
self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(span))
}
fn ty_infer_for_def(&self,
ty_param_def: &ty::TypeParameterDef,
span: Span) -> Ty<'tcx> {
self.type_var_for_def(span, ty_param_def)
self.type_var_for_def(ty::UniverseIndex::ROOT, span, ty_param_def)
}
fn projected_ty_from_poly_trait_ref(&self,
@@ -2315,7 +2321,8 @@ fn try_index_step(&self,
// If some lookup succeeds, write callee into table and extract index/element
// type from the method signature.
// If some lookup succeeded, install method in table
let input_ty = self.next_ty_var(TypeVariableOrigin::AutoDeref(base_expr.span));
let input_ty = self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::AutoDeref(base_expr.span));
let method = self.try_overloaded_place_op(
expr.span, self_ty, &[input_ty], needs, PlaceOp::Index);
@@ -2754,6 +2761,7 @@ fn check_expr_meets_expectation_or_error(&self,
assert!(!self.tables.borrow().adjustments().contains_key(expr.hir_id),
"expression with never type wound up being adjusted");
let adj_ty = self.next_diverging_ty_var(
ty::UniverseIndex::ROOT,
TypeVariableOrigin::AdjustmentType(expr.span));
self.apply_adjustments(expr, vec![Adjustment {
kind: Adjust::NeverToAny,
@@ -2831,7 +2839,7 @@ pub fn impl_self_ty(&self,
let ity = self.tcx.type_of(did);
debug!("impl_self_ty: ity={:?}", ity);
let substs = self.fresh_substs_for_item(span, did);
let substs = self.fresh_substs_for_item(ty::UniverseIndex::ROOT, span, did);
let substd_ty = self.instantiate_type_scheme(span, &substs, &ity);
TypeAndSubsts { substs: substs, ty: substd_ty }
@@ -3971,7 +3979,8 @@ fn check_expr_kind(&self,
let element_ty = if !args.is_empty() {
let coerce_to = uty.unwrap_or_else(
|| self.next_ty_var(TypeVariableOrigin::TypeInference(expr.span)));
|| self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(expr.span)));
let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args);
assert_eq!(self.diverges.get(), Diverges::Maybe);
for e in args {
@@ -3981,7 +3990,8 @@ fn check_expr_kind(&self,
}
coerce.complete(self)
} else {
self.next_ty_var(TypeVariableOrigin::TypeInference(expr.span))
self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::TypeInference(expr.span))
};
tcx.mk_array(element_ty, args.len() as u64)
}
@@ -4011,7 +4021,8 @@ fn check_expr_kind(&self,
(uty, uty)
}
None => {
let t: Ty = self.next_ty_var(TypeVariableOrigin::MiscVariable(element.span));
let t: Ty = self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(element.span));
let element_ty = self.check_expr_has_type_or_error(&element, t);
(element_ty, t)
}
@@ -4792,7 +4803,7 @@ pub fn instantiate_value_path(&self,
// Handle Self first, so we can adjust the index to match the AST.
if has_self && i == 0 {
return opt_self_ty.unwrap_or_else(|| {
self.type_var_for_def(span, def)
self.type_var_for_def(ty::UniverseIndex::ROOT, span, def)
});
}
i -= has_self as usize;
@@ -4825,7 +4836,7 @@ pub fn instantiate_value_path(&self,
// This can also be reached in some error cases:
// We prefer to use inference variables instead of
// TyError to let type inference recover somewhat.
self.type_var_for_def(span, def)
self.type_var_for_def(ty::UniverseIndex::ROOT, span, def)
}
});
+6 -3
View File
@@ -174,8 +174,10 @@ fn check_overloaded_binop(&self,
// trait matching creating lifetime constraints that are too strict.
// E.g. adding `&'a T` and `&'b T`, given `&'x T: Add<&'x T>`, will result
// in `&'a T <: &'x T` and `&'b T <: &'x T`, instead of `'a = 'b = 'x`.
let lhs_ty = self.check_expr_coercable_to_type_with_needs(lhs_expr,
self.next_ty_var(TypeVariableOrigin::MiscVariable(lhs_expr.span)),
let lhs_ty = self.check_expr_coercable_to_type_with_needs(
lhs_expr,
self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(lhs_expr.span)),
lhs_needs);
let lhs_ty = self.resolve_type_vars_with_obligations(lhs_ty);
@@ -185,7 +187,8 @@ fn check_overloaded_binop(&self,
// using this variable as the expected type, which sometimes lets
// us do better coercions than we would be able to do otherwise,
// particularly for things like `String + &String`.
let rhs_ty_var = self.next_ty_var(TypeVariableOrigin::MiscVariable(rhs_expr.span));
let rhs_ty_var = self.next_ty_var(ty::UniverseIndex::ROOT,
TypeVariableOrigin::MiscVariable(rhs_expr.span));
let result = self.lookup_op_method(lhs_ty, &[rhs_ty_var], Op::Binary(op, is_assign));