Skip to content

Use the TypeOrigin variants qualified. #30054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"
}
};
Expand Down
39 changes: 20 additions & 19 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(|_| ())
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(|_| ())
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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(()) => { }
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_typeck::middle::subst;
use rustc_typeck::middle::subst::Subst;
use rustc_typeck::middle::ty::{self, Ty, RegionEscape};
use rustc_typeck::middle::ty::relate::TypeRelation;
use rustc_typeck::middle::infer;
use rustc_typeck::middle::infer::{self, TypeOrigin};
use rustc_typeck::middle::infer::lub::Lub;
use rustc_typeck::middle::infer::glb::Glb;
use rustc_typeck::middle::infer::sub::Sub;
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
}

pub fn make_subtype(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
match infer::mk_subty(self.infcx, true, infer::Misc(DUMMY_SP), a, b) {
match infer::mk_subty(self.infcx, true, TypeOrigin::Misc(DUMMY_SP), a, b) {
Ok(_) => true,
Err(ref e) => panic!("Encountered error: {}", e),
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use middle::def;
use middle::infer;
use middle::infer::{self, TypeOrigin};
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding};
use middle::pat_util::pat_is_resolved_const;
use middle::privacy::{AllPublic, LastMod};
Expand Down Expand Up @@ -509,12 +509,12 @@ pub fn check_match<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
/* if-let construct without an else block */
hir::MatchSource::IfLetDesugar { contains_else_clause }
if !contains_else_clause => (
infer::IfExpressionWithNoElse(expr.span),
TypeOrigin::IfExpressionWithNoElse(expr.span),
bty,
result_ty,
),
_ => (
infer::MatchExpressionArm(expr.span, arm.body.span, match_src),
TypeOrigin::MatchExpressionArm(expr.span, arm.body.span, match_src),
result_ty,
bty,
),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

use check::{autoderef, FnCtxt, UnresolvedTypeAction};

use middle::infer::{self, Coercion};
use middle::infer::{self, Coercion, TypeOrigin};
use middle::traits::{self, ObligationCause};
use middle::traits::{predicate_for_trait_def, report_selection_error};
use middle::ty::adjustment::{AutoAdjustment, AutoDerefRef, AdjustDerefRef};
Expand Down Expand Up @@ -444,7 +444,7 @@ pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
fcx.infcx().commit_if_ok(|_| {
let coerce = Coerce {
fcx: fcx,
origin: infer::ExprAssignable(expr.span),
origin: TypeOrigin::ExprAssignable(expr.span),
unsizing_obligations: RefCell::new(vec![])
};
let adjustment = try!(coerce.coerce(expr, a, b));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use middle::free_region::FreeRegionMap;
use middle::infer;
use middle::infer::{self, TypeOrigin};
use middle::traits;
use middle::ty::{self};
use middle::subst::{self, Subst, Substs, VecPerParamSpace};
Expand Down Expand Up @@ -282,7 +282,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
let trait_fty = trait_fty.subst(tcx, &trait_to_skol_substs);

let err = infcx.commit_if_ok(|snapshot| {
let origin = infer::MethodCompatCheck(impl_m_span);
let origin = TypeOrigin::MethodCompatCheck(impl_m_span);

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

let err = infcx.commit_if_ok(|_| {
let origin = infer::Misc(impl_c_span);
let origin = TypeOrigin::Misc(impl_c_span);

// There is no "body" here, so just pass dummy id.
let impl_ty =
Expand Down
Loading