]> git.lizzy.rs Git - rust.git/commitdiff
Do not make fake types for upvars if we haven't yet inferred whether they are borrowed
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 27 Jan 2015 18:45:42 +0000 (13:45 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Sun, 1 Feb 2015 11:13:05 +0000 (06:13 -0500)
or by value.

src/librustc/middle/ty.rs

index cd9684b840b77b3bd6dd455ae16cc71afd29eaff..f1e73ddc5a1e4389c4de13b84346a12edf68e976 100644 (file)
@@ -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
-                            }
-
-                            Some(UpvarCapture::ByRef(borrow)) => {
-                                mk_rptr(tcx,
-                                        tcx.mk_region(borrow.region),
-                                        ty::mt {
-                                            ty: freevar_ty,
-                                            mutbl: borrow.kind.to_mutbl_lossy(),
-                                        })
-                            }
+                        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(),
+                                            })
+                                }
+                            };
 
-                            None => {
-                                // FIXME(#16640) we should really return None here;
-                                // but that requires better inference integration,
-                                // for now gin up something.
-                                freevar_ty
+                            ClosureUpvar {
+                                def: freevar.def,
+                                span: freevar.span,
+                                ty: freevar_ref_ty,
                             }
-                        };
-
-                        Some(ClosureUpvar {
-                            def: freevar.def,
-                            span: freevar.span,
-                            ty: captured_freevar_ty,
                         })
                     })
                     .collect()