-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests for public-private dependencies.
- Loading branch information
Showing
16 changed files
with
360 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//@ aux-crate:shared=shared.rs | ||
|
||
extern crate shared; | ||
|
||
pub use shared::Shared; | ||
|
||
pub struct SharedInType { | ||
pub f: Shared | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//@ aux-crate:shared=shared.rs | ||
|
||
extern crate shared; | ||
|
||
pub use shared::Shared; | ||
|
||
pub struct SharedInType { | ||
pub f: Shared | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//@ aux-crate:priv:indirect2=indirect2.rs | ||
//@ compile-flags: -Zunstable-options | ||
|
||
extern crate indirect2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//@ aux-crate:shared=shared.rs | ||
|
||
// This is public. | ||
extern crate shared; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//@ force-host | ||
//@ no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn fn_like(input: TokenStream) -> TokenStream { | ||
"".parse().unwrap() | ||
} | ||
|
||
#[proc_macro_derive(PmDerive)] | ||
pub fn pm_derive(item: TokenStream) -> TokenStream { | ||
"".parse().unwrap() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn pm_attr(attr: TokenStream, item: TokenStream) -> TokenStream { | ||
"".parse().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
pub struct OtherType; | ||
pub trait OtherTrait {} | ||
|
||
#[macro_export] | ||
macro_rules! m { | ||
() => {}; | ||
} | ||
|
||
pub enum E { | ||
V1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//@ aux-crate:shared=shared.rs | ||
|
||
extern crate shared; | ||
|
||
pub use shared::Shared; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub struct Shared; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//@ aux-crate:priv:diamond_priv_dep=diamond_priv_dep.rs | ||
//@ aux-crate:diamond_pub_dep=diamond_pub_dep.rs | ||
//@ compile-flags: -Zunstable-options | ||
|
||
// A diamond dependency: | ||
// | ||
// diamond_reepxort | ||
// /\ | ||
// (public) / \ (PRIVATE) | ||
// / \ | ||
// diamond_pub_dep diamond_priv_dep | ||
// \ / | ||
// (public) \ / (public) | ||
// \/ | ||
// shared | ||
// | ||
// Where the pub and private crates reexport something from the shared crate. | ||
// | ||
// Checks the behavior when the same shared item appears in the public API, | ||
// depending on whether it comes from the public side or the private side. | ||
// | ||
// NOTE: compiletest does not support deduplicating shared dependencies. | ||
// However, it should work well enough for this test, the only downside is | ||
// that diamond_shared gets built twice. | ||
|
||
#![crate_type = "lib"] | ||
#![deny(exported_private_dependencies)] | ||
|
||
extern crate diamond_priv_dep; | ||
extern crate diamond_pub_dep; | ||
|
||
// FIXME: This should trigger. | ||
pub fn leaks_priv() -> diamond_priv_dep::Shared { | ||
diamond_priv_dep::Shared | ||
} | ||
|
||
pub fn leaks_pub() -> diamond_pub_dep::Shared { | ||
diamond_pub_dep::Shared | ||
} | ||
|
||
pub struct PrivInStruct { | ||
pub f: diamond_priv_dep::SharedInType | ||
//~^ ERROR type `diamond_priv_dep::SharedInType` from private dependency 'diamond_priv_dep' in public interface | ||
} | ||
|
||
pub struct PubInStruct { | ||
pub f: diamond_pub_dep::SharedInType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: type `diamond_priv_dep::SharedInType` from private dependency 'diamond_priv_dep' in public interface | ||
--> $DIR/diamond_deps.rs:42:5 | ||
| | ||
LL | pub f: diamond_priv_dep::SharedInType | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/diamond_deps.rs:27:9 | ||
| | ||
LL | #![deny(exported_private_dependencies)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,74 @@ | ||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:21:5 | ||
--> $DIR/pub-priv1.rs:29:5 | ||
| | ||
LL | pub field: OtherType, | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/pub-priv1.rs:4:9 | ||
--> $DIR/pub-priv1.rs:9:9 | ||
| | ||
LL | #![deny(exported_private_dependencies)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:28:5 | ||
--> $DIR/pub-priv1.rs:36:5 | ||
| | ||
LL | pub fn pub_fn(param: OtherType) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | pub fn pub_fn_param(param: OtherType) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:39:5 | ||
| | ||
LL | pub fn pub_fn_return() -> OtherType { OtherType } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:35:5 | ||
--> $DIR/pub-priv1.rs:46:5 | ||
| | ||
LL | type Foo: OtherTrait; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:50:1 | ||
| | ||
LL | pub trait WithSuperTrait: OtherTrait {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:59:5 | ||
| | ||
LL | type X = OtherType; | ||
| ^^^^^^ | ||
|
||
error: trait `OtherTrait` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:63:1 | ||
| | ||
LL | pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:66:1 | ||
| | ||
LL | pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:69:1 | ||
| | ||
LL | pub static STATIC: OtherType = OtherType; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:72:1 | ||
| | ||
LL | pub const CONST: OtherType = OtherType; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:75:1 | ||
| | ||
LL | pub type Alias = OtherType; | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 11 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//@ aux-crate:priv:reexport=reexport.rs | ||
//@ compile-flags: -Zunstable-options | ||
//@ check-pass | ||
|
||
// Checks the behavior of a reexported item from a private dependency. | ||
|
||
#![crate_type = "lib"] | ||
#![deny(exported_private_dependencies)] | ||
|
||
extern crate reexport; | ||
|
||
// FIXME: This should trigger. | ||
pub fn leaks_priv() -> reexport::Shared { | ||
reexport::Shared | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//@ aux-crate:priv:shared=shared.rs | ||
//@ aux-crate:reexport=reexport.rs | ||
//@ compile-flags: -Zunstable-options | ||
//@ check-pass | ||
|
||
// A shared dependency, where a private dependency reexports a public dependency. | ||
// | ||
// shared_both_private | ||
// /\ | ||
// (PRIVATE) / | (PRIVATE) | ||
// / | | ||
// reexport | | ||
// \ | | ||
// (public) \ / | ||
// \/ | ||
// shared | ||
|
||
#![crate_type = "lib"] | ||
#![deny(exported_private_dependencies)] | ||
|
||
extern crate shared; | ||
extern crate reexport; | ||
|
||
// FIXME: This should trigger. | ||
pub fn leaks_priv() -> shared::Shared { | ||
shared::Shared | ||
} | ||
|
||
// FIXME: This should trigger. | ||
pub fn leaks_priv_reexport() -> reexport::Shared { | ||
reexport::Shared | ||
} |
Oops, something went wrong.