From 4853456be0efa376064148f480618985b076c196 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 26 Aug 2016 19:58:31 -0700 Subject: [PATCH] Fix lifetime rules for 'if' conditions --- src/librustc/middle/region.rs | 3 ++- src/test/run-pass/issue-12033.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/issue-12033.rs diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index faf2f7dae08c5..ef905b51edfb2 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -803,7 +803,8 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &hir::Expr) { terminating(r.id); } - hir::ExprIf(_, ref then, Some(ref otherwise)) => { + hir::ExprIf(ref expr, ref then, Some(ref otherwise)) => { + terminating(expr.id); terminating(then.id); terminating(otherwise.id); } diff --git a/src/test/run-pass/issue-12033.rs b/src/test/run-pass/issue-12033.rs new file mode 100644 index 0000000000000..5e1d82ce52cc6 --- /dev/null +++ b/src/test/run-pass/issue-12033.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::cell::RefCell; + +fn main() { + let x = RefCell::new(0); + if *x.borrow() == 0 {} else {} +}