Skip to content
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

Incorrect unreachable_pub warning #92903

Closed
jyn514 opened this issue Jan 14, 2022 · 3 comments
Closed

Incorrect unreachable_pub warning #92903

jyn514 opened this issue Jan 14, 2022 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-visibility Area: Visibility / privacy. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 14, 2022

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=028239a954b1baf0326d31262947a247

#![warn(unreachable_pub)]
use inner::FlowData;

mod inner {
    pub struct FlowData {
        pub data: Vec<u8>,
    }
}

pub fn f() -> tokio::sync::mpsc::Receiver<FlowData> {
    todo!()
}

async fn foo() {
    println!("{:?}", f().recv().await.unwrap().data);
}

I expected to see this happen: No unreachable_pub lint. foo only uses publicly accessible APIs, it never mentions inner.

Instead, this happened:

warning: unreachable `pub` field
 --> src/lib.rs:6:9
  |
6 |         pub data: Vec<u8>,
  |         ---^^^^^^^^^^^^^^
  |         |
  |         help: consider restricting its visibility: `pub(crate)`
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(unreachable_pub)]
  |         ^^^^^^^^^^^^^^^

cc @petrochenkov

Meta

rustc --version --verbose: 1.60.0-nightly (2022-01-13 22e491a)

@jyn514 jyn514 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-visibility Area: Visibility / privacy. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Jan 14, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 14, 2022
@jyn514
Copy link
Member Author

jyn514 commented Jan 14, 2022

In particular, it seems wrong to say that a public field is unreachable whenever the type it belongs to is publicly reachable.

@tmiasko
Copy link
Contributor

tmiasko commented Jan 14, 2022

This was fixed in #92781 (not available as nightly yet).

@jyn514
Copy link
Member Author

jyn514 commented Jan 18, 2022

Yes it was, thank you!

@jyn514 jyn514 closed this as completed Jan 18, 2022
@rustbot rustbot removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-visibility Area: Visibility / privacy. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

3 participants