Skip to content

Commit 1c76d55

Browse files
committed
rustc: Encode the visibility of foreign items
The privacy pass of the compiler was previously not taking into account the privacy of foreign items, or bindings to external functions. This commit fixes this oversight by encoding the visibility of foreign items into the metadata for each crate. Any code relying on this will start to fail to compile and the bindings must be marked with `pub` to indicate that they can be used externally. Closes #16725 [breaking-change]
1 parent 17f79af commit 1c76d55

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/librustc/metadata/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
13711371

13721372
rbml_w.start_tag(tag_items_data_item);
13731373
encode_def_id(rbml_w, local_def(nitem.id));
1374+
encode_visibility(rbml_w, nitem.vis);
13741375
match nitem.node {
13751376
ForeignItemFn(..) => {
13761377
encode_family(rbml_w, style_fn_family(NormalFn));

src/test/auxiliary/foreign_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub mod rustrt {
1515

1616
#[link(name = "rust_test_helpers")]
1717
extern {
18-
fn rust_get_test_int() -> libc::intptr_t;
18+
pub fn rust_get_test_int() -> libc::intptr_t;
1919
}
2020
}

src/test/auxiliary/issue-16725.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
fn bar();
13+
}
14+

src/test/compile-fail/issue-16725.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// aux-build:issue-16725.rs
12+
13+
extern crate foo = "issue-16725";
14+
15+
fn main() {
16+
unsafe { foo::bar(); }
17+
//~^ ERROR: function `bar` is private
18+
}
19+

0 commit comments

Comments
 (0)