Skip to content

Commit da0444d

Browse files
committed
Auto merge of #30054 - Ms2ger:TypeOrigin, r=eddyb
2 parents 6d88afe + f24077f commit da0444d

File tree

16 files changed

+83
-82
lines changed

16 files changed

+83
-82
lines changed

src/librustc/middle/infer/error_reporting.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use rustc_front::print::pprust;
7878

7979
use middle::def;
8080
use middle::def_id::DefId;
81-
use middle::infer;
81+
use middle::infer::{self, TypeOrigin};
8282
use middle::region;
8383
use middle::subst;
8484
use middle::ty::{self, Ty, HasTypeFlags};
@@ -474,7 +474,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
474474
self.check_and_note_conflicting_crates(terr, trace.origin.span());
475475

476476
match trace.origin {
477-
infer::MatchExpressionArm(_, arm_span, source) => match source {
477+
TypeOrigin::MatchExpressionArm(_, arm_span, source) => match source {
478478
hir::MatchSource::IfLetDesugar{..} =>
479479
self.tcx.sess.span_note(arm_span, "`if let` arm with an incompatible type"),
480480
_ => 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> {
16021602
}
16031603
infer::Subtype(ref trace) => {
16041604
let desc = match trace.origin {
1605-
infer::Misc(_) => {
1605+
TypeOrigin::Misc(_) => {
16061606
"types are compatible"
16071607
}
1608-
infer::MethodCompatCheck(_) => {
1608+
TypeOrigin::MethodCompatCheck(_) => {
16091609
"method type is compatible with trait"
16101610
}
1611-
infer::ExprAssignable(_) => {
1611+
TypeOrigin::ExprAssignable(_) => {
16121612
"expression is assignable"
16131613
}
1614-
infer::RelateTraitRefs(_) => {
1614+
TypeOrigin::RelateTraitRefs(_) => {
16151615
"traits are compatible"
16161616
}
1617-
infer::RelateSelfType(_) => {
1617+
TypeOrigin::RelateSelfType(_) => {
16181618
"self type matches impl self type"
16191619
}
1620-
infer::RelateOutputImplTypes(_) => {
1620+
TypeOrigin::RelateOutputImplTypes(_) => {
16211621
"trait type parameters matches those \
16221622
specified on the impl"
16231623
}
1624-
infer::MatchExpressionArm(_, _, _) => {
1624+
TypeOrigin::MatchExpressionArm(_, _, _) => {
16251625
"match arms have compatible types"
16261626
}
1627-
infer::IfExpression(_) => {
1627+
TypeOrigin::IfExpression(_) => {
16281628
"if and else have compatible types"
16291629
}
1630-
infer::IfExpressionWithNoElse(_) => {
1630+
TypeOrigin::IfExpressionWithNoElse(_) => {
16311631
"if may be missing an else clause"
16321632
}
1633-
infer::RangeExpression(_) => {
1633+
TypeOrigin::RangeExpression(_) => {
16341634
"start and end of range have compatible types"
16351635
}
1636-
infer::EquatePredicate(_) => {
1636+
TypeOrigin::EquatePredicate(_) => {
16371637
"equality where clause is satisfied"
16381638
}
16391639
};

src/librustc/middle/infer/mod.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
pub use self::LateBoundRegionConversionTime::*;
1414
pub use self::RegionVariableOrigin::*;
1515
pub use self::SubregionOrigin::*;
16-
pub use self::TypeOrigin::*;
1716
pub use self::ValuePairs::*;
1817
pub use middle::ty::IntVarValue;
1918
pub use self::freshen::TypeFreshener;
@@ -440,7 +439,7 @@ pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
440439
debug!("can_mk_subty({:?} <: {:?})", a, b);
441440
cx.probe(|_| {
442441
let trace = TypeTrace {
443-
origin: Misc(codemap::DUMMY_SP),
442+
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
444443
values: Types(expected_found(true, a, b))
445444
};
446445
cx.sub(true, trace).relate(&a, &b).map(|_| ())
@@ -950,7 +949,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
950949
self.commit_if_ok(|snapshot| {
951950
let (ty::EquatePredicate(a, b), skol_map) =
952951
self.skolemize_late_bound_regions(predicate, snapshot);
953-
let origin = EquatePredicate(span);
952+
let origin = TypeOrigin::EquatePredicate(span);
954953
let () = try!(mk_eqty(self, false, origin, a, b));
955954
self.leak_check(&skol_map, snapshot)
956955
})
@@ -1328,7 +1327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13281327
actual: Ty<'tcx>,
13291328
err: &TypeError<'tcx>) {
13301329
let trace = TypeTrace {
1331-
origin: Misc(span),
1330+
origin: TypeOrigin::Misc(span),
13321331
values: Types(ExpectedFound {
13331332
expected: expected,
13341333
found: actual
@@ -1342,7 +1341,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13421341
expected: type_variable::Default<'tcx>,
13431342
actual: type_variable::Default<'tcx>) {
13441343
let trace = TypeTrace {
1345-
origin: Misc(span),
1344+
origin: TypeOrigin::Misc(span),
13461345
values: Types(ExpectedFound {
13471346
expected: expected.ty,
13481347
found: actual.ty
@@ -1393,8 +1392,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13931392
// generic so we don't have to do anything quite this
13941393
// terrible.
13951394
let e = self.tcx.types.err;
1396-
let trace = TypeTrace { origin: Misc(codemap::DUMMY_SP),
1397-
values: Types(expected_found(true, e, e)) };
1395+
let trace = TypeTrace {
1396+
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
1397+
values: Types(expected_found(true, e, e))
1398+
};
13981399
self.equate(true, trace).relate(a, b)
13991400
}).map(|_| ())
14001401
}
@@ -1525,7 +1526,7 @@ impl<'tcx> TypeTrace<'tcx> {
15251526

15261527
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
15271528
TypeTrace {
1528-
origin: Misc(codemap::DUMMY_SP),
1529+
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
15291530
values: Types(ExpectedFound {
15301531
expected: tcx.types.err,
15311532
found: tcx.types.err,
@@ -1543,17 +1544,17 @@ impl<'tcx> fmt::Debug for TypeTrace<'tcx> {
15431544
impl TypeOrigin {
15441545
pub fn span(&self) -> Span {
15451546
match *self {
1546-
MethodCompatCheck(span) => span,
1547-
ExprAssignable(span) => span,
1548-
Misc(span) => span,
1549-
RelateTraitRefs(span) => span,
1550-
RelateSelfType(span) => span,
1551-
RelateOutputImplTypes(span) => span,
1552-
MatchExpressionArm(match_span, _, _) => match_span,
1553-
IfExpression(span) => span,
1554-
IfExpressionWithNoElse(span) => span,
1555-
RangeExpression(span) => span,
1556-
EquatePredicate(span) => span,
1547+
TypeOrigin::MethodCompatCheck(span) => span,
1548+
TypeOrigin::ExprAssignable(span) => span,
1549+
TypeOrigin::Misc(span) => span,
1550+
TypeOrigin::RelateTraitRefs(span) => span,
1551+
TypeOrigin::RelateSelfType(span) => span,
1552+
TypeOrigin::RelateOutputImplTypes(span) => span,
1553+
TypeOrigin::MatchExpressionArm(match_span, _, _) => match_span,
1554+
TypeOrigin::IfExpression(span) => span,
1555+
TypeOrigin::IfExpressionWithNoElse(span) => span,
1556+
TypeOrigin::RangeExpression(span) => span,
1557+
TypeOrigin::EquatePredicate(span) => span,
15571558
}
15581559
}
15591560
}

src/librustc/middle/traits/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use metadata::cstore::LOCAL_CRATE;
2121
use middle::def_id::DefId;
2222
use middle::subst::{Subst, Substs, TypeSpace};
2323
use middle::ty::{self, Ty};
24-
use middle::infer::{self, InferCtxt};
24+
use middle::infer::{self, InferCtxt, TypeOrigin};
2525
use syntax::codemap::{DUMMY_SP, Span};
2626

2727
#[derive(Copy, Clone)]
@@ -70,7 +70,7 @@ fn overlap(selcx: &mut SelectionContext,
7070
// Do `a` and `b` unify? If not, no overlap.
7171
if let Err(_) = infer::mk_eq_trait_refs(selcx.infcx(),
7272
true,
73-
infer::Misc(DUMMY_SP),
73+
TypeOrigin::Misc(DUMMY_SP),
7474
a_trait_ref,
7575
b_trait_ref) {
7676
return false;

src/librustc/middle/traits/project.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::VtableClosureData;
2121
use super::VtableImplData;
2222
use super::util;
2323

24-
use middle::infer;
24+
use middle::infer::{self, TypeOrigin};
2525
use middle::subst::Subst;
2626
use middle::ty::{self, ToPredicate, RegionEscape, HasTypeFlags, ToPolyTraitRef, Ty};
2727
use middle::ty::fold::{TypeFoldable, TypeFolder};
@@ -138,7 +138,7 @@ fn project_and_unify_type<'cx,'tcx>(
138138
obligations);
139139

140140
let infcx = selcx.infcx();
141-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
141+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
142142
match infer::mk_eqty(infcx, true, origin, normalized_ty, obligation.predicate.ty) {
143143
Ok(()) => Ok(Some(obligations)),
144144
Err(err) => Err(MismatchedProjectionTypes { err: err }),
@@ -183,7 +183,7 @@ fn consider_unification_despite_ambiguity<'cx,'tcx>(selcx: &mut SelectionContext
183183

184184
debug!("consider_unification_despite_ambiguity: ret_type={:?}",
185185
ret_type);
186-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
186+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
187187
let obligation_ty = obligation.predicate.ty;
188188
match infer::mk_eqty(infcx, true, origin, obligation_ty, ret_type) {
189189
Ok(()) => { }
@@ -645,7 +645,7 @@ fn assemble_candidates_from_predicates<'cx,'tcx,I>(
645645
let same_name = data.item_name() == obligation.predicate.item_name;
646646

647647
let is_match = same_name && infcx.probe(|_| {
648-
let origin = infer::Misc(obligation.cause.span);
648+
let origin = TypeOrigin::Misc(obligation.cause.span);
649649
let data_poly_trait_ref =
650650
data.to_poly_trait_ref();
651651
let obligation_poly_trait_ref =
@@ -901,7 +901,7 @@ fn confirm_param_env_candidate<'cx,'tcx>(
901901
assert_eq!(projection.projection_ty.item_name,
902902
obligation.predicate.item_name);
903903

904-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
904+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
905905
match infcx.eq_trait_refs(false,
906906
origin,
907907
obligation.predicate.trait_ref.clone(),

src/librustc/middle/traits/select.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use super::util;
3838

3939
use middle::def_id::DefId;
4040
use middle::infer;
41-
use middle::infer::{InferCtxt, TypeFreshener};
41+
use middle::infer::{InferCtxt, TypeFreshener, TypeOrigin};
4242
use middle::subst::{Subst, Substs, TypeSpace};
4343
use middle::ty::{self, ToPredicate, RegionEscape, ToPolyTraitRef, Ty, HasTypeFlags};
4444
use middle::ty::fast_reject;
@@ -1155,7 +1155,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11551155
-> bool
11561156
{
11571157
assert!(!skol_trait_ref.has_escaping_regions());
1158-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
1158+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
11591159
match self.infcx.sub_poly_trait_refs(false,
11601160
origin,
11611161
trait_bound.clone(),
@@ -2444,7 +2444,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24442444
expected_trait_ref: ty::PolyTraitRef<'tcx>)
24452445
-> Result<(), SelectionError<'tcx>>
24462446
{
2447-
let origin = infer::RelateOutputImplTypes(obligation_cause.span);
2447+
let origin = TypeOrigin::RelateOutputImplTypes(obligation_cause.span);
24482448

24492449
let obligation_trait_ref = obligation_trait_ref.clone();
24502450
match self.infcx.sub_poly_trait_refs(false,
@@ -2483,7 +2483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24832483
};
24842484

24852485
let new_trait = tcx.mk_trait(data_a.principal.clone(), bounds);
2486-
let origin = infer::Misc(obligation.cause.span);
2486+
let origin = TypeOrigin::Misc(obligation.cause.span);
24872487
if self.infcx.sub_types(false, origin, new_trait, target).is_err() {
24882488
return Err(Unimplemented);
24892489
}
@@ -2548,7 +2548,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25482548

25492549
// [T; n] -> [T].
25502550
(&ty::TyArray(a, _), &ty::TySlice(b)) => {
2551-
let origin = infer::Misc(obligation.cause.span);
2551+
let origin = TypeOrigin::Misc(obligation.cause.span);
25522552
if self.infcx.sub_types(false, origin, a, b).is_err() {
25532553
return Err(Unimplemented);
25542554
}
@@ -2606,7 +2606,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26062606
new_substs.types.get_mut_slice(TypeSpace)[i] = param_b;
26072607
}
26082608
let new_struct = tcx.mk_struct(def, tcx.mk_substs(new_substs));
2609-
let origin = infer::Misc(obligation.cause.span);
2609+
let origin = TypeOrigin::Misc(obligation.cause.span);
26102610
if self.infcx.sub_types(false, origin, new_struct, target).is_err() {
26112611
return Err(Unimplemented);
26122612
}
@@ -2694,7 +2694,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26942694
impl_trait_ref,
26952695
skol_obligation_trait_ref);
26962696

2697-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
2697+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
26982698
if let Err(e) = self.infcx.eq_trait_refs(false,
26992699
origin,
27002700
impl_trait_ref.value.clone(),
@@ -2763,7 +2763,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27632763
obligation,
27642764
poly_trait_ref);
27652765

2766-
let origin = infer::RelateOutputImplTypes(obligation.cause.span);
2766+
let origin = TypeOrigin::RelateOutputImplTypes(obligation.cause.span);
27672767
match self.infcx.sub_poly_trait_refs(false,
27682768
origin,
27692769
poly_trait_ref,

src/librustc_driver/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_typeck::middle::subst;
2525
use rustc_typeck::middle::subst::Subst;
2626
use rustc_typeck::middle::ty::{self, Ty, RegionEscape};
2727
use rustc_typeck::middle::ty::relate::TypeRelation;
28-
use rustc_typeck::middle::infer;
28+
use rustc_typeck::middle::infer::{self, TypeOrigin};
2929
use rustc_typeck::middle::infer::lub::Lub;
3030
use rustc_typeck::middle::infer::glb::Glb;
3131
use rustc_typeck::middle::infer::sub::Sub;
@@ -230,7 +230,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
230230
}
231231

232232
pub fn make_subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
233-
match infer::mk_subty(self.infcx, true, infer::Misc(DUMMY_SP), a, b) {
233+
match infer::mk_subty(self.infcx, true, TypeOrigin::Misc(DUMMY_SP), a, b) {
234234
Ok(_) => true,
235235
Err(ref e) => panic!("Encountered error: {}", e),
236236
}

src/librustc_typeck/check/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use middle::def;
12-
use middle::infer;
12+
use middle::infer::{self, TypeOrigin};
1313
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding};
1414
use middle::pat_util::pat_is_resolved_const;
1515
use middle::privacy::{AllPublic, LastMod};
@@ -509,12 +509,12 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
509509
/* if-let construct without an else block */
510510
hir::MatchSource::IfLetDesugar { contains_else_clause }
511511
if !contains_else_clause => (
512-
infer::IfExpressionWithNoElse(expr.span),
512+
TypeOrigin::IfExpressionWithNoElse(expr.span),
513513
bty,
514514
result_ty,
515515
),
516516
_ => (
517-
infer::MatchExpressionArm(expr.span, arm.body.span, match_src),
517+
TypeOrigin::MatchExpressionArm(expr.span, arm.body.span, match_src),
518518
result_ty,
519519
bty,
520520
),

src/librustc_typeck/check/coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
6363
use check::{autoderef, FnCtxt, UnresolvedTypeAction};
6464

65-
use middle::infer::{self, Coercion};
65+
use middle::infer::{self, Coercion, TypeOrigin};
6666
use middle::traits::{self, ObligationCause};
6767
use middle::traits::{predicate_for_trait_def, report_selection_error};
6868
use middle::ty::adjustment::{AutoAdjustment, AutoDerefRef, AdjustDerefRef};
@@ -444,7 +444,7 @@ pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
444444
fcx.infcx().commit_if_ok(|_| {
445445
let coerce = Coerce {
446446
fcx: fcx,
447-
origin: infer::ExprAssignable(expr.span),
447+
origin: TypeOrigin::ExprAssignable(expr.span),
448448
unsizing_obligations: RefCell::new(vec![])
449449
};
450450
let adjustment = try!(coerce.coerce(expr, a, b));

src/librustc_typeck/check/compare_method.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use middle::free_region::FreeRegionMap;
12-
use middle::infer;
12+
use middle::infer::{self, TypeOrigin};
1313
use middle::traits;
1414
use middle::ty::{self};
1515
use middle::subst::{self, Subst, Substs, VecPerParamSpace};
@@ -282,7 +282,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
282282
let trait_fty = trait_fty.subst(tcx, &trait_to_skol_substs);
283283

284284
let err = infcx.commit_if_ok(|snapshot| {
285-
let origin = infer::MethodCompatCheck(impl_m_span);
285+
let origin = TypeOrigin::MethodCompatCheck(impl_m_span);
286286

287287
let (impl_sig, _) =
288288
infcx.replace_late_bound_regions_with_fresh_var(impl_m_span,
@@ -448,7 +448,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>,
448448
let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
449449

450450
let err = infcx.commit_if_ok(|_| {
451-
let origin = infer::Misc(impl_c_span);
451+
let origin = TypeOrigin::Misc(impl_c_span);
452452

453453
// There is no "body" here, so just pass dummy id.
454454
let impl_ty =

0 commit comments

Comments
 (0)