Skip to content

Incorrect unreachable_pub warning #92903

Closed

Description

@jyn514

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)

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    A-visibilityArea: Visibility / privacy
    C-bugCategory: This is a bug.
    on Jan 14, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 14, 2022
  3. jyn514 commented on Jan 14, 2022

    @jyn514
    MemberAuthor

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

  4. tmiasko commented on Jan 14, 2022

    @tmiasko
    Contributor

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

  5. jyn514 commented on Jan 18, 2022

    @jyn514
    MemberAuthor

    Yes it was, thank you!

  6. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions