Skip to content

Commit

Permalink
rustc: make ty::mk_* constructors into methods on ty::ctxt.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jun 26, 2015
1 parent 2332765 commit 6db5126
Show file tree
Hide file tree
Showing 48 changed files with 481 additions and 526 deletions.
34 changes: 17 additions & 17 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,14 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let def = parse_def_(st, NominalType, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_enum(tcx, def, st.tcx.mk_substs(substs));
return tcx.mk_enum(def, st.tcx.mk_substs(substs));
}
'x' => {
assert_eq!(next(st), '[');
let trait_ref = ty::Binder(parse_trait_ref_(st, conv));
let bounds = parse_existential_bounds_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_trait(tcx, trait_ref, bounds);
return tcx.mk_trait(trait_ref, bounds);
}
'p' => {
assert_eq!(next(st), '[');
Expand All @@ -487,38 +487,38 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let space = parse_param_space(st);
assert_eq!(next(st), '|');
let name = token::intern(&parse_str(st, ']'));
return ty::mk_param(tcx, space, index, name);
return tcx.mk_param(space, index, name);
}
'~' => return ty::mk_uniq(tcx, parse_ty_(st, conv)),
'*' => return ty::mk_ptr(tcx, parse_mt_(st, conv)),
'~' => return tcx.mk_box(parse_ty_(st, conv)),
'*' => return tcx.mk_ptr(parse_mt_(st, conv)),
'&' => {
let r = parse_region_(st, conv);
let mt = parse_mt_(st, conv);
return ty::mk_rptr(tcx, tcx.mk_region(r), mt);
return tcx.mk_ref(tcx.mk_region(r), mt);
}
'V' => {
let t = parse_ty_(st, conv);
let sz = parse_size(st);
return ty::mk_vec(tcx, t, sz);
return match parse_size(st) {
Some(n) => tcx.mk_array(t, n),
None => tcx.mk_slice(t)
};
}
'v' => {
return ty::mk_str(tcx);
return tcx.mk_str();
}
'T' => {
assert_eq!(next(st), '[');
let mut params = Vec::new();
while peek(st) != ']' { params.push(parse_ty_(st, conv)); }
st.pos = st.pos + 1;
return ty::mk_tup(tcx, params);
return tcx.mk_tup(params);
}
'F' => {
let def_id = parse_def_(st, NominalType, conv);
return ty::mk_bare_fn(tcx, Some(def_id),
tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
return tcx.mk_fn(Some(def_id), tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
}
'G' => {
return ty::mk_bare_fn(tcx, None,
tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
return tcx.mk_fn(None, tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
}
'#' => {
let pos = parse_hex(st);
Expand Down Expand Up @@ -558,20 +558,20 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let did = parse_def_(st, NominalType, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_struct(st.tcx, did, st.tcx.mk_substs(substs));
return st.tcx.mk_struct(did, st.tcx.mk_substs(substs));
}
'k' => {
assert_eq!(next(st), '[');
let did = parse_def_(st, ClosureSource, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_closure(st.tcx, did, st.tcx.mk_substs(substs));
return st.tcx.mk_closure(did, st.tcx.mk_substs(substs));
}
'P' => {
assert_eq!(next(st), '[');
let trait_ref = parse_trait_ref_(st, conv);
let name = token::intern(&parse_str(st, ']'));
return ty::mk_projection(tcx, trait_ref, name);
return tcx.mk_projection(trait_ref, name);
}
'e' => {
return tcx.types.err;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/astconv_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
match nty {
ast::TyBool => tcx.types.bool,
ast::TyChar => tcx.types.char,
ast::TyInt(it) => ty::mk_mach_int(tcx, it),
ast::TyUint(uit) => ty::mk_mach_uint(tcx, uit),
ast::TyFloat(ft) => ty::mk_mach_float(tcx, ft),
ast::TyStr => ty::mk_str(tcx)
ast::TyInt(it) => tcx.mk_mach_int(it),
ast::TyUint(uit) => tcx.mk_mach_uint(uit),
ast::TyFloat(ft) => tcx.mk_mach_float(ft),
ast::TyStr => tcx.mk_str()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ fn is_useful(cx: &MatchCheckCtxt,
None => v[0]
};
let left_ty = if real_pat.id == DUMMY_NODE_ID {
ty::mk_nil(cx.tcx)
cx.tcx.mk_nil()
} else {
let left_ty = ty::pat_ty(cx.tcx, &*real_pat);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/implicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
let assoc_type_projections: Vec<_> =
trait_def.associated_type_names
.iter()
.map(|&name| ty::mk_projection(self.tcx(), trait_ref.clone(), name))
.map(|&name| self.tcx().mk_projection(trait_ref.clone(), name))
.collect();
debug!("accumulate_from_assoc_types: assoc_type_projections={:?}",
assoc_type_projections);
Expand Down Expand Up @@ -437,7 +437,7 @@ pub fn object_region_bounds<'tcx>(
// Since we don't actually *know* the self type for an object,
// this "open(err)" serves as a kind of dummy standin -- basically
// a skolemized type.
let open_ty = ty::mk_infer(tcx, ty::FreshTy(0));
let open_ty = tcx.mk_infer(ty::FreshTy(0));

// Note that we preserve the overall binding levels here.
assert!(!open_ty.has_escaping_regions());
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
.unify_var_value(vid, val)
.map_err(|e| int_unification_error(vid_is_expected, e)));
match val {
IntType(v) => Ok(ty::mk_mach_int(infcx.tcx, v)),
UintType(v) => Ok(ty::mk_mach_uint(infcx.tcx, v)),
IntType(v) => Ok(infcx.tcx.mk_mach_int(v)),
UintType(v) => Ok(infcx.tcx.mk_mach_uint(v)),
}
}

Expand All @@ -145,7 +145,7 @@ fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
.borrow_mut()
.unify_var_value(vid, val)
.map_err(|e| float_unification_error(vid_is_expected, e)));
Ok(ty::mk_mach_float(infcx.tcx, val))
Ok(infcx.tcx.mk_mach_float(val))
}

impl<'a, 'tcx> CombineFields<'a, 'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
Entry::Vacant(entry) => {
let index = self.freshen_count;
self.freshen_count += 1;
let t = ty::mk_infer(self.infcx.tcx, freshener(index));
let t = self.infcx.tcx.mk_infer(freshener(index));
entry.insert(t);
t
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ pub fn construct_skolemized_substs<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
types: &mut subst::VecPerParamSpace<ty::Ty<'tcx>>,
defs: &[ty::TypeParameterDef<'tcx>]) {
for def in defs {
let ty = ty::mk_param_from_def(tcx, def);
let ty = tcx.mk_param_from_def(def);
types.push(def.space, ty);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

pub fn next_ty_var(&self) -> Ty<'tcx> {
ty::mk_var(self.tcx, self.next_ty_var_id(false))
self.tcx.mk_var(self.next_ty_var_id(false))
}

pub fn next_diverging_ty_var(&self) -> Ty<'tcx> {
ty::mk_var(self.tcx, self.next_ty_var_id(true))
self.tcx.mk_var(self.next_ty_var_id(true))
}

pub fn next_ty_vars(&self, n: usize) -> Vec<Ty<'tcx>> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ impl<'tcx> GenericKind<'tcx> {
GenericKind::Param(ref p) =>
p.to_ty(tcx),
GenericKind::Projection(ref p) =>
ty::mk_projection(tcx, p.trait_ref.clone(), p.item_name),
tcx.mk_projection(p.trait_ref.clone(), p.item_name),
}
}
}
6 changes: 3 additions & 3 deletions src/librustc/middle/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl UnifyKey for ty::IntVid {
impl<'tcx> ToType<'tcx> for IntVarValue {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
match *self {
ty::IntType(i) => ty::mk_mach_int(tcx, i),
ty::UintType(i) => ty::mk_mach_uint(tcx, i),
ty::IntType(i) => tcx.mk_mach_int(i),
ty::UintType(i) => tcx.mk_mach_uint(i),
}
}
}
Expand All @@ -43,6 +43,6 @@ impl UnifyKey for ty::FloatVid {

impl<'tcx> ToType<'tcx> for ast::FloatTy {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
ty::mk_mach_float(tcx, *self)
tcx.mk_mach_float(*self)
}
}
2 changes: 1 addition & 1 deletion src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn check_crate(tcx: &ctxt) {
tcx: tcx,
param_envs: Vec::new(),
dummy_sized_ty: tcx.types.isize,
dummy_unsized_ty: ty::mk_vec(tcx, tcx.types.isize, None),
dummy_unsized_ty: tcx.mk_slice(tcx.types.isize),
};
visit::walk_crate(&mut visitor, tcx.map.krate());
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ fn project_type<'cx,'tcx>(
Ok(ProjectedTy::Progress(ty, obligations))
}
None => {
Ok(ProjectedTy::NoProgress(ty::mk_projection(selcx.tcx(),
obligation.predicate.trait_ref.clone(),
obligation.predicate.item_name)))
Ok(ProjectedTy::NoProgress(selcx.tcx().mk_projection(
obligation.predicate.trait_ref.clone(),
obligation.predicate.item_name)))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
projection_bounds: data_a.bounds.projection_bounds.clone(),
};

let new_trait = ty::mk_trait(tcx, data_a.principal.clone(), bounds);
let new_trait = tcx.mk_trait(data_a.principal.clone(), bounds);
let origin = infer::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, new_trait, target).is_err() {
return Err(Unimplemented);
Expand Down Expand Up @@ -2573,7 +2573,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let param_b = *substs_b.types.get(TypeSpace, i);
new_substs.types.get_mut_slice(TypeSpace)[i] = param_b;
}
let new_struct = ty::mk_struct(tcx, def_id, tcx.mk_substs(new_substs));
let new_struct = tcx.mk_struct(def_id, tcx.mk_substs(new_substs));
let origin = infer::Misc(obligation.cause.span);
if self.infcx.sub_types(false, origin, new_struct, target).is_err() {
return Err(Unimplemented);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,14 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
{
let arguments_tuple = match tuple_arguments {
TupleArgumentsFlag::No => sig.0.inputs[0],
TupleArgumentsFlag::Yes => ty::mk_tup(tcx, sig.0.inputs.to_vec()),
TupleArgumentsFlag::Yes => tcx.mk_tup(sig.0.inputs.to_vec()),
};
let trait_substs = Substs::new_trait(vec![arguments_tuple], vec![], self_ty);
let trait_ref = ty::TraitRef {
def_id: fn_trait_def_id,
substs: tcx.mk_substs(trait_substs),
};
ty::Binder((trait_ref, sig.0.output.unwrap_or(ty::mk_nil(tcx))))
ty::Binder((trait_ref, sig.0.output.unwrap_or(tcx.mk_nil())))
}

impl<'tcx,O:fmt::Debug> fmt::Debug for super::Obligation<'tcx, O> {
Expand Down
Loading

0 comments on commit 6db5126

Please sign in to comment.