From f5281e2bb56fa9ef4debf04e6141d2ad3650ca61 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 27 Jan 2015 13:45:42 -0500 Subject: [PATCH] Do not make fake types for upvars if we haven't yet inferred whether they are borrowed or by value. --- src/librustc/middle/ty.rs | 42 +++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index cd9684b840b7..f1e73ddc5a1e 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -5643,32 +5643,26 @@ pub fn closure_upvars<'tcx>(typer: &mc::Typer<'tcx>, closure_expr_id: closure_id.node }; - let captured_freevar_ty = match typer.upvar_capture(upvar_id) { - Some(UpvarCapture::ByValue) => { - freevar_ty - } + typer.upvar_capture(upvar_id).map(|capture| { + let freevar_ref_ty = match capture { + UpvarCapture::ByValue => { + freevar_ty + } + UpvarCapture::ByRef(borrow) => { + mk_rptr(tcx, + tcx.mk_region(borrow.region), + ty::mt { + ty: freevar_ty, + mutbl: borrow.kind.to_mutbl_lossy(), + }) + } + }; - Some(UpvarCapture::ByRef(borrow)) => { - mk_rptr(tcx, - tcx.mk_region(borrow.region), - ty::mt { - ty: freevar_ty, - mutbl: borrow.kind.to_mutbl_lossy(), - }) + ClosureUpvar { + def: freevar.def, + span: freevar.span, + ty: freevar_ref_ty, } - - None => { - // FIXME(#16640) we should really return None here; - // but that requires better inference integration, - // for now gin up something. - freevar_ty - } - }; - - Some(ClosureUpvar { - def: freevar.def, - span: freevar.span, - ty: captured_freevar_ty, }) }) .collect()