Skip to content

Commit 4853456

Browse files
committed
Fix lifetime rules for 'if' conditions
1 parent 1987131 commit 4853456

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/librustc/middle/region.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,8 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &hir::Expr) {
803803
terminating(r.id);
804804
}
805805

806-
hir::ExprIf(_, ref then, Some(ref otherwise)) => {
806+
hir::ExprIf(ref expr, ref then, Some(ref otherwise)) => {
807+
terminating(expr.id);
807808
terminating(then.id);
808809
terminating(otherwise.id);
809810
}

Diff for: src/test/run-pass/issue-12033.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::cell::RefCell;
12+
13+
fn main() {
14+
let x = RefCell::new(0);
15+
if *x.borrow() == 0 {} else {}
16+
}

0 commit comments

Comments
 (0)