-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #57586 - Aaron1011:feature/pub-priv-dep, r=petrochenkov
Implement public/private dependency feature Implements #44663 The core implementation is done - however, there are a few issues that still need to be resolved: - [x] The `EXTERNAL_PRIVATE_DEPENDENCY` lint currently does notthing when the `public_private_dependencies` is not enabled. Should mentioning the lint (in an `allow` or `deny` attribute) be an error if the feature is not enabled? (Resolved- the feature was removed) - [x] Crates with the name `core` and `std` are always marked public, without the need to explcitily specify them on the command line. Is this what we want to do? Do we want to allow`no_std`/`no_core` crates to explicitly control this in some way? (Resolved - private crates are now explicitly specified) - [x] Should I add additional UI tests? (Resolved - added more tests) - [x] Does it make sense to be able to allow/deny the `EXTERNAL_PRIVATE_DEPENDENCY` on an individual item? (Resolved - this is implemented)
- Loading branch information
Showing
12 changed files
with
183 additions
and
2 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
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
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
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 PubType; |
20 changes: 20 additions & 0 deletions
20
src/test/ui/feature-gates/feature-gate-public_private_dependencies.rs
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,20 @@ | ||
// This test is different from other feature gate tests. | ||
// Instead of checking that an error occurs without the feature gate, | ||
// it checks that *no* errors/warnings occurs without the feature gate. | ||
// This is due to the fact that 'public_private_dependencies' just enables | ||
// a lint, so disabling it shouldn't cause any code to stop compiling. | ||
|
||
// run-pass | ||
// aux-build:pub_dep.rs | ||
|
||
// Without ![feature(public_private_dependencies)], | ||
// this should do nothing/ | ||
#![deny(exported_private_dependencies)] | ||
|
||
extern crate pub_dep; | ||
|
||
pub struct Foo { | ||
pub field: pub_dep::PubType | ||
} | ||
|
||
fn main() {} |
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,2 @@ | ||
pub struct OtherType; | ||
pub trait OtherTrait {} |
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 PubType; |
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,46 @@ | ||
// aux-build:priv_dep.rs | ||
// aux-build:pub_dep.rs | ||
// compile-flags: --extern-private priv_dep | ||
#![deny(exported_private_dependencies)] | ||
|
||
// This crate is a private dependency | ||
extern crate priv_dep; | ||
// This crate is a public dependenct | ||
extern crate pub_dep; | ||
|
||
use priv_dep::{OtherType, OtherTrait}; | ||
use pub_dep::PubType; | ||
|
||
// Type from private dependency used in private | ||
// type - this is fine | ||
struct PrivateType { | ||
field: OtherType | ||
} | ||
|
||
pub struct PublicType { | ||
pub field: OtherType, | ||
//~^ ERROR type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface | ||
priv_field: OtherType, // Private field - this is fine | ||
pub other_field: PubType // Type from public dependency - this is fine | ||
} | ||
|
||
impl PublicType { | ||
pub fn pub_fn(param: OtherType) {} | ||
//~^ ERROR type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface | ||
|
||
fn priv_fn(param: OtherType) {} | ||
} | ||
|
||
pub trait MyPubTrait { | ||
type Foo: OtherTrait; | ||
} | ||
//~^^^ ERROR trait `priv_dep::OtherTrait` from private dependency 'priv_dep' in public interface | ||
|
||
pub struct AllowedPrivType { | ||
#[allow(exported_private_dependencies)] | ||
pub allowed: OtherType | ||
} | ||
|
||
|
||
|
||
fn main() {} |
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,28 @@ | ||
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:21:5 | ||
| | ||
LL | pub field: OtherType, | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/pub-priv1.rs:4:9 | ||
| | ||
LL | #![deny(exported_private_dependencies)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: type `priv_dep::OtherType` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:28:5 | ||
| | ||
LL | pub fn pub_fn(param: OtherType) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: trait `priv_dep::OtherTrait` from private dependency 'priv_dep' in public interface | ||
--> $DIR/pub-priv1.rs:34:1 | ||
| | ||
LL | / pub trait MyPubTrait { | ||
LL | | type Foo: OtherTrait; | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to 3 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,12 @@ | ||
// The 'std' crates should always be implicitly public, | ||
// without having to pass any compiler arguments | ||
|
||
// run-pass | ||
|
||
#![deny(exported_private_dependencies)] | ||
|
||
pub struct PublicType { | ||
pub field: Option<u8> | ||
} | ||
|
||
fn main() {} |