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

Lint unreachable_pub got easily confused by multiple items in a single pub use ... statement #64762

Closed
imp opened this issue Sep 25, 2019 · 7 comments
Assignees
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@imp
Copy link

imp commented Sep 25, 2019

This code (playground) trips unreachable_pub lint (while being completely legit).

#![deny(unreachable_pub)]

pub use self::m1::{Item1, Item2};

mod m1 {
    pub use self::m2::{Item1, Item2};
    
    mod m2 {
        pub struct Item1;
        pub struct Item2;
    }
}

However, if we break the top-level pub use ... statement into two separate statements (playground) - unreachable_pub lint convinces itself that the code is, indeed, legit.

#![deny(unreachable_pub)]

pub use self::m1::Item1;
pub use self::m1::Item2;

mod m1 {

    pub use self::m2::{Item1, Item2};
    
    mod m2 {
        pub struct Item1;
        pub struct Item2;
    }
}
@imp imp changed the title Lint unreachable_pub got easily confused by multiple items in single pub use ... statement Lint unreachable_pub got easily confused by multiple items in a single pub use ... statement Sep 25, 2019
@csmoe csmoe added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-visibility Area: Visibility / privacy. labels Sep 25, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 25, 2019
@jhpratt
Copy link
Member

jhpratt commented Nov 13, 2019

Running into this myself. Right now I'm just #[allow]ing it with a link to this issue.

If someone could lead me in the right direction, I'll give fixing this a shot.

@HeroicKatora
Copy link
Contributor

HeroicKatora commented Dec 19, 2019

It also gets confused if the export happens via a glob, also on a single item (Playground).

#![deny(unreachable_pub)]

mod m1 {
    pub mod m2 {
        pub use super::Item1;
    }
    
    pub struct Item1;
}

pub use m1::m2::*;

ischeinkman added a commit to ischeinkman/mpris-rs that referenced this issue Feb 12, 2020
…ccuring.

Note: due to a compiler error, the root-level `metadata` re-exports had to be
split into 3; see
rust-lang/rust#64762
Mange pushed a commit to Mange/mpris-rs that referenced this issue Feb 15, 2020
Added unreachable_pub lint which should help to prevent this issue from
happening again.

Note: due to a compiler error, the root-level `metadata` re-exports had
to be split into 3; see
rust-lang/rust#64762
@jyn514
Copy link
Member

jyn514 commented Feb 28, 2020

Looks like this is because of #57922 (comment)

Seeker14491 added a commit to Seeker14491/steamworks-rs that referenced this issue Sep 11, 2020
Also, remove the `unreachable_pub` lint, which suggested the erroneous change. Rust issue: rust-lang/rust#64762
bochaco pushed a commit to maidsafe/temp_safe_network that referenced this issue Jul 6, 2021
Sadly, due to a known issue ([#64762]) with the lint, `pub` items that
are exposed through multi-item intermediate `pub use` re-exports trigger
false positives with the lint. There are two ways of working around
this:

1. Avoiding multi-item `pub use` statements. This leads to swathes of
   mostly redundant `pub use` lines, especially on modules like `types`.
2. Leaking the structure of nested modules up to a reachable `pub use`.
   This leaves the export-point vulnerable to module reorganisation.

For this module, option 2 was chosen due to the sheer number of
re-exported items, and the relatively shallow module hierarchies.

[#64726]: rust-lang/rust#64762
@lambinoo
Copy link
Contributor

@rustbot claim

@lambinoo
Copy link
Contributor

Since I claimed it 8 days ago, just a follow up.
I've been able to break the compiler a few times but I'm getting somewhere I think...
Not to a proper solution tho, just more mess, but that means more knowledge!

tl;dr: I haven't given up!

@petrochenkov
Copy link
Contributor

How to fix this: #82064.

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 10, 2022
…, r=petrochenkov

Fixes wrong unreachable_pub lints on nested and glob public reexport

Linked issues: rust-lang#64762 & rust-lang#82064
@lambinoo
Copy link
Contributor

Closed by #87487

@camelid camelid closed this as completed Jan 10, 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants