Skip to content

private-dependency warnings that should not be generated #122756

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
h1467792822 opened this issue Mar 20, 2024 · 0 comments · Fixed by #122757
Closed

private-dependency warnings that should not be generated #122756

h1467792822 opened this issue Mar 20, 2024 · 0 comments · Fixed by #122757
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@h1467792822
Copy link
Contributor

h1467792822 commented Mar 20, 2024

I tried this code:

/// foo.rs
pub struct Foo(pub i32);

Build command: rustc --crate-type rlib foo.rs

/// bar.rs
extern crate foo;
pub struct Bar(pub i32);

Build command: rustc --crate-type rlib bar.rs --extern priv:foo=libfoo.rlib -Zunstable-options

/// baz.rs
extern crate bar;
extern crate foo;
pub fn baz() -> (Option<foo::Foo>, Option<bar::Bar>) {(None, None)}

Build command: `rustc --crate-type rlib baz.rs -L all=. '.

I expected to see this happen: no warning message

Instead, this happened:

warning: type'Foo' from private dependency'foo' in public interface
--> baz.rs:3:1
|
3 | pub fn baz() -> (Option<foo::Foo>, Option<bar::Bar>) {(None, None)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(exported_private_dependencies)]` on by default

warning: 1 warning emitted

But if you take rustc --crate-type rlib baz.rs -L all=. --extern foo then there will be no warning message, or adjust the statement in baz.rs as follows, and there will be no warning message

extern crate foo;
extern crate bar;
pub fn baz() -> (Option<foo::Foo>, Option<bar::Bar>) {(None, None)}

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (4a0cc881d 2024-03-11)
binary: rustc
commit-hash: 4a0cc881dcc4d800f10672747f61a94377ff6662
commit-date: 2024-03-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
Backtrace

@h1467792822 h1467792822 added the C-bug Category: This is a bug. label Mar 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 20, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 24, 2024
Fixed the `private-dependency` bug

Fixed the private-dependency bug: If the directly dependent crate is loaded last and is not configured with `--extern`, it may be incorrectly set to `private-dependency`

Fixes rust-lang#122756
@bors bors closed this as completed in 04eedb2 Mar 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 24, 2024
Rollup merge of rust-lang#122757 - h1467792822:priv-dep, r=davidtwco

Fixed the `private-dependency` bug

Fixed the private-dependency bug: If the directly dependent crate is loaded last and is not configured with `--extern`, it may be incorrectly set to `private-dependency`

Fixes rust-lang#122756
@saethlin saethlin added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 25, 2024
RenjiSann pushed a commit to RenjiSann/rust that referenced this issue Mar 25, 2024
Fixed the `private-dependency` bug

Fixed the private-dependency bug: If the directly dependent crate is loaded last and is not configured with `--extern`, it may be incorrectly set to `private-dependency`

Fixes rust-lang#122756
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants