Skip to content

Commit 59935f7

Browse files
committed
rustc: move some functions in middle::ty working on Ty to methods.
1 parent aa03871 commit 59935f7

37 files changed

+395
-439
lines changed

src/librustc/middle/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl<'tcx> CastTy<'tcx> {
6666
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
6767
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
6868
ty::TyFloat(_) => Some(CastTy::Float),
69-
ty::TyEnum(..) if ty::type_is_c_like_enum(
70-
tcx, t) => Some(CastTy::Int(IntTy::CEnum)),
69+
ty::TyEnum(..) if t.is_c_like_enum(tcx) =>
70+
Some(CastTy::Int(IntTy::CEnum)),
7171
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
7272
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
7373
ty::TyBareFn(..) => Some(CastTy::FnPtr),

src/librustc/middle/cfg/construct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
411411
func_or_rcvr: &ast::Expr,
412412
args: I) -> CFGIndex {
413413
let method_call = ty::MethodCall::expr(call_expr.id);
414-
let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().get(&method_call) {
414+
let fn_ty = match self.tcx.method_map.borrow().get(&method_call) {
415415
Some(method) => method.ty,
416416
None => ty::expr_ty_adjusted(self.tcx, func_or_rcvr)
417-
});
417+
};
418418

419419
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
420420
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
421-
if return_ty.diverges() {
421+
if fn_ty.fn_ret().diverges() {
422422
self.add_unreachable_node()
423423
} else {
424424
ret

src/librustc/middle/check_match.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,9 @@ fn is_useful(cx: &MatchCheckCtxt,
656656
let left_ty = ty::pat_ty(cx.tcx, &*real_pat);
657657

658658
match real_pat.node {
659-
ast::PatIdent(ast::BindByRef(..), _, _) => ty::deref(left_ty, false).unwrap().ty,
659+
ast::PatIdent(ast::BindByRef(..), _, _) => {
660+
left_ty.builtin_deref(false).unwrap().ty
661+
}
660662
_ => left_ty,
661663
}
662664
};

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
821821

822822
// the method call infrastructure should have
823823
// replaced all late-bound regions with variables:
824-
let self_ty = ty::ty_fn_sig(method_ty).input(0);
824+
let self_ty = method_ty.fn_sig().input(0);
825825
let self_ty = ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap();
826826

827827
let (m, r) = match self_ty.sty {

src/librustc/middle/liveness.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11371137
}
11381138

11391139
ast::ExprCall(ref f, ref args) => {
1140-
let diverges = !self.ir.tcx.is_method_call(expr.id) && {
1141-
ty::ty_fn_ret(ty::expr_ty_adjusted(self.ir.tcx, &**f)).diverges()
1142-
};
1140+
let diverges = !self.ir.tcx.is_method_call(expr.id) &&
1141+
ty::expr_ty_adjusted(self.ir.tcx, &**f).fn_ret().diverges();
11431142
let succ = if diverges {
11441143
self.s.exit_ln
11451144
} else {
@@ -1152,8 +1151,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11521151
ast::ExprMethodCall(_, _, ref args) => {
11531152
let method_call = ty::MethodCall::expr(expr.id);
11541153
let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty;
1155-
let diverges = ty::ty_fn_ret(method_ty).diverges();
1156-
let succ = if diverges {
1154+
let succ = if method_ty.fn_ret().diverges() {
11571155
self.s.exit_ln
11581156
} else {
11591157
succ
@@ -1500,8 +1498,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15001498
match fn_ty.sty {
15011499
ty::TyClosure(closure_def_id, substs) =>
15021500
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
1503-
_ =>
1504-
ty::ty_fn_ret(fn_ty),
1501+
_ => fn_ty.fn_ret()
15051502
}
15061503
}
15071504

@@ -1523,7 +1520,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15231520
ty::FnConverging(t_ret)
15241521
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
15251522

1526-
if ty::type_is_nil(t_ret) {
1523+
if t_ret.is_nil() {
15271524
// for nil return types, it is ok to not return a value expl.
15281525
} else {
15291526
let ends_with_stmt = match body.expr {

src/librustc/middle/mem_categorization.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
426426
// a bind-by-ref means that the base_ty will be the type of the ident itself,
427427
// but what we want here is the type of the underlying value being borrowed.
428428
// So peel off one-level, turning the &T into T.
429-
match ty::deref(base_ty, false) {
429+
match base_ty.builtin_deref(false) {
430430
Some(t) => t.ty,
431431
None => { return Err(()); }
432432
}
@@ -928,13 +928,13 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
928928
Some(method_ty) => {
929929
let ref_ty =
930930
ty::no_late_bound_regions(
931-
self.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
931+
self.tcx(), &method_ty.fn_ret()).unwrap().unwrap();
932932
self.cat_rvalue_node(node.id(), node.span(), ref_ty)
933933
}
934934
None => base_cmt
935935
};
936936
let base_cmt_ty = base_cmt.ty;
937-
match ty::deref(base_cmt_ty, true) {
937+
match base_cmt_ty.builtin_deref(true) {
938938
Some(mt) => {
939939
let ret = self.cat_deref_common(node, base_cmt, deref_cnt,
940940
mt.ty,
@@ -1023,11 +1023,11 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10231023
base_cmt = self.cat_rvalue_node(elt.id(), elt.span(), ref_ty);
10241024

10251025
// FIXME(#20649) -- why are we using the `self_ty` as the element type...?
1026-
let self_ty = ty::ty_fn_sig(method_ty).input(0);
1026+
let self_ty = method_ty.fn_sig().input(0);
10271027
ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap()
10281028
}
10291029
None => {
1030-
match ty::array_element_ty(self.tcx(), base_cmt.ty) {
1030+
match base_cmt.ty.builtin_index() {
10311031
Some(ty) => ty,
10321032
None => {
10331033
return Err(());
@@ -1081,7 +1081,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10811081
span:elt.span(),
10821082
cat:cat_deref(base_cmt.clone(), 0, ptr),
10831083
mutbl:m,
1084-
ty: match ty::deref(base_cmt.ty, false) {
1084+
ty: match base_cmt.ty.builtin_deref(false) {
10851085
Some(mt) => mt.ty,
10861086
None => self.tcx().sess.bug("Found non-derefable type")
10871087
},
@@ -1375,7 +1375,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
13751375
// types are generated by method resolution and always have
13761376
// all late-bound regions fully instantiated, so we just want
13771377
// to skip past the binder.
1378-
ty::no_late_bound_regions(self.tcx(), &ty::ty_fn_ret(method_ty))
1378+
ty::no_late_bound_regions(self.tcx(), &method_ty.fn_ret())
13791379
.unwrap()
13801380
.unwrap() // overloaded ops do not diverge, either
13811381
}

src/librustc/middle/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn contains_illegal_self_type_reference<'tcx>(tcx: &ty::ctxt<'tcx>,
306306

307307
let mut supertraits: Option<Vec<ty::PolyTraitRef<'tcx>>> = None;
308308
let mut error = false;
309-
ty::maybe_walk_ty(ty, |ty| {
309+
ty.maybe_walk(|ty| {
310310
match ty.sty {
311311
ty::TyParam(ref param_ty) => {
312312
if param_ty.space == SelfSpace {

src/librustc/middle/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ fn confirm_fn_pointer_candidate<'cx,'tcx>(
773773
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
774774
{
775775
let fn_type = selcx.infcx().shallow_resolve(fn_type);
776-
let sig = ty::ty_fn_sig(fn_type);
776+
let sig = fn_type.fn_sig();
777777
confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
778778
}
779779

src/librustc/middle/traits/select.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
540540
// terms of `Fn` etc, but we could probably make this more
541541
// precise still.
542542
let input_types = stack.fresh_trait_ref.0.input_types();
543-
let unbound_input_types = input_types.iter().any(|&t| ty::type_is_fresh(t));
543+
let unbound_input_types = input_types.iter().any(|ty| ty.is_fresh());
544544
if
545545
unbound_input_types &&
546546
(self.intercrate ||
@@ -2334,7 +2334,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23342334

23352335
// ok to skip binder; it is reintroduced below
23362336
let self_ty = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
2337-
let sig = ty::ty_fn_sig(self_ty);
2337+
let sig = self_ty.fn_sig();
23382338
let trait_ref =
23392339
util::closure_trait_ref_and_return_type(self.tcx(),
23402340
obligation.predicate.def_id(),
@@ -2536,15 +2536,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25362536
return Err(Unimplemented);
25372537
};
25382538
let mut ty_params = vec![];
2539-
ty::walk_ty(field, |ty| {
2539+
for ty in field.walk() {
25402540
if let ty::TyParam(p) = ty.sty {
25412541
assert!(p.space == TypeSpace);
25422542
let idx = p.idx as usize;
25432543
if !ty_params.contains(&idx) {
25442544
ty_params.push(idx);
25452545
}
25462546
}
2547-
});
2547+
}
25482548
if ty_params.is_empty() {
25492549
return Err(Unimplemented);
25502550
}

0 commit comments

Comments
 (0)