Skip to content

Commit 22510f3

Browse files
committed
rustc: replace TyFnDef in MethodCallee with just the FnSig.
1 parent b4988f0 commit 22510f3

File tree

17 files changed

+88
-135
lines changed

17 files changed

+88
-135
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Ad
112112
}
113113

114114
impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
115-
impl_stable_hash_for!(struct ty::MethodCallee<'tcx> { def_id, ty, substs });
115+
impl_stable_hash_for!(struct ty::MethodCallee<'tcx> { def_id, substs, sig });
116116
impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
117117
impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
118118

src/librustc/middle/effect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
173173
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
174174
match expr.node {
175175
hir::ExprMethodCall(..) => {
176-
let base_type = self.tables.method_map[&expr.id].ty;
176+
let method_sig = self.tables.method_map[&expr.id].sig;
177177
debug!("effect: method call case, base type is {:?}",
178-
base_type);
179-
if type_is_unsafe_function(base_type) {
178+
method_sig);
179+
if method_sig.unsafety == hir::Unsafety::Unsafe {
180180
self.require_unsafe(expr.span,
181181
"invocation of unsafe method")
182182
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
751751

752752
for &overloaded in autoderefs {
753753
if let Some(method) = overloaded {
754-
// the method call infrastructure should have
755-
// replaced all late-bound regions with variables:
756-
let self_ty = method.ty.fn_sig().input(0);
754+
let self_ty = method.sig.inputs()[0];
757755
let self_ty = self.mc.infcx.resolve_type_vars_if_possible(&self_ty);
758-
let self_ty = self.tcx().no_late_bound_regions(&self_ty).unwrap();
759756

760757
let (m, r) = match self_ty.sty {
761758
ty::TyRef(r, ref m) => (m.mutbl, r),

src/librustc/middle/liveness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10731073
hir::ExprCall(ref f, ref args) => {
10741074
// FIXME(canndrew): This is_never should really be an is_uninhabited
10751075
let diverges = !self.tables.is_method_call(expr.id) &&
1076-
self.tables.expr_ty_adjusted(&f).fn_ret().0.is_never();
1076+
self.tables.expr_ty_adjusted(&f).fn_sig().output().0.is_never();
10771077
let succ = if diverges {
10781078
self.s.exit_ln
10791079
} else {
@@ -1084,9 +1084,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10841084
}
10851085

10861086
hir::ExprMethodCall(.., ref args) => {
1087-
let method_ty = self.tables.method_map[&expr.id].ty;
1087+
let ret_ty = self.tables.method_map[&expr.id].sig.output();
10881088
// FIXME(canndrew): This is_never should really be an is_uninhabited
1089-
let succ = if method_ty.fn_ret().0.is_never() {
1089+
let succ = if ret_ty.is_never() {
10901090
self.s.exit_ln
10911091
} else {
10921092
succ

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,9 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12501250
-> Ty<'tcx>
12511251
{
12521252
// When we process an overloaded `*` or `[]` etc, we often
1253-
// need to extract the return type of the method. These method
1254-
// types are generated by method resolution and always have
1255-
// all late-bound regions fully instantiated, so we just want
1256-
// to skip past the binder.
1257-
let ret_ty = method.ty.fn_ret();
1258-
let ret_ty = self.infcx.resolve_type_vars_if_possible(&ret_ty);
1259-
self.tcx().no_late_bound_regions(&ret_ty).unwrap()
1253+
// need to extract the return type of the method.
1254+
let ret_ty = method.sig.output();
1255+
self.infcx.resolve_type_vars_if_possible(&ret_ty)
12601256
}
12611257
}
12621258

src/librustc/ty/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,12 @@ impl Variance {
394394
pub struct MethodCallee<'tcx> {
395395
/// Impl method ID, for inherent methods, or trait method ID, otherwise.
396396
pub def_id: DefId,
397-
pub ty: Ty<'tcx>,
398-
pub substs: &'tcx Substs<'tcx>
397+
pub substs: &'tcx Substs<'tcx>,
398+
399+
/// Instantiated method signature, i.e. it has been substituted,
400+
/// normalized, and has had late-bound lifetimes replaced
401+
/// (with inference variables, during type-checking).
402+
pub sig: FnSig<'tcx>,
399403
}
400404

401405
// Contains information needed to resolve types and (in the future) look up

src/librustc/ty/sty.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,15 +1313,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
13131313
}
13141314
}
13151315

1316-
/// Type accessors for substructures of types
1317-
pub fn fn_args(&self) -> ty::Binder<&'tcx [Ty<'tcx>]> {
1318-
self.fn_sig().inputs()
1319-
}
1320-
1321-
pub fn fn_ret(&self) -> Binder<Ty<'tcx>> {
1322-
self.fn_sig().output()
1323-
}
1324-
13251316
pub fn is_fn(&self) -> bool {
13261317
match self.sty {
13271318
TyFnDef(..) | TyFnPtr(_) => true,

src/librustc_mir/build/expr/into.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
201201
exit_block.unit()
202202
}
203203
ExprKind::Call { ty, fun, args } => {
204-
let diverges = match ty.sty {
205-
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
206-
// FIXME(canndrew): This is_never should probably be an is_uninhabited
207-
f.output().skip_binder().is_never()
208-
}
209-
_ => false
210-
};
204+
// FIXME(canndrew): This is_never should probably be an is_uninhabited
205+
let diverges = expr.ty.is_never();
211206
let intrinsic = match ty.sty {
212207
ty::TyFnDef(def_id, _, ref f) if
213208
f.abi() == Abi::RustIntrinsic ||

src/librustc_mir/hair/cx/expr.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc::hir::def::{Def, CtorKind};
1818
use rustc::middle::const_val::ConstVal;
1919
use rustc::ty::{self, AdtKind, VariantDef, Ty};
2020
use rustc::ty::cast::CastKind as TyCastKind;
21+
use rustc::ty::subst::Subst;
2122
use rustc::hir;
2223
use syntax::ptr::P;
2324

@@ -92,9 +93,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
9293
let kind = if let Some(method) = overloaded {
9394
debug!("make_mirror: overloaded autoderef (method={:?})", method);
9495

95-
// Method calls always have all late-bound regions
96-
// fully instantiated.
97-
ref_ty = cx.tcx.no_late_bound_regions(&method.ty.fn_ret()).unwrap();
96+
ref_ty = method.sig.output();
9897
let (region, mutbl) = match ref_ty.sty {
9998
ty::TyRef(region, mt) => (region, mt.mutbl),
10099
_ => span_bug!(expr.span, "autoderef returned bad type"),
@@ -265,14 +264,9 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
265264

266265
// rewrite f(u, v) into FnOnce::call_once(f, (u, v))
267266

267+
let sig = method.sig;
268268
let method = method_callee(cx, expr, method);
269269

270-
let sig = method.ty.fn_sig();
271-
272-
let sig = cx.tcx
273-
.no_late_bound_regions(&sig)
274-
.unwrap_or_else(|| span_bug!(expr.span, "method call has late-bound regions"));
275-
276270
assert_eq!(sig.inputs().len(), 2);
277271

278272
let tupled_args = Expr {
@@ -711,7 +705,7 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
711705
Expr {
712706
temp_lifetime: temp_lifetime,
713707
temp_lifetime_was_shrunk: was_shrunk,
714-
ty: callee.ty,
708+
ty: cx.tcx.type_of(callee.def_id).subst(cx.tcx, callee.substs),
715709
span: expr.span,
716710
kind: ExprKind::Literal {
717711
literal: Literal::Value {
@@ -1012,9 +1006,7 @@ fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
10121006
// line up (this is because `*x` and `x[y]` represent lvalues):
10131007

10141008
// to find the type &T of the content returned by the method;
1015-
let ref_ty = method.ty.fn_ret();
1016-
let ref_ty = cx.tcx.no_late_bound_regions(&ref_ty).unwrap();
1017-
// callees always have all late-bound regions fully instantiated,
1009+
let ref_ty = method.sig.output();
10181010

10191011
// construct the complete expression `foo()` for the overloaded call,
10201012
// which will yield the &T type

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
619619
// Type check the path.
620620
let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id);
621621
// Replace constructor type with constructed type for tuple struct patterns.
622-
let pat_ty = tcx.no_late_bound_regions(&pat_ty.fn_ret()).expect("expected fn type");
622+
let pat_ty = pat_ty.fn_sig().output();
623+
let pat_ty = tcx.no_late_bound_regions(&pat_ty).expect("expected fn type");
623624
self.demand_eqtype(pat.span, expected, pat_ty);
624625

625626
// Type check subpatterns.

0 commit comments

Comments
 (0)