Auto merge of #30054 - Ms2ger:TypeOrigin, r=eddyb

This commit is contained in:
bors 2015-11-26 13:07:18 +00:00
commit da0444d5d4
16 changed files with 83 additions and 82 deletions

View file

@ -78,7 +78,7 @@ use rustc_front::print::pprust;
use middle::def;
use middle::def_id::DefId;
use middle::infer;
use middle::infer::{self, TypeOrigin};
use middle::region;
use middle::subst;
use middle::ty::{self, Ty, HasTypeFlags};
@ -474,7 +474,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
self.check_and_note_conflicting_crates(terr, trace.origin.span());
match trace.origin {
infer::MatchExpressionArm(_, arm_span, source) => match source {
TypeOrigin::MatchExpressionArm(_, arm_span, source) => match source {
hir::MatchSource::IfLetDesugar{..} =>
self.tcx.sess.span_note(arm_span, "`if let` arm with an incompatible type"),
_ => self.tcx.sess.span_note(arm_span, "match arm with an incompatible type"),
@ -1602,38 +1602,38 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
}
infer::Subtype(ref trace) => {
let desc = match trace.origin {
infer::Misc(_) => {
TypeOrigin::Misc(_) => {
"types are compatible"
}
infer::MethodCompatCheck(_) => {
TypeOrigin::MethodCompatCheck(_) => {
"method type is compatible with trait"
}
infer::ExprAssignable(_) => {
TypeOrigin::ExprAssignable(_) => {
"expression is assignable"
}
infer::RelateTraitRefs(_) => {
TypeOrigin::RelateTraitRefs(_) => {
"traits are compatible"
}
infer::RelateSelfType(_) => {
TypeOrigin::RelateSelfType(_) => {
"self type matches impl self type"
}
infer::RelateOutputImplTypes(_) => {
TypeOrigin::RelateOutputImplTypes(_) => {
"trait type parameters matches those \
specified on the impl"
}
infer::MatchExpressionArm(_, _, _) => {
TypeOrigin::MatchExpressionArm(_, _, _) => {
"match arms have compatible types"
}
infer::IfExpression(_) => {
TypeOrigin::IfExpression(_) => {
"if and else have compatible types"
}
infer::IfExpressionWithNoElse(_) => {
TypeOrigin::IfExpressionWithNoElse(_) => {
"if may be missing an else clause"
}
infer::RangeExpression(_) => {
TypeOrigin::RangeExpression(_) => {
"start and end of range have compatible types"
}
infer::EquatePredicate(_) => {
TypeOrigin::EquatePredicate(_) => {
"equality where clause is satisfied"
}
};

View file

@ -13,7 +13,6 @@
pub use self::LateBoundRegionConversionTime::*;
pub use self::RegionVariableOrigin::*;
pub use self::SubregionOrigin::*;
pub use self::TypeOrigin::*;
pub use self::ValuePairs::*;
pub use middle::ty::IntVarValue;
pub use self::freshen::TypeFreshener;
@ -440,7 +439,7 @@ pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
debug!("can_mk_subty({:?} <: {:?})", a, b);
cx.probe(|_| {
let trace = TypeTrace {
origin: Misc(codemap::DUMMY_SP),
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
values: Types(expected_found(true, a, b))
};
cx.sub(true, trace).relate(&a, &b).map(|_| ())
@ -950,7 +949,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.commit_if_ok(|snapshot| {
let (ty::EquatePredicate(a, b), skol_map) =
self.skolemize_late_bound_regions(predicate, snapshot);
let origin = EquatePredicate(span);
let origin = TypeOrigin::EquatePredicate(span);
let () = try!(mk_eqty(self, false, origin, a, b));
self.leak_check(&skol_map, snapshot)
})
@ -1328,7 +1327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
actual: Ty<'tcx>,
err: &TypeError<'tcx>) {
let trace = TypeTrace {
origin: Misc(span),
origin: TypeOrigin::Misc(span),
values: Types(ExpectedFound {
expected: expected,
found: actual
@ -1342,7 +1341,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
expected: type_variable::Default<'tcx>,
actual: type_variable::Default<'tcx>) {
let trace = TypeTrace {
origin: Misc(span),
origin: TypeOrigin::Misc(span),
values: Types(ExpectedFound {
expected: expected.ty,
found: actual.ty
@ -1393,8 +1392,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// generic so we don't have to do anything quite this
// terrible.
let e = self.tcx.types.err;
let trace = TypeTrace { origin: Misc(codemap::DUMMY_SP),
values: Types(expected_found(true, e, e)) };
let trace = TypeTrace {
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
values: Types(expected_found(true, e, e))
};
self.equate(true, trace).relate(a, b)
}).map(|_| ())
}
@ -1525,7 +1526,7 @@ impl<'tcx> TypeTrace<'tcx> {
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
TypeTrace {
origin: Misc(codemap::DUMMY_SP),
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
values: Types(ExpectedFound {
expected: tcx.types.err,
found: tcx.types.err,
@ -1543,17 +1544,17 @@ impl<'tcx> fmt::Debug for TypeTrace<'tcx> {
impl TypeOrigin {
pub fn span(&self) -> Span {
match *self {
MethodCompatCheck(span) => span,
ExprAssignable(span) => span,
Misc(span) => span,
RelateTraitRefs(span) => span,
RelateSelfType(span) => span,
RelateOutputImplTypes(span) => span,
MatchExpressionArm(match_span, _, _) => match_span,
IfExpression(span) => span,
IfExpressionWithNoElse(span) => span,
RangeExpression(span) => span,
EquatePredicate(span) => span,
TypeOrigin::MethodCompatCheck(span) => span,
TypeOrigin::ExprAssignable(span) => span,
TypeOrigin::Misc(span) => span,
TypeOrigin::RelateTraitRefs(span) => span,
TypeOrigin::RelateSelfType(span) => span,
TypeOrigin::RelateOutputImplTypes(span) => span,
TypeOrigin::MatchExpressionArm(match_span, _, _) => match_span,
TypeOrigin::IfExpression(span) => span,
TypeOrigin::IfExpressionWithNoElse(span) => span,
TypeOrigin::RangeExpression(span) => span,
TypeOrigin::EquatePredicate(span) => span,
}
}
}

View file

@ -21,7 +21,7 @@ use metadata::cstore::LOCAL_CRATE;
use middle::def_id::DefId;
use middle::subst::{Subst, Substs, TypeSpace};
use middle::ty::{self, Ty};
use middle::infer::{self, InferCtxt};
use middle::infer::{self, InferCtxt, TypeOrigin};
use syntax::codemap::{DUMMY_SP, Span};
#[derive(Copy, Clone)]
@ -70,7 +70,7 @@ fn overlap(selcx: &mut SelectionContext,
// Do `a` and `b` unify? If not, no overlap.
if let Err(_) = infer::mk_eq_trait_refs(selcx.infcx(),
true,
infer::Misc(DUMMY_SP),
TypeOrigin::Misc(DUMMY_SP),
a_trait_ref,
b_trait_ref) {
return false;

View file

@ -21,7 +21,7 @@ use super::VtableClosureData;
use super::VtableImplData;
use super::util;
use middle::infer;
use middle::infer::{self, TypeOrigin};
use middle::subst::Subst;
use middle::ty::{self, ToPredicate, RegionEscape, HasTypeFlags, ToPolyTraitRef, Ty};
use middle::ty::fold::{TypeFoldable, TypeFolder};
@ -138,7 +138,7 @@ fn project_and_unify_type<'cx,'tcx>(
obligations);
let infcx = selcx.infcx();
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
match infer::mk_eqty(infcx, true, origin, normalized_ty, obligation.predicate.ty) {
Ok(()) => Ok(Some(obligations)),
Err(err) => Err(MismatchedProjectionTypes { err: err }),
@ -183,7 +183,7 @@ fn consider_unification_despite_ambiguity<'cx,'tcx>(selcx: &mut SelectionContext
debug!("consider_unification_despite_ambiguity: ret_type={:?}",
ret_type);
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
let obligation_ty = obligation.predicate.ty;
match infer::mk_eqty(infcx, true, origin, obligation_ty, ret_type) {
Ok(()) => { }
@ -645,7 +645,7 @@ fn assemble_candidates_from_predicates<'cx,'tcx,I>(
let same_name = data.item_name() == obligation.predicate.item_name;
let is_match = same_name && infcx.probe(|_| {
let origin = infer::Misc(obligation.cause.span);
let origin = TypeOrigin::Misc(obligation.cause.span);
let data_poly_trait_ref =
data.to_poly_trait_ref();
let obligation_poly_trait_ref =
@ -901,7 +901,7 @@ fn confirm_param_env_candidate<'cx,'tcx>(
assert_eq!(projection.projection_ty.item_name,
obligation.predicate.item_name);
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
match infcx.eq_trait_refs(false,
origin,
obligation.predicate.trait_ref.clone(),

View file

@ -38,7 +38,7 @@ use super::util;
use middle::def_id::DefId;
use middle::infer;
use middle::infer::{InferCtxt, TypeFreshener};
use middle::infer::{InferCtxt, TypeFreshener, TypeOrigin};
use middle::subst::{Subst, Substs, TypeSpace};
use middle::ty::{self, ToPredicate, RegionEscape, ToPolyTraitRef, Ty, HasTypeFlags};
use middle::ty::fast_reject;
@ -1155,7 +1155,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
-> bool
{
assert!(!skol_trait_ref.has_escaping_regions());
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
match self.infcx.sub_poly_trait_refs(false,
origin,
trait_bound.clone(),
@ -2444,7 +2444,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
expected_trait_ref: ty::PolyTraitRef<'tcx>)
-> Result<(), SelectionError<'tcx>>
{
let origin = infer::RelateOutputImplTypes(obligation_cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation_cause.span);
let obligation_trait_ref = obligation_trait_ref.clone();
match self.infcx.sub_poly_trait_refs(false,
@ -2483,7 +2483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
};
let new_trait = tcx.mk_trait(data_a.principal.clone(), bounds);
let origin = infer::Misc(obligation.cause.span);
let origin = TypeOrigin::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, new_trait, target).is_err() {
return Err(Unimplemented);
}
@ -2548,7 +2548,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// [T; n] -> [T].
(&ty::TyArray(a, _), &ty::TySlice(b)) => {
let origin = infer::Misc(obligation.cause.span);
let origin = TypeOrigin::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, a, b).is_err() {
return Err(Unimplemented);
}
@ -2606,7 +2606,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
new_substs.types.get_mut_slice(TypeSpace)[i] = param_b;
}
let new_struct = tcx.mk_struct(def, tcx.mk_substs(new_substs));
let origin = infer::Misc(obligation.cause.span);
let origin = TypeOrigin::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, new_struct, target).is_err() {
return Err(Unimplemented);
}
@ -2694,7 +2694,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
impl_trait_ref,
skol_obligation_trait_ref);
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
if let Err(e) = self.infcx.eq_trait_refs(false,
origin,
impl_trait_ref.value.clone(),
@ -2763,7 +2763,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation,
poly_trait_ref);
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
match self.infcx.sub_poly_trait_refs(false,
origin,
poly_trait_ref,