Miscellaneous reformatting and commenting.

This commit is contained in:
Niko Matsakis 2015-01-04 05:23:29 -05:00
parent 9b820d0d63
commit a17a7c9f75
3 changed files with 18 additions and 16 deletions

View file

@ -30,7 +30,9 @@ use syntax::print::pprust;
use syntax::ptr::P;
pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
pat: &ast::Pat, expected: Ty<'tcx>) {
pat: &ast::Pat,
expected: Ty<'tcx>)
{
let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx;
@ -90,7 +92,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
}
} else {
span_err!(tcx.sess, begin.span, E0029,
"only char and numeric types are allowed in range");
"only char and numeric types are allowed in range");
}
fcx.write_ty(pat.id, lhs_ty);
@ -154,8 +156,9 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
check_pat_struct(pcx, pat, path, fields.as_slice(), etc, expected);
}
ast::PatTup(ref elements) => {
let element_tys: Vec<_> = range(0, elements.len()).map(|_| fcx.infcx()
.next_ty_var()).collect();
let element_tys: Vec<_> =
range(0, elements.len()).map(|_| fcx.infcx().next_ty_var())
.collect();
let pat_ty = ty::mk_tup(tcx, element_tys.clone());
fcx.write_ty(pat.id, pat_ty);
demand::eqtype(fcx, pat.span, expected, pat_ty);
@ -183,8 +186,8 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let inner_ty = fcx.infcx().next_ty_var();
let mutbl =
ty::deref(fcx.infcx().shallow_resolve(expected), true)
.map_or(ast::MutImmutable, |mt| mt.mutbl);
ty::deref(fcx.infcx().shallow_resolve(expected), true).map(|mt| mt.mutbl)
.unwrap_or(ast::MutImmutable);
let mt = ty::mt { ty: inner_ty, mutbl: mutbl };
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
@ -217,8 +220,8 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let region = fcx.infcx().next_region_var(infer::PatternRegion(pat.span));
ty::mk_slice(tcx, tcx.mk_region(region), ty::mt {
ty: inner_ty,
mutbl: ty::deref(expected_ty, true)
.map_or(ast::MutImmutable, |mt| mt.mutbl)
mutbl: ty::deref(expected_ty, true).map(|mt| mt.mutbl)
.unwrap_or(ast::MutImmutable)
})
}
};

View file

@ -18,14 +18,15 @@ use syntax::ast;
use syntax::codemap::Span;
use util::ppaux::Repr;
// Requires that the two types unify, and prints an error message if they
// don't.
// Requires that the two types unify, and prints an error message if
// they don't.
pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
expected: Ty<'tcx>, actual: Ty<'tcx>) {
suptype_with_fn(fcx, sp, false, expected, actual,
ty_expected: Ty<'tcx>, ty_actual: Ty<'tcx>) {
suptype_with_fn(fcx, sp, false, ty_expected, ty_actual,
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
}
/// As `suptype`, but call `handle_err` if unification for subtyping fails.
pub fn suptype_with_fn<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
sp: Span,
b_is_expected: bool,
@ -48,9 +49,7 @@ pub fn eqtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
expected: Ty<'tcx>, actual: Ty<'tcx>) {
match infer::mk_eqty(fcx.infcx(), false, infer::Misc(sp), actual, expected) {
Ok(()) => { /* ok */ }
Err(ref err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
}
Err(ref err) => { fcx.report_mismatched_types(sp, expected, actual, err); }
}
}

View file

@ -4683,7 +4683,7 @@ impl<'tcx> Repr<'tcx> for Expectation<'tcx> {
pub fn check_decl_initializer(fcx: &FnCtxt,
nid: ast::NodeId,
init: &ast::Expr)
{
{
let local_ty = fcx.local_ty(init.span, nid);
check_expr_coercable_to_type(fcx, init, local_ty)
}