}
}
-fn parse_mt_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> ty::TypeWithMutability<'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::TypeWithMutability { 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
}
fn enc_mt<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
- mt: ty::TypeWithMutability<'tcx>) {
+ mt: ty::TypeAndMut<'tcx>) {
enc_mutability(w, mt.mutbl);
enc_ty(w, cx, mt.ty);
}
/// Function Pointers
FnPtr,
/// Raw pointers
- Ptr(&'tcx ty::TypeWithMutability<'tcx>),
+ Ptr(&'tcx ty::TypeAndMut<'tcx>),
/// References
- RPtr(&'tcx ty::TypeWithMutability<'tcx>),
+ RPtr(&'tcx ty::TypeAndMut<'tcx>),
}
/// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)
}
}
- ty::TyRef(_, ty::TypeWithMutability { ty, mutbl }) => {
+ ty::TyRef(_, ty::TypeAndMut { ty, mutbl }) => {
match ty.sty {
ty::TyArray(_, n) => match ctor {
&Single => {
ty::TyBool =>
[true, false].iter().map(|b| ConstantValue(ConstVal::Bool(*b))).collect(),
- ty::TyRef(_, ty::TypeWithMutability { 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)
match ty.sty {
ty::TyTuple(ref fs) => fs.len(),
ty::TyBox(_) => 1,
- ty::TyRef(_, ty::TypeWithMutability { ty, .. }) => match ty.sty {
+ ty::TyRef(_, ty::TypeAndMut { ty, .. }) => match ty.sty {
ty::TySlice(_) => match *ctor {
Slice(length) => length,
ConstantValue(_) => 0,
ty::TyArray(t, _) |
ty::TySlice(t) |
- ty::TyRawPtr(ty::TypeWithMutability { ty: t, .. }) |
+ ty::TyRawPtr(ty::TypeAndMut { ty: t, .. }) |
ty::TyBox(t) => {
self.accumulate_from_ty(t)
}
fn element_kind(t: Ty) -> ElementKind {
match t.sty {
- ty::TyRef(_, ty::TypeWithMutability{ty, ..}) |
+ ty::TyRef(_, ty::TypeAndMut{ty, ..}) |
ty::TyBox(ty) => match ty.sty {
ty::TySlice(_) => VecElement,
_ => OtherElement
}
}
- ty::TyRef(_, ty::TypeWithMutability { ty: _, mutbl }) => {
+ ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl }) => {
// &mut T or &T
match bound {
ty::BoundCopy => {
Some(vec![referent_ty])
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: element_ty, ..}) |
- ty::TyRef(_, ty::TypeWithMutability { ty: element_ty, ..}) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: element_ty, ..}) |
+ ty::TyRef(_, ty::TypeAndMut { ty: element_ty, ..}) => {
Some(vec![element_ty])
},
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Field<'tcx> {
pub name: ast::Name,
- pub mt: TypeWithMutability<'tcx>
+ pub mt: TypeAndMut<'tcx>
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
-pub struct TypeWithMutability<'tcx> {
+pub struct TypeAndMut<'tcx> {
pub ty: Ty<'tcx>,
pub mutbl: ast::Mutability,
}
TySlice(Ty<'tcx>),
/// A raw pointer. Written as `*mut T` or `*const T`
- TyRawPtr(TypeWithMutability<'tcx>),
+ TyRawPtr(TypeAndMut<'tcx>),
/// A reference; a pointer with an associated lifetime. Written as
/// `&a mut T` or `&'a T`.
- TyRef(&'tcx Region, TypeWithMutability<'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.
self.mk_ty(TyBox(ty))
}
- pub fn mk_ptr(&self, tm: TypeWithMutability<'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: TypeWithMutability<'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, TypeWithMutability {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, TypeWithMutability {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(TypeWithMutability {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(TypeWithMutability {ty: ty, mutbl: ast::MutImmutable})
+ self.mk_ptr(TypeAndMut {ty: ty, mutbl: ast::MutImmutable})
}
pub fn mk_nil_ptr(&self) -> Ty<'tcx> {
}
fn tc_mt<'tcx>(cx: &ctxt<'tcx>,
- mt: TypeWithMutability<'tcx>,
+ mt: TypeAndMut<'tcx>,
cache: &mut FnvHashMap<Ty<'tcx>, TypeContents>) -> TypeContents
{
let mc = TC::ReachesMutable.when(mt.mutbl == MutMutable);
// Fast-path for primitive types
let result = match self.sty {
TyBool | TyChar | TyInt(..) | TyUint(..) | TyFloat(..) |
- TyRawPtr(..) | TyBareFn(..) | TyRef(_, TypeWithMutability {
+ TyRawPtr(..) | TyBareFn(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutImmutable, ..
}) => Some(false),
- TyStr | TyBox(..) | TyRef(_, TypeWithMutability {
+ TyStr | TyBox(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutMutable, ..
}) => Some(true),
//
// 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<TypeWithMutability<'tcx>> {
+ pub fn builtin_deref(&self, explicit: bool) -> Option<TypeAndMut<'tcx>> {
match self.sty {
TyBox(ty) => {
- Some(TypeWithMutability {
+ Some(TypeAndMut {
ty: ty,
mutbl: ast::MutImmutable,
})
match autoref {
None => self,
Some(AutoPtr(r, m)) => {
- cx.mk_ref(r, TypeWithMutability { ty: self, mutbl: m })
+ cx.mk_ref(r, TypeAndMut { ty: self, mutbl: m })
}
Some(AutoUnsafe(m)) => {
- cx.mk_ptr(TypeWithMutability { ty: self, mutbl: m })
+ cx.mk_ptr(TypeAndMut { ty: self, mutbl: m })
}
}
}
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, "...");
self.lookup_struct_fields(did).iter().map(|f| {
Field {
name: f.name,
- mt: TypeWithMutability {
+ mt: TypeAndMut {
ty: self.lookup_field_type(did, f.id, substs),
mutbl: MutImmutable
}
}
UpvarCapture::ByRef(borrow) => {
tcx.mk_ref(tcx.mk_region(borrow.region),
- ty::TypeWithMutability {
+ ty::TypeAndMut {
ty: freevar_ty,
mutbl: borrow.kind.to_mutbl_lossy(),
})
h.as_str().hash(state);
did.node.hash(state);
};
- let mt = |state: &mut SipHasher, mt: TypeWithMutability| {
+ let mt = |state: &mut SipHasher, mt: TypeAndMut| {
mt.mutbl.hash(state);
};
let fn_sig = |state: &mut SipHasher, sig: &Binder<FnSig<'tcx>>| {
super_fold_ty(self, t)
}
- fn fold_mt(&mut self, t: &ty::TypeWithMutability<'tcx>) -> ty::TypeWithMutability<'tcx> {
+ fn fold_mt(&mut self, t: &ty::TypeAndMut<'tcx>) -> ty::TypeAndMut<'tcx> {
super_fold_mt(self, t)
}
}
}
-impl<'tcx> TypeFoldable<'tcx> for ty::TypeWithMutability<'tcx> {
- fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TypeWithMutability<'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)
}
}
}
pub fn super_fold_mt<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
- mt: &ty::TypeWithMutability<'tcx>)
- -> ty::TypeWithMutability<'tcx> {
- ty::TypeWithMutability {ty: mt.ty.fold_with(this),
+ mt: &ty::TypeAndMut<'tcx>)
+ -> ty::TypeAndMut<'tcx> {
+ ty::TypeAndMut {ty: mt.ty.fold_with(this),
mutbl: mt.mutbl}
}
///////////////////////////////////////////////////////////////////////////
// Relate impls
-impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeWithMutability<'tcx> {
+impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeAndMut<'tcx> {
fn relate<R>(relation: &mut R,
- a: &ty::TypeWithMutability<'tcx>,
- b: &ty::TypeWithMutability<'tcx>)
- -> RelateResult<'tcx, ty::TypeWithMutability<'tcx>>
+ a: &ty::TypeAndMut<'tcx>,
+ b: &ty::TypeAndMut<'tcx>)
+ -> RelateResult<'tcx, ty::TypeAndMut<'tcx>>
where R: TypeRelation<'a,'tcx>
{
debug!("{}.mts({:?}, {:?})",
ast::MutMutable => ty::Invariant,
};
let ty = try!(relation.relate_with_variance(variance, &a.ty, &b.ty));
- Ok(ty::TypeWithMutability {ty: ty, mutbl: mutbl})
+ Ok(ty::TypeAndMut {ty: ty, mutbl: mutbl})
}
}
}
use middle::ty::{TyParam, TyRawPtr, TyRef, TyTuple};
use middle::ty::TyClosure;
use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer};
-use middle::ty::{self, TypeWithMutability, Ty, HasTypeFlags};
+use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags};
use middle::ty_fold::{self, TypeFoldable};
use std::fmt;
}
}
-impl<'tcx> fmt::Display for ty::TypeWithMutability<'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 { "" },
mut path: DiscrField) -> Option<DiscrField> {
match ty.sty {
// Fat &T/&mut T/Box<T> i.e. T is [T], str, or Trait
- ty::TyRef(_, ty::TypeWithMutability { ty, .. }) | ty::TyBox(ty) if !type_is_sized(tcx, ty) => {
+ ty::TyRef(_, ty::TypeAndMut { ty, .. }) | ty::TyBox(ty) if !type_is_sized(tcx, ty) => {
path.push(FAT_PTR_ADDR);
Some(path)
},
assert_eq!(nonzero_fields.len(), 1);
let nonzero_field = tcx.lookup_field_type(did, nonzero_fields[0].id, substs);
match nonzero_field.sty {
- ty::TyRawPtr(ty::TypeWithMutability { ty, .. }) if !type_is_sized(tcx, ty) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty, .. }) if !type_is_sized(tcx, ty) => {
path.push_all(&[0, FAT_PTR_ADDR]);
Some(path)
},
// We can also mark the return value as `dereferenceable` in certain cases
match ret_ty.sty {
// These are not really pointers but pairs, (pointer, len)
- ty::TyRef(_, ty::TypeWithMutability { ty: inner, .. })
+ ty::TyRef(_, ty::TypeAndMut { ty: inner, .. })
| ty::TyBox(inner) if common::type_is_sized(ccx.tcx(), inner) => {
let llret_sz = machine::llsize_of_real(ccx, type_of::type_of(ccx, inner));
attrs.ret(llvm::DereferenceableAttribute(llret_sz));
pub fn type_is_fat_ptr<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
match ty.sty {
- ty::TyRawPtr(ty::TypeWithMutability{ty, ..}) |
- ty::TyRef(_, ty::TypeWithMutability{ty, ..}) |
+ ty::TyRawPtr(ty::TypeAndMut{ty, ..}) |
+ ty::TyRef(_, ty::TypeAndMut{ty, ..}) |
ty::TyBox(ty) => {
!type_is_sized(cx, ty)
}
let len = unsafe { llvm::LLVMConstIntGetZExtValue(len) as u64 };
let len = match bt.sty {
- ty::TyBox(ty) | ty::TyRef(_, ty::TypeWithMutability{ty, ..}) => match ty.sty {
+ ty::TyBox(ty) | ty::TyRef(_, ty::TypeAndMut{ty, ..}) => match ty.sty {
ty::TyStr => {
assert!(len > 0);
len - 1
let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
unique_type_id.push_str(&inner_type_id[..]);
},
- ty::TyRawPtr(ty::TypeWithMutability { ty: inner_type, mutbl } ) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
unique_type_id.push('*');
if mutbl == ast::MutMutable {
unique_type_id.push_str("mut");
let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
unique_type_id.push_str(&inner_type_id[..]);
},
- ty::TyRef(_, ty::TypeWithMutability { ty: inner_type, mutbl }) => {
+ ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
unique_type_id.push('&');
if mutbl == ast::MutMutable {
unique_type_id.push_str("mut");
unique_type_id: UniqueTypeId,
span: Span)
-> MetadataCreationResult {
- let data_ptr_type = cx.tcx().mk_ptr(ty::TypeWithMutability {
+ let data_ptr_type = cx.tcx().mk_ptr(ty::TypeAndMut {
ty: element_type,
mutbl: ast::MutImmutable
});
trait_pointer_metadata(cx, t, None, unique_type_id),
false)
}
- ty::TyBox(ty) | ty::TyRawPtr(ty::TypeWithMutability{ty, ..}) | ty::TyRef(_, ty::TypeWithMutability{ty, ..}) => {
+ ty::TyBox(ty) | ty::TyRawPtr(ty::TypeAndMut{ty, ..}) | ty::TyRef(_, ty::TypeAndMut{ty, ..}) => {
match ty.sty {
ty::TySlice(typ) => {
vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)
push_debuginfo_type_name(cx, inner_type, true, output);
output.push('>');
},
- ty::TyRawPtr(ty::TypeWithMutability { ty: inner_type, mutbl } ) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
output.push('*');
match mutbl {
ast::MutImmutable => output.push_str("const "),
push_debuginfo_type_name(cx, inner_type, true, output);
},
- ty::TyRef(_, ty::TypeWithMutability { ty: inner_type, mutbl }) => {
+ ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
output.push('&');
if mutbl == ast::MutMutable {
output.push_str("mut ");
match (&source.ty.sty, &target.ty.sty) {
(&ty::TyBox(a), &ty::TyBox(b)) |
- (&ty::TyRef(_, ty::TypeWithMutability { ty: a, .. }), &ty::TyRef(_, ty::TypeWithMutability { ty: b, .. })) |
- (&ty::TyRef(_, ty::TypeWithMutability { ty: a, .. }), &ty::TyRawPtr(ty::TypeWithMutability { ty: b, .. })) |
- (&ty::TyRawPtr(ty::TypeWithMutability { ty: a, .. }), &ty::TyRawPtr(ty::TypeWithMutability { ty: b, .. })) => {
+ (&ty::TyRef(_, ty::TypeAndMut { ty: a, .. }), &ty::TyRef(_, ty::TypeAndMut { ty: b, .. })) |
+ (&ty::TyRef(_, ty::TypeAndMut { ty: a, .. }), &ty::TyRawPtr(ty::TypeAndMut { ty: b, .. })) |
+ (&ty::TyRawPtr(ty::TypeAndMut { ty: a, .. }), &ty::TyRawPtr(ty::TypeAndMut { ty: b, .. })) => {
let (inner_source, inner_target) = (a, b);
let (base, old_info) = if !type_is_sized(bcx.tcx(), inner_source) {
let fields: Vec<_> = v.iter().enumerate().map(|(i, &f)| {
ty::Field {
name: token::intern(&i.to_string()),
- mt: ty::TypeWithMutability {
+ mt: ty::TypeAndMut {
ty: f,
mutbl: ast::MutImmutable
}
}
match (t_in.builtin_deref(true), t_out.builtin_deref(true)) {
- (Some(ty::TypeWithMutability{ ty: t_in, .. }), Some(ty::TypeWithMutability{ ty: t_out, .. })) => {
+ (Some(ty::TypeAndMut{ ty: t_in, .. }), Some(ty::TypeAndMut{ ty: t_out, .. })) => {
t_in == t_out
}
_ => {
}
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: content_ty, .. }) |
- ty::TyRef(_, ty::TypeWithMutability { ty: content_ty, .. }) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: content_ty, .. }) |
+ ty::TyRef(_, ty::TypeAndMut { ty: content_ty, .. }) => {
if type_is_sized(bcx.tcx(), content_ty) {
let ptr = datum.to_llscalarish(bcx);
}
// Only used for pattern matching.
- ty::TyBox(ty) | ty::TyRef(_, ty::TypeWithMutability{ty, ..}) => {
+ ty::TyBox(ty) | ty::TyRef(_, ty::TypeAndMut{ty, ..}) => {
let inner = if type_is_sized(bcx.tcx(), ty) {
Load(bcx, llval)
} else {
ty::TyUint(t) => Type::uint_from_ty(cx, t),
ty::TyFloat(t) => Type::float_from_ty(cx, t),
- ty::TyBox(ty) | ty::TyRef(_, ty::TypeWithMutability{ty, ..}) | ty::TyRawPtr(ty::TypeWithMutability{ty, ..}) => {
+ ty::TyBox(ty) | ty::TyRef(_, ty::TypeAndMut{ty, ..}) | ty::TyRawPtr(ty::TypeAndMut{ty, ..}) => {
if type_is_sized(cx.tcx(), ty) {
Type::i8p(cx)
} else {
adt::incomplete_type_of(cx, &*repr, "closure")
}
- ty::TyBox(ty) | ty::TyRef(_, ty::TypeWithMutability{ty, ..}) | ty::TyRawPtr(ty::TypeWithMutability{ty, ..}) => {
+ ty::TyBox(ty) | ty::TyRef(_, ty::TypeAndMut{ty, ..}) | ty::TyRawPtr(ty::TypeAndMut{ty, ..}) => {
if !type_is_sized(cx.tcx(), ty) {
if let ty::TyStr = ty.sty {
// This means we get a nicer name in the output (str is always
}
}
ast::TyPtr(ref mt) => {
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: ast_ty_to_ty(this, rscope, &*mt.ty),
mutbl: mt.mutbl
})
rscope,
ty::ObjectLifetimeDefault::Specific(r));
let t = ast_ty_to_ty(this, rscope1, &*mt.ty);
- tcx.mk_ref(tcx.mk_region(r), ty::TypeWithMutability {ty: t, mutbl: mt.mutbl})
+ tcx.mk_ref(tcx.mk_region(r), ty::TypeAndMut {ty: t, mutbl: mt.mutbl})
}
ast::TyTup(ref fields) => {
let flds = fields.iter()
ty::ByReferenceExplicitSelfCategory(region, mutability) => {
(Some(this.tcx().mk_ref(
this.tcx().mk_region(region),
- ty::TypeWithMutability {
+ ty::TypeAndMut {
ty: self_info.untransformed_self_ty,
mutbl: mutability
})),
// then `x` is assigned a value of type `&M T` where M is the mutability
// and T is the expected type.
let region_var = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
- let mt = ty::TypeWithMutability { ty: expected, mutbl: mutbl };
+ let mt = ty::TypeAndMut { ty: expected, mutbl: mutbl };
let region_ty = tcx.mk_ref(tcx.mk_region(region_var), mt);
// `x` is assigned a value of type `&M T`, hence `&M T <: typeof(x)` is
ast::PatRegion(ref inner, mutbl) => {
let inner_ty = fcx.infcx().next_ty_var();
- let mt = ty::TypeWithMutability { ty: inner_ty, mutbl: mutbl };
+ let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
let rptr_ty = tcx.mk_ref(tcx.mk_region(region), mt);
}),
_ => {
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
- tcx.mk_ref(tcx.mk_region(region), ty::TypeWithMutability {
+ tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
ty: tcx.mk_slice(inner_ty),
mutbl: expected_ty.builtin_deref(true).map(|mt| mt.mutbl)
.unwrap_or(ast::MutImmutable)
let mutbl = expected_ty.builtin_deref(true)
.map_or(ast::MutImmutable, |mt| mt.mutbl);
- let slice_ty = tcx.mk_ref(tcx.mk_region(region), ty::TypeWithMutability {
+ let slice_ty = tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
ty: tcx.mk_slice(inner_ty),
mutbl: mutbl
});
fn check_ptr_ptr_cast<'a>(&self,
fcx: &FnCtxt<'a, 'tcx>,
- m_expr: &'tcx ty::TypeWithMutability<'tcx>,
- m_cast: &'tcx ty::TypeWithMutability<'tcx>)
+ m_expr: &'tcx ty::TypeAndMut<'tcx>,
+ m_cast: &'tcx ty::TypeAndMut<'tcx>)
-> Result<CastKind, CastError>
{
debug!("check_ptr_ptr_cast m_expr={:?} m_cast={:?}",
fn check_fptr_ptr_cast<'a>(&self,
fcx: &FnCtxt<'a, 'tcx>,
- m_cast: &'tcx ty::TypeWithMutability<'tcx>)
+ m_cast: &'tcx ty::TypeAndMut<'tcx>)
-> Result<CastKind, CastError>
{
// fptr-ptr cast. must be to sized ptr
fn check_ptr_addr_cast<'a>(&self,
fcx: &FnCtxt<'a, 'tcx>,
- m_expr: &'tcx ty::TypeWithMutability<'tcx>)
+ m_expr: &'tcx ty::TypeAndMut<'tcx>)
-> Result<CastKind, CastError>
{
// ptr-addr cast. must be from sized ptr
fn check_ref_cast<'a>(&self,
fcx: &FnCtxt<'a, 'tcx>,
- m_expr: &'tcx ty::TypeWithMutability<'tcx>,
- m_cast: &'tcx ty::TypeWithMutability<'tcx>)
+ m_expr: &'tcx ty::TypeAndMut<'tcx>,
+ m_cast: &'tcx ty::TypeAndMut<'tcx>)
-> Result<CastKind, CastError>
{
// array-ptr-cast.
fn check_addr_ptr_cast<'a>(&self,
fcx: &FnCtxt<'a, 'tcx>,
- m_cast: &'tcx ty::TypeWithMutability<'tcx>)
+ m_cast: &'tcx ty::TypeAndMut<'tcx>)
-> Result<CastKind, CastError>
{
// ptr-addr cast. pointer must be thin.
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, TypeError};
+use middle::ty::{self, TypeAndMut, Ty, TypeError};
use middle::ty_relate::RelateResult;
use util::common::indent;
return None;
}
let ty = self.tcx().mk_ref(r_borrow,
- TypeWithMutability {ty: inner_ty, mutbl: mutbl_b});
+ TypeAndMut {ty: inner_ty, mutbl: mutbl_b});
if let Err(err) = self.subtype(ty, b) {
if first_error.is_none() {
first_error = Some(err);
};
// Check that the types which they point at are compatible.
- let a_unsafe = self.tcx().mk_ptr(ty::TypeWithMutability{ mutbl: mutbl_b, ty: mt_a.ty });
+ let a_unsafe = self.tcx().mk_ptr(ty::TypeAndMut{ mutbl: mutbl_b, ty: mt_a.ty });
try!(self.subtype(a_unsafe, b));
try!(coerce_mutbls(mt_a.mutbl, mutbl_b));
};
match sig.0.inputs[0].sty {
- ty::TyRef(_, ty::TypeWithMutability {
+ ty::TyRef(_, ty::TypeAndMut {
ty: _,
mutbl: ast::MutMutable,
}) => {}
// Trait method is fn(&self) or fn(&mut self), need an
// autoref. Pull the region etc out of the type of first argument.
match transformed_self_ty.sty {
- ty::TyRef(region, ty::TypeWithMutability { mutbl, ty: _ }) => {
+ ty::TyRef(region, ty::TypeAndMut { mutbl, ty: _ }) => {
fcx.write_adjustment(self_expr.id,
ty::AdjustDerefRef(ty::AutoDerefRef {
autoderefs: autoderefs,
let lang_def_id = self.tcx().lang_items.slice_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: _, mutbl: ast::MutImmutable }) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutImmutable }) => {
let lang_def_id = self.tcx().lang_items.const_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: _, mutbl: ast::MutMutable }) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutMutable }) => {
let lang_def_id = self.tcx().lang_items.mut_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
// Search through mutabilities in order to find one where pick works:
[ast::MutImmutable, ast::MutMutable].iter().filter_map(|&m| {
- let autoref_ty = tcx.mk_ref(region, ty::TypeWithMutability {
+ let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut {
ty: step.self_ty,
mutbl: m
});
format!("cast to unsized type: `{}` as `{}`", actual, tstr)
}, t_expr, None);
match t_expr.sty {
- ty::TyRef(_, ty::TypeWithMutability { mutbl: mt, .. }) => {
+ ty::TyRef(_, ty::TypeAndMut { mutbl: mt, .. }) => {
let mtstr = match mt {
ast::MutMutable => "mut ",
ast::MutImmutable => ""
base_expr: Option<&ast::Expr>,
base_ty: Ty<'tcx>,
lvalue_pref: LvaluePreference)
- -> Option<ty::TypeWithMutability<'tcx>>
+ -> Option<ty::TypeAndMut<'tcx>>
{
// Try DerefMut first, if preferred.
let method = match (lvalue_pref, fcx.tcx().lang_items.deref_mut_trait()) {
fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
method_call: Option<MethodCall>,
method: Option<MethodCallee<'tcx>>)
- -> Option<ty::TypeWithMutability<'tcx>>
+ -> Option<ty::TypeAndMut<'tcx>>
{
match method {
Some(method) => {
hint,
lvalue_pref);
- let tm = ty::TypeWithMutability { ty: fcx.expr_ty(&**oprnd), mutbl: mutbl };
+ let tm = ty::TypeAndMut { ty: fcx.expr_ty(&**oprnd), mutbl: mutbl };
let oprnd_t = if tm.ty.references_error() {
tcx.types.err
} else {
"offset" | "arith_offset" => {
(1,
vec!(
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutImmutable
}),
ccx.tcx.types.isize
),
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutImmutable
}))
"copy" | "copy_nonoverlapping" => {
(1,
vec!(
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutImmutable
}),
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutMutable
}),
"volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => {
(1,
vec!(
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutMutable
}),
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutImmutable
}),
"write_bytes" | "volatile_set_memory" => {
(1,
vec!(
- tcx.mk_ptr(ty::TypeWithMutability {
+ tcx.mk_ptr(ty::TypeAndMut {
ty: param(ccx, 0),
mutbl: ast::MutMutable
}),
let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env), true);
- let check_mutbl = |mt_a: ty::TypeWithMutability<'tcx>, mt_b: ty::TypeWithMutability<'tcx>,
+ let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
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),
"[T]",
item.span);
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: _, mutbl: ast::MutImmutable }) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutImmutable }) => {
self.check_primitive_impl(def_id,
self.tcx.lang_items.const_ptr_impl(),
"const_ptr",
"*const T",
item.span);
}
- ty::TyRawPtr(ty::TypeWithMutability { ty: _, mutbl: ast::MutMutable }) => {
+ ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: ast::MutMutable }) => {
self.check_primitive_impl(def_id,
self.tcx.lang_items.mut_ptr_impl(),
"mut_ptr",
/// appearing in a context with ambient variance `variance`
fn add_constraints_from_mt(&mut self,
generics: &ty::Generics<'tcx>,
- mt: &ty::TypeWithMutability<'tcx>,
+ mt: &ty::TypeAndMut<'tcx>,
variance: VarianceTermPtr<'a>) {
match mt.mutbl {
ast::MutMutable => {