]> git.lizzy.rs Git - rust.git/commitdiff
Fix lifetime rules for 'if' conditions
authorKeith Yeung <kungfukeith11@gmail.com>
Sat, 27 Aug 2016 02:58:31 +0000 (19:58 -0700)
committerKeith Yeung <kungfukeith11@gmail.com>
Sat, 27 Aug 2016 19:27:34 +0000 (12:27 -0700)
src/librustc/middle/region.rs
src/test/run-pass/issue-12033.rs [new file with mode: 0644]

index faf2f7dae08c5a9793eb8ba303e02e8f88e146ee..ef905b51edfb2982db89492d8634f795740fd493 100644 (file)
@@ -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 (file)
index 0000000..5e1d82c
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 {}
+}