-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Lint exported_private_dependencies misses public dependency via trait impl #71043
Open
Tracked by
#44663
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
A-visibility
Area: Visibility / privacy
C-bug
Category: This is a bug.
F-public_private_dependencies
feature: public_private_dependencies
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
This is still a problem and is much wider than this one case What is linted today
What is missing
Some cases that might be worth trying:
My reproduction case:
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pub struct FromFoo;
pub trait FooTrait {}
impl FooTrait for FromFoo {}
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
cargo-features = ["public-dependency"]
[package]
name = "cargo-pub-priv"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
foo.path = "foo"
pub use foo;
pub use foo::add;
pub use foo::FromFoo;
pub fn use_foo_struct(_: foo::FromFoo) {}
pub fn returns_foo() -> foo::FromFoo {
unreachable!()
}
pub trait UseFoo: foo::FooTrait {}
pub struct Local;
impl foo::FooTrait for Local {}
impl UseFoo for foo::FromFoo {}
impl From<foo::FromFoo> for Local {
fn from(_: foo::FromFoo) -> Self {
Local
}
}
pub fn use_foo_trait<F: foo::FooTrait>(_: Local) {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
} $ RUSTFLAGS=-Wexported-private-dependencies cargo +nightly check
Checking foo v0.1.0 (/home/epage/src/personal/dump/cargo-pub-priv/foo)
Checking cargo-pub-priv v0.1.0 (/home/epage/src/personal/dump/cargo-pub-priv)
warning: type `FromFoo` from private dependency 'foo' in public interface
--> src/lib.rs:5:1
|
5 | pub fn use_foo_struct(_: foo::FromFoo) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: requested on the command line with `-W exported-private-dependencies`
warning: type `FromFoo` from private dependency 'foo' in public interface
--> src/lib.rs:7:1
|
7 | pub fn returns_foo() -> foo::FromFoo {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: trait `FooTrait` from private dependency 'foo' in public interface
--> src/lib.rs:11:1
|
11 | pub trait UseFoo: foo::FooTrait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: type `FromFoo` from private dependency 'foo' in public interface
--> src/lib.rs:20:5
|
20 | fn from(_: foo::FromFoo) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: trait `FooTrait` from private dependency 'foo' in public interface
--> src/lib.rs:25:1
|
25 | pub fn use_foo_trait<F: foo::FooTrait>(_: Local) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `cargo-pub-priv` (lib) generated 5 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.05s |
27 tasks
Some other cases to validate as suggested by @obi1kenobi
mod other_crate {
pub enum Example {
First,
Second,
}
}
pub use other_crate::Example::First; (arguably this last one should lint regardless of the private deps because it's fishy in general, but that's just my opinion) |
FYI @matthewjasper |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
A-visibility
Area: Visibility / privacy
C-bug
Category: This is a bug.
F-public_private_dependencies
feature: public_private_dependencies
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Tracking issue: #44663, RFC: rust-lang/rfcs#1977
Cargo.toml:
lib.rs:
Also, a plain
pub use
seems to be missed as well.The text was updated successfully, but these errors were encountered: