use middle::ty::{TyVar};
use middle::ty::{IntType, UintType};
-use middle::ty::{self, Ty};
+use middle::ty::{self, Ty, TypeError};
use middle::ty_fold;
use middle::ty_fold::{TypeFolder, TypeFoldable};
use middle::ty_relate::{self, Relate, RelateResult, TypeRelation};
// All other cases of inference are errors
(&ty::TyInfer(_), _) |
(_, &ty::TyInfer(_)) => {
- Err(ty::Sorts(ty_relate::expected_found(relation, &a, &b)))
+ Err(TypeError::Sorts(ty_relate::expected_found(relation, &a, &b)))
}
};
let u = ty.fold_with(&mut generalize);
if generalize.cycle_detected {
- Err(ty::CyclicTy)
+ Err(TypeError::CyclicTy)
} else {
Ok(u)
}
-> ty::TypeError<'tcx>
{
let (a, b) = v;
- ty::IntMismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
+ TypeError::IntMismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
}
fn float_unification_error<'tcx>(a_is_expected: bool,
-> ty::TypeError<'tcx>
{
let (a, b) = v;
- ty::FloatMismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
+ TypeError::FloatMismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
}
use middle::infer;
use middle::region;
use middle::subst;
-use middle::ty::{self, Ty, HasTypeFlags};
+use middle::ty::{self, Ty, TypeError, HasTypeFlags};
use middle::ty::{Region, ReFree};
use std::cell::{Cell, RefCell};
match free_regions_from_same_fn(self.tcx, sub, sup) {
Some(ref same_frs) if trace.is_some() => {
let trace = trace.unwrap();
- let terr = ty::RegionsDoesNotOutlive(sup,
- sub);
+ let terr = TypeError::RegionsDoesNotOutlive(sup,
+ sub);
trace_origins.push((trace, terr));
append_to_same_regions(&mut same_regions, same_frs);
}
match origin {
infer::Subtype(trace) |
infer::DefaultExistentialBound(trace) => {
- let terr = ty::RegionsDoesNotOutlive(sup, sub);
+ let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
self.report_and_explain_type_error(trace, &terr);
}
infer::Reborrow(span) => {
use super::combine::CombineFields;
use middle::subst;
-use middle::ty::{self, Binder};
+use middle::ty::{self, TypeError, Binder};
use middle::ty_fold::{self, TypeFoldable};
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
use syntax::codemap::Span;
Err((skol_br, tainted_region)) => {
if self.a_is_expected {
debug!("Not as polymorphic!");
- return Err(ty::RegionsInsufficientlyPolymorphic(skol_br,
+ return Err(TypeError::RegionsInsufficientlyPolymorphic(skol_br,
tainted_region));
} else {
debug!("Overly polymorphic!");
- return Err(ty::RegionsOverlyPolymorphic(skol_br,
+ return Err(TypeError::RegionsOverlyPolymorphic(skol_br,
tainted_region));
}
}
use middle::traits::{self, FulfillmentContext, Normalized,
SelectionContext, ObligationCause};
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric};
-use middle::ty::{self, Ty, HasTypeFlags};
+use middle::ty::{self, Ty, TypeError, HasTypeFlags};
use middle::ty_fold::{self, TypeFolder, TypeFoldable};
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
use rustc_data_structures::unify::{self, UnificationTable};
match higher_ranked::leak_check(self, skol_map, snapshot) {
Ok(()) => Ok(()),
- Err((br, r)) => Err(ty::RegionsInsufficientlyPolymorphic(br, r))
+ Err((br, r)) => Err(TypeError::RegionsInsufficientlyPolymorphic(br, r))
}
}
use rustc_data_structures::graph::{self, Direction, NodeIndex};
use middle::free_region::FreeRegionMap;
use middle::region;
-use middle::ty::{self, Ty};
+use middle::ty::{self, Ty, TypeError};
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound};
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope {
Ok(s)
} else {
- Err(ty::RegionsNoOverlap(b, a))
+ Err(TypeError::RegionsNoOverlap(b, a))
}
}
if a == b {
Ok(a)
} else {
- Err(ty::RegionsNoOverlap(b, a))
+ Err(TypeError::RegionsNoOverlap(b, a))
}
}
}
} else if r_id == scope_b {
Ok(ReScope(scope_a))
} else {
- Err(ty::RegionsNoOverlap(region_a, region_b))
+ Err(TypeError::RegionsNoOverlap(region_a, region_b))
}
}
}
// FIXME: (@jroesch) @eddyb should remove this when he renames ctxt
#![allow(non_camel_case_types)]
-pub use self::TypeError::*;
pub use self::InferTy::*;
pub use self::InferRegion::*;
pub use self::ImplOrTraitItemId::*;
}
fn sort_string(&self, cx: &ctxt) -> String {
+
match self.sty {
TyBool | TyChar | TyInt(_) |
TyUint(_) | TyFloat(_) | TyStr => self.to_string(),
/// errors.
impl<'tcx> fmt::Display for TypeError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use self::TypeError::*;
+
match *self {
CyclicTy => write!(f, "cyclic type of infinite size"),
Mismatch => write!(f, "types differ"),
}
pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
+ use self::TypeError::*;
+
match *err {
RegionsDoesNotOutlive(subregion, superregion) => {
self.note_and_explain_region("", subregion, "...");
(&ty::TyInfer(_), _) |
(_, &ty::TyInfer(_)) => {
- Err(ty::Sorts(ty_relate::expected_found(self, &a, &b)))
+ Err(ty::TypeError::Sorts(ty_relate::expected_found(self, &a, &b)))
}
(&ty::TyError, _) | (_, &ty::TyError) => {
//! type equality, etc.
use middle::subst::{ErasedRegions, NonerasedRegions, ParamSpace, Substs};
-use middle::ty::{self, Ty};
+use middle::ty::{self, Ty, TypeError};
use middle::ty_fold::TypeFoldable;
use std::rc::Rc;
use syntax::abi;
a,
b);
if a.mutbl != b.mutbl {
- Err(ty::Mutability)
+ Err(TypeError::Mutability)
} else {
let mutbl = a.mutbl;
let variance = match mutbl {
where R: TypeRelation<'a,'tcx>
{
if a_tys.len() != b_tys.len() {
- return Err(ty::TyParamSize(expected_found(relation,
+ return Err(TypeError::TyParamSize(expected_found(relation,
&a_tys.len(),
&b_tys.len())));
}
where R: TypeRelation<'a,'tcx>
{
if a.variadic != b.variadic {
- return Err(ty::VariadicMismatch(
+ return Err(TypeError::VariadicMismatch(
expected_found(relation, &a.variadic, &b.variadic)));
}
(ty::FnDiverging, ty::FnDiverging) =>
Ok(ty::FnDiverging),
(a, b) =>
- Err(ty::ConvergenceMismatch(
+ Err(TypeError::ConvergenceMismatch(
expected_found(relation, &(a != ty::FnDiverging), &(b != ty::FnDiverging)))),
});
where R: TypeRelation<'a,'tcx>
{
if a_args.len() != b_args.len() {
- return Err(ty::ArgCount);
+ return Err(TypeError::ArgCount);
}
a_args.iter().zip(b_args)
where R: TypeRelation<'a,'tcx>
{
if a != b {
- Err(ty::UnsafetyMismatch(expected_found(relation, a, b)))
+ Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
} else {
Ok(*a)
}
if a == b {
Ok(*a)
} else {
- Err(ty::AbiMismatch(expected_found(relation, a, b)))
+ Err(TypeError::AbiMismatch(expected_found(relation, a, b)))
}
}
}
where R: TypeRelation<'a,'tcx>
{
if a.item_name != b.item_name {
- Err(ty::ProjectionNameMismatched(
+ Err(TypeError::ProjectionNameMismatched(
expected_found(relation, &a.item_name, &b.item_name)))
} else {
let trait_ref = try!(relation.relate(&a.trait_ref, &b.trait_ref));
// so we can just iterate through the lists pairwise, so long as they are the
// same length.
if a.len() != b.len() {
- Err(ty::ProjectionBoundsLength(expected_found(relation, &a.len(), &b.len())))
+ Err(TypeError::ProjectionBoundsLength(expected_found(relation, &a.len(), &b.len())))
} else {
a.iter().zip(b)
.map(|(a, b)| relation.relate(a, b))
// Two sets of builtin bounds are only relatable if they are
// precisely the same (but see the coercion code).
if a != b {
- Err(ty::BuiltinBoundsMismatch(expected_found(relation, a, b)))
+ Err(TypeError::BuiltinBoundsMismatch(expected_found(relation, a, b)))
} else {
Ok(*a)
}
{
// Different traits cannot be related
if a.def_id != b.def_id {
- Err(ty::Traits(expected_found(relation, &a.def_id, &b.def_id)))
+ Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
} else {
let substs = try!(relate_item_substs(relation, a.def_id, a.substs, b.substs));
Ok(ty::TraitRef { def_id: a.def_id, substs: relation.tcx().mk_substs(substs) })
if sz_a == sz_b {
Ok(tcx.mk_array(t, sz_a))
} else {
- Err(ty::FixedArraySize(expected_found(relation, &sz_a, &sz_b)))
+ Err(TypeError::FixedArraySize(expected_found(relation, &sz_a, &sz_b)))
}
}
.collect::<Result<_, _>>());
Ok(tcx.mk_tup(ts))
} else if !(as_.is_empty() || bs.is_empty()) {
- Err(ty::TupleSize(
+ Err(TypeError::TupleSize(
expected_found(relation, &as_.len(), &bs.len())))
} else {
- Err(ty::Sorts(expected_found(relation, &a, &b)))
+ Err(TypeError::Sorts(expected_found(relation, &a, &b)))
}
}
_ =>
{
- Err(ty::Sorts(expected_found(relation, &a, &b)))
+ Err(TypeError::Sorts(expected_found(relation, &a, &b)))
}
}
}
use middle::traits::{self, ObligationCause};
use middle::traits::{predicate_for_trait_def, report_selection_error};
use middle::ty::{AutoDerefRef, AdjustDerefRef};
-use middle::ty::{self, TypeWithMutability, Ty};
+use middle::ty::{self, TypeWithMutability, Ty, TypeError};
use middle::ty_relate::RelateResult;
use util::common::indent;
(u, cu)
} else {
debug!("Missing Unsize or CoerceUnsized traits");
- return Err(ty::Mismatch);
+ return Err(TypeError::Mismatch);
};
// Note, we want to avoid unnecessary unsizing. We don't want to coerce to
// Uncertain or unimplemented.
Ok(None) | Err(traits::Unimplemented) => {
debug!("coerce_unsized: early return - can't prove obligation");
- return Err(ty::Mismatch);
+ return Err(TypeError::Mismatch);
}
// Object safety violations or miscellaneous.
(ast::MutMutable, ast::MutMutable) |
(ast::MutImmutable, ast::MutImmutable) |
(ast::MutMutable, ast::MutImmutable) => Ok(None),
- (ast::MutImmutable, ast::MutMutable) => Err(ty::Mutability)
+ (ast::MutImmutable, ast::MutMutable) => Err(TypeError::Mutability)
}
}
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
if (mt_a.mutbl, mt_b.mutbl) == (ast::MutImmutable, ast::MutMutable) {
infcx.report_mismatched_types(span, mk_ptr(mt_b.ty),
- target, &ty::Mutability);
+ target, &ty::TypeError::Mutability);
}
(mt_a.ty, mt_b.ty, unsize_trait, None)
};