-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Limit exported-private-dependencies lints to libraries #13135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,3 +246,227 @@ fn workspace_dep_made_public() { | |
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.run() | ||
} | ||
|
||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] | ||
fn allow_priv_in_tests() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another one we should cover is build scripts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like proc-macros are lib's but I'm assuming those shouldn't be checked with Example libs are an odd case. I'm more mixed about crate types, like cdylibs. @ehuss any thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK, add a test for custom build script There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good if all libs warn just like a normal rlib. Any lib type can expose types within item signatures, and it seems like it would be good hygiene to be explicit about that. For proc-macros, it is not possible to have public items (other than the proc-macros themselves), so it is not possible to "leak" anything AFAIK. But I wouldn't go out of my way to try to disable it there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll go for that. We can always re-visit. |
||
Package::new("priv_dep", "0.1.0") | ||
.file("src/lib.rs", "pub struct FromPriv;") | ||
.publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["public-dependency"] | ||
|
||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
priv_dep = {version = "0.1.0", public = false} | ||
"#, | ||
) | ||
.file( | ||
"tests/mod.rs", | ||
" | ||
extern crate priv_dep; | ||
pub fn use_priv(_: priv_dep::FromPriv) {} | ||
", | ||
) | ||
.build(); | ||
|
||
p.cargo("check --tests --message-format=short") | ||
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `[..]` index | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] priv_dep v0.1.0 ([..]) | ||
[CHECKING] priv_dep v0.1.0 | ||
[CHECKING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run() | ||
} | ||
|
||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] | ||
fn allow_priv_in_benchs() { | ||
Package::new("priv_dep", "0.1.0") | ||
.file("src/lib.rs", "pub struct FromPriv;") | ||
.publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["public-dependency"] | ||
|
||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
priv_dep = {version = "0.1.0", public = false} | ||
"#, | ||
) | ||
.file( | ||
"benches/mod.rs", | ||
" | ||
extern crate priv_dep; | ||
pub fn use_priv(_: priv_dep::FromPriv) {} | ||
", | ||
) | ||
.build(); | ||
|
||
p.cargo("check --benches --message-format=short") | ||
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `[..]` index | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] priv_dep v0.1.0 ([..]) | ||
[CHECKING] priv_dep v0.1.0 | ||
[CHECKING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run() | ||
} | ||
|
||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] | ||
fn allow_priv_in_bins() { | ||
Package::new("priv_dep", "0.1.0") | ||
.file("src/lib.rs", "pub struct FromPriv;") | ||
.publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["public-dependency"] | ||
|
||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
priv_dep = {version = "0.1.0", public = false} | ||
"#, | ||
) | ||
.file( | ||
"src/main.rs", | ||
" | ||
extern crate priv_dep; | ||
pub fn use_priv(_: priv_dep::FromPriv) {} | ||
fn main() {} | ||
", | ||
) | ||
.build(); | ||
|
||
p.cargo("check --bins --message-format=short") | ||
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `[..]` index | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] priv_dep v0.1.0 ([..]) | ||
[CHECKING] priv_dep v0.1.0 | ||
[CHECKING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run() | ||
} | ||
|
||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] | ||
fn allow_priv_in_examples() { | ||
Package::new("priv_dep", "0.1.0") | ||
.file("src/lib.rs", "pub struct FromPriv;") | ||
.publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["public-dependency"] | ||
|
||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
priv_dep = {version = "0.1.0", public = false} | ||
"#, | ||
) | ||
.file( | ||
"examples/lib.rs", | ||
" | ||
extern crate priv_dep; | ||
pub fn use_priv(_: priv_dep::FromPriv) {} | ||
fn main() {} | ||
", | ||
) | ||
.build(); | ||
|
||
p.cargo("check --examples --message-format=short") | ||
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `[..]` index | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] priv_dep v0.1.0 ([..]) | ||
[CHECKING] priv_dep v0.1.0 | ||
[CHECKING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run() | ||
} | ||
|
||
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")] | ||
fn allow_priv_in_custom_build() { | ||
Package::new("priv_dep", "0.1.0") | ||
.file("src/lib.rs", "pub struct FromPriv;") | ||
.publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["public-dependency"] | ||
|
||
[package] | ||
name = "foo" | ||
version = "0.0.1" | ||
|
||
[build-dependencies] | ||
priv_dep = "0.1.0" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}") | ||
.file( | ||
"build.rs", | ||
" | ||
extern crate priv_dep; | ||
pub fn use_priv(_: priv_dep::FromPriv) {} | ||
fn main() {} | ||
", | ||
) | ||
.build(); | ||
|
||
p.cargo("check --all-targets --message-format=short") | ||
.masquerade_as_nightly_cargo(&["public-dependency"]) | ||
.with_stderr( | ||
"\ | ||
[UPDATING] `[..]` index | ||
[DOWNLOADING] crates ... | ||
[DOWNLOADED] priv_dep v0.1.0 ([..]) | ||
[COMPILING] priv_dep v0.1.0 | ||
[COMPILING] foo v0.0.1 ([CWD]) | ||
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] | ||
", | ||
) | ||
.run() | ||
} |
Uh oh!
There was an error while loading. Please reload this page.