Auto merge of #26895 - jroesch:modernize-typeck-names, r=nikomatsakis

This PR modernizes some names in the type checker. The only remaining snake_case name in ty.rs is `ctxt` which should be resolved by @eddyb's pending refactor. We can bike shed over the names, it would just be nice to bring the type checker inline with modern Rust.

r? @eddyb 

cc @nikomatsakis
This commit is contained in:
bors 2015-07-12 19:22:11 +00:00
commit adcae006d2
48 changed files with 316 additions and 312 deletions

View file

@ -197,7 +197,7 @@ pub fn get_item_attrs(cstore: &cstore::CStore,
pub fn get_struct_fields(cstore: &cstore::CStore,
def: ast::DefId)
-> Vec<ty::field_ty> {
-> Vec<ty::FieldTy> {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
}

View file

@ -1049,7 +1049,7 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
}
pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
-> Vec<ty::field_ty> {
-> Vec<ty::FieldTy> {
let data = cdata.data();
let item = lookup_item(id, data);
reader::tagged_docs(item, tag_item_field).filter_map(|an_item| {
@ -1059,7 +1059,7 @@ pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
let did = item_def_id(an_item, cdata);
let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
let origin_id = translated_def_id(cdata, tagdoc);
Some(ty::field_ty {
Some(ty::FieldTy {
name: name,
id: did,
vis: struct_field_family_to_visibility(f),
@ -1073,7 +1073,7 @@ pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
let f = item_family(an_item);
let origin_id = translated_def_id(cdata, tagdoc);
ty::field_ty {
ty::FieldTy {
name: special_idents::unnamed_field.name,
id: did,
vis: struct_field_family_to_visibility(f),

View file

@ -267,7 +267,7 @@ fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
}
fn encode_struct_fields(rbml_w: &mut Encoder,
fields: &[ty::field_ty],
fields: &[ty::FieldTy],
origin: DefId) {
for f in fields {
if f.name == special_idents::unnamed_field.name {
@ -636,7 +636,7 @@ fn encode_provided_source(rbml_w: &mut Encoder,
/* Returns an index of items in this class */
fn encode_info_for_struct(ecx: &EncodeContext,
rbml_w: &mut Encoder,
fields: &[ty::field_ty],
fields: &[ty::FieldTy],
global_index: &mut Vec<entry<i64>>)
-> Vec<entry<i64>> {
/* Each class has its own index, since different classes

View file

@ -525,7 +525,7 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
assert_eq!(next(st), ':');
let len = parse_hex(st);
assert_eq!(next(st), '#');
let key = ty::creader_cache_key {cnum: st.krate,
let key = ty::CReaderCacheKey {cnum: st.krate,
pos: pos,
len: len };
@ -587,11 +587,11 @@ fn parse_mutability(st: &mut PState) -> ast::Mutability {
}
}
fn parse_mt_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> ty::mt<'tcx> where
fn parse_mt_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> ty::TypeAndMut<'tcx> where
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
{
let m = parse_mutability(st);
ty::mt { ty: parse_ty_(st, conv), mutbl: m }
ty::TypeAndMut { ty: parse_ty_(st, conv), mutbl: m }
}
fn parse_def_<F>(st: &mut PState, source: DefIdSource, conv: &mut F) -> ast::DefId where

View file

@ -183,7 +183,7 @@ fn enc_mutability(w: &mut Encoder, mt: ast::Mutability) {
}
fn enc_mt<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
mt: ty::mt<'tcx>) {
mt: ty::TypeAndMut<'tcx>) {
enc_mutability(w, mt.mutbl);
enc_ty(w, cx, mt.ty);
}

View file

@ -36,9 +36,9 @@ pub enum CastTy<'tcx> {
/// Function Pointers
FnPtr,
/// Raw pointers
Ptr(&'tcx ty::mt<'tcx>),
Ptr(&'tcx ty::TypeAndMut<'tcx>),
/// References
RPtr(&'tcx ty::mt<'tcx>),
RPtr(&'tcx ty::TypeAndMut<'tcx>),
}
/// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)

View file

@ -535,7 +535,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
}
}
ty::TyRef(_, ty::mt { ty, mutbl }) => {
ty::TyRef(_, ty::TypeAndMut { ty, mutbl }) => {
match ty.sty {
ty::TyArray(_, n) => match ctor {
&Single => {
@ -600,7 +600,7 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: Ty,
ty::TyBool =>
[true, false].iter().map(|b| ConstantValue(ConstVal::Bool(*b))).collect(),
ty::TyRef(_, ty::mt { ty, .. }) => match ty.sty {
ty::TyRef(_, ty::TypeAndMut { ty, .. }) => match ty.sty {
ty::TySlice(_) =>
range_inclusive(0, max_slice_length).map(|length| Slice(length)).collect(),
_ => vec!(Single)
@ -808,7 +808,7 @@ pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> usi
match ty.sty {
ty::TyTuple(ref fs) => fs.len(),
ty::TyBox(_) => 1,
ty::TyRef(_, ty::mt { ty, .. }) => match ty.sty {
ty::TyRef(_, ty::TypeAndMut { ty, .. }) => match ty.sty {
ty::TySlice(_) => match *ctor {
Slice(length) => length,
ConstantValue(_) => 0,

View file

@ -720,7 +720,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
// are properly handled.
self.walk_expr(with_expr);
fn contains_field_named(field: &ty::field,
fn contains_field_named(field: &ty::Field,
fields: &Vec<ast::Field>)
-> bool
{

View file

@ -115,7 +115,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
ty::TyArray(t, _) |
ty::TySlice(t) |
ty::TyRawPtr(ty::mt { ty: t, .. }) |
ty::TyRawPtr(ty::TypeAndMut { ty: t, .. }) |
ty::TyBox(t) => {
self.accumulate_from_ty(t)
}

View file

@ -43,7 +43,7 @@ use super::type_variable::{RelationDir, BiTo, EqTo, SubtypeOf, SupertypeOf};
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};
@ -108,7 +108,7 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>,
// All other cases of inference are errors
(&ty::TyInfer(_), _) |
(_, &ty::TyInfer(_)) => {
Err(ty::terr_sorts(ty_relate::expected_found(relation, &a, &b)))
Err(TypeError::Sorts(ty_relate::expected_found(relation, &a, &b)))
}
@ -278,7 +278,7 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
};
let u = ty.fold_with(&mut generalize);
if generalize.cycle_detected {
Err(ty::terr_cyclic_ty)
Err(TypeError::CyclicTy)
} else {
Ok(u)
}
@ -363,12 +363,12 @@ impl<'cx, 'tcx> ty_fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
pub trait RelateResultCompare<'tcx, T> {
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T> where
F: FnOnce() -> ty::type_err<'tcx>;
F: FnOnce() -> ty::TypeError<'tcx>;
}
impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'tcx, T> {
fn compare<F>(&self, t: T, f: F) -> RelateResult<'tcx, T> where
F: FnOnce() -> ty::type_err<'tcx>,
F: FnOnce() -> ty::TypeError<'tcx>,
{
self.clone().and_then(|s| {
if s == t {
@ -381,16 +381,16 @@ impl<'tcx, T:Clone + PartialEq> RelateResultCompare<'tcx, T> for RelateResult<'t
}
fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::IntVarValue))
-> ty::type_err<'tcx>
-> ty::TypeError<'tcx>
{
let (a, b) = v;
ty::terr_int_mismatch(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,
v: (ast::FloatTy, ast::FloatTy))
-> ty::type_err<'tcx>
-> ty::TypeError<'tcx>
{
let (a, b) = v;
ty::terr_float_mismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
TypeError::FloatMismatch(ty_relate::expected_found_bool(a_is_expected, &a, &b))
}

View file

@ -77,7 +77,7 @@ use middle::def;
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};
@ -220,17 +220,17 @@ pub trait ErrorReporting<'tcx> {
fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
-> Vec<RegionResolutionError<'tcx>>;
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>);
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::TypeError<'tcx>);
fn report_and_explain_type_error(&self,
trace: TypeTrace<'tcx>,
terr: &ty::type_err<'tcx>);
terr: &ty::TypeError<'tcx>);
fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<String>;
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
&self,
exp_found: &ty::expected_found<T>)
exp_found: &ty::ExpectedFound<T>)
-> Option<String>;
fn report_concrete_failure(&self,
@ -260,7 +260,7 @@ pub trait ErrorReporting<'tcx> {
fn report_processed_errors(&self,
var_origin: &[RegionVariableOrigin],
trace_origin: &[(TypeTrace<'tcx>, ty::type_err<'tcx>)],
trace_origin: &[(TypeTrace<'tcx>, ty::TypeError<'tcx>)],
same_regions: &[SameRegions]);
fn give_suggestion(&self, same_regions: &[SameRegions]);
@ -351,8 +351,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
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::terr_regions_does_not_outlive(sup,
sub);
let terr = TypeError::RegionsDoesNotOutlive(sup,
sub);
trace_origins.push((trace, terr));
append_to_same_regions(&mut same_regions, same_frs);
}
@ -467,7 +467,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
}
}
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::type_err<'tcx>) {
fn report_type_error(&self, trace: TypeTrace<'tcx>, terr: &ty::TypeError<'tcx>) {
let expected_found_str = match self.values_str(&trace.values) {
Some(v) => v,
None => {
@ -490,7 +490,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
fn report_and_explain_type_error(&self,
trace: TypeTrace<'tcx>,
terr: &ty::type_err<'tcx>) {
terr: &ty::TypeError<'tcx>) {
let span = trace.origin.span();
self.report_type_error(trace, terr);
self.tcx.note_and_explain_type_err(terr, span);
@ -508,7 +508,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
&self,
exp_found: &ty::expected_found<T>)
exp_found: &ty::ExpectedFound<T>)
-> Option<String>
{
let expected = exp_found.expected.resolve(self);
@ -595,7 +595,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
match origin {
infer::Subtype(trace) |
infer::DefaultExistentialBound(trace) => {
let terr = ty::terr_regions_does_not_outlive(sup, sub);
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
self.report_and_explain_type_error(trace, &terr);
}
infer::Reborrow(span) => {
@ -888,7 +888,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
fn report_processed_errors(&self,
var_origins: &[RegionVariableOrigin],
trace_origins: &[(TypeTrace<'tcx>, ty::type_err<'tcx>)],
trace_origins: &[(TypeTrace<'tcx>, ty::TypeError<'tcx>)],
same_regions: &[SameRegions]) {
for vo in var_origins {
self.report_inference_failure(vo.clone());

View file

@ -15,7 +15,7 @@ use super::{CombinedSnapshot, InferCtxt, HigherRankedType, SkolemizationMap};
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;
@ -85,11 +85,11 @@ impl<'a,'tcx> HigherRankedRelations<'a,'tcx> for CombineFields<'a,'tcx> {
Err((skol_br, tainted_region)) => {
if self.a_is_expected {
debug!("Not as polymorphic!");
return Err(ty::terr_regions_insufficiently_polymorphic(skol_br,
return Err(TypeError::RegionsInsufficientlyPolymorphic(skol_br,
tainted_region));
} else {
debug!("Overly polymorphic!");
return Err(ty::terr_regions_overly_polymorphic(skol_br,
return Err(TypeError::RegionsOverlyPolymorphic(skol_br,
tainted_region));
}
}

View file

@ -10,14 +10,11 @@
//! See the Book for more information.
#![allow(non_camel_case_types)]
pub use self::LateBoundRegionConversionTime::*;
pub use self::RegionVariableOrigin::*;
pub use self::SubregionOrigin::*;
pub use self::TypeOrigin::*;
pub use self::ValuePairs::*;
pub use self::fixup_err::*;
pub use middle::ty::IntVarValue;
pub use self::freshen::TypeFreshener;
pub use self::region_inference::GenericKind;
@ -32,7 +29,7 @@ use middle::subst::Subst;
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};
@ -65,7 +62,7 @@ pub mod unify_key;
pub type Bound<T> = Option<T>;
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
pub struct InferCtxt<'a, 'tcx: 'a> {
pub tcx: &'a ty::ctxt<'tcx>,
@ -171,9 +168,9 @@ impl fmt::Display for TypeOrigin {
/// See `error_reporting.rs` for more details
#[derive(Clone, Debug)]
pub enum ValuePairs<'tcx> {
Types(ty::expected_found<Ty<'tcx>>),
TraitRefs(ty::expected_found<ty::TraitRef<'tcx>>),
PolyTraitRefs(ty::expected_found<ty::PolyTraitRef<'tcx>>),
Types(ty::ExpectedFound<Ty<'tcx>>),
TraitRefs(ty::ExpectedFound<ty::TraitRef<'tcx>>),
PolyTraitRefs(ty::ExpectedFound<ty::PolyTraitRef<'tcx>>),
}
/// The trace designates the path through inference that we took to
@ -313,23 +310,25 @@ pub enum RegionVariableOrigin {
}
#[derive(Copy, Clone, Debug)]
pub enum fixup_err {
unresolved_int_ty(IntVid),
unresolved_float_ty(FloatVid),
unresolved_ty(TyVid)
pub enum FixupError {
UnresolvedIntTy(IntVid),
UnresolvedFloatTy(FloatVid),
UnresolvedTy(TyVid)
}
pub fn fixup_err_to_string(f: fixup_err) -> String {
pub fn fixup_err_to_string(f: FixupError) -> String {
use self::FixupError::*;
match f {
unresolved_int_ty(_) => {
UnresolvedIntTy(_) => {
"cannot determine the type of this integer; add a suffix to \
specify the type explicitly".to_string()
}
unresolved_float_ty(_) => {
UnresolvedFloatTy(_) => {
"cannot determine the type of this number; add a suffix to specify \
the type explicitly".to_string()
}
unresolved_ty(_) => "unconstrained type".to_string(),
UnresolvedTy(_) => "unconstrained type".to_string(),
}
}
@ -460,12 +459,12 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
fn expected_found<T>(a_is_expected: bool,
a: T,
b: T)
-> ty::expected_found<T>
-> ty::ExpectedFound<T>
{
if a_is_expected {
ty::expected_found {expected: a, found: b}
ty::ExpectedFound {expected: a, found: b}
} else {
ty::expected_found {expected: b, found: a}
ty::ExpectedFound {expected: b, found: a}
}
}
@ -913,7 +912,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
match higher_ranked::leak_check(self, skol_map, snapshot) {
Ok(()) => Ok(()),
Err((br, r)) => Err(ty::terr_regions_insufficiently_polymorphic(br, r))
Err((br, r)) => Err(TypeError::RegionsInsufficientlyPolymorphic(br, r))
}
}
@ -1169,7 +1168,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }
}
pub fn fully_resolve<T:TypeFoldable<'tcx>>(&self, value: &T) -> fres<T> {
pub fn fully_resolve<T:TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<T> {
/*!
* Attempts to resolve all type/region variables in
* `value`. Region inference must have been run already (e.g.,
@ -1198,7 +1197,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
sp: Span,
mk_msg: M,
actual_ty: String,
err: Option<&ty::type_err<'tcx>>) where
err: Option<&ty::TypeError<'tcx>>) where
M: FnOnce(Option<String>, String) -> String,
{
self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
@ -1209,7 +1208,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
mk_msg: M,
expected_ty: Option<Ty<'tcx>>,
actual_ty: String,
err: Option<&ty::type_err<'tcx>>) where
err: Option<&ty::TypeError<'tcx>>) where
M: FnOnce(Option<String>, String) -> String,
{
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
@ -1235,7 +1234,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
sp: Span,
mk_msg: M,
actual_ty: Ty<'tcx>,
err: Option<&ty::type_err<'tcx>>) where
err: Option<&ty::TypeError<'tcx>>) where
M: FnOnce(String) -> String,
{
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
@ -1254,10 +1253,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
span: Span,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
err: &ty::type_err<'tcx>) {
err: &ty::TypeError<'tcx>) {
let trace = TypeTrace {
origin: Misc(span),
values: Types(ty::expected_found {
values: Types(ty::ExpectedFound {
expected: expected,
found: actual
})
@ -1431,7 +1430,7 @@ impl<'tcx> TypeTrace<'tcx> {
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
TypeTrace {
origin: Misc(codemap::DUMMY_SP),
values: Types(ty::expected_found {
values: Types(ty::ExpectedFound {
expected: tcx.types.err,
found: tcx.types.err,
})

View file

@ -23,7 +23,7 @@ use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
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};
@ -132,7 +132,7 @@ pub enum RegionResolutionError<'tcx> {
/// should put a lifetime. In those cases we process and put those errors
/// into `ProcessedErrors` before we do any reporting.
ProcessedErrors(Vec<RegionVariableOrigin>,
Vec<(TypeTrace<'tcx>, ty::type_err<'tcx>)>,
Vec<(TypeTrace<'tcx>, ty::TypeError<'tcx>)>,
Vec<SameRegions>),
}
@ -872,7 +872,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope {
Ok(s)
} else {
Err(ty::terr_regions_no_overlap(b, a))
Err(TypeError::RegionsNoOverlap(b, a))
}
}
@ -891,7 +891,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
if a == b {
Ok(a)
} else {
Err(ty::terr_regions_no_overlap(b, a))
Err(TypeError::RegionsNoOverlap(b, a))
}
}
}
@ -948,7 +948,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
} else if r_id == scope_b {
Ok(ReScope(scope_a))
} else {
Err(ty::terr_regions_no_overlap(region_a, region_b))
Err(TypeError::RegionsNoOverlap(region_a, region_b))
}
}
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use super::{InferCtxt, fixup_err, fres, unresolved_ty, unresolved_int_ty, unresolved_float_ty};
use super::{InferCtxt, FixupError, FixupResult};
use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty_fold::{self, TypeFoldable};
@ -51,7 +51,7 @@ impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for OpportunisticTypeResolver<'a, 'tcx>
/// Full type resolution replaces all type and region variables with
/// their concrete results. If any variable cannot be replaced (never unified, etc)
/// then an `Err` result is returned.
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a,'tcx>, value: &T) -> fres<T>
pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a,'tcx>, value: &T) -> FixupResult<T>
where T : TypeFoldable<'tcx>
{
let mut full_resolver = FullTypeResolver { infcx: infcx, err: None };
@ -66,7 +66,7 @@ pub fn fully_resolve<'a, 'tcx, T>(infcx: &InferCtxt<'a,'tcx>, value: &T) -> fres
// `err` field is not enforcable otherwise.
struct FullTypeResolver<'a, 'tcx:'a> {
infcx: &'a InferCtxt<'a, 'tcx>,
err: Option<fixup_err>,
err: Option<FixupError>,
}
impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
@ -81,15 +81,15 @@ impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
let t = self.infcx.shallow_resolve(t);
match t.sty {
ty::TyInfer(ty::TyVar(vid)) => {
self.err = Some(unresolved_ty(vid));
self.err = Some(FixupError::UnresolvedTy(vid));
self.tcx().types.err
}
ty::TyInfer(ty::IntVar(vid)) => {
self.err = Some(unresolved_int_ty(vid));
self.err = Some(FixupError::UnresolvedIntTy(vid));
self.tcx().types.err
}
ty::TyInfer(ty::FloatVar(vid)) => {
self.err = Some(unresolved_float_ty(vid));
self.err = Some(FixupError::UnresolvedFloatTy(vid));
self.tcx().types.err
}
ty::TyInfer(_) => {

View file

@ -1614,7 +1614,7 @@ impl fmt::Debug for InteriorKind {
fn element_kind(t: Ty) -> ElementKind {
match t.sty {
ty::TyRef(_, ty::mt{ty, ..}) |
ty::TyRef(_, ty::TypeAndMut{ty, ..}) |
ty::TyBox(ty) => match ty.sty {
ty::TySlice(_) => VecElement,
_ => OtherElement

View file

@ -155,7 +155,7 @@ pub enum SelectionError<'tcx> {
Unimplemented,
OutputTypeParameterMismatch(ty::PolyTraitRef<'tcx>,
ty::PolyTraitRef<'tcx>,
ty::type_err<'tcx>),
ty::TypeError<'tcx>),
TraitNotObjectSafe(ast::DefId),
}

View file

@ -51,7 +51,7 @@ pub enum ProjectionTyError<'tcx> {
#[derive(Clone)]
pub struct MismatchedProjectionTypes<'tcx> {
pub err: ty::type_err<'tcx>
pub err: ty::TypeError<'tcx>
}
#[derive(PartialEq, Eq, Debug)]

View file

@ -1659,7 +1659,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
ty::TyRef(_, ty::mt { ty: _, mutbl }) => {
ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl }) => {
// &mut T or &T
match bound {
ty::BoundCopy => {
@ -1851,8 +1851,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Some(vec![referent_ty])
}
ty::TyRawPtr(ty::mt { ty: element_ty, ..}) |
ty::TyRef(_, ty::mt { ty: element_ty, ..}) => {
ty::TyRawPtr(ty::TypeAndMut { ty: element_ty, ..}) |
ty::TyRef(_, ty::TypeAndMut { ty: element_ty, ..}) => {
Some(vec![element_ty])
},

View file

@ -8,10 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// FIXME: (@jroesch) @eddyb should remove this when he renames ctxt
#![allow(non_camel_case_types)]
pub use self::terr_vstore_kind::*;
pub use self::type_err::*;
pub use self::InferTy::*;
pub use self::InferRegion::*;
pub use self::ImplOrTraitItemId::*;
@ -109,9 +108,9 @@ pub struct CrateAnalysis {
}
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct field<'tcx> {
pub struct Field<'tcx> {
pub name: ast::Name,
pub mt: mt<'tcx>
pub mt: TypeAndMut<'tcx>
}
@ -488,13 +487,13 @@ pub struct AssociatedType<'tcx> {
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct mt<'tcx> {
pub struct TypeAndMut<'tcx> {
pub ty: Ty<'tcx>,
pub mutbl: ast::Mutability,
}
#[derive(Clone, Copy, Debug)]
pub struct field_ty {
pub struct FieldTy {
pub name: Name,
pub id: DefId,
pub vis: ast::Visibility,
@ -674,7 +673,7 @@ pub type MethodMap<'tcx> = FnvHashMap<MethodCall, MethodCallee<'tcx>>;
// Contains information needed to resolve types and (in the future) look up
// the types of AST nodes.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct creader_cache_key {
pub struct CReaderCacheKey {
pub cnum: CrateNum,
pub pos: usize,
pub len: usize
@ -864,7 +863,7 @@ pub struct ctxt<'tcx> {
pub map: ast_map::Map<'tcx>,
pub freevars: RefCell<FreevarMap>,
pub tcache: RefCell<DefIdMap<TypeScheme<'tcx>>>,
pub rcache: RefCell<FnvHashMap<creader_cache_key, Ty<'tcx>>>,
pub rcache: RefCell<FnvHashMap<CReaderCacheKey, Ty<'tcx>>>,
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, TypeContents>>,
pub ast_ty_to_ty_cache: RefCell<NodeMap<Ty<'tcx>>>,
pub enum_var_cache: RefCell<DefIdMap<Rc<Vec<Rc<VariantInfo<'tcx>>>>>>,
@ -873,7 +872,7 @@ pub struct ctxt<'tcx> {
pub lang_items: middle::lang_items::LanguageItems,
/// A mapping of fake provided method def_ids to the default implementation
pub provided_method_sources: RefCell<DefIdMap<ast::DefId>>,
pub struct_fields: RefCell<DefIdMap<Rc<Vec<field_ty>>>>,
pub struct_fields: RefCell<DefIdMap<Rc<Vec<FieldTy>>>>,
/// Maps from def-id of a type or region parameter to its
/// (inferred) variance.
@ -1747,11 +1746,11 @@ pub enum TypeVariants<'tcx> {
TySlice(Ty<'tcx>),
/// A raw pointer. Written as `*mut T` or `*const T`
TyRawPtr(mt<'tcx>),
TyRawPtr(TypeAndMut<'tcx>),
/// A reference; a pointer with an associated lifetime. Written as
/// `&a mut T` or `&'a T`.
TyRef(&'tcx Region, mt<'tcx>),
TyRef(&'tcx Region, TypeAndMut<'tcx>),
/// If the def-id is Some(_), then this is the type of a specific
/// fn item. Otherwise, if None(_), it a fn pointer type.
@ -1945,50 +1944,42 @@ pub enum IntVarValue {
}
#[derive(Clone, Copy, Debug)]
pub enum terr_vstore_kind {
terr_vec,
terr_str,
terr_fn,
terr_trait
}
#[derive(Clone, Copy, Debug)]
pub struct expected_found<T> {
pub struct ExpectedFound<T> {
pub expected: T,
pub found: T
}
// Data structures used in type unification
#[derive(Clone, Copy, Debug)]
pub enum type_err<'tcx> {
terr_mismatch,
terr_unsafety_mismatch(expected_found<ast::Unsafety>),
terr_abi_mismatch(expected_found<abi::Abi>),
terr_mutability,
terr_box_mutability,
terr_ptr_mutability,
terr_ref_mutability,
terr_vec_mutability,
terr_tuple_size(expected_found<usize>),
terr_fixed_array_size(expected_found<usize>),
terr_ty_param_size(expected_found<usize>),
terr_arg_count,
terr_regions_does_not_outlive(Region, Region),
terr_regions_not_same(Region, Region),
terr_regions_no_overlap(Region, Region),
terr_regions_insufficiently_polymorphic(BoundRegion, Region),
terr_regions_overly_polymorphic(BoundRegion, Region),
terr_sorts(expected_found<Ty<'tcx>>),
terr_integer_as_char,
terr_int_mismatch(expected_found<IntVarValue>),
terr_float_mismatch(expected_found<ast::FloatTy>),
terr_traits(expected_found<ast::DefId>),
terr_builtin_bounds(expected_found<BuiltinBounds>),
terr_variadic_mismatch(expected_found<bool>),
terr_cyclic_ty,
terr_convergence_mismatch(expected_found<bool>),
terr_projection_name_mismatched(expected_found<ast::Name>),
terr_projection_bounds_length(expected_found<usize>),
pub enum TypeError<'tcx> {
Mismatch,
UnsafetyMismatch(ExpectedFound<ast::Unsafety>),
AbiMismatch(ExpectedFound<abi::Abi>),
Mutability,
BoxMutability,
PtrMutability,
RefMutability,
VecMutability,
TupleSize(ExpectedFound<usize>),
FixedArraySize(ExpectedFound<usize>),
TyParamSize(ExpectedFound<usize>),
ArgCount,
RegionsDoesNotOutlive(Region, Region),
RegionsNotSame(Region, Region),
RegionsNoOverlap(Region, Region),
RegionsInsufficientlyPolymorphic(BoundRegion, Region),
RegionsOverlyPolymorphic(BoundRegion, Region),
Sorts(ExpectedFound<Ty<'tcx>>),
IntegerAsChar,
IntMismatch(ExpectedFound<IntVarValue>),
FloatMismatch(ExpectedFound<ast::FloatTy>),
Traits(ExpectedFound<ast::DefId>),
BuiltinBoundsMismatch(ExpectedFound<BuiltinBounds>),
VariadicMismatch(ExpectedFound<bool>),
CyclicTy,
ConvergenceMismatch(ExpectedFound<bool>),
ProjectionNameMismatched(ExpectedFound<ast::Name>),
ProjectionBoundsLength(ExpectedFound<usize>),
}
/// Bounds suitable for an existentially quantified type parameter
@ -3573,28 +3564,28 @@ impl<'tcx> ctxt<'tcx> {
self.mk_ty(TyBox(ty))
}
pub fn mk_ptr(&self, tm: mt<'tcx>) -> Ty<'tcx> {
pub fn mk_ptr(&self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
self.mk_ty(TyRawPtr(tm))
}
pub fn mk_ref(&self, r: &'tcx Region, tm: mt<'tcx>) -> Ty<'tcx> {
pub fn mk_ref(&self, r: &'tcx Region, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
self.mk_ty(TyRef(r, tm))
}
pub fn mk_mut_ref(&self, r: &'tcx Region, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, mt {ty: ty, mutbl: ast::MutMutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: ast::MutMutable})
}
pub fn mk_imm_ref(&self, r: &'tcx Region, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, mt {ty: ty, mutbl: ast::MutImmutable})
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: ast::MutImmutable})
}
pub fn mk_mut_ptr(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(mt {ty: ty, mutbl: ast::MutMutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: ast::MutMutable})
}
pub fn mk_imm_ptr(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(mt {ty: ty, mutbl: ast::MutImmutable})
self.mk_ptr(TypeAndMut {ty: ty, mutbl: ast::MutImmutable})
}
pub fn mk_nil_ptr(&self) -> Ty<'tcx> {
@ -4278,7 +4269,7 @@ impl<'tcx> TyS<'tcx> {
}
fn tc_mt<'tcx>(cx: &ctxt<'tcx>,
mt: mt<'tcx>,
mt: TypeAndMut<'tcx>,
cache: &mut FnvHashMap<Ty<'tcx>, TypeContents>) -> TypeContents
{
let mc = TC::ReachesMutable.when(mt.mutbl == MutMutable);
@ -4350,11 +4341,11 @@ impl<'tcx> TyS<'tcx> {
// Fast-path for primitive types
let result = match self.sty {
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
TyRawPtr(..) | TyBareFn(..) | TyRef(_, mt {
TyRawPtr(..) | TyBareFn(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutImmutable, ..
}) => Some(false),
TyStr | TyBox(..) | TyRef(_, mt {
TyStr | TyBox(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutMutable, ..
}) => Some(true),
@ -4789,10 +4780,10 @@ impl<'tcx> TyS<'tcx> {
//
// The parameter `explicit` indicates if this is an *explicit* dereference.
// Some types---notably unsafe ptrs---can only be dereferenced explicitly.
pub fn builtin_deref(&self, explicit: bool) -> Option<mt<'tcx>> {
pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut<'tcx>> {
match self.sty {
TyBox(ty) => {
Some(mt {
Some(TypeAndMut {
ty: ty,
mutbl: ast::MutImmutable,
})
@ -4931,15 +4922,16 @@ impl<'tcx> TyS<'tcx> {
match autoref {
None => self,
Some(AutoPtr(r, m)) => {
cx.mk_ref(r, mt { ty: self, mutbl: m })
cx.mk_ref(r, TypeAndMut { ty: self, mutbl: m })
}
Some(AutoUnsafe(m)) => {
cx.mk_ptr(mt { ty: self, mutbl: m })
cx.mk_ptr(TypeAndMut { ty: self, mutbl: m })
}
}
}
fn sort_string(&self, cx: &ctxt) -> String {
match self.sty {
TyBool | TyChar | TyInt(_) |
TyUint(_) | TyFloat(_) | TyStr => self.to_string(),
@ -4983,67 +4975,69 @@ impl<'tcx> TyS<'tcx> {
/// in parentheses after some larger message. You should also invoke `note_and_explain_type_err()`
/// afterwards to present additional details, particularly when it comes to lifetime-related
/// errors.
impl<'tcx> fmt::Display for type_err<'tcx> {
impl<'tcx> fmt::Display for TypeError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::TypeError::*;
match *self {
terr_cyclic_ty => write!(f, "cyclic type of infinite size"),
terr_mismatch => write!(f, "types differ"),
terr_unsafety_mismatch(values) => {
CyclicTy => write!(f, "cyclic type of infinite size"),
Mismatch => write!(f, "types differ"),
UnsafetyMismatch(values) => {
write!(f, "expected {} fn, found {} fn",
values.expected,
values.found)
}
terr_abi_mismatch(values) => {
AbiMismatch(values) => {
write!(f, "expected {} fn, found {} fn",
values.expected,
values.found)
}
terr_mutability => write!(f, "values differ in mutability"),
terr_box_mutability => {
Mutability => write!(f, "values differ in mutability"),
BoxMutability => {
write!(f, "boxed values differ in mutability")
}
terr_vec_mutability => write!(f, "vectors differ in mutability"),
terr_ptr_mutability => write!(f, "pointers differ in mutability"),
terr_ref_mutability => write!(f, "references differ in mutability"),
terr_ty_param_size(values) => {
VecMutability => write!(f, "vectors differ in mutability"),
PtrMutability => write!(f, "pointers differ in mutability"),
RefMutability => write!(f, "references differ in mutability"),
TyParamSize(values) => {
write!(f, "expected a type with {} type params, \
found one with {} type params",
values.expected,
values.found)
}
terr_fixed_array_size(values) => {
FixedArraySize(values) => {
write!(f, "expected an array with a fixed size of {} elements, \
found one with {} elements",
values.expected,
values.found)
}
terr_tuple_size(values) => {
TupleSize(values) => {
write!(f, "expected a tuple with {} elements, \
found one with {} elements",
values.expected,
values.found)
}
terr_arg_count => {
ArgCount => {
write!(f, "incorrect number of function parameters")
}
terr_regions_does_not_outlive(..) => {
RegionsDoesNotOutlive(..) => {
write!(f, "lifetime mismatch")
}
terr_regions_not_same(..) => {
RegionsNotSame(..) => {
write!(f, "lifetimes are not the same")
}
terr_regions_no_overlap(..) => {
RegionsNoOverlap(..) => {
write!(f, "lifetimes do not intersect")
}
terr_regions_insufficiently_polymorphic(br, _) => {
RegionsInsufficientlyPolymorphic(br, _) => {
write!(f, "expected bound lifetime parameter {}, \
found concrete lifetime", br)
}
terr_regions_overly_polymorphic(br, _) => {
RegionsOverlyPolymorphic(br, _) => {
write!(f, "expected concrete lifetime, \
found bound lifetime parameter {}", br)
}
terr_sorts(values) => tls::with(|tcx| {
Sorts(values) => tls::with(|tcx| {
// A naive approach to making sure that we're not reporting silly errors such as:
// (expected closure, found closure).
let expected_str = values.expected.sort_string(tcx);
@ -5054,12 +5048,12 @@ impl<'tcx> fmt::Display for type_err<'tcx> {
write!(f, "expected {}, found {}", expected_str, found_str)
}
}),
terr_traits(values) => tls::with(|tcx| {
Traits(values) => tls::with(|tcx| {
write!(f, "expected trait `{}`, found trait `{}`",
tcx.item_path_str(values.expected),
tcx.item_path_str(values.found))
}),
terr_builtin_bounds(values) => {
BuiltinBoundsMismatch(values) => {
if values.expected.is_empty() {
write!(f, "expected no bounds, found `{}`",
values.found)
@ -5072,35 +5066,35 @@ impl<'tcx> fmt::Display for type_err<'tcx> {
values.found)
}
}
terr_integer_as_char => {
IntegerAsChar => {
write!(f, "expected an integral type, found `char`")
}
terr_int_mismatch(ref values) => {
IntMismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`",
values.expected,
values.found)
}
terr_float_mismatch(ref values) => {
FloatMismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`",
values.expected,
values.found)
}
terr_variadic_mismatch(ref values) => {
VariadicMismatch(ref values) => {
write!(f, "expected {} fn, found {} function",
if values.expected { "variadic" } else { "non-variadic" },
if values.found { "variadic" } else { "non-variadic" })
}
terr_convergence_mismatch(ref values) => {
ConvergenceMismatch(ref values) => {
write!(f, "expected {} fn, found {} function",
if values.expected { "converging" } else { "diverging" },
if values.found { "converging" } else { "diverging" })
}
terr_projection_name_mismatched(ref values) => {
ProjectionNameMismatched(ref values) => {
write!(f, "expected {}, found {}",
values.expected,
values.found)
}
terr_projection_bounds_length(ref values) => {
ProjectionBoundsLength(ref values) => {
write!(f, "expected {} associated type bindings, found {}",
values.expected,
values.found)
@ -5408,7 +5402,7 @@ impl<'tcx> ctxt<'tcx> {
}
}
pub fn field_idx_strict(&self, name: ast::Name, fields: &[field])
pub fn field_idx_strict(&self, name: ast::Name, fields: &[Field<'tcx>])
-> usize {
let mut i = 0;
for f in fields { if f.name == name { return i; } i += 1; }
@ -5420,36 +5414,38 @@ impl<'tcx> ctxt<'tcx> {
.collect::<Vec<String>>()));
}
pub fn note_and_explain_type_err(&self, err: &type_err<'tcx>, sp: Span) {
pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
use self::TypeError::*;
match *err {
terr_regions_does_not_outlive(subregion, superregion) => {
RegionsDoesNotOutlive(subregion, superregion) => {
self.note_and_explain_region("", subregion, "...");
self.note_and_explain_region("...does not necessarily outlive ",
superregion, "");
}
terr_regions_not_same(region1, region2) => {
RegionsNotSame(region1, region2) => {
self.note_and_explain_region("", region1, "...");
self.note_and_explain_region("...is not the same lifetime as ",
region2, "");
}
terr_regions_no_overlap(region1, region2) => {
RegionsNoOverlap(region1, region2) => {
self.note_and_explain_region("", region1, "...");
self.note_and_explain_region("...does not overlap ",
region2, "");
}
terr_regions_insufficiently_polymorphic(_, conc_region) => {
RegionsInsufficientlyPolymorphic(_, conc_region) => {
self.note_and_explain_region("concrete lifetime that was found is ",
conc_region, "");
}
terr_regions_overly_polymorphic(_, ty::ReInfer(ty::ReVar(_))) => {
RegionsOverlyPolymorphic(_, ty::ReInfer(ty::ReVar(_))) => {
// don't bother to print out the message below for
// inference variables, it's not very illuminating.
}
terr_regions_overly_polymorphic(_, conc_region) => {
RegionsOverlyPolymorphic(_, conc_region) => {
self.note_and_explain_region("expected concrete lifetime is ",
conc_region, "");
}
terr_sorts(values) => {
Sorts(values) => {
let expected_str = values.expected.sort_string(self);
let found_str = values.found.sort_string(self);
if expected_str == found_str && expected_str == "closure" {
@ -5960,7 +5956,7 @@ impl<'tcx> ctxt<'tcx> {
// Look up the list of field names and IDs for a given struct.
// Panics if the id is not bound to a struct.
pub fn lookup_struct_fields(&self, did: ast::DefId) -> Vec<field_ty> {
pub fn lookup_struct_fields(&self, did: ast::DefId) -> Vec<FieldTy> {
if did.krate == ast::LOCAL_CRATE {
let struct_fields = self.struct_fields.borrow();
match struct_fields.get(&did) {
@ -5984,11 +5980,11 @@ impl<'tcx> ctxt<'tcx> {
// Returns a list of fields corresponding to the struct's items. trans uses
// this. Takes a list of substs with which to instantiate field types.
pub fn struct_fields(&self, did: ast::DefId, substs: &Substs<'tcx>)
-> Vec<field<'tcx>> {
-> Vec<Field<'tcx>> {
self.lookup_struct_fields(did).iter().map(|f| {
field {
Field {
name: f.name,
mt: mt {
mt: TypeAndMut {
ty: self.lookup_field_type(did, f.id, substs),
mutbl: MutImmutable
}
@ -6074,7 +6070,7 @@ impl<'tcx> ctxt<'tcx> {
}
UpvarCapture::ByRef(borrow) => {
tcx.mk_ref(tcx.mk_region(borrow.region),
ty::mt {
ty::TypeAndMut {
ty: freevar_ty,
mutbl: borrow.kind.to_mutbl_lossy(),
})
@ -6427,7 +6423,7 @@ impl<'tcx> ctxt<'tcx> {
h.as_str().hash(state);
did.node.hash(state);
};
let mt = |state: &mut SipHasher, mt: mt| {
let mt = |state: &mut SipHasher, mt: TypeAndMut| {
mt.mutbl.hash(state);
};
let fn_sig = |state: &mut SipHasher, sig: &Binder<FnSig<'tcx>>| {
@ -7227,7 +7223,7 @@ impl<'tcx> HasTypeFlags for FnSig<'tcx> {
}
}
impl<'tcx> HasTypeFlags for field<'tcx> {
impl<'tcx> HasTypeFlags for Field<'tcx> {
fn has_type_flags(&self, flags: TypeFlags) -> bool {
self.mt.ty.has_type_flags(flags)
}
@ -7256,7 +7252,7 @@ impl<'tcx> fmt::Debug for ClosureUpvar<'tcx> {
}
}
impl<'tcx> fmt::Debug for field<'tcx> {
impl<'tcx> fmt::Debug for Field<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "field({},{})", self.name, self.mt)
}

View file

@ -85,7 +85,7 @@ pub trait TypeFolder<'tcx> : Sized {
super_fold_ty(self, t)
}
fn fold_mt(&mut self, t: &ty::mt<'tcx>) -> ty::mt<'tcx> {
fn fold_mt(&mut self, t: &ty::TypeAndMut<'tcx>) -> ty::TypeAndMut<'tcx> {
super_fold_mt(self, t)
}
@ -251,8 +251,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for ty::mt<'tcx> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::mt<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TypeAndMut<'tcx> {
folder.fold_mt(self)
}
}
@ -275,9 +275,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for ty::field<'tcx> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::field<'tcx> {
ty::field {
impl<'tcx> TypeFoldable<'tcx> for ty::Field<'tcx> {
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Field<'tcx> {
ty::Field {
name: self.name,
mt: self.mt.fold_with(folder),
}
@ -685,9 +685,9 @@ pub fn super_fold_trait_ref<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
}
pub fn super_fold_mt<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
mt: &ty::mt<'tcx>)
-> ty::mt<'tcx> {
ty::mt {ty: mt.ty.fold_with(this),
mt: &ty::TypeAndMut<'tcx>)
-> ty::TypeAndMut<'tcx> {
ty::TypeAndMut {ty: mt.ty.fold_with(this),
mutbl: mt.mutbl}
}

View file

@ -78,7 +78,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
(&ty::TyInfer(_), _) |
(_, &ty::TyInfer(_)) => {
Err(ty::terr_sorts(ty_relate::expected_found(self, &a, &b)))
Err(ty::TypeError::Sorts(ty_relate::expected_found(self, &a, &b)))
}
(&ty::TyError, _) | (_, &ty::TyError) => {

View file

@ -14,13 +14,13 @@
//! 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;
use syntax::ast;
pub type RelateResult<'tcx, T> = Result<T, ty::type_err<'tcx>>;
pub type RelateResult<'tcx, T> = Result<T, ty::TypeError<'tcx>>;
#[derive(Clone, Debug)]
pub enum Cause {
@ -89,11 +89,11 @@ pub trait Relate<'a,'tcx>: TypeFoldable<'tcx> {
///////////////////////////////////////////////////////////////////////////
// Relate impls
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::mt<'tcx> {
impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeAndMut<'tcx> {
fn relate<R>(relation: &mut R,
a: &ty::mt<'tcx>,
b: &ty::mt<'tcx>)
-> RelateResult<'tcx, ty::mt<'tcx>>
a: &ty::TypeAndMut<'tcx>,
b: &ty::TypeAndMut<'tcx>)
-> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
where R: TypeRelation<'a,'tcx>
{
debug!("{}.mts({:?}, {:?})",
@ -101,7 +101,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::mt<'tcx> {
a,
b);
if a.mutbl != b.mutbl {
Err(ty::terr_mutability)
Err(TypeError::Mutability)
} else {
let mutbl = a.mutbl;
let variance = match mutbl {
@ -109,7 +109,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::mt<'tcx> {
ast::MutMutable => ty::Invariant,
};
let ty = try!(relation.relate_with_variance(variance, &a.ty, &b.ty));
Ok(ty::mt {ty: ty, mutbl: mutbl})
Ok(ty::TypeAndMut {ty: ty, mutbl: mutbl})
}
}
}
@ -186,7 +186,7 @@ fn relate_type_params<'a,'tcx:'a,R>(relation: &mut R,
where R: TypeRelation<'a,'tcx>
{
if a_tys.len() != b_tys.len() {
return Err(ty::terr_ty_param_size(expected_found(relation,
return Err(TypeError::TyParamSize(expected_found(relation,
&a_tys.len(),
&b_tys.len())));
}
@ -256,7 +256,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> {
where R: TypeRelation<'a,'tcx>
{
if a.variadic != b.variadic {
return Err(ty::terr_variadic_mismatch(
return Err(TypeError::VariadicMismatch(
expected_found(relation, &a.variadic, &b.variadic)));
}
@ -270,7 +270,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> {
(ty::FnDiverging, ty::FnDiverging) =>
Ok(ty::FnDiverging),
(a, b) =>
Err(ty::terr_convergence_mismatch(
Err(TypeError::ConvergenceMismatch(
expected_found(relation, &(a != ty::FnDiverging), &(b != ty::FnDiverging)))),
});
@ -287,7 +287,7 @@ fn relate_arg_vecs<'a,'tcx:'a,R>(relation: &mut R,
where R: TypeRelation<'a,'tcx>
{
if a_args.len() != b_args.len() {
return Err(ty::terr_arg_count);
return Err(TypeError::ArgCount);
}
a_args.iter().zip(b_args)
@ -303,7 +303,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ast::Unsafety {
where R: TypeRelation<'a,'tcx>
{
if a != b {
Err(ty::terr_unsafety_mismatch(expected_found(relation, a, b)))
Err(TypeError::UnsafetyMismatch(expected_found(relation, a, b)))
} else {
Ok(*a)
}
@ -320,7 +320,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for abi::Abi {
if a == b {
Ok(*a)
} else {
Err(ty::terr_abi_mismatch(expected_found(relation, a, b)))
Err(TypeError::AbiMismatch(expected_found(relation, a, b)))
}
}
}
@ -333,7 +333,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ProjectionTy<'tcx> {
where R: TypeRelation<'a,'tcx>
{
if a.item_name != b.item_name {
Err(ty::terr_projection_name_mismatched(
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));
@ -368,7 +368,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for Vec<ty::PolyProjectionPredicate<'tcx>> {
// so we can just iterate through the lists pairwise, so long as they are the
// same length.
if a.len() != b.len() {
Err(ty::terr_projection_bounds_length(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))
@ -412,7 +412,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::BuiltinBounds {
// Two sets of builtin bounds are only relatable if they are
// precisely the same (but see the coercion code).
if a != b {
Err(ty::terr_builtin_bounds(expected_found(relation, a, b)))
Err(TypeError::BuiltinBoundsMismatch(expected_found(relation, a, b)))
} else {
Ok(*a)
}
@ -428,7 +428,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TraitRef<'tcx> {
{
// Different traits cannot be related
if a.def_id != b.def_id {
Err(ty::terr_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) })
@ -547,7 +547,7 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
if sz_a == sz_b {
Ok(tcx.mk_array(t, sz_a))
} else {
Err(ty::terr_fixed_array_size(expected_found(relation, &sz_a, &sz_b)))
Err(TypeError::FixedArraySize(expected_found(relation, &sz_a, &sz_b)))
}
}
@ -565,10 +565,10 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
.collect::<Result<_, _>>());
Ok(tcx.mk_tup(ts))
} else if !(as_.is_empty() || bs.is_empty()) {
Err(ty::terr_tuple_size(
Err(TypeError::TupleSize(
expected_found(relation, &as_.len(), &bs.len())))
} else {
Err(ty::terr_sorts(expected_found(relation, &a, &b)))
Err(TypeError::Sorts(expected_found(relation, &a, &b)))
}
}
@ -587,7 +587,7 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
_ =>
{
Err(ty::terr_sorts(expected_found(relation, &a, &b)))
Err(TypeError::Sorts(expected_found(relation, &a, &b)))
}
}
}
@ -652,7 +652,7 @@ impl<'a,'tcx:'a,T> Relate<'a,'tcx> for Box<T>
pub fn expected_found<'a,'tcx:'a,R,T>(relation: &mut R,
a: &T,
b: &T)
-> ty::expected_found<T>
-> ty::ExpectedFound<T>
where R: TypeRelation<'a,'tcx>, T: Clone
{
expected_found_bool(relation.a_is_expected(), a, b)
@ -661,14 +661,14 @@ pub fn expected_found<'a,'tcx:'a,R,T>(relation: &mut R,
pub fn expected_found_bool<T>(a_is_expected: bool,
a: &T,
b: &T)
-> ty::expected_found<T>
-> ty::ExpectedFound<T>
where T: Clone
{
let a = a.clone();
let b = b.clone();
if a_is_expected {
ty::expected_found {expected: a, found: b}
ty::ExpectedFound {expected: a, found: b}
} else {
ty::expected_found {expected: b, found: a}
ty::ExpectedFound {expected: b, found: a}
}
}

View file

@ -19,7 +19,7 @@ use middle::ty::{TyError, TyStr, TyArray, TySlice, TyFloat, TyBareFn};
use middle::ty::{TyParam, TyRawPtr, TyRef, TyTuple};
use middle::ty::TyClosure;
use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
use middle::ty::{self, mt, Ty, HasTypeFlags};
use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags};
use middle::ty_fold::{self, TypeFoldable};
use std::fmt;
@ -321,7 +321,7 @@ impl<'tcx> fmt::Debug for ty::TyS<'tcx> {
}
}
impl<'tcx> fmt::Display for ty::mt<'tcx> {
impl<'tcx> fmt::Display for ty::TypeAndMut<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}",
if self.mutbl == ast::MutMutable { "mut " } else { "" },