Skip to content

Commit

Permalink
Rename TypeWithMutability to TypeAndMut
Browse files Browse the repository at this point in the history
  • Loading branch information
jroesch committed Jul 11, 2015
1 parent fe30f62 commit 1a268f4
Show file tree
Hide file tree
Showing 31 changed files with 106 additions and 106 deletions.
4 changes: 2 additions & 2 deletions src/librustc/metadata/tydecode.rs
Expand Up @@ -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::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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Expand Up @@ -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::TypeWithMutability<'tcx>) {
mt: ty::TypeAndMut<'tcx>) {
enc_mutability(w, mt.mutbl);
enc_ty(w, cx, mt.ty);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/cast.rs
Expand Up @@ -36,9 +36,9 @@ pub enum CastTy<'tcx> {
/// 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)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/check_match.rs
Expand Up @@ -535,7 +535,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
}
}

ty::TyRef(_, ty::TypeWithMutability { ty, mutbl }) => {
ty::TyRef(_, ty::TypeAndMut { ty, mutbl }) => {
match ty.sty {
ty::TyArray(_, n) => match ctor {
&Single => {
Expand Down Expand Up @@ -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::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)
Expand Down Expand Up @@ -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::TypeWithMutability { ty, .. }) => match ty.sty {
ty::TyRef(_, ty::TypeAndMut { ty, .. }) => match ty.sty {
ty::TySlice(_) => match *ctor {
Slice(length) => length,
ConstantValue(_) => 0,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/implicator.rs
Expand Up @@ -115,7 +115,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {

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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -1614,7 +1614,7 @@ impl fmt::Debug for InteriorKind {

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
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/traits/select.rs
Expand Up @@ -1659,7 +1659,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}

ty::TyRef(_, ty::TypeWithMutability { ty: _, mutbl }) => {
ty::TyRef(_, ty::TypeAndMut { ty: _, mutbl }) => {
// &mut T or &T
match bound {
ty::BoundCopy => {
Expand Down Expand Up @@ -1851,8 +1851,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
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])
},

Expand Down
42 changes: 21 additions & 21 deletions src/librustc/middle/ty.rs
Expand Up @@ -110,7 +110,7 @@ pub struct CrateAnalysis {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub struct Field<'tcx> {
pub name: ast::Name,
pub mt: TypeWithMutability<'tcx>
pub mt: TypeAndMut<'tcx>
}


Expand Down Expand Up @@ -487,7 +487,7 @@ pub struct AssociatedType<'tcx> {
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct TypeWithMutability<'tcx> {
pub struct TypeAndMut<'tcx> {
pub ty: Ty<'tcx>,
pub mutbl: ast::Mutability,
}
Expand Down Expand Up @@ -1746,11 +1746,11 @@ pub enum TypeVariants<'tcx> {
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.
Expand Down Expand Up @@ -3564,28 +3564,28 @@ impl<'tcx> ctxt<'tcx> {
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> {
Expand Down Expand Up @@ -4269,7 +4269,7 @@ impl<'tcx> TyS<'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);
Expand Down Expand Up @@ -4341,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(_, TypeWithMutability {
TyRawPtr(..) | TyBareFn(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutImmutable, ..
}) => Some(false),

TyStr | TyBox(..) | TyRef(_, TypeWithMutability {
TyStr | TyBox(..) | TyRef(_, TypeAndMut {
mutbl: ast::MutMutable, ..
}) => Some(true),

Expand Down Expand Up @@ -4780,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<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,
})
Expand Down Expand Up @@ -4922,10 +4922,10 @@ impl<'tcx> TyS<'tcx> {
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 })
}
}
}
Expand Down Expand Up @@ -5416,7 +5416,7 @@ impl<'tcx> ctxt<'tcx> {

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, "...");
Expand Down Expand Up @@ -5984,7 +5984,7 @@ impl<'tcx> ctxt<'tcx> {
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
}
Expand Down Expand Up @@ -6070,7 +6070,7 @@ impl<'tcx> ctxt<'tcx> {
}
UpvarCapture::ByRef(borrow) => {
tcx.mk_ref(tcx.mk_region(borrow.region),
ty::TypeWithMutability {
ty::TypeAndMut {
ty: freevar_ty,
mutbl: borrow.kind.to_mutbl_lossy(),
})
Expand Down Expand Up @@ -6423,7 +6423,7 @@ impl<'tcx> ctxt<'tcx> {
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>>| {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/ty_fold.rs
Expand Up @@ -85,7 +85,7 @@ pub trait TypeFolder<'tcx> : Sized {
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)
}

Expand Down Expand Up @@ -251,8 +251,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
}
}

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)
}
}
Expand Down Expand Up @@ -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::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}
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/ty_relate/mod.rs
Expand Up @@ -89,11 +89,11 @@ pub trait Relate<'a,'tcx>: TypeFoldable<'tcx> {
///////////////////////////////////////////////////////////////////////////
// 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({:?}, {:?})",
Expand All @@ -109,7 +109,7 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeWithMutability<'tcx> {
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})
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/util/ppaux.rs
Expand Up @@ -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, TypeWithMutability, Ty, HasTypeFlags};
use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags};
use middle::ty_fold::{self, TypeFoldable};

use std::fmt;
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'tcx> fmt::Debug for ty::TyS<'tcx> {
}
}

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 { "" },
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/adt.rs
Expand Up @@ -398,7 +398,7 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>,
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)
},
Expand All @@ -415,7 +415,7 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>,
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)
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/attributes.rs
Expand Up @@ -223,7 +223,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
// 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));
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/common.rs
Expand Up @@ -130,8 +130,8 @@ pub fn type_is_sized<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {

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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/consts.rs
Expand Up @@ -621,7 +621,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,

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
Expand Down

0 comments on commit 1a268f4

Please sign in to comment.