Skip to content

Commit dcdcd30

Browse files
committed
auto merge of #10067 : sanxiyn/rust/addr-of-bot, r=thestinger
Fix #5500.
2 parents 953e560 + f04886b commit dcdcd30

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/librustc/middle/borrowck/gather_loans/mod.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
230230

231231
// make sure that the thing we are pointing out stays valid
232232
// for the lifetime `scope_r` of the resulting ptr:
233-
let scope_r = ty_region(tcx, ex.span, ty::expr_ty(tcx, ex));
234-
this.guarantee_valid(ex.id,
235-
ex.span,
236-
base_cmt,
237-
LoanMutability::from_ast_mutability(mutbl),
238-
scope_r);
233+
let expr_ty = ty::expr_ty(tcx, ex);
234+
if !ty::type_is_bot(expr_ty) {
235+
let scope_r = ty_region(tcx, ex.span, expr_ty);
236+
this.guarantee_valid(ex.id,
237+
ex.span,
238+
base_cmt,
239+
LoanMutability::from_ast_mutability(mutbl),
240+
scope_r);
241+
}
239242
visit::walk_expr(this, ex, ());
240243
}
241244

src/test/run-fail/addr-of-bot.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 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+
// error-pattern:explicit failure
12+
13+
fn main() {
14+
&fail!()
15+
}

0 commit comments

Comments
 (0)