Skip to content
Permalink
Browse files

Refactor `ConstVariableOrigin` into `ConstVariableOrigin` and `ConstV…

…ariableOriginKind`
  • Loading branch information...
varkor committed May 31, 2019
1 parent 4dcc49c commit 8577bb49bf0ba789e6eca6d6b328a65ca5d70695
@@ -22,7 +22,7 @@
//! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html

use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
use crate::infer::ConstVariableOrigin;
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
use crate::mir::interpret::ConstValue;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_macros::HashStable;
@@ -407,10 +407,16 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
CanonicalVarKind::Const(ui) => {
self.next_const_var_in_universe(
self.next_ty_var_in_universe(
TypeVariableOrigin::MiscVariable(span),
TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
span,
},
universe_map(ui),
),
ConstVariableOrigin::MiscVariable(span),
ConstVariableOrigin {
kind: ConstVariableOriginKind::MiscVariable,
span,
},
universe_map(ui),
).into()
}
@@ -28,7 +28,8 @@ use super::{InferCtxt, MiscVariable, TypeTrace};
use super::lub::Lub;
use super::sub::Sub;
use super::type_variable::TypeVariableValue;
use super::unify_key::{ConstVarValue, ConstVariableValue, ConstVariableOrigin};
use super::unify_key::{ConstVarValue, ConstVariableValue};
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};

use crate::hir::def_id::DefId;
use crate::mir::interpret::ConstValue;
@@ -165,7 +166,10 @@ impl<'infcx, 'gcx, 'tcx> InferCtxt<'infcx, 'gcx, 'tcx> {
self.const_unification_table
.borrow_mut()
.unify_var_value(vid, ConstVarValue {
origin: ConstVariableOrigin::ConstInference(DUMMY_SP),
origin: ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstInference,
span: DUMMY_SP,
},
val: ConstVariableValue::Known { value },
})
.map_err(|e| const_unification_error(vid_is_expected, e))?;
@@ -40,7 +40,7 @@ use self::outlives::env::OutlivesEnvironment;
use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound};
use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use self::unify_key::{ToType, ConstVariableOrigin};
use self::unify_key::{ToType, ConstVariableOrigin, ConstVariableOriginKind};

pub mod at;
pub mod canonical;
@@ -1119,7 +1119,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.tcx.mk_ty_var(ty_var_id).into()
}
GenericParamDefKind::Const { .. } => {
let origin = ConstVariableOrigin::ConstParameterDefinition(span, param.name);
let origin = ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstParameterDefinition(param.name),
span,
};
let const_var_id =
self.const_unification_table
.borrow_mut()
@@ -1421,7 +1424,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
span,
})
};
let fld_c = |_, ty| self.next_const_var(ty, ConstVariableOrigin::MiscVariable(span));
let fld_c = |_, ty| self.next_const_var(ty, ConstVariableOrigin {
kind: ConstVariableOriginKind:: MiscVariable,
span,
});
self.tcx.replace_bound_vars(value, fld_r, fld_t, fld_c)
}

@@ -1,4 +1,5 @@
use super::{InferCtxt, FixupError, FixupResult, Span, type_variable::TypeVariableOrigin};
use super::{InferCtxt, FixupError, FixupResult, Span};
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::mir::interpret::ConstValue;
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags};
use crate::ty::fold::{TypeFolder, TypeVisitor};
@@ -123,8 +124,10 @@ impl<'a, 'gcx, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'gcx, 'tcx>
let ty_var_span =
if let ty::TyVar(ty_vid) = infer_ty {
let ty_vars = self.infcx.type_variables.borrow();
if let TypeVariableOrigin::TypeParameterDefinition(span, _name)
= *ty_vars.var_origin(ty_vid)
if let TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeParameterDefinition(_),
span,
} = *ty_vars.var_origin(ty_vid)
{
Some(span)
} else {
@@ -79,13 +79,19 @@ impl ToType for FloatVarValue {

// Generic consts.

#[derive(Copy, Clone, Debug)]
pub struct ConstVariableOrigin {
pub kind: ConstVariableOriginKind,
pub span: Span,
}

/// Reasons to create a const inference variable
#[derive(Copy, Clone, Debug)]
pub enum ConstVariableOrigin {
MiscVariable(Span),
ConstInference(Span),
ConstParameterDefinition(Span, InternedString),
SubstitutionPlaceholder(Span),
pub enum ConstVariableOriginKind {
MiscVariable,
ConstInference,
ConstParameterDefinition(InternedString),
SubstitutionPlaceholder,
}

#[derive(Copy, Clone, Debug)]
@@ -159,7 +165,10 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
}?;

Ok(ConstVarValue {
origin: ConstVariableOrigin::ConstInference(DUMMY_SP),
origin: ConstVariableOrigin {
kind: ConstVariableOriginKind::ConstInference,
span: DUMMY_SP,
},
val,
})
}
@@ -1009,7 +1009,10 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
// ...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.
let discrim_ty = self.next_ty_var(TypeVariableOrigin::TypeInference(discrim.span));
let discrim_ty = self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference,
span: discrim.span,
});
self.check_expr_has_type_or_error(discrim, discrim_ty);
discrim_ty
}
@@ -21,7 +21,7 @@ use rustc::traits::query::method_autoderef::{MethodAutoderefBadTy};
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt, ToPolyTraitRef, ToPredicate, TraitRef, TypeFoldable};
use rustc::ty::GenericParamDefKind;
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc::infer::unify_key::ConstVariableOrigin;
use rustc::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc::util::nodemap::FxHashSet;
use rustc::infer::{self, InferOk};
use rustc::infer::canonical::{Canonical, QueryResponse};
@@ -1580,7 +1580,10 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
}
GenericParamDefKind::Const { .. } => {
let span = self.tcx.def_span(def_id);
let origin = ConstVariableOrigin::SubstitutionPlaceholder(span);
let origin = ConstVariableOrigin {
kind: ConstVariableOriginKind::SubstitutionPlaceholder,
span,
};
self.next_const_var(self.tcx.type_of(param.def_id), origin).into()
}
}

0 comments on commit 8577bb4

Please sign in to comment.
You can’t perform that action at this time.