Skip to content

Commit 99cda0b

Browse files
author
whataloadofwhat
committed
Stop ICE when using foreign statics in statics
Only change is to stop an ICE when a foreign static are referenced in consts and statics. See: #16538, #16479, #14227, #13325
1 parent cd1fa91 commit 99cda0b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/librustc/middle/check_static_recursion.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,20 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
9696
match e.node {
9797
ast::ExprPath(..) => {
9898
match self.def_map.borrow().find(&e.id) {
99-
Some(&DefStatic(def_id, _)) |
100-
Some(&DefConst(def_id)) if
99+
Some(&DefStatic(def_id, _)) | Some(&DefConst(def_id)) if
101100
ast_util::is_local(def_id) => {
102-
self.visit_item(&*self.ast_map.expect_item(def_id.node));
101+
match self.ast_map.find(def_id.node) {
102+
Some(ast_map::NodeItem(item)) => {
103+
self.visit_item(item);
104+
}
105+
Some(ast_map::NodeForeignItem(item)) => {
106+
//External statics don't have values so it
107+
//won't be recursive.
108+
self.visit_foreign_item(item);
109+
}
110+
_ => fail!("expected item or foreign item, got {}",
111+
self.ast_map.node_to_string(def_id.node))
112+
}
103113
}
104114
_ => ()
105115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
extern {
12+
static x: i32;
13+
}
14+
15+
static X: &'static i32 = &x;
16+
17+
fn main() { }

0 commit comments

Comments
 (0)