-
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
exported_private_dependencies
lint only take effect in innermost dependency
#119428
Comments
Going back to $ cargo +nightly clean && cargo +nightly check --all -vvv
Removed 44 files, 183.6KiB total
Checking grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
Running `CARGO=/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=grandpa
rent_dep CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep CARGO_PKG_AUTH
ORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=gr
andparent_dep CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_
VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/
home/epage/src/personal/dump/recursive_pub_reexport LD_LIBRARY_PATH='/home/epage/src/personal/dump/recursive_pub_reexp
ort/target/debug/deps:/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/epage/.rustup/toolchai
ns/nightly-x86_64-unknown-linux-gnu/lib' /home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --c
rate-name grandparent_dep --edition=2021 crates/grandparent_dep/src/lib.rs --error-format=json --json=diagnostic-rende
red-ansi,artifacts,future-incompat --diagnostic-width=118 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=n
o -C debuginfo=2 -C metadata=ec231377d3a2b1c4 -C extra-filename=-ec231377d3a2b1c4 --out-dir /home/epage/src/personal/d
ump/recursive_pub_reexport/target/debug/deps -C incremental=/home/epage/src/personal/dump/recursive_pub_reexport/targe
t/debug/incremental -L dependency=/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/deps`
Checking parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
Running `CARGO=/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=parent_
dep CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep CARGO_PKG_AUTHORS='' CAR
GO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=parent_dep C
ARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0
CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/epage/src/
personal/dump/recursive_pub_reexport LD_LIBRARY_PATH='/home/epage/src/personal/dump/recursive_pub_reexport/target/debu
g/deps:/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/epage/.rustup/toolchains/nightly-x86_
64-unknown-linux-gnu/lib' /home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name paren
t_dep --edition=2021 crates/parent_dep/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future
-incompat --diagnostic-width=118 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metad
ata=b0e93a3b309a3856 -C extra-filename=-b0e93a3b309a3856 --out-dir /home/epage/src/personal/dump/recursive_pub_reexpor
t/target/debug/deps -C incremental=/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/incremental -L de
pendency=/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/deps --extern grandparent_dep=/home/epage/s
rc/personal/dump/recursive_pub_reexport/target/debug/deps/libgrandparent_dep-ec231377d3a2b1c4.rmeta`
Checking pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
Running `CARGO=/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=pub_dep
CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep CARGO_PKG_AUTHORS='' CARGO_PKG
_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=pub_dep CARGO_PKG_
README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PK
G_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_RUSTC_CURRENT_DIR=/home/epage/src/personal/
dump/recursive_pub_reexport LD_LIBRARY_PATH='/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/deps:/h
ome/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/epage/.rustup/toolchains/nightly-x86_64-unknow
n-linux-gnu/lib' /home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name pub_dep --edit
ion=2021 crates/pub_dep/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --dia
gnostic-width=118 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=523c770971b
0c118 -C extra-filename=-523c770971b0c118 --out-dir /home/epage/src/personal/dump/recursive_pub_reexport/target/debug/
deps -C incremental=/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/incremental -L dependency=/home/
epage/src/personal/dump/recursive_pub_reexport/target/debug/deps --extern parent_dep=/home/epage/src/personal/dump/rec
ursive_pub_reexport/target/debug/deps/libparent_dep-b0e93a3b309a3856.rmeta`
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
Running `CARGO=/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=simple
CARGO_MANIFEST_DIR=/home/epage/src/personal/dump/recursive_pub_reexport CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION=''
CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=simple CARGO_PKG_README='' CARGO_P
KG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1
CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 CARGO_RUSTC_CURRENT_DIR=/home/epage/src/pe
rsonal/dump/recursive_pub_reexport LD_LIBRARY_PATH='/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/
deps:/home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/epage/.rustup/toolchains/nightly-x86_64
-unknown-linux-gnu/lib' /home/epage/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name simple
--edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-w
idth=118 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=2b1b07927f979b6c -C
extra-filename=-2b1b07927f979b6c --out-dir /home/epage/src/personal/dump/recursive_pub_reexport/target/debug/deps -C i
ncremental=/home/epage/src/personal/dump/recursive_pub_reexport/target/debug/incremental -L dependency=/home/epage/src
/personal/dump/recursive_pub_reexport/target/debug/deps --extern 'priv:pub_dep=/home/epage/src/personal/dump/recursive
_pub_reexport/target/debug/deps/libpub_dep-523c770971b0c118.rmeta' -Z unstable-options`
Finished dev [unoptimized + debuginfo] target(s) in 0.08s |
We only pass In the transitional case where foundational packages have not been updated, users will have to use In the transitional case where foundation packages have been updated but intermediate packages have not been, no warning will be given even when it should. So the next questions are
|
Thank you for dig into this issue. |
Another case I want to test is when a package has a private dependency in its API (so should warn) but it is declared public in a transitive dependency. |
Summary: only direct dependencies are marked as public/private; all transitive uses of it respect the highest visibility present in that subtree of the dependency graph. Example Side effects
This is because we only pass Possible solutions (without knowing the compiler side)
@ehuss I think you were involved in the conversations on the cargo/rustc handshake for this. Any thoughts on how to move this forward? |
This scenario is more common and worth writing a test case for. I plan to add this in rust-lang/cargo#13183 |
I believe that is a I don't think it is necessary to pass more visibility data to rustc. It should be able to compute the effective visibility from the information it has. It sounds like there needs to be a more principled definition of what it means to "leak" a private item, since it seems like there are some edge cases that the current approach doesn't handle correctly. |
If checking the visibility from where it is re-expoerted from has problems, another idea (without any compiler knowledge) is to compute the effective visibility between the current crate and the DefId, by walking the tree of public dependencies to see if there is a path that can reach it. |
Nominating for a compiler meeting discussion @rustbot label +I-compiler-nominated +T-compiler |
@petrochenkov do you have expertise with the visibility analysis? If so, do you agree with the assessment here or is there a better way to perform the |
@wesleywiser The current implementation just set these flags to Someone need to decide how these flags should propagate through the dependency graph in general case (with all kinds of chain and diamond cases), after that it could be properly implemented in |
Let's say A is a graph with N nodes with privacy flags PA1..PAN, and B is a graph with M nodes with privacy flags PB1..PBN. The final flags will then be the result of a repeated application of this function for adding all direct dependencies of the current crate. |
@petrochenkov To clarify, are you suggesting there should be some kind of precedence rules to deal with conflicts? For example: foo → (public) bar → (public) baz Here, I was originally thinking it would be path-sensitive, so that they would be different ( Do people have an intuition of which approach would be easier to grasp? If it is based on where items are defined (as opposed to path-based), does anyone want to suggest what rules would be used to break conflicts? (I started writing some down, but they seemed horribly complicated.) I'm trying to think about what the intentions of the user might be in such a case, and it isn't obvious to me. I also can't decide whether or not it would be better to err on the side of warning. |
FYI @matthewjasper |
I have not checked the case in the top post, but some of this has been improved with #135501. |
Thanks @tgross35 ! Stepping through the different cases (with an in-dev Original$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
└── pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep) (*)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
Checking grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
Checking parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
Checking pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:3:1
|
3 | pub fn use_priv(_: pub_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `simple` (lib) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Original variant 1$ git diff
diff --git i/crates/parent_dep/Cargo.toml w/crates/parent_dep/Cargo.toml
index 5f27dc7..a73d7cc 100644
--- i/crates/parent_dep/Cargo.toml
+++ w/crates/parent_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = true }
+grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
└── pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep) (*)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
Checking grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
Checking parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/parent_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `parent_dep` (lib) generated 1 warning
Checking pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/pub_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: parent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `pub_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:3:1
|
3 | pub fn use_priv(_: pub_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `simple` (lib) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
Original variant 2$ git diff
diff --git i/Cargo.toml w/Cargo.toml
index a9012ec..8ac91a5 100644
--- i/Cargo.toml
+++ w/Cargo.toml
@@ -9,4 +9,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-pub_dep = { version = "0.1.0", path = "./crates/pub_dep" }
+pub_dep = { version = "0.1.0", path = "./crates/pub_dep", public = true }
diff --git i/crates/parent_dep/Cargo.toml w/crates/parent_dep/Cargo.toml
index 5f27dc7..a73d7cc 100644
--- i/crates/parent_dep/Cargo.toml
+++ w/crates/parent_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = true }
+grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
└── pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep) (*)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
└── pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep) (*)
$ cargo +nightly check --all
Checking grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
Checking parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/parent_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `parent_dep` (lib) generated 1 warning
Checking pub_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/pub_dep)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/pub_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: parent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `pub_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:3:1
|
3 | pub fn use_priv(_: pub_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `simple` (lib) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
Diamond$ nargo tree --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
│ └── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
└── right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
Checking priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
Checking left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
Checking right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> src/lib.rs:2:5
|
2 | pub fn use_priv(_: left_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> src/lib.rs:5:5
|
5 | pub fn use_priv(_: right_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `simple` (lib) generated 2 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
Diamond variant 1$ git diff
diff --git i/crates/left_dep/Cargo.toml w/crates/left_dep/Cargo.toml
index 41f2079..41cd713 100644
--- i/crates/left_dep/Cargo.toml
+++ w/crates/left_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-priv_dep = { version = "0.1.0", path = "../priv_dep", public = true }
+priv_dep = { version = "0.1.0", path = "../priv_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
│ └── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
└── right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
Checking priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
Checking right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
Checking left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> crates/left_dep/src/lib.rs:3:1
|
3 | pub fn use_priv(_: priv_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `left_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> src/lib.rs:2:5
|
2 | pub fn use_priv(_: left_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> src/lib.rs:5:5
|
5 | pub fn use_priv(_: right_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `simple` (lib) generated 2 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
Diamond variant 2$ git diff
diff --git i/Cargo.toml w/Cargo.toml
index c47b24d..d9aeedb 100644
--- i/Cargo.toml
+++ w/Cargo.toml
@@ -9,5 +9,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-left_dep = { version = "0.1.0", path = "./crates/left_dep" }
-right_dep = { version = "0.1.0", path = "./crates/right_dep" }
+left_dep = { version = "0.1.0", path = "./crates/left_dep", public = true }
+right_dep = { version = "0.1.0", path = "./crates/right_dep", public = true }
diff --git i/crates/left_dep/Cargo.toml w/crates/left_dep/Cargo.toml
index 41f2079..41cd713 100644
--- i/crates/left_dep/Cargo.toml
+++ w/crates/left_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-priv_dep = { version = "0.1.0", path = "../priv_dep", public = true }
+priv_dep = { version = "0.1.0", path = "../priv_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
│ └── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
└── right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep)
priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep)
└── priv_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/priv_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── left_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/left_dep) (*)
└── right_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/right_dep) (*)
$ cargo +nightly check --all
warning: type `FromPriv` from private dependency 'priv_dep' in public interface
--> crates/left_dep/src/lib.rs:3:1
|
3 | pub fn use_priv(_: priv_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `left_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Direct and transitive$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
Checking grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
Checking parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:2:5
|
2 | pub fn use_priv(_: parent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:5:5
|
5 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `simple` (lib) generated 2 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Direct and transitive variant 1$ git diff
diff --git i/crates/parent_dep/Cargo.toml w/crates/parent_dep/Cargo.toml
index 5f27dc7..a73d7cc 100644
--- i/crates/parent_dep/Cargo.toml
+++ w/crates/parent_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = true }
+grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
$ cargo +nightly check --all
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/parent_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `parent_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:2:5
|
2 | pub fn use_priv(_: parent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> src/lib.rs:5:5
|
5 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: `simple` (lib) generated 2 warnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Direct and transitive variant 2$ git diff
diff --git i/Cargo.toml w/Cargo.toml
index ed242c1..55c073c 100644
--- i/Cargo.toml
+++ w/Cargo.toml
@@ -9,5 +9,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-grandparent_dep = { version = "0.1.0", path = "crates/grandparent_dep" }
-parent_dep = { version = "0.1.0", path = "./crates/parent_dep" }
+grandparent_dep = { version = "0.1.0", path = "crates/grandparent_dep", public = true }
+parent_dep = { version = "0.1.0", path = "./crates/parent_dep", public = true }
diff --git i/crates/parent_dep/Cargo.toml w/crates/parent_dep/Cargo.toml
index 5f27dc7..a73d7cc 100644
--- i/crates/parent_dep/Cargo.toml
+++ w/crates/parent_dep/Cargo.toml
@@ -6,4 +6,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = true }
+grandparent_dep = { version = "0.1.0", path = "../grandparent_dep", public = false }
$ nargo tree
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
└── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
$ nargo tree --depth public --workspace
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s
grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep)
simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
├── grandparent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/grandparent_dep)
└── parent_dep v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport/crates/parent_dep) (*)
$ cargo +nightly check --all
warning: type `FromPriv` from private dependency 'grandparent_dep' in public interface
--> crates/parent_dep/src/lib.rs:4:1
|
4 | pub fn use_priv(_: grandparent_dep::FromPriv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default
warning: `parent_dep` (lib) generated 1 warning
Checking simple v0.1.0 (/home/epage/src/personal/dump/recursive_pub_reexport)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
|
I'm not sure if this should be a blocker for stabilization. The type is public in your API, just the path used to access it isn't.
I worry this will make adoption of this feature more difficult. Take Applying that here, adoption of private dependencies will need to happen from the bottom up unless people workaround non-compliant dependencies by adding a direct public dependency on their transitive dependency (leveraging the "Direct and transitive variant 2" case). If the lint could make the assumption that everything public in a dependency comes from a public transitive dependency (i.e. only warn if I reference something from a item path that is not public), this might smooth out adoption. Whether a dependency intended for a transitive dependency to be public or not won't be noticeable from the noise until it has adopted |
I've been working on this for some days and managed to create a PoC that fixes the remaining part of this issue; the access path things. I made the following design choices:
However, I'm still unsure about some implementation details, so I’ve asked a question on Zulip: Question about tracking crate provenance in PartialRes. I'd really appreciate any feedback on this |
### What does this PR try to resolve? I was investigating some issues around public dependency lints and wanted to see the structure of the public dependencies and had the idea to add this with us having added `--depth workspace`. See rust-lang/rust#119428 (comment) for some example output (comparing `cargo tree` with `cargo tree --depth public`) ### How should we test and review this PR? ### Additional information
Problem
The
exported_private_dependencies
lint only take affect in the innermost dependency in a recursively dependent environment.This inspired by #44663 (comment).
Steps
In order to prove this problem, I purposely contructed a code repository, here
in the repository, the
crates
folder has three crates,grandparent_dep
as public and reexport pub struct from grandparent_depparent_dep
as public and reexport pub struct from parent_dep(the crates in
crates
can be treated as download from respority(like github, crates.io))in src/lib.rs, add
pub_dep
as dependency but private.After downloading the resposity,
1、 run
cargo build
, no lint warning message2、 change the
public = false
incrates/pub_dep/Cargo.toml
, then runcargo build
, no lint warning message3、 change the
public = false
incrates/parent_dep/Cargo.toml
, runcargo build
and a lint warning message comes up.Possible Solution(s)
The focus of this issue is to verify whether there is a problem with the current situation, so the solution will not be considered for the time being.
Notes
No response
Version
The text was updated successfully, but these errors were encountered: