From 1c76d559c37bf313a31e260b986255cc45912014 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 24 Aug 2014 17:05:47 -0700 Subject: [PATCH] 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] --- src/librustc/metadata/encoder.rs | 1 + src/test/auxiliary/foreign_lib.rs | 2 +- src/test/auxiliary/issue-16725.rs | 14 ++++++++++++++ src/test/compile-fail/issue-16725.rs | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/auxiliary/issue-16725.rs create mode 100644 src/test/compile-fail/issue-16725.rs diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 29b5db51cc4..ffa4a1b5bf0 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1371,6 +1371,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, local_def(nitem.id)); + encode_visibility(rbml_w, nitem.vis); match nitem.node { ForeignItemFn(..) => { encode_family(rbml_w, style_fn_family(NormalFn)); diff --git a/src/test/auxiliary/foreign_lib.rs b/src/test/auxiliary/foreign_lib.rs index a6bbd40f810..500475091e0 100644 --- a/src/test/auxiliary/foreign_lib.rs +++ b/src/test/auxiliary/foreign_lib.rs @@ -15,6 +15,6 @@ pub mod rustrt { #[link(name = "rust_test_helpers")] extern { - fn rust_get_test_int() -> libc::intptr_t; + pub fn rust_get_test_int() -> libc::intptr_t; } } diff --git a/src/test/auxiliary/issue-16725.rs b/src/test/auxiliary/issue-16725.rs new file mode 100644 index 00000000000..7f388c13e15 --- /dev/null +++ b/src/test/auxiliary/issue-16725.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { + fn bar(); +} + diff --git a/src/test/compile-fail/issue-16725.rs b/src/test/compile-fail/issue-16725.rs new file mode 100644 index 00000000000..f70d88a41cd --- /dev/null +++ b/src/test/compile-fail/issue-16725.rs @@ -0,0 +1,19 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-16725.rs + +extern crate foo = "issue-16725"; + +fn main() { + unsafe { foo::bar(); } + //~^ ERROR: function `bar` is private +} + -- GitLab