Skip to content

Commit c40fc79

Browse files
committed
auto merge of #18279 : bgamari/rust/check-static-recursion, r=alexcrichton
I just found this patch which at some point solved a problem I encountered. Unfortunately I apparently dropped it before I managed to write a test case. I'll try to dig up the code that triggered the issue.
2 parents 2d27bfa + b9251cd commit c40fc79

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/librustc/middle/check_static_recursion.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> {
9999
Some(&DefStatic(def_id, _)) |
100100
Some(&DefConst(def_id)) if
101101
ast_util::is_local(def_id) => {
102-
self.visit_item(&*self.ast_map.expect_item(def_id.node));
102+
match self.ast_map.get(def_id.node) {
103+
ast_map::NodeItem(item) =>
104+
self.visit_item(item),
105+
ast_map::NodeForeignItem(_) => {},
106+
_ => {
107+
self.sess.span_err(e.span,
108+
format!("expected item, found {}",
109+
self.ast_map.node_to_string(def_id.node)).as_slice());
110+
return;
111+
},
112+
}
103113
}
104114
_ => ()
105115
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 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+
// Helper definition for test/run-pass/check-static-recursion-foreign.rs.
12+
13+
#[crate_id = "check_static_recursion_foreign_helper"]
14+
#[crate_type = "lib"]
15+
16+
extern crate libc;
17+
18+
#[no_mangle]
19+
pub static test_static: libc::c_int = 0;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012 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+
// Static recursion check shouldn't fail when given a foreign item (#18279)
12+
13+
// aux-build:check_static_recursion_foreign_helper.rs
14+
extern crate check_static_recursion_foreign_helper;
15+
extern crate libc;
16+
17+
use libc::c_int;
18+
19+
#[link_name = "check_static_recursion_foreign_helper"]
20+
extern "C" {
21+
#[allow(dead_code)]
22+
static test_static: c_int;
23+
}
24+
25+
static B: &'static c_int = &test_static;
26+
27+
pub fn main() {}

0 commit comments

Comments
 (0)