Skip to content

Commit 4e5c225

Browse files
committed
Rollup merge of rust-lang#44082 - pnkfelix:issue-43457, r=eddyb
Fix destruction extent lookup during HIR -> HAIR translation My method for finding the destruction extent, if any, from cbed41a (in rust-lang#39409), was buggy in that it sometimes failed to find an extent that was nonetheless present. This fixes that, and is cleaner code to boot. Fix rust-lang#43457
2 parents 4ecbc7f + d1a15cd commit 4e5c225

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

src/librustc_mir/hair/cx/block.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
2222
// We have to eagerly translate the "spine" of the statements
2323
// in order to get the lexical scoping correctly.
2424
let stmts = mirror_stmts(cx, self.id, &*self.stmts);
25-
let opt_def_id = cx.tcx.hir.opt_local_def_id(self.id);
26-
let opt_destruction_extent = opt_def_id.and_then(|def_id| {
27-
cx.tcx.region_maps(def_id).opt_destruction_extent(self.id)
28-
});
25+
let opt_destruction_extent = cx.region_maps.opt_destruction_extent(self.id);
2926
Block {
3027
targeted_by_break: self.targeted_by_break,
3128
extent: CodeExtent::Misc(self.id),
@@ -42,11 +39,8 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
4239
stmts: &'tcx [hir::Stmt])
4340
-> Vec<StmtRef<'tcx>> {
4441
let mut result = vec![];
45-
let opt_def_id = cx.tcx.hir.opt_local_def_id(block_id);
4642
for (index, stmt) in stmts.iter().enumerate() {
47-
let opt_dxn_ext = opt_def_id.and_then(|def_id| {
48-
cx.tcx.region_maps(def_id).opt_destruction_extent(stmt.node.id())
49-
});
43+
let opt_dxn_ext = cx.region_maps.opt_destruction_extent(stmt.node.id());
5044
match stmt.node {
5145
hir::StmtExpr(ref expr, id) |
5246
hir::StmtSemi(ref expr, id) => {

src/test/mir-opt/issue-43457.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2017 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+
// compile-flags: -Z identify_regions -Z span_free_formats
12+
// ignore-tidy-linelength
13+
14+
// Regression test for #43457: an `EndRegion` was missing from output
15+
// because compiler was using a faulty means for region map lookup.
16+
17+
use std::cell::RefCell;
18+
19+
fn rc_refcell_test(r: RefCell<i32>) {
20+
r.borrow_mut();
21+
}
22+
23+
fn main() { }
24+
25+
// END RUST SOURCE
26+
// START rustc.node5.SimplifyCfg-qualify-consts.after.mir
27+
//
28+
// fn rc_refcell_test(_1: std::cell::RefCell<i32>) -> () {
29+
// let mut _0: ();
30+
// scope 1 {
31+
// let _2: std::cell::RefCell<i32>;
32+
// }
33+
// let mut _3: std::cell::RefMut<'17dce, i32>;
34+
// let mut _4: &'17dce std::cell::RefCell<i32>;
35+
//
36+
// bb0: {
37+
// StorageLive(_2);
38+
// _2 = _1;
39+
// StorageLive(_4);
40+
// _4 = &'17dce _2;
41+
// _3 = const <std::cell::RefCell<T>>::borrow_mut(_4) -> bb1;
42+
// }
43+
//
44+
// bb1: {
45+
// drop(_3) -> bb2;
46+
// }
47+
//
48+
// bb2: {
49+
// StorageDead(_4);
50+
// EndRegion('17dce);
51+
// _0 = ();
52+
// StorageDead(_2);
53+
// return;
54+
// }
55+
// }

0 commit comments

Comments
 (0)