Skip to content

Commit 87bac6d

Browse files
committed
rustc: Restrict the scope of a borrow on def_map
This addresses the ICE from rust-lang#13763, but it does not allow the test to compile, due to rust-lang#13768. An alternate test was checked in in the meantime. Closes rust-lang#13763
1 parent eea4909 commit 87bac6d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/librustc/middle/typeck/check/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3199,12 +3199,13 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
31993199
}
32003200
ast::ExprStruct(ref path, ref fields, base_expr) => {
32013201
// Resolve the path.
3202-
match tcx.def_map.borrow().find(&id) {
3203-
Some(&ast::DefStruct(type_def_id)) => {
3202+
let def = tcx.def_map.borrow().find(&id).map(|i| *i);
3203+
match def {
3204+
Some(ast::DefStruct(type_def_id)) => {
32043205
check_struct_constructor(fcx, id, expr.span, type_def_id,
32053206
fields.as_slice(), base_expr);
32063207
}
3207-
Some(&ast::DefVariant(enum_id, variant_id, _)) => {
3208+
Some(ast::DefVariant(enum_id, variant_id, _)) => {
32083209
check_struct_enum_variant(fcx, id, expr.span, enum_id,
32093210
variant_id, fields.as_slice());
32103211
}

src/test/run-pass/issue-13763.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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::u8;
12+
13+
static NUM: uint = u8::BITS as uint;
14+
15+
struct MyStruct { nums: [uint, ..8] }
16+
17+
18+
fn main() {
19+
let _s = MyStruct { nums: [0, ..NUM] };
20+
}

0 commit comments

Comments
 (0)