From 5f52669296bceac4907608a6ac3bfba41de7dab9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 26 Mar 2013 09:41:27 -0400 Subject: [PATCH 1/2] Fix #4855: handle bot in regionck --- src/librustc/middle/typeck/check/regionck.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 3a02c19dbaf83..d6a7e6103b14f 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -615,7 +615,7 @@ pub mod guarantor { // expressions, both of which always yield a region variable, so // mk_subr should never fail. let rptr_ty = rcx.resolve_node_type(id); - if !ty::type_is_error(rptr_ty) { + if !ty::type_is_error(rptr_ty) && !ty::type_is_bot(rptr_ty) { let tcx = rcx.fcx.ccx.tcx; debug!("rptr_ty=%s", ty_to_str(tcx, rptr_ty)); let r = ty::ty_region(tcx, span, rptr_ty); From 0dc6c414af158370b73bfd379bec84a1a8d480f6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 26 Mar 2013 13:20:44 -0400 Subject: [PATCH 2/2] Check for null in return_to_mut. Fixes #4904. --- src/libcore/unstable/lang.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs index 5d7920ce820eb..554083fcdb53b 100644 --- a/src/libcore/unstable/lang.rs +++ b/src/libcore/unstable/lang.rs @@ -99,8 +99,12 @@ pub unsafe fn borrow_as_imm(a: *u8) { #[lang="return_to_mut"] #[inline(always)] pub unsafe fn return_to_mut(a: *u8) { - let a: *mut BoxRepr = transmute(a); - (*a).header.ref_count &= !FROZEN_BIT; + // Sometimes the box is null, if it is conditionally frozen. + // See e.g. #4904. + if !a.is_null() { + let a: *mut BoxRepr = transmute(a); + (*a).header.ref_count &= !FROZEN_BIT; + } } #[lang="check_not_borrowed"]