Skip to content

Commit d7ee56e

Browse files
committed
typeck: Turn everything operating on FnCtxt into a method.
1 parent ef2f5f6 commit d7ee56e

File tree

17 files changed

+1914
-2065
lines changed

17 files changed

+1914
-2065
lines changed

src/librustc_trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'tcx> Callee<'tcx> {
154154
let method_item = tcx.impl_or_trait_item(def_id);
155155
let trait_id = method_item.container().id();
156156
let trait_ref = ty::Binder(substs.to_trait_ref(tcx, trait_id));
157-
let trait_ref = infer::normalize_associated_type(tcx, &trait_ref);
157+
let trait_ref = tcx.normalize_associated_type(&trait_ref);
158158
match common::fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref) {
159159
traits::VtableImpl(vtable_impl) => {
160160
let impl_did = vtable_impl.impl_def_id;

src/librustc_typeck/check/_match.rs

Lines changed: 194 additions & 197 deletions
Large diffs are not rendered by default.

src/librustc_typeck/check/callee.rs

Lines changed: 130 additions & 149 deletions
Large diffs are not rendered by default.

src/librustc_typeck/check/cast.rs

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
//! expression, `e as U2` is not necessarily so (in fact it will only be valid if
3939
//! `U1` coerces to `U2`).
4040
41-
use super::coercion;
42-
use super::demand;
4341
use super::FnCtxt;
44-
use super::structurally_resolved_type;
4542

4643
use lint;
4744
use hir::def_id::DefId;
@@ -75,19 +72,18 @@ enum UnsizeKind<'tcx> {
7572
OfParam(&'tcx ty::ParamTy)
7673
}
7774

75+
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7876
/// Returns the kind of unsize information of t, or None
7977
/// if t is sized or it is unknown.
80-
fn unsize_kind<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
81-
t: Ty<'tcx>)
82-
-> Option<UnsizeKind<'tcx>> {
78+
fn unsize_kind(&self, t: Ty<'tcx>) -> Option<UnsizeKind<'tcx>> {
8379
match t.sty {
8480
ty::TySlice(_) | ty::TyStr => Some(UnsizeKind::Length),
8581
ty::TyTrait(ref tty) => Some(UnsizeKind::Vtable(tty.principal_def_id())),
8682
ty::TyStruct(def, substs) => {
8783
// FIXME(arielb1): do some kind of normalization
8884
match def.struct_variant().fields.last() {
8985
None => None,
90-
Some(f) => unsize_kind(fcx, f.ty(fcx.tcx(), substs))
86+
Some(f) => self.unsize_kind(f.ty(self.tcx(), substs))
9187
}
9288
}
9389
// We should really try to normalize here.
@@ -96,6 +92,7 @@ fn unsize_kind<'a,'tcx>(fcx: &FnCtxt<'a, 'tcx>,
9692
_ => None
9793
}
9894
}
95+
}
9996

10097
#[derive(Copy, Clone)]
10198
enum CastError {
@@ -112,14 +109,14 @@ enum CastError {
112109
NonScalar,
113110
}
114111

115-
impl<'tcx> CastCheck<'tcx> {
116-
pub fn new<'a>(fcx: &FnCtxt<'a, 'tcx>,
117-
expr: &'tcx hir::Expr,
118-
expr_ty: Ty<'tcx>,
119-
cast_ty: Ty<'tcx>,
120-
cast_span: Span,
121-
span: Span)
122-
-> Result<CastCheck<'tcx>, ErrorReported> {
112+
impl<'a, 'tcx> CastCheck<'tcx> {
113+
pub fn new(fcx: &FnCtxt<'a, 'tcx>,
114+
expr: &'tcx hir::Expr,
115+
expr_ty: Ty<'tcx>,
116+
cast_ty: Ty<'tcx>,
117+
cast_span: Span,
118+
span: Span)
119+
-> Result<CastCheck<'tcx>, ErrorReported> {
123120
let check = CastCheck {
124121
expr: expr,
125122
expr_ty: expr_ty,
@@ -142,9 +139,7 @@ impl<'tcx> CastCheck<'tcx> {
142139
}
143140
}
144141

145-
fn report_cast_error<'a>(&self,
146-
fcx: &FnCtxt<'a, 'tcx>,
147-
e: CastError) {
142+
fn report_cast_error(&self, fcx: &FnCtxt<'a, 'tcx>, e: CastError) {
148143
match e {
149144
CastError::NeedViaPtr |
150145
CastError::NeedViaThinPtr |
@@ -207,8 +202,7 @@ impl<'tcx> CastCheck<'tcx> {
207202
}
208203
}
209204

210-
fn report_cast_to_unsized_type<'a>(&self,
211-
fcx: &FnCtxt<'a, 'tcx>) {
205+
fn report_cast_to_unsized_type(&self, fcx: &FnCtxt<'a, 'tcx>) {
212206
if
213207
self.cast_ty.references_error() ||
214208
self.expr_ty.references_error()
@@ -262,7 +256,7 @@ impl<'tcx> CastCheck<'tcx> {
262256
err.emit();
263257
}
264258

265-
fn trivial_cast_lint<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) {
259+
fn trivial_cast_lint(&self, fcx: &FnCtxt<'a, 'tcx>) {
266260
let t_cast = self.cast_ty;
267261
let t_expr = self.expr_ty;
268262
if t_cast.is_numeric() && t_expr.is_numeric() {
@@ -287,9 +281,9 @@ impl<'tcx> CastCheck<'tcx> {
287281

288282
}
289283

290-
pub fn check<'a>(mut self, fcx: &FnCtxt<'a, 'tcx>) {
291-
self.expr_ty = structurally_resolved_type(fcx, self.span, self.expr_ty);
292-
self.cast_ty = structurally_resolved_type(fcx, self.span, self.cast_ty);
284+
pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) {
285+
self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty);
286+
self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty);
293287

294288
debug!("check_cast({}, {:?} as {:?})", self.expr.id, self.expr_ty,
295289
self.cast_ty);
@@ -315,7 +309,7 @@ impl<'tcx> CastCheck<'tcx> {
315309
/// Check a cast, and report an error if one exists. In some cases, this
316310
/// can return Ok and create type errors in the fcx rather than returning
317311
/// directly. coercion-cast is handled in check instead of here.
318-
fn do_check<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
312+
fn do_check(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
319313
use rustc::ty::cast::IntTy::*;
320314
use rustc::ty::cast::CastTy::*;
321315

@@ -326,8 +320,8 @@ impl<'tcx> CastCheck<'tcx> {
326320
(None, Some(t_cast)) => {
327321
if let ty::TyFnDef(_, _, f) = self.expr_ty.sty {
328322
// Attempt a coercion to a fn pointer type.
329-
let res = coercion::try(fcx, self.expr,
330-
fcx.tcx().mk_ty(ty::TyFnPtr(f)));
323+
let res = fcx.try_coerce(self.expr,
324+
fcx.tcx().mk_ty(ty::TyFnPtr(f)));
331325
if !res.is_ok() {
332326
return Err(CastError::NonScalar);
333327
}
@@ -382,11 +376,11 @@ impl<'tcx> CastCheck<'tcx> {
382376
}
383377
}
384378

385-
fn check_ptr_ptr_cast<'a>(&self,
386-
fcx: &FnCtxt<'a, 'tcx>,
387-
m_expr: &'tcx ty::TypeAndMut<'tcx>,
388-
m_cast: &'tcx ty::TypeAndMut<'tcx>)
389-
-> Result<CastKind, CastError>
379+
fn check_ptr_ptr_cast(&self,
380+
fcx: &FnCtxt<'a, 'tcx>,
381+
m_expr: &'tcx ty::TypeAndMut<'tcx>,
382+
m_cast: &'tcx ty::TypeAndMut<'tcx>)
383+
-> Result<CastKind, CastError>
390384
{
391385
debug!("check_ptr_ptr_cast m_expr={:?} m_cast={:?}",
392386
m_expr, m_cast);
@@ -403,16 +397,16 @@ impl<'tcx> CastCheck<'tcx> {
403397
}
404398

405399
// vtable kinds must match
406-
match (unsize_kind(fcx, m_cast.ty), unsize_kind(fcx, m_expr.ty)) {
400+
match (fcx.unsize_kind(m_cast.ty), fcx.unsize_kind(m_expr.ty)) {
407401
(Some(a), Some(b)) if a == b => Ok(CastKind::PtrPtrCast),
408402
_ => Err(CastError::DifferingKinds)
409403
}
410404
}
411405

412-
fn check_fptr_ptr_cast<'a>(&self,
413-
fcx: &FnCtxt<'a, 'tcx>,
414-
m_cast: &'tcx ty::TypeAndMut<'tcx>)
415-
-> Result<CastKind, CastError>
406+
fn check_fptr_ptr_cast(&self,
407+
fcx: &FnCtxt<'a, 'tcx>,
408+
m_cast: &'tcx ty::TypeAndMut<'tcx>)
409+
-> Result<CastKind, CastError>
416410
{
417411
// fptr-ptr cast. must be to sized ptr
418412

@@ -423,10 +417,10 @@ impl<'tcx> CastCheck<'tcx> {
423417
}
424418
}
425419

426-
fn check_ptr_addr_cast<'a>(&self,
427-
fcx: &FnCtxt<'a, 'tcx>,
428-
m_expr: &'tcx ty::TypeAndMut<'tcx>)
429-
-> Result<CastKind, CastError>
420+
fn check_ptr_addr_cast(&self,
421+
fcx: &FnCtxt<'a, 'tcx>,
422+
m_expr: &'tcx ty::TypeAndMut<'tcx>)
423+
-> Result<CastKind, CastError>
430424
{
431425
// ptr-addr cast. must be from sized ptr
432426

@@ -437,11 +431,11 @@ impl<'tcx> CastCheck<'tcx> {
437431
}
438432
}
439433

440-
fn check_ref_cast<'a>(&self,
441-
fcx: &FnCtxt<'a, 'tcx>,
442-
m_expr: &'tcx ty::TypeAndMut<'tcx>,
443-
m_cast: &'tcx ty::TypeAndMut<'tcx>)
444-
-> Result<CastKind, CastError>
434+
fn check_ref_cast(&self,
435+
fcx: &FnCtxt<'a, 'tcx>,
436+
m_expr: &'tcx ty::TypeAndMut<'tcx>,
437+
m_cast: &'tcx ty::TypeAndMut<'tcx>)
438+
-> Result<CastKind, CastError>
445439
{
446440
// array-ptr-cast.
447441

@@ -455,18 +449,18 @@ impl<'tcx> CastCheck<'tcx> {
455449
// from a region pointer to a vector.
456450

457451
// this will report a type mismatch if needed
458-
demand::eqtype(fcx, self.span, ety, m_cast.ty);
452+
fcx.demand_eqtype(self.span, ety, m_cast.ty);
459453
return Ok(CastKind::ArrayPtrCast);
460454
}
461455
}
462456

463457
Err(CastError::IllegalCast)
464458
}
465459

466-
fn check_addr_ptr_cast<'a>(&self,
467-
fcx: &FnCtxt<'a, 'tcx>,
468-
m_cast: &'tcx ty::TypeAndMut<'tcx>)
469-
-> Result<CastKind, CastError>
460+
fn check_addr_ptr_cast(&self,
461+
fcx: &FnCtxt<'a, 'tcx>,
462+
m_cast: &'tcx ty::TypeAndMut<'tcx>)
463+
-> Result<CastKind, CastError>
470464
{
471465
// ptr-addr cast. pointer must be thin.
472466
if fcx.type_is_known_to_be_sized(m_cast.ty, self.span) {
@@ -476,8 +470,8 @@ impl<'tcx> CastCheck<'tcx> {
476470
}
477471
}
478472

479-
fn try_coercion_cast<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool {
480-
coercion::try(fcx, self.expr, self.cast_ty).is_ok()
473+
fn try_coercion_cast(&self, fcx: &FnCtxt<'a, 'tcx>) -> bool {
474+
fcx.try_coerce(self.expr, self.cast_ty).is_ok()
481475
}
482476

483477
}

0 commit comments

Comments
 (0)