Skip to content

Commit 5811d2b

Browse files
committed
auto merge of #14428 : alexcrichton/rust/issue-14422, r=pcwalton
This ensures that a public typedef to a private item is ensured to be public in terms of linkage. This affects both the visibility of the library's symbols as well as other lints based on privacy (dead_code for example). Closes #14421 Closes #14422
2 parents a01bedc + 49a6581 commit 5811d2b

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

src/librustc/middle/privacy.rs

+17
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
297297
}
298298
}
299299

300+
ast::ItemTy(ref ty, _) if public_first => {
301+
match ty.node {
302+
ast::TyPath(_, _, id) => {
303+
match self.tcx.def_map.borrow().get_copy(&id) {
304+
ast::DefPrimTy(..) => {},
305+
def => {
306+
let did = def_id_of_def(def);
307+
if is_local(did) {
308+
self.exported_items.insert(did.node);
309+
}
310+
}
311+
}
312+
}
313+
_ => {}
314+
}
315+
}
316+
300317
_ => {}
301318
}
302319

src/test/auxiliary/issue-14421.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#![crate_type="lib"]
12+
#![deny(warnings)]
13+
14+
pub use src::aliases::B;
15+
pub use src::hidden_core::make;
16+
17+
mod src {
18+
pub mod aliases {
19+
use super::hidden_core::A;
20+
pub type B = A<f32>;
21+
}
22+
23+
pub mod hidden_core {
24+
use super::aliases::B;
25+
26+
pub struct A<T>;
27+
28+
pub fn make() -> B { A }
29+
30+
impl<T> A<T> {
31+
pub fn foo(&mut self) { println!("called foo"); }
32+
}
33+
}
34+
}

src/test/auxiliary/issue-14422.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#![crate_type="lib"]
12+
#![deny(warnings)]
13+
14+
pub use src::aliases::B;
15+
pub use src::hidden_core::make;
16+
17+
mod src {
18+
pub mod aliases {
19+
use super::hidden_core::A;
20+
pub type B = A;
21+
}
22+
23+
pub mod hidden_core {
24+
use super::aliases::B;
25+
26+
pub struct A;
27+
28+
pub fn make() -> B { A }
29+
30+
impl A {
31+
pub fn foo(&mut self) { println!("called foo"); }
32+
}
33+
}
34+
}

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

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-14421.rs
12+
13+
extern crate bug_lib = "issue-14421";
14+
15+
use bug_lib::B;
16+
use bug_lib::make;
17+
18+
pub fn main() {
19+
let mut an_A: B = make();
20+
an_A.foo();
21+
}
22+

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

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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-14422.rs
12+
13+
extern crate bug_lib = "issue-14422";
14+
15+
use bug_lib::B;
16+
use bug_lib::make;
17+
18+
pub fn main() {
19+
let mut an_A: B = make();
20+
an_A.foo();
21+
}

0 commit comments

Comments
 (0)