Skip to content

Commit 5ee8267

Browse files
authored
Rollup merge of #122665 - ehuss:pub-priv-tests, r=davidtwco
Add some tests for public-private dependencies. This adds some tests to show more scenarios for the `exported_private_dependencies` lint. Several of these illustrate that the lint is not working as expected, and I have annotated those places with `FIXME`. Note also that this includes some diamond dependency structures which compiletest doesn't exactly support. However, I don't think it should be a problem, it just results in the common dependency being built twice.
2 parents 9cdfe28 + 07b7cd6 commit 5ee8267

16 files changed

+360
-9
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ aux-crate:shared=shared.rs
2+
3+
extern crate shared;
4+
5+
pub use shared::Shared;
6+
7+
pub struct SharedInType {
8+
pub f: Shared
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ aux-crate:shared=shared.rs
2+
3+
extern crate shared;
4+
5+
pub use shared::Shared;
6+
7+
pub struct SharedInType {
8+
pub f: Shared
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ aux-crate:priv:indirect2=indirect2.rs
2+
//@ compile-flags: -Zunstable-options
3+
4+
extern crate indirect2;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ aux-crate:shared=shared.rs
2+
3+
// This is public.
4+
extern crate shared;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ force-host
2+
//@ no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::TokenStream;
8+
9+
#[proc_macro]
10+
pub fn fn_like(input: TokenStream) -> TokenStream {
11+
"".parse().unwrap()
12+
}
13+
14+
#[proc_macro_derive(PmDerive)]
15+
pub fn pm_derive(item: TokenStream) -> TokenStream {
16+
"".parse().unwrap()
17+
}
18+
19+
#[proc_macro_attribute]
20+
pub fn pm_attr(attr: TokenStream, item: TokenStream) -> TokenStream {
21+
"".parse().unwrap()
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
pub struct OtherType;
22
pub trait OtherTrait {}
3+
4+
#[macro_export]
5+
macro_rules! m {
6+
() => {};
7+
}
8+
9+
pub enum E {
10+
V1
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ aux-crate:shared=shared.rs
2+
3+
extern crate shared;
4+
5+
pub use shared::Shared;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub struct Shared;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@ aux-crate:priv:diamond_priv_dep=diamond_priv_dep.rs
2+
//@ aux-crate:diamond_pub_dep=diamond_pub_dep.rs
3+
//@ compile-flags: -Zunstable-options
4+
5+
// A diamond dependency:
6+
//
7+
// diamond_reepxort
8+
// /\
9+
// (public) / \ (PRIVATE)
10+
// / \
11+
// diamond_pub_dep diamond_priv_dep
12+
// \ /
13+
// (public) \ / (public)
14+
// \/
15+
// shared
16+
//
17+
// Where the pub and private crates reexport something from the shared crate.
18+
//
19+
// Checks the behavior when the same shared item appears in the public API,
20+
// depending on whether it comes from the public side or the private side.
21+
//
22+
// NOTE: compiletest does not support deduplicating shared dependencies.
23+
// However, it should work well enough for this test, the only downside is
24+
// that diamond_shared gets built twice.
25+
26+
#![crate_type = "lib"]
27+
#![deny(exported_private_dependencies)]
28+
29+
extern crate diamond_priv_dep;
30+
extern crate diamond_pub_dep;
31+
32+
// FIXME: This should trigger.
33+
pub fn leaks_priv() -> diamond_priv_dep::Shared {
34+
diamond_priv_dep::Shared
35+
}
36+
37+
pub fn leaks_pub() -> diamond_pub_dep::Shared {
38+
diamond_pub_dep::Shared
39+
}
40+
41+
pub struct PrivInStruct {
42+
pub f: diamond_priv_dep::SharedInType
43+
//~^ ERROR type `diamond_priv_dep::SharedInType` from private dependency 'diamond_priv_dep' in public interface
44+
}
45+
46+
pub struct PubInStruct {
47+
pub f: diamond_pub_dep::SharedInType
48+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: type `diamond_priv_dep::SharedInType` from private dependency 'diamond_priv_dep' in public interface
2+
--> $DIR/diamond_deps.rs:42:5
3+
|
4+
LL | pub f: diamond_priv_dep::SharedInType
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/diamond_deps.rs:27:9
9+
|
10+
LL | #![deny(exported_private_dependencies)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)